zoukankan      html  css  js  c++  java
  • 高速改动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

    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

    1149         * the property. http://b/11463182

    1150         */

    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.

    1160            Slog.w(TAG, "System clock is before 1970; setting to 1970.");

    1161            SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);

    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);
             }

          看了是不是感觉非常认为,改这个是简单,知道在这里能够改并不简单,加油!

     

     

     

     

  • 相关阅读:
    删库了一定要跑路吗?爱情 36 技之记忆重生!
    程序员和他的朋友们!
    聊起 BigTable,让你不再胆怯
    [Ant Design] Warning: Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?
    Git 常用命令
    Git 名词解释
    js中void 0和undefined的区别
    js运算符优先级
    搭建React项目(低配版)
    mac常用shell指令笔记
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/7069659.html
Copyright © 2011-2022 走看看