Permission denied while using runtime in android application - android

When trying to execute shell commands on Lollipop I am getting permission denied error.
Runtime.getRuntime().exec("su")
I do have super user permission in the manifest
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
The device is rooted.

Since your device is rooted, you can try installing the apk in the system directory:
system/app
Certain 'serious' permissions are granted only to apks in this directory. (On your rooted device, browse to this directory in your file browser, and you will find all pre-installed apks here).

Related

Granting Runtime Permission for a thirdparty app

I need to grant the Permission android.permission.INSTALL_PACKAGES to an Android App, which is not made by me. My Device is running on LineageOS and is rooted, but the Command
pm grant <package> android.permission.INSTALL_PACKAGES
returns
Operation not allowed: java.lang.SecurityException: Permission android.permission.INSTALL_PACKAGES is not a changeable permission type.
Is there any way to bypass this?
Ok, I found a solution: Copying the app to the /system/app folder through TWRP works fine

How to bypass permissions on a rooted device?

I am creating an android app for media box. The box is rooted. I have to bypass permissions (run time permission too) because user will not be interacting with the device. I tried to push the apk in system/priv-app folder also to make it system app. Still, whenever my app is launched, it asks for permissions. Is there any way to bypass permissions in rooted device? I have used following commands to push the APK to priv-app folder.
adb remount
adb push apk-filename-here /system/app/
adb shell chmod 644 /system/app/apk-filename-here
adb reboot
App seems to be like system app because it is not uninstallable now. But permission problem is still there. Is anything extra required to be done to grant all permissions? Please help.
I tried bypass android usb host permission confirmation dialog also but this seems to be a very old story now.
Some permissions are signature-level, meaning they can't be granted unless your app is signed with the same key used to sign the rest of the system. If you need any of these, there's very little you can do, unless the relevant APIs have shell-command alternatives.
Other permissions are privileged-level, meaning they're only granted if the app is located in /system/priv-app/. You haven't mentioned which permissions you're using, but I recommend putting your app in priv-app instead of app anyway. If this device is on Lollipop or later, apps should have a sub-folder inside priv-app (eg /system/priv-app/SomeApp/SomeApp.apk).
The third type is app-op permissions. These aren't runtime permissions, but they can be granted with a shell command:
cmd appops set <PACKAGE> <OP> <MODE>
For example, to grant the SYSTEM_ALERT_WINDOW permission:
cmd appops set com.some.package android:system_alert_window allow
The fourth type is runtime/development permissions. Both can be granted with the following:
pm grant <PACKAGE> <PERMISSION>
For example, to grant WRITE_EXTERNAL_STORAGE:
pm grant com.some.package android.permission.WRITE_EXTERNAL_STORAGE
You can check which type your permissions are by looking at the platform AndroidManifest.xml. Find your permission and check the protectionLevel field.
signature means signature
privileged means privileged
development means development
dangerous means runtime
normal permissions will be automatically granted
Certain permissions, like WRITE_SECURE_SETTINGS have multiple protection levels: signature|privileged|development.
If any of those conditions is met, Android will grant the permission to your app. With WSS, you could either put the app in priv-app or use pm grant. Either way will get you access.
If a permission's protection levels have both appops and development, such as PACKAGE_USAGE_STATS, be careful. Using cmd appops will grant that permission for certain functions, while pm grant will for others.

Android 8 Bug: Starting apk installation via adb doesn't work, needs permission REQUEST_INSTALL_PACKAGES

I need to start the installation of an apk on an android 8 phone, but this should not be silent (adb install). The behavior should be as if the user has touched the apk file on the device.
Before android 8 it was possible to launch the installation of an apk by adb like this:
adb shell am start -d file:"///sdcard/foobar.apk" -p com.google.android.packageinstaller
This is not possible anymore on android 8. According to the log file the permission android.permission.REQUEST_INSTALL_PACKAGES is necessary.
09-25 16:39:55.691 6066 6066 E InstallStart: Requesting uid 2000 needs to declare permission android.permission.REQUEST_INSTALL_PACKAGES
I know that since android 8 apps that requests installing other apps needs this permission, but this shouldn't be the case by doing it via adb, right?
Is this a bug in android 8? Is it somehow possible to do it in an other way?
Try adding in Manifest
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

How to debug/reset Android 6.0 permissions?

While migrating one of my apps to use the Android 6.0 permissions system, I found it very hard to debug permissions using the emulator.
Findings:
Disabling a permission in the app info screen doesn't re-show the grant permission dialog when using the requestPermissions() method.
Reinstalling the app seems to be the only way to make the app show the grant permission dialog again.
What is the proper method to debug permission using the Android emulator?
It’s actually very easy to debug Android 6.0 permissions. You can reset the permissions to the "install state" for the current foreground app all apps using the following ADB shell command:
adb shell pm reset-permissions
Note: Currently you can't reset the runtime permissions for a specific package, the package manger (pm) tool help section states:
revert all runtime permissions to their default state.
You can easily execute the reset-permissions command using the terminal interface in Android Studio. Note that ADB commands only works if the ADB directory is added to the PATH system environment variable (see: add ADB to path variable).
You can also reset/revoke a specific permissions using:
adb shell pm revoke com.your.package android.permission.WRITE_EXTERNAL_STORAGE
A downside of this command is that it will restart your app, but this doesn't reset the runtime permissions for all apps. To grant a permission replace revoke with grant.

Why doesn't program in /system/app get SuperUser access?

We are creating an Android application which requires super user privileges. The SuperUser.apk and su are installed. However there seems to be a difference between installing our application in /data/app vs. /system/app. If we install in /data/app, everything seems to work fine. If we install in /system/app, SuperUser.apk does not popup to grant privileges.
Are there certain types of programs that must be installed in one location vs. another?
TIA
APK files in the /system/app folder already have system-level permissions so they don't require SuperUser, which I assume is why it doesn't pop up.
You should confirm that your application already has the permission you have requested. For instance, AlarmManager.setTime requires the signatureOrSystem permission android.permission.SET_TIME and will throw an exception if it doesn't have it. You can also check explicitly with PackageManager.checkPermission.
If this doesn't work, check the attributes of the APK file. If they don't match the other APKs in the system folder Android may ignore them. You can fix it like this:
chmod 644 <filename>

Categories

Resources