FileDocCategorySizeDatePackage
PowerCommand.javaAPI DocAndroid 1.5 API2594Wed May 06 22:41:54 BST 2009com.android.commands.svc

PowerCommand

public class PowerCommand extends Svc.Command

Fields Summary
Constructors Summary
public PowerCommand()

        super("power");
    
Methods Summary
public java.lang.StringlongHelp()

        return shortHelp() + "\n"
                + "\n"
                + "usage: svc power stayon [true|false|usb|ac]\n"
                + "         Set the 'keep awake while plugged in' setting.\n";
    
public voidrun(java.lang.String[] args)

        fail: {
            if (args.length >= 2) {
                if ("stayon".equals(args[1]) && args.length == 3) {
                    int val;
                    if ("true".equals(args[2])) {
                        val = BatteryManager.BATTERY_PLUGGED_AC |
                                BatteryManager.BATTERY_PLUGGED_USB;
                    }
                    else if ("false".equals(args[2])) {
                        val = 0;
                    } else if ("usb".equals(args[2])) {
                        val = BatteryManager.BATTERY_PLUGGED_USB;
                    } else if ("ac".equals(args[2])) {
                        val = BatteryManager.BATTERY_PLUGGED_AC;
                    }
                    else {
                        break fail;
                    }
                    IPowerManager pm
                            = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
                    try {
                        pm.setStayOnSetting(val);
                    }
                    catch (RemoteException e) {
                        System.err.println("Faild to set setting: " + e);
                    }
                    return;
                }
            }
        }
        System.err.println(longHelp());
    
public java.lang.StringshortHelp()

        return "Control the power manager";