How can Android capture system factory reset events?

Source: Internet
Author: User

After you click "Restore factory settings", the system restarts and enters the system again. All data is cleared. How can you determine whether to restore the factory settings? How can I mark the restore factory settings event? After the system is restarted, I want to determine the factory settings that have just been restored based on the customer's needs, and then add some responses and processing. What should I do when it is different from normal boot or restart?

I was helpless when I first encountered this problem, but I guess it should be very troublesome to capture the mark in bootloarder, so I sent a post asking.

A friend provided solution:

Modify the recovery. c file in the bootable directory so that, after removing the usrdata partition, add a flag file to the cache partition. My suggestion is that when the factory settings are restored, a log file will be stored in the cache partition recovery. After you start the system, you can immediately read this file, after Android runs, the cache/recovery/log files will be cleared. Therefore, you need to process the files as appropriate.

This method is theoretically correct. After I started my experiment on a real machine, I had to quickly copy the cache, recovery/log and run it on the Android system, complete this operation. However, the reason is that, in order to meet the customer's requirements, increase the startup speed and reduce the time required to format the cache before entering the system, our engineers made changes here. This limits the write operations on the cache from startup. Even if the factory settings are restored, no recovery directory is created, and no log files are available.

Although this solution failed, fortunately another friend provided solution B:

Generally, this error will be reported after the first boot or factory reset:

W/entropyservice (761): Unable to load initial entropy (first boot ?)
W/entropyservice (761): Java. Io. filenotfoundexception:/data/system/entropy. dat (no such file or directory)
W/entropyservice (761): At org. Apache. Harmony. luni. Platform. osfilesystem. openimpl (native method)
W/entropyservice (761): At org. Apache. Harmony. luni. Platform. osfilesystem. Open (osfilesystem. Java: 152)
W/entropyservice (761): At java. Io. fileinputstream. <init> (fileinputstream. Java: 82)
W/entropyservice (761): At java. Io. fileinputstream. <init> (fileinputstream. Java: 134)
W/entropyservice (761): At com. Android. server. randomblock. fromfile (randomblock. Java: 45)
W/entropyservice (761): At com. Android. server. entropyservice. loadinitialentropy (entropyservice. Java: 99)
W/entropyservice (761): At com. Android. server. entropyservice. <init> (entropyservice. Java: 86)
W/entropyservice (761): At com. Android. server. entropyservice. <init> (entropyservice. Java: 76)
W/entropyservice (761): At com. Android. server. serverthread. Run (systemserver. Java: 109)

 

Specifically, the code is in entropyservice:

 

Private void loadinitialentropy (){
Try {
Randomblock. fromfile (entropyfile). tofile (randomdevice );
} Catch (ioexception e ){
Slog. W (TAG, "unable to load initial entropy (first boot ?) ", E );
}
}

Add the desired processing in catch. Note: This is the first service in Android. If the processing is complicated, you need to use other android services, we recommend that you set only one flag here (for example, create a temporary file) and then process it.

 

This method is simple and easy to operate. In addition, entropyservice never reports an error (W or E) when the system is started normally or restarted normally, which truly achieves the purpose of flag restoring factory settings.

 

My post asking questions at: http://topic.csdn.net/u/20110427/14/4df32953-fec5-44c0-8847-375b5a44bee8.html

Welcome to the discussion ~

Author: yiyaaixuexi published on 21:48:00 Original article link reading: 374 comments: 10 views comments

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.