Merge "add reboot and shutdown to svc power command" into jb-mr2-dev

This commit is contained in:
Guang Zhu
2013-03-19 01:31:17 +00:00
committed by Android (Google) Code Review

View File

@@ -36,12 +36,18 @@ public class PowerCommand extends Svc.Command {
return shortHelp() + "\n" return shortHelp() + "\n"
+ "\n" + "\n"
+ "usage: svc power stayon [true|false|usb|ac|wireless]\n" + "usage: svc power stayon [true|false|usb|ac|wireless]\n"
+ " Set the 'keep awake while plugged in' setting.\n"; + " Set the 'keep awake while plugged in' setting.\n"
+ " 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";
} }
public void run(String[] args) { public void run(String[] args) {
fail: { fail: {
if (args.length >= 2) { if (args.length >= 2) {
IPowerManager pm = IPowerManager.Stub.asInterface(
ServiceManager.getService(Context.POWER_SERVICE));
if ("stayon".equals(args[1]) && args.length == 3) { if ("stayon".equals(args[1]) && args.length == 3) {
int val; int val;
if ("true".equals(args[2])) { if ("true".equals(args[2])) {
@@ -60,8 +66,6 @@ public class PowerCommand extends Svc.Command {
} else { } else {
break fail; break fail;
} }
IPowerManager pm
= IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
try { try {
if (val != 0) { if (val != 0) {
// if the request is not to set it to false, wake up the screen so that // if the request is not to set it to false, wake up the screen so that
@@ -74,6 +78,26 @@ public class PowerCommand extends Svc.Command {
System.err.println("Faild to set setting: " + e); System.err.println("Faild to set setting: " + e);
} }
return; return;
} else if ("reboot".equals(args[1])) {
String mode = null;
if (args.length == 3) {
mode = args[2];
}
try {
// no confirm, wait till device is rebooted
pm.reboot(false, mode, true);
} catch (RemoteException e) {
System.err.println("Failed to reboot.");
}
return;
} else if ("shutdown".equals(args[1])) {
try {
// no confirm, wait till device is off
pm.shutdown(false, true);
} catch (RemoteException e) {
System.err.println("Failed to shutdown.");
}
return;
} }
} }
} }