Quickly modify the Android system default date method
On the Android device, there is a default start date, see a lot of devices, some devices do not sync to the system time when not connected to the network, actually the default is the 1970 date, also saw some devices by default to January 1, 2000, so a relatively step, but not enough. The author of the following very simple introduction of a super simple method:
/*****************************************************************************************************/
Disclaimer: The content of this blog is by http://blog.csdn.net/edsam49 original, reproduced please indicate the source, thank you!
/*****************************************************************************************************/
Familiar with the systemserver is still very good, systemserver inside has good things, first or from main in, we can be sure that the original code is written like this:
public static void Main (string[] args) {
1141
1142 /*
1143 * The runtime switched since last boot (such as when
1144 * The old runtime is removed in an OTA), set the system
1145 * Property so it's 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's
1148 * Running as root and we need to is 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 }
Obviously there is a judge of course time, with a preset time point of a comparison, if it is more than the preset time point, set to this point in time, make full use of this point is very easy. Or use this method, just to move the preset time point, in fact, as long as the code to change a line is not the code can be, the author modified as follows:
- private static final Long Earliest_supported_time = 86400 * 1000;-+ //private static final long Earliest_support Ed_time = 86400 * 1000;+ //default 2014-07-01-12:00+ private static final long Earliest_supported_time = 14041872 00000l;+ /** * 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); }
See is not feel very feel, change this is simple, know here can change is not simple, refueling!