How to debug Android App to grant privilege permission? - android

I am new to Android development. My current task requires to grant "Capture_audio_output" runtime permission. Android Developer site describes the permission as "Not for use by third-party applications".
I learned from some answers that I can root my phone and install system app. But I don't want to do that way.
I also tried to generate a signed debug apk file, but the app didn't show up even ADB told me it was installed successfully.

CAPTURE_AUDIO_OUTPUT is not a dangerous permission and so does not work with the runtime permission system. CAPTURE_AUDIO_OUTPUT has android:protectionLevel="signature|privileged", so it can only be held by apps that are installed on the privileged (a.k.a., system) partition or are signed by the platform signing key.
Even if you create your release signed APK, still it will not get the privilege of getting this permission. Either you have to root your device or you can't get it.

Related

why can not update my application in android

recently I get Installed blocked : The app permissions error error when updating my application(in app updating).
I know my app signatures are same because I can install new app manually.
can some know why this happen?
Do you think I need to grant android.permission.INSTALL_PACKAGES while I granted android.permission.REQUEST_INSTALL_PACKAGES? if yes can explain deference of both?
Note: my application updated correctly in many devices!! but in some devices(android Version: 5.1.1) have problem!!!
The INSTALL_PACKAGES permission allows an application to install packages. It is not for use by third-party applications.
Developers of apps that require the ability to download and install other apps via the Package Installer may need to make some changes. If an app uses a targetSdkLevel of 26 or above and prompts the user to install other apps, the manifest file needs to include the REQUEST_INSTALL_PACKAGES permission.
Read more here: https://android-developers.googleblog.com/2017/08/making-it-safer-to-get-apps-on-android-o.html?m=1

Android APK signed with PLATFORM key not given system privileges?

I have access to an Android tablets' platform key and certificate. I'm attempting to build an app and install it with system level privileges by doing the following:
Create a Java KeyStore file with platform.pk8 and platform.x509.pem using the bash script called platform_import_keystore found on GitHub.
In AndroidManifex.xml add the following:
<uses-permission android:name="android.permission.READ_LOGS"/>
android:sharedUserId="android.uid.system"
Sign APK with PLATFORM key and certificate using a Java KeyStore file in Android Studio.
Install APK
When the app runs, the system denies READ_LOGS permission.
Why isn't my app running with system level permissions?
What #Mark mentions is correct to some extent, for system apps.
I think you are doing something else wrong.
I have tried this with system apps as well, and as long it was signed with the platform keystore, it works. Now this was on Android 8 and Android 9. You haven't mentioned the AOSP version running the device.
That changes things AFAIK, so if it's AOSP 10+, it might behave differently.
Also the other comments are missing another key thing SELinux. SELinux is not permissive for user builds. Verity is enabled, and you cannot have root access. So you cannot push the app into /system/priv-app/ or push it into /vendor/app/.
You cannot access system resources without proper SE Policy files. You can check the logs yourself, to see avc denied messages.
I think overall what you are seeing should be inline with AOSP's security ideals. An app signed with System keys should not be able to get system permissions. It also needs to be located in the correct place, either as a privileged app or vendor app. Such apps need to be whitelisted. There's a built in script in AOSP source to even generate the permissions for whitelisting (it produces the required xml)
There's two classes of system apps, /system/app/ and /system/priv-app/
The privileged apps are the only ones that get signature level permissions, and according to newer versions of android, you need to enable whitelisting in the /system/etc/priv_app-permissions_device_name.
If you make any changes to the system or vendor when verity is enabled, firstly they are mounted read only, but somehow if you do make a change, the device will brick itself. This is the security feature. All custom development needs to be done in userdebug builds with SELinux in permissive mode, and then all the permissions need to be predefined, SE Policies fine tuned to utmost minimal, only then the user build can function normally. User build is not at all suitable for AOSP development activities, even if it's just for testing or trying out a single app.
User build is production type build that the end user can use and is not for development. It's the most secure form of android, so if you have platform keys, it may never be enough.
All that being said, I'm sure you don't have the right keys. Just pull an app from system/priv-app/ and use keytool or similar to check it's signature, and then try to match with your release apk.
It's little complicated as it is, and kind of hard to explain and there are levels of permissions also in android, so if you aren't following a specific approach/path, you will not be able to get it to work.

Create System Application

What I should to do to create a system app (to obtain rights to use android:sharedUserId="android.uid.system"in manifest file without receiving an error from package manager about certification problem?
I use rooted phone with stock firmware.
Ok, I think that I find sollution from great xda developers: http://forum.xda-developers.com/showthread.php?t=1776095 here is full description how to obtain access to apps signed by platform keys.
Do you apply with this approach?
PS it is interesting that users from stack instead of investigating hard problem immediately say that you can not solve it, then reduce novice user's reputation...
What I should to do to create a system app
There are two types of system apps:
Apps installed on the system partition, which can be accomplished by users with root privileges
Apps signed by the same signing key that signed the firmware
to obtain rights to use android:sharedUserId="android.uid.system"
That definitely would require your app to be signed by the same signing key that signed the firmware. That's true for any android:sharedUserId.
But some guys edit stock apps, prepare zip file which user can update system apps by recovery.
You are welcome to provide any evidence that what they do somehow involves android:sharedUserId="android.uid.system".
A system app must be signed with the platform key. This is done by developers deploying an android platform on their own device, or mobile carriers.
If that is your case, the easiest way is to add this to your Android.mk:
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
or this to your Android.bp:
certificate: "platform",
privileged: true,
If you add those lines without adding android:sharedUserId="android.uid.system" to your manifest, you will be a platform_app. A system app is more privileged than a platform app. That uses the platform key and runs as the system user.
If you are not the platform vendor, the platform vendor would need to sign your application using their platform key. Some vendors, including my company, will do this for 3rd parties demonstrating a valid reason for doing so.
Without the signature, your application can only be used on rooted devices.
I did not need to sign my app with the firmware signature! I have a rooted device. Therefore I can grant myself rights to write to certain directories using adb.
I moved my app to /system/priv-app instead of /system/app using those steps: Push my apk to /system/app
Now, I can access system permissions like android.permission.SHUTDOWN
There is two types of system apps.
Type 1: The App which is in the same signature of the Device ROM .
Type 2: The Signed app which is in system/priv-app ( Might differ based on adnroid version ) in your device storage location .
Visit this link -> http://www.archive.ricston.com/blog/explaining-behavior-android-application-system-apps-nonsystem-apps/

when I add android.permission.UPDATE_DEVICE_STATS to my app.error occur

I developed an app which needs to get the android.permission.UPDATE_DEVICE_STATS permission. However, when I add this permission to my app's AndroidMainfest.xml file, I get this error:
"Permission is only granted to system apps"
What can I do to change my app to system app? Are there any other ways to solve this problem?
Most importantly to know: A system app can only be run by people who have rooted their device. Meaning you can't test and run your own application if you don't have a rooted device.
You can declare your app to run as a system app by setting the sharedUserId as follows in the AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[your package name]"
android:sharedUserId="android.uid.system">
Otherwise you have to sign your application with system key , see this thread How to compile Android Application with system permissions
what can I do to change my app to system app.
Build your own firmware (i.e., ROM mod) and sign your app with the same signing key as you used with that firmware.
Or, since this is a signature-or-system permission, you can root your device and install the APK on the system partition.

grant system permissions to an app in the android emulator

I am building an app that will be bundled on an android device as a system app. The manufacturer is a ways out on delivering the device to us, so in the meantime I'd like to grant my app system level permissions in the emulator so I can work on an auto update feature that will do silent installs of APKs without any interactions from the user. From what I've read, its my understanding that the only way to be able to do silent installs on android is if your app is signed with the same cert as the OS. So how can I simulate this in the emulator?
If you want a signatureOrSystem permission, you just need to be placed on the system image; you don't need to be signed with any special cert. You can do this as a one-off (until you exit the emulator) like this:
> adb root
> adb remount
> adb push /path/to/My.apk /system/app/My.apk
Once you have done that, you can use the normal process to install further updates on the data partition ("adb install -r /path/to/My.apk" which is what the developer tools do when you run from Eclipse). When installing this way, the app retains any signatureOrSystem permissions it had requested from the original version on the system image, but can not gain any new such permissions.
If you need pure signature permissions, you need to sign your app with the same cert as whatever is declaring those permissions (typically the core framework, but the media system is a separate cert etc). If you are requesting signature permissions you don't need to be installed on the system image, you can just install it as a normal app and it can still get the permissions because of the signing.
As far as I can tell, you need to:
download the Android source and build an emulator firmware image.
sign your application with the keys in the Android source tree at /build/target/product/security/.
add android:sharedUserId="android.uid.system" to your application's manifest.
run your application on an emulator using the image built in step 1.
The reason for having to build your own firmware image is so that you can get at the keys. Now, it might be possible that the keys for the standard emulator image are available somewhere, which will save you the long and exceedingly tedious process of building your own Android, but I'm afraid I have no idea where these might be.
Disclaimer: never tried this myself.

Categories

Resources