Merge "prevent Monkey from reboot or shutdown the device" into udc-dev

This commit is contained in:
Guang Zhu
2023-03-08 19:45:54 +00:00
committed by Android (Google) Code Review
4 changed files with 47 additions and 0 deletions

View File

@@ -788,6 +788,11 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
@Override
public boolean onLongPress() {
// don't actually trigger the reboot if we are running stability
// tests via monkey
if (ActivityManager.isUserAMonkey()) {
return false;
}
mUiEventLogger.log(GlobalActionsEvent.GA_SHUTDOWN_LONG_PRESS);
if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
mWindowManagerFuncs.reboot(true);
@@ -808,6 +813,11 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
@Override
public void onPress() {
// don't actually trigger the shutdown if we are running stability
// tests via monkey
if (ActivityManager.isUserAMonkey()) {
return;
}
mUiEventLogger.log(GlobalActionsEvent.GA_SHUTDOWN_PRESS);
// shutdown by making sure radio and power are handled accordingly.
mWindowManagerFuncs.shutdown();
@@ -919,6 +929,11 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
@Override
public boolean onLongPress() {
// don't actually trigger the reboot if we are running stability
// tests via monkey
if (ActivityManager.isUserAMonkey()) {
return false;
}
mUiEventLogger.log(GlobalActionsEvent.GA_REBOOT_LONG_PRESS);
if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
mWindowManagerFuncs.reboot(true);
@@ -939,6 +954,11 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
@Override
public void onPress() {
// don't actually trigger the reboot if we are running stability
// tests via monkey
if (ActivityManager.isUserAMonkey()) {
return;
}
mUiEventLogger.log(GlobalActionsEvent.GA_REBOOT_PRESS);
mWindowManagerFuncs.reboot(false);
}

View File

@@ -1247,6 +1247,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
case LONG_PRESS_POWER_SHUT_OFF:
case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
mPowerKeyHandled = true;
// don't actually trigger the shutdown if we are running stability
// tests via monkey
if (ActivityManager.isUserAMonkey()) {
break;
}
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS_POWER_BUTTON, false,
"Power - Long Press - Shut Off");
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);

View File

@@ -15,6 +15,7 @@
*/
package com.android.server.policy;
import android.app.ActivityManager;
import android.content.Context;
import android.os.UserManager;
import com.android.internal.globalactions.LongPressAction;
@@ -35,6 +36,11 @@ public final class PowerAction extends SinglePressAction implements LongPressAct
@Override
public boolean onLongPress() {
// don't actually trigger the reboot if we are running stability
// tests via monkey
if (ActivityManager.isUserAMonkey()) {
return false;
}
UserManager um = mContext.getSystemService(UserManager.class);
if (!um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
mWindowManagerFuncs.rebootSafeMode(true);
@@ -55,6 +61,11 @@ public final class PowerAction extends SinglePressAction implements LongPressAct
@Override
public void onPress() {
// don't actually trigger the shutdown if we are running stability
// tests via monkey
if (ActivityManager.isUserAMonkey()) {
return;
}
// shutdown by making sure radio and power are handled accordingly.
mWindowManagerFuncs.shutdown(false /* confirm */);
}

View File

@@ -15,6 +15,7 @@
*/
package com.android.server.policy;
import android.app.ActivityManager;
import android.content.Context;
import android.os.UserManager;
import com.android.internal.globalactions.LongPressAction;
@@ -35,6 +36,11 @@ public final class RestartAction extends SinglePressAction implements LongPressA
@Override
public boolean onLongPress() {
// don't actually trigger the reboot if we are running stability
// tests via monkey
if (ActivityManager.isUserAMonkey()) {
return false;
}
UserManager um = mContext.getSystemService(UserManager.class);
if (!um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
mWindowManagerFuncs.rebootSafeMode(true);
@@ -55,6 +61,11 @@ public final class RestartAction extends SinglePressAction implements LongPressA
@Override
public void onPress() {
// don't actually trigger the reboot if we are running stability
// tests via monkey
if (ActivityManager.isUserAMonkey()) {
return;
}
mWindowManagerFuncs.reboot(false /* confirm */);
}
}