Android 8.0恢复出厂设置
2017-12-22 15:52
477 查看
在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有说明不允许第三方应用使用是否对此有影响还不知。
个人能力有效,以上观点仅供参考
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 高通代码预制apk可卸载,恢复出厂设置apk可恢复
- Android 8.0接收通知后会手机崩溃,闪屏,恢复出厂设置的解决方法
- Android设备管理(锁屏、恢复出厂设置、设置密码、设置屏幕灯光等操作)
- android恢复出厂设置以及系统升级流程
- android 恢复出厂设置流程
- Android恢复出厂设置流程分析【Android源码解析十】
- android 代码实现手机自动恢复出厂设置不需要权限
- android恢复出厂设置流程
- android 恢复出厂设置之后如何将时间变为初始值
- android恢复出厂设置以及系统升级流程
- Android恢复出厂设置流程分析【Android源码解析十】
- 关于定制 android 恢复出厂设置的一点思路
- android7 恢复出厂设置后一直正在检查网络连接开不了机
- android恢复出厂设置流程简述
- android恢复出厂设置以及系统升级流程
- Android 如何才能捕获系统的恢复出厂设置事件
- Android恢复出厂设置流程分析
- Android恢复出厂设置保存文件标志位到 persist 分区
- android恢复出厂设置流程分析
- android-恢复出厂设置