diff options
Diffstat (limited to 'cmds/svc')
-rw-r--r-- | cmds/svc/src/com/android/commands/svc/PowerCommand.java | 28 |
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; } } } |