【Android】修改Android系統初始默認日期

在Android系統的設備上,都有一個默認的開始日期,有些設備在沒有聯網沒有同步到系統時間的時候,默認的日期一般是1970年。最近遇到一個系統遺留BUG,測試猿反饋手動設置日期的默認年份太久遠了,問能不能更新下到最近的年份,比如2016年1月1日,自己找到了一個簡單的修改方法,故在這記錄一下。通過SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME)設置系統默認日期,只需要修改EARLIEST_SUPPORTED_TIME變量的值就可以了。

修改路徑:frameworks/base/services/java/com/android/server/SystemServer.java


- private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
+ private static final long EARLIEST_SUPPORTED_TIME = 1451606400 * 1000; //2016年01月01日

  ...

  private void run() {
        ...
        // If a device's clock is before 1970 (before 0), a lot of
        // APIs crash dealing with negative numbers, notably
        // java.io.File#setLastModified, so instead we fake it and
        // hope that time from cell towers or NTP fixes it shortly.
        if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
            Slog.w(TAG, "System clock is before 1970; setting to 1970.");
            SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
        }
        // Here we go!
        Slog.i(TAG, "Entered the Android system server!");
        ...
  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章