Android系统恢复出厂时由于一些有序广播的阻塞和还锁的耗时操作导致恢复出厂按键按下时需要等待一点时间才能重启并恢复出厂,从用户角度来说,体验并不好,那么如何解决这个问题呢?
1.等待的时候可以加一个旋转的进度条,这样用户体验会好一些,此方法这里就不多做赘述
2.修改RecoverySystem流程
文件:RecoverySystem.java (frameworks\base\core\java\android\os)
1)bootCommand提前执行
public static void rebootWipeUserData(Context context) throws IOException {
final ConditionVariable condition = new ConditionVariable();+ bootCommand(context, "--wipe_data\n--locale=" + Locale.getDefault().toString());
Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION");
context.sendOrderedBroadcastAsUser(intent, UserHandle.OWNER,
android.Manifest.permission.MASTER_CLEAR,
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
condition.open();
}
}, null, 0, null, null);
// Block until the ordered broadcast has completed.
condition.block();
- bootCommand(context, "--wipe_data\n--locale=" + Locale.getDefault().toString());
}
2)通过系统属性sys.powerctl设置立刻重启,当然reason要写清楚
private static void bootCommand(Context context, String arg, boolean needRebootNow) throws IOException {
。。。。。。。
FileWriter command = new FileWriter(COMMAND_FILE);
try {
// MStar Android Patch Begin
String cmd = arg.substring(0,16);
String label = null;
String uuid = null;
if (cmd.equals("--update_package")) {
cmd = arg.substring(17,23);
if (cmd.equals("/cache")) {
command.write("--uuid=mstar-cache");
command.write("\n");
command.write("--label=mstar-cache");
command.write("\n");
} else {
int pos = arg.indexOf("/", 22);
cmd = arg.substring(17,pos);
if (cmd.equals("/mnt/usb")) {
pos = arg.indexOf("/", 26);
cmd = arg.substring(17,pos);
uuid = "--uuid=" + getVolumeUUID(cmd).toString();
label = "--label=" + getVolumeLabel(cmd).toString();
command.write(uuid);
command.write("\n");
command.write(label);
command.write("\n");
} else {
if (cmd.equals("/mnt/sdcard")) {
uuid = "--uuid=" + getVolumeUUID(cmd).toString();
label = "--label=" + getVolumeLabel(cmd).toString();
command.write(uuid);
command.write("\n");
command.write(label);
command.write("\n");
}
}
}
}
command.write(arg);
command.write("\n");
} finally {
command.close();
}
+ if(arg.contains("--wipe_data"))
+ {
+ String reason = ("1" + "recovery");
+ SystemProperties.set("sys.shutdown.requested", reason);
+ android.os.SystemProperties.set("sys.powerctl", "reboot," + "recovery");
+ }
。。。。。
3.恢复出厂设下去后立刻熄屏,此方法没个平台方法不一样,我用的是切断hdmi输入的方法