In Android 2.3, after the default time is written in the. h file, the time may not be restored after the factory settings are restored. If you want to restore the instance to an initial value after it is started for the first time after download and after the factory settings are restored, follow these steps:
Currently, you can set the factory time by specifying the first boot time in the Code. The specific method is as follows:
1. Define global variables
In the NetworkTimeUpdateService. java (frameworksbaseservicesjavacomandroidserver) file, add:
Private static final String DECRYPT_STATE = trigger_restart_framework;
Private static final String BOOT_SYS_PROPERTY = persist. sys. first_time_boot;
Private static int mDefaultYear = 2013;
2. Set the first boot time
Add the following statement at the end of the public void systemReady () function to the same file:
// Add for first boot time set ++
String tempString = SystemProperties. get (BOOT_SYS_PROPERTY ,);
Boolean isFirstBoot = (tempString! = Null &. equals (tempString) true false;
If (isFirstBoot ){
TempString = SystemProperties. get (ro. kernel. qemu ,);
Boolean isEmulator = 1. equals (tempString) true false;
If (isEmulator ){
Log. d (TAG, isEmulator + tempString );
Return;
}
String decryptState = SystemProperties. get (vold. decrypt ,);
Log. d (TAG, decryptState + decryptState );
If (. equals (decryptState) DECRYPT_STATE.equals (decryptState )){
Time today = new Time (Time. getCurrentTimezone ());
Today. setToNow ();
Log. d (TAG, First boot + tempString + with date + today );
Today. set (1, 0, mDefaultYear); // you can specify a date.
Log. d (TAG, Set the year to + mDefaultYear );
SystemProperties. set (BOOT_SYS_PROPERTY, false );
SystemClock. setCurrentTimeMillis (today. toMillis (false ));
}
}
// Add for first boot time set ---