In versions earlier than ics40, if the program needs to set the APN, you only need to declare <uses-Permission Android: Name = "android. permission. write_apn_settings "> </uses-Permission>. Running on 40 machines throws the following exception: Java. Lang. securityexception: no permission to write APN settings: Neither user *** nor current process has Android. Permission. write_apn_settings.
The reason is that Google has blocked third-party applications from accessing the APN based on security considerations. Some people on the Internet say that they can set the program as a system app. Using the ADB push command to put the APK under the/system/APP/directory is indeed feasible, but most apps are used as third-party applications, this is not feasible. Therefore, the system signature is used to allow the app to access the APN.
The first method is simple, but it needs to be compiled using make in the environment of the Android system source code:
1. Add the Android: shareduserid = "android. uid. System" attribute to the manifest node in androidmanifest. xml of the application.
2. Modify the Android. mk file and add local_certificate: = platform.
3. Use the MM command to compile the generated APK and you will have the permission to modify the system time.
The second method is troublesome, but you do not need to run the virtual machine to the source code environment and use make to compile it:
1. Similarly, add the Android: shareduserid = "android. uid. System" attribute.
2. Compile the APK file using eclipse, but this APK file cannot be used.
3. Open the APK file with the compression software, and delete the CERT. SF and cert. RSA files under the META-INF directory.
4. Use the platform key of the target system to re-sign the APK file. This step is troublesome. First, find the key file. The location in my android source code directory is "build \ target \ product \ Security", and the following two files are platform. pk8 and platform. x509.pem. Then, use the signapk tool provided by Android for signature. The source code of signapk is under "build \ tools \ signapk", and its usage is Java-jar signapk. jar platform. x509.pem platform. pk8 ***. APK *** _ signed.apk obtains the APK with the corresponding permissions.
Tools and keys: http://download.csdn.net/detail/bulkin/4329253
In this way, the final APK is the same as the first method.
The following explains the principle. First, add the Android: shareduserid = "android. uid. System" attribute. With the shared user ID, multiple APK with the same user ID can be configured to run in the same process. Then, assign the UID of the program to Android. uid. system, that is, to allow the program to run in the system process, so that you have the permission to modify the system time.
It is not enough to add the UID. If the APK cannot be installed at this time, the system prompts that the signature is inconsistent because the program wants to run in the system process and the platform of the target system is required. key, which is the platform mentioned in the second method above. pk8 and platform. x509.pem files. After these two keys are signed, the APK can be put into the system process. Adding local_certificate: = platform to the first method is actually using the two keys for signature.
There is also a problem, that is, the program generated in this way can only be used in the original Android system or a self-compiled system, because such a system can get the platform. pk8 and platform. x509.pem files. If other companies do not even install Android. Try the original Android key for signature. The program runs OK on the simulator, but the prompt "package... has no signatures that match those in shared user android. UID. system ", which also protects the system security.
Finally, the Android: shareduserid attribute can not only put the apk in the system process, but also configure multiple APK to run in one process to share data, it should be very useful.