首页 技术 正文
技术 2022年11月22日
0 收藏 416 点赞 4,139 浏览 2423 个字

高速改动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

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

1150         */

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.

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

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,990
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,504
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,348
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,133
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,765
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,843