I thought there was no way to change the system time at the application level, but I searched the Internet for a long time and knew that this goal could still be achieved.
the first method is simpler, but it needs to be compiled with make in the source code environment of Android system:
1. Add the attribute
"Android: shared userid =" android.uid.system "to the manifest node in AndroidManifest.xml of the application.
2. modify the Android.mk file and add the line LOCAL_CERTIFICATE := platform
3. use the mm command to compile, and the generated apk will have the right to modify the system time.
the second method is a bit troublesome, but you don't need to run a virtual machine to the source environment to compile with make:
1. Same as above, add the attribute "Android: shared userid =" android.uid.system ".
2. compile the apk file using eclipse, but this apk file is unusable.
3. open the apk file with compression software and delete the CERT.SF and CERT.RSA files in 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 directory is "build argetproductsecurity", and the following two files are platform.pk8 and platform.x59.pem.
then use the Signapk tool provided by Android to sign. The source code of signapk is under "build oolssignapk", and the usage is "signapkplatform.x59.pemplatform.pk8 input.apkoutput.apk". It is best to use the absolute path to prevent the file name from being found, or you can modify the source code and use it directly. In this way, the final apk is the same as the first method.
finally, explain the principle. First, add the attribute of Android: shared userid = "android.uid.system". With Shared User id, multiple apks with the same User id can be configured to run in the same process. Then match the UID of the program to android.uid.system, that is, let the program run in the system process, so that you have the right to modify the system time.
it is not enough to add UID. If you install APK at this time, you will find that it cannot be installed, prompting that the signature does not match. The reason is that if the program wants to run in the system process, it must have the platform key of the target system, that is, the two files platform.pk8 and platform.x59.pem mentioned in the second method above. Only after signing with these two keys can apk really be put into the system process. Adding LOCAL_CERTIFICATE := platform to the first method actually uses these two keys to sign.
there is also a problem, that is, the program generated in this way can only be used in the original Android system or the self-compiled system, because such a system can get two files, platform.pk8 and platform.x59.pem If you can't even install it on Android made by another company. Try the key in the original Android to sign. The program runs OK on the simulator, but install the direct prompt "package ... has no signatures that match this in shared user Android. uid.system" on G3, which also protects the security of the system.