1 /* 2 * Copyright (C) 2007 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 17 package android.os; 18 19 import java.io.IOException; 20 import android.os.ServiceManager; 21 22 /** 23 * Class that provides access to some of the power management functions. 24 * 25 * {@hide} 26 */ 27 public class Power 28 { 29 // can't instantiate this class Power()30 private Power() 31 { 32 } 33 34 /** 35 * Wake lock that ensures that the CPU is running. The screen might 36 * not be on. 37 */ 38 public static final int PARTIAL_WAKE_LOCK = 1; 39 40 /** 41 * Wake lock that ensures that the screen is on. 42 */ 43 public static final int FULL_WAKE_LOCK = 2; 44 acquireWakeLock(int lock, String id)45 public static native void acquireWakeLock(int lock, String id); releaseWakeLock(String id)46 public static native void releaseWakeLock(String id); 47 48 /** 49 * Brightness value for fully off 50 */ 51 public static final int BRIGHTNESS_OFF = 0; 52 53 /** 54 * Brightness value for dim backlight 55 */ 56 public static final int BRIGHTNESS_DIM = 20; 57 58 /** 59 * Brightness value for fully on 60 */ 61 public static final int BRIGHTNESS_ON = 255; 62 63 /** 64 * Brightness value to use when battery is low 65 */ 66 public static final int BRIGHTNESS_LOW_BATTERY = 10; 67 68 /** 69 * Threshold for BRIGHTNESS_LOW_BATTERY (percentage) 70 * Screen will stay dim if battery level is <= LOW_BATTERY_THRESHOLD 71 */ 72 public static final int LOW_BATTERY_THRESHOLD = 10; 73 74 /** 75 * Turn the screen on or off 76 * 77 * @param on Whether you want the screen on or off 78 */ setScreenState(boolean on)79 public static native int setScreenState(boolean on); 80 setLastUserActivityTimeout(long ms)81 public static native int setLastUserActivityTimeout(long ms); 82 83 /** 84 * Low-level function turn the device off immediately, without trying 85 * to be clean. Most people should use 86 * {@link android.internal.app.ShutdownThread} for a clean shutdown. 87 * 88 * @deprecated 89 * @hide 90 */ 91 @Deprecated shutdown()92 public static native void shutdown(); 93 94 /** 95 * Reboot the device. 96 * @param reason code to pass to the kernel (e.g. "recovery"), or null. 97 * 98 * @throws IOException if reboot fails for some reason (eg, lack of 99 * permission) 100 */ reboot(String reason)101 public static void reboot(String reason) throws IOException 102 { 103 rebootNative(reason); 104 } 105 rebootNative(String reason)106 private static native void rebootNative(String reason) throws IOException ; 107 } 108