高速改動android系統預設日期方法

來源:互聯網
上載者:User

標籤:oid   libnative   where   tab   roo   利用   syn   initial   dsa   

高速改動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系統預設日期方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.