summaryrefslogtreecommitdiff
path: root/cmds/svc
diff options
context:
space:
mode:
authorSantos Cordon <santoscordon@google.com>2019-02-01 21:28:47 +0000
committerSantos Cordon <santoscordon@google.com>2019-02-15 17:23:18 +0000
commit12f92eb6cf222b9998c3a8affaa909a44b5c0ad0 (patch)
treeacbbf0a68c368ec7346bb07c93e2207120c644d8 /cmds/svc
parentb68b8a84831d480c1c254dcb271f0f31f95f315f (diff)
Add force suspend API to PowerManager.
Add a hidden system API (protected by DEVICE_POWER) that forces suspend, ignoring any existing wakelock. Add a shell cmd to trigger the API to run. Bug: 111991113 Test: 'adb shell svc power forcesuspend' Change-Id: I5a258e1b7c8b1391fe1baf3930dd9d9af47235c9
Diffstat (limited to 'cmds/svc')
-rw-r--r--cmds/svc/src/com/android/commands/svc/PowerCommand.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/cmds/svc/src/com/android/commands/svc/PowerCommand.java b/cmds/svc/src/com/android/commands/svc/PowerCommand.java
index d29e68e5a187..3180b77f5700 100644
--- a/cmds/svc/src/com/android/commands/svc/PowerCommand.java
+++ b/cmds/svc/src/com/android/commands/svc/PowerCommand.java
@@ -26,6 +26,8 @@ import android.os.SystemClock;
import android.os.SystemProperties;
public class PowerCommand extends Svc.Command {
+ private static final int FORCE_SUSPEND_DELAY_DEFAULT_MILLIS = 0;
+
public PowerCommand() {
super("power");
}
@@ -42,7 +44,17 @@ public class PowerCommand extends Svc.Command {
+ " svc power reboot [reason]\n"
+ " Perform a runtime shutdown and reboot device with specified reason.\n"
+ " svc power shutdown\n"
- + " Perform a runtime shutdown and power off the device.\n";
+ + " Perform a runtime shutdown and power off the device.\n"
+ + " svc power forcesuspend [t]\n"
+ + " Force the system into suspend, ignoring all wakelocks.\n"
+ + " t - Number of milliseconds to wait before issuing force-suspend.\n"
+ + " Helps with devices that can't suspend while plugged in.\n"
+ + " Defaults to " + FORCE_SUSPEND_DELAY_DEFAULT_MILLIS + ".\n"
+ + " When using a delay, you must use the nohup shell modifier:\n"
+ + " 'adb shell nohup svc power forcesuspend [time]'\n"
+ + " Use caution; this is dangerous. It puts the device to sleep\n"
+ + " immediately without giving apps or the system an opportunity to\n"
+ + " save their state.\n";
}
public void run(String[] args) {
@@ -101,6 +113,20 @@ public class PowerCommand extends Svc.Command {
maybeLogRemoteException("Failed to shutdown.");
}
return;
+ } else if ("forcesuspend".equals(args[1])) {
+ int delayMillis = args.length > 2
+ ? Integer.parseInt(args[2]) : FORCE_SUSPEND_DELAY_DEFAULT_MILLIS;
+ try {
+ Thread.sleep(delayMillis);
+ if (!pm.forceSuspend()) {
+ System.err.println("Failed to force suspend.");
+ }
+ } catch (InterruptedException e) {
+ System.err.println("Failed to force suspend: " + e);
+ } catch (RemoteException e) {
+ maybeLogRemoteException("Failed to force-suspend with exception: " + e);
+ }
+ return;
}
}
}