Go How to get system permissions on the Android platform and how to use the platform key to sign the APK

Source: Internet
Author: User

Many functions in Android can only be called by a system program or a program with root privileges, otherwise there will be "Permission denied" exceptions. So if you call such a function at development time, you must grant the program root permission. here are two specific implementations, from <http://lufengdie.iteye.com/blog/918975>, I use method Two, method one is not used.

Note: Both methods do not necessarily apply to all Android systems.

Method One: You need to use make to compile in the context of the Android system source code:

    1. Add the Android:shareduserid= "Android.uid.system" attribute to the manifest node in the application's Androidmanifest.xml
    2. Modify the Android.mk file, add local_certificate: = Platform this line
    3. Using the MM command to compile, the generated apk will have the ability to modify the system time.

Method Two:

    1. Ibid., add android:shareduserid= "Android.uid.system" to this property.
    2. Use eclipse to compile the apk file, but this apk file is not available.
    3. To open the APK file with compression software, delete the cert.sf and cert.rsa two files in the Meta-inf directory. (This step I skipped (originally unintentional, later found also mentioned below), as a result can be)
    4. Use the target system's platform key to re-sign the apk file. This step is more troublesome, first find the key file, the location in the Android source directory is "Build\target\product\security", the following platform.pk8 and Platform.x509.pem two files. Then use Android to provide the signapk tool to sign, signapk source code is under "build\tools\signapk", the use of "signapk Platform.x509.pem platform.pk8 input.apk output.apk ", the file name is best to use absolute path to prevent not found, you can also modify the source code to use directly.

< at this point the last available apk is the same as the first method >
explain the principle ., first add android:shareduserid= "Android.uid.system" this property. With the shared user ID, multiple apk with the same user ID can be configured to run in the same process. Then put the UID of the program into Android.uid.system, that is, to let the program run in the system process, so that there is permission to call those who need system permissions of the function. Just adding UID is not enough, if you install the APK at this time found unable to install, prompt signature does not match, because the program wants to run in the system process and the target system platform key, The second method mentioned above is the PLATFORM.PK8 and Platform.x509.pem two files. Using these two keys to sign the APK before it can actually be put into the system process. The first method adds Local_certificate: = Platform is actually signed with these two keys.
One problem is that the generated programs can only be used in the original Android system or in their own compiled system, because such a system can get platform.pk8 and Platform.x509.pem two files. If the other company does not have the Android installed on the installation. Try the original Android key to sign, the program runs OK on the emulator, but put on the G3 to install the direct prompt "package ... has no signatures that match those in shared user Android.uid. System ", which also protects the security of the systems.
Finally, this Android:shareduserid property can not only put the APK into the system process, but also can configure multiple apk running in a process, so that the data can be shared, it should be useful.
The above sections are from: http://blog.csdn.net/liujian885/archive/2010/03/22/5404834.aspx
To apply debug annotations:
1. signapk.jar:signapk executable file, in Out/host/linux-x86/framework/signapk.jar;
2. SIGNAPK usage: Execute to out/host/linux-x86/framework/directory

    1. Java-jar Signapk.jar Platform.x509.pem platform.pk8 input.apk output.apk;

It must PLATFORM.X509.PEM before platform.pk8, otherwise it will be an error.

INPUT.APK is to be signed apk,output.apk is the APK after signing. This way, if your code is useful for functions that require platform permissions, it can be unblocked.
Of course, different system platform.pk8 and PLATFORM.X509.PEM files may not be the same,

Therefore, this method does not apply to all Android systems.

3. Under Build\target\product\security\ platform, GKFX, TestKey, media four keys, verified, if not android.uid.system, should use shared key , such as android.uid.phone; 
4. According to the user verification, do not need to delete the Meta-inf directory cert.sf and Cert.rsa two files, directly signapk can.  
such as: http://hi.baidu.com/donghaozheng/blog/item/30a00d4f9fca873baec3ab69.html 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.