PowerCommand.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.commands.svc; 18 19import android.os.IPowerManager; 20import android.os.ServiceManager; 21import android.os.RemoteException; 22 23public class PowerCommand extends Svc.Command { 24 public PowerCommand() { 25 super("power"); 26 } 27 28 public String shortHelp() { 29 return "Control the power manager"; 30 } 31 32 public String longHelp() { 33 return shortHelp() + "\n" 34 + "\n" 35 + "usage: svc power stayon [true|false]\n" 36 + " Set the 'keep awake while plugged in' setting.\n"; 37 } 38 39 public void run(String[] args) { 40 fail: { 41 if (args.length >= 2) { 42 if ("stayon".equals(args[1]) && args.length == 3) { 43 boolean val; 44 if ("true".equals(args[2])) { 45 val = true; 46 } 47 else if ("false".equals(args[2])) { 48 val = false; 49 } 50 else { 51 break fail; 52 } 53 IPowerManager pm 54 = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); 55 try { 56 pm.setStayOnSetting(val); 57 } 58 catch (RemoteException e) { 59 System.err.println("Faild to set setting: " + e); 60 } 61 return; 62 } 63 } 64 } 65 System.err.println(longHelp()); 66 } 67} 68