Android 8.0恢复出厂设置
来源:互联网 发布:海文工程项目网络计划 编辑:程序博客网 时间:2024/05/20 06:25
在8.0之前做过恢复出厂的demo,执行代码如下:
Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, true);//清除数据
sendBroadcast(intent);
后面更新到8.0发现执行不了了,打开7.0正常执行的步骤,跟踪log提示Background execution not allowed:跟踪到源码发现在BroadcastQueue的scheduleTempWhitelistLocked方法时如下的判断影响到后面是否能成功执行恢复出厂设置
==========================================8.8==========================================================================
if (!skip) {
final int allowed = mService.getAppStartModeLocked(
info.activityInfo.applicationInfo.uid, info.activityInfo.packageName,
info.activityInfo.applicationInfo.targetSdkVersion, -1, true, false);
if (allowed != ActivityManager.APP_START_MODE_NORMAL) {
// We won't allow this receiver to be launched if the app has been
// completely disabled from launches, or it was not explicitly sent
// to it and the app is in a state that should not receive it
// (depending on how getAppStartModeLocked has determined that).
if (allowed == ActivityManager.APP_START_MODE_DISABLED) {
Slog.w(TAG, "Background execution disabled: receiving "
+ r.intent + " to "
+ component.flattenToShortString());
skip = true;
} else if (((r.intent.getFlags()&Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND) != 0)
|| (r.intent.getComponent() == null
&& r.intent.getPackage() == null
&& ((r.intent.getFlags()
& Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND) == 0)
&& !isSignaturePerm(r.requiredPermissions))) {
mService.addBackgroundCheckViolationLocked(r.intent.getAction(),
component.getPackageName());
Slog.w(TAG, "Background execution not allowed: receiving "
+ r.intent + " to "
+ component.flattenToShortString());
skip = true;
}
}
}
源码中的skip如果不设置为true就可以正常恢复出厂,我们可以在执行恢复出厂操作时,在注册的FLAG中增加intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)来绕过skip设置为true的情况,进而成功恢复出厂设置。
另外,在8.0Setting源码中,恢复出厂时原先的Intent.ACTION_MASTER_CLEAR替换为最新的Intent.ACTION_FACTORY_RESET;这一点注释中有做说明,但最新的ACTION_FACTORY_RESET有说明不允许第三方应用使用是否对此有影响还不知。
个人能力有效,以上观点仅供参考
- Android 8.0恢复出厂设置
- android-恢复出厂设置
- android-恢复出厂设置
- Android恢复出厂设置
- Android恢复出厂设置
- android恢复出厂设置
- Android恢复出厂设置
- android 恢复出厂设置流程
- android 恢复出厂设置流程
- Android 恢复出厂设置(recovery)
- android恢复出厂设置流程
- android 恢复出厂设置流程
- Android 恢复出厂设置(recovery)
- android恢复出厂设置以及系统升级流程
- android恢复出厂设置以及系统升级流程
- android恢复出厂设置以及系统升级流程
- android恢复出厂设置流程简述
- android恢复出厂设置的流程
- 配置 Ubuntu 环境
- If this view is optional add '@Nullable' (fields) or '@Optional' (methods) ...
- VS2015 + Qt5.7学习心得
- Android studio在打包时候的问题
- unity编辑器拓展九——删除场景中丢失的脚本
- Android 8.0恢复出厂设置
- Redis的RDB(快照)与AOF
- JS快速获取当前时间减一小时、一天及日期格式处理
- bootstrap-Table sub父子表的使用
- QT5安装教程图文教程 QT5环境配置图文教程
- flex布局
- 线性判别分析(LDA)
- 面向对象
- C++ int与string的转化