移除SafeMode第一次尝试的方法是在systemui下面直接将ShutDownAction的onLongPress和onPress方法回调都执行shutdown流程。客户不同意在SystemUI目录下做此修改。尝试第二中修改方案。
vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\globalactions\GlobalActionsDialog.java
final class ShutDownAction extends SinglePressAction implements LongPressAction {
private ShutDownAction() {
super(R.drawable.ic_lock_power_off,
R.string.global_action_power_off);
}
//长按回调
@Override
public boolean onLongPress() {
Log.i("Xxxx", "111 GlobalActionsDialog.java onLongPress");
/**if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
mWindowManagerFuncs.reboot(true);
return true;
}**/
去掉走reboot(true),直接调用shutdown()方法,实现去除safemode模式需求
mWindowManagerFuncs.shutdown();
return true;
}
//点击回调
@Override
public void onPress() {
Log.i("Xxxx", "GlobalActionsDialog.java onPress");
// shutdown by making sure radio and power are handled accordingly.
mWindowManagerFuncs.shutdown();
}
}
mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)
增加DISALLOW_SAFE_BOOT限制
修改方案
\frameworks\base\core\res\res\values\config.xml
<string-array translatable="false" name="config_defaultFirstUserRestrictions">
<item>no_safe_boot</item>
</string-array>
查看/data/system/users/0.xml文件
\frameworks\base\services\core\java\com\android\server\pm\UserManagerService.java
/** @return a specific user restriction that's in effect currently. */
@Override
public boolean hasUserRestriction(String restrictionKey, @UserIdInt int userId) {
checkManageOrInteractPermissionIfCallerInOtherProfileGroup(userId, "hasUserRestriction");
return mLocalService.hasUserRestriction(restrictionKey, userId);
}
调用内部类LocalService
private class LocalService extends UserManagerInternal {
@Override
public boolean hasUserRestriction(String restrictionKey, @UserIdInt int userId) {
if (!UserRestrictionsUtils.isValidRestriction(restrictionKey)) {
return false;
}
Bundle restrictions = getEffectiveUserRestrictions(userId);
return restrictions != null && restrictions.getBoolean(restrictionKey);
}
\frameworks\base\core\java\android\os\Bundle.java
public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
\frameworks\base\core\java\android\os\BaseBundle.java
//restrictions是从UserRestrictionsUtils中拷贝的
final Bundle effective = UserRestrictionsUtils.clone(baseRestrictions);
\frameworks\base\services\core\java\com\android\server\pm\UserRestrictionsUtils.java