高速改動android系統默認日期方法
高速改動android系統默認日期方法
在android系統的設備上,都有一個默認的開始日期,看過非常多設備,有些設備在沒有聯網的時候沒有同步到系統時間的時候,竟然默認的還是1970年的日期。也見過有些設備默認到2000年1月1日的,這樣相對進了一步。可是還不夠。
筆者以下非常簡單的介紹一下一個超級簡單的方法:
/*****************************************************************************************************/
聲明:本博內容均由http://blog.csdn.net/edsam49原創,轉載請註明出處,謝謝!
/*****************************************************************************************************/
熟悉一下systemserver還是非常好的。systemserver裏面有好東西,首先還是從main進去,我們能夠肯定原始的代碼是這樣寫的:
public static void main(String[] args) {
1141
1142 /*
1143 * In case the runtime switched since last boot (such as when
1144 * the old runtime was removed in an OTA), set the system
p=android/platform/frameworks/base.git;a=blob;f=services/java/com/android/server/SystemServer.java;h=e55e2766226a5031f40ac5c4cde5535712392898;hb=e55e2766226a5031f40ac5c4cde5535712392898#l1145">1145 * property so that it is in sync. We can‘t do this in
1146 * libnativehelper‘s JniInvocation::Init code where we already
1147 * had to fallback to a different runtime because it is
1148 * running as root and we need to be the system user to set
p=android/platform/frameworks/base.git;a=blob;f=services/java/com/android/server/SystemServer.java;h=e55e2766226a5031f40ac5c4cde5535712392898;hb=e55e2766226a5031f40ac5c4cde5535712392898#l1149">1149 * the property. http://b/11463182
1150 */
p=android/platform/frameworks/base.git;a=blob;f=services/java/com/android/server/SystemServer.java;h=e55e2766226a5031f40ac5c4cde5535712392898;hb=e55e2766226a5031f40ac5c4cde5535712392898#l1151">1151 SystemProperties.set("persist.sys.dalvik.vm.lib",
1152 VMRuntime.getRuntime().vmLibrary());
1153
1154 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
1155 // If a device‘s clock is before 1970 (before 0), a lot of
1156 // APIs crash dealing with negative numbers, notably
1157 // java.io.File#setLastModified, so instead we fake it and
1158 // hope that time from cell towers or NTP fixes it
1159 // shortly.
p=android/platform/frameworks/base.git;a=blob;f=services/java/com/android/server/SystemServer.java;h=e55e2766226a5031f40ac5c4cde5535712392898;hb=e55e2766226a5031f40ac5c4cde5535712392898#l1160">1160 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
1161 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
p=android/platform/frameworks/base.git;a=blob;f=services/java/com/android/server/SystemServer.java;h=e55e2766226a5031f40ac5c4cde5535712392898;hb=e55e2766226a5031f40ac5c4cde5535712392898#l1162">1162 }
明顯裏面有一個推斷當然時間。跟預設時間點的一個比較,假設比預設時間點晚的話,就設置成這個時間點,充分利用這一點就非常easy了。還是用這樣的方法,僅僅只是把預設的時間點挪動一下。實際上僅僅要改一行不是代碼的代碼就能夠了,筆者改動例如以下:
- private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000; - + //private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000; + //default 2014-07-01-12:00 + private static final long EARLIEST_SUPPORTED_TIME = 1404187200000L; + /** * Called to initialize native system services. */ @@ -1157,7 +1159,8 @@ public class SystemServer { // java.io.File#setLastModified, so instead we fake it and // hope that time from cell towers or NTP fixes it // shortly. - Slog.w(TAG, "System clock is before 1970; setting to 1970."); + //Slog.w(TAG, "System clock is before 1970; setting to 1970."); + Slog.w(TAG, "System clock is before 20140701; setting to 20140701."); SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME); }
看了是不是感覺非常認為,改這個是簡單,知道在這裏能夠改並不簡單,加油!
高速改動android系統默認日期方法