Android 2.3版本中,在.h文件中寫入瞭默認時間後,可能恢復出廠設置後,時間沒有恢復。 如果希望在download完後第一次開機、恢復出廠設置後時間恢復到一個初始值,請按照下面步驟修改:
目前可以通過在代碼中指定第一次開機的時間的方法設置出廠時間,具體方法如下:
1. 定義全局變量
在NetworkTimeUpdateService.java (frameworksbaseservicesjavacomandroidserver)這個文件中,在全局變量定義部分加入:
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. 設置第一次開機時間
同一個文件,在函數 public void systemReady()最後面加入下面的語句:
//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 ); //設置想要設定的日期
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 —