The default factory time set for Android 2.3 is invalid.

Source: Internet
Author: User

 

 

In Android 2.3, after the default time is written in the. h file, the time may not be restored after the factory settings are restored. If you want to restore the instance to an initial value after it is started for the first time after download and after the factory settings are restored, follow these steps:

Currently, you can set the factory time by specifying the first boot time in the Code. The specific method is as follows:

 

1. Define global variables

In the NetworkTimeUpdateService. java (frameworksbaseservicesjavacomandroidserver) file, add:

Private static final String DECRYPT_STATE = trigger_restart_framework;

Private static final String BOOT_SYS_PROPERTY = persist. sys. first_time_boot;

Private static int mDefaultYear = 2013;

2. Set the first boot time

Add the following statement at the end of the public void systemReady () function to the same file:

// Add for first boot time set ++

String tempString = SystemProperties. get (BOOT_SYS_PROPERTY ,);

Boolean isFirstBoot = (tempString! = Null &. equals (tempString) true false;

If (isFirstBoot ){

TempString = SystemProperties. get (ro. kernel. qemu ,);

Boolean isEmulator = 1. equals (tempString) true false;

If (isEmulator ){

Log. d (TAG, isEmulator + tempString );

Return;

}

 

String decryptState = SystemProperties. get (vold. decrypt ,);

Log. d (TAG, decryptState + decryptState );

If (. equals (decryptState) DECRYPT_STATE.equals (decryptState )){

Time today = new Time (Time. getCurrentTimezone ());

Today. setToNow ();

Log. d (TAG, First boot + tempString + with date + today );

Today. set (1, 0, mDefaultYear); // you can specify a date.

Log. d (TAG, Set the year to + mDefaultYear );

SystemProperties. set (BOOT_SYS_PROPERTY, false );

SystemClock. setCurrentTimeMillis (today. toMillis (false ));

}

}

// Add for first boot time set ---

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.