Android中快速进入恢复出厂的方法

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输入的方法

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值