How to obtain system permissions for Android apk
In Android systems, permission levels are classified
["Normal" | "dangerous" | "signature" | "signatureOrSystem"]
Normal and dangerous can be obtained after the apk is declared in Mainifest.
Signature must have a system-level signature before it can be obtained.
SignatureOrSystem has a system-level signature or has system permissions.
Take SET_PREFERRED_APPLICATIONS as an example.
Use signapk to sign the APK
AddPreferredActivity requires permission for android. permission. SET_PREFERRED_APPLICATIONS (permission level: [signature ])
To use this permission, you need to sign the signapk. The required tool
Source code package
1) .. \ out \ host \ linux-x86 \ framework \ signapk. jar
2) .. \ build \ target \ product \ security \ platform. pk8
3) .. \ build \ target \ product \ security \ platform. x509.pk8
Put the above three files and the APK to be signed in the same directory
Cmd-> java-jar signapk. jarplatform. x509.pem platform. pk8 LauncherDemo.apk Launcher_sign.apk
This permission is used to compile an application that requires system permissions.
After installation, you can use the common install method to install the application and use zipalign to optimize the APK.
Zipalign directory android-sdk \ tools \ zipalign.exe
L optimize alignment APK
Cmd-> zipalign-v 4 old.apk new.apk
L verify alignment
Cmd-> zipalign-c-v 4 new.apk
Verification succesful indicates that the alignment is optimized successfully.
Source code compilation APK sharing system UID
This method does not require the permission SET_PREFERRED_APPLICATIONS.
1) add it to the Mainfest File
Android: sharedUserId = "android. uid. system"
2) Add the Android. mk File
LOCAL_CERTIFICATE: = platform
After compilation, use push to install the application.
Android. mk:
#Copyright 2007-2008 The Android Open Source ProjectLOCAL_PATH:=$(call my-dir)include$(CLEAR_VARS)LOCAL_SRC_FILES:= $(call all-java-files-under, src)LOCAL_PACKAGE_NAME:= LauncherDemoLOCAL_CERTIFICATE:= platforminclude$(BUILD_PACKAGE)# Use thefolloing include to make our test apk.include$(call all-makefiles-under,$(LOCAL_PATH))