diff options
17 files changed, 221 insertions, 311 deletions
diff --git a/core/java/android/os/Power.java b/core/java/android/os/Power.java deleted file mode 100644 index 58df940..0000000 --- a/core/java/android/os/Power.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.os; - -import java.io.IOException; -import android.os.ServiceManager; - -/** - * Class that provides access to some of the power management functions. - * - * {@hide} - */ -public class Power -{ - // can't instantiate this class - private Power() - { - } - - /** - * Wake lock that ensures that the CPU is running. The screen might - * not be on. - */ - public static final int PARTIAL_WAKE_LOCK = 1; - - /** - * Wake lock that ensures that the screen is on. - */ - public static final int FULL_WAKE_LOCK = 2; - - public static native void acquireWakeLock(int lock, String id); - public static native void releaseWakeLock(String id); - - /** - * Brightness value for fully off - */ - public static final int BRIGHTNESS_OFF = 0; - - /** - * Brightness value for dim backlight - */ - public static final int BRIGHTNESS_DIM = 20; - - /** - * Brightness value for fully on - */ - public static final int BRIGHTNESS_ON = 255; - - /** - * Brightness value to use when battery is low - */ - public static final int BRIGHTNESS_LOW_BATTERY = 10; - - /** - * Threshold for BRIGHTNESS_LOW_BATTERY (percentage) - * Screen will stay dim if battery level is <= LOW_BATTERY_THRESHOLD - */ - public static final int LOW_BATTERY_THRESHOLD = 10; - - /** - * Turn the screen on or off - * - * @param on Whether you want the screen on or off - */ - public static native int setScreenState(boolean on); - - public static native int setLastUserActivityTimeout(long ms); - - /** - * Low-level function turn the device off immediately, without trying - * to be clean. Most people should use - * {@link android.internal.app.ShutdownThread} for a clean shutdown. - * - * @deprecated - * @hide - */ - @Deprecated - public static native void shutdown(); - - /** - * Reboot the device. - * @param reason code to pass to the kernel (e.g. "recovery"), or null. - * - * @throws IOException if reboot fails for some reason (eg, lack of - * permission) - */ - public static void reboot(String reason) throws IOException - { - rebootNative(reason); - } - - private static native void rebootNative(String reason) throws IOException ; - - public static native int powerInitNative(); -} diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 21373ec..903c8b3 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -197,7 +197,31 @@ public class PowerManager * Does not work with PARTIAL_WAKE_LOCKs. */ public static final int ON_AFTER_RELEASE = 0x20000000; - + + /** + * Brightness value to use when battery is low. + * @hide + */ + public static final int BRIGHTNESS_LOW_BATTERY = 10; + + /** + * Brightness value for fully on. + * @hide + */ + public static final int BRIGHTNESS_ON = 255; + + /** + * Brightness value for dim backlight. + * @hide + */ + public static final int BRIGHTNESS_DIM = 20; + + /** + * Brightness value for fully off. + * @hide + */ + public static final int BRIGHTNESS_OFF = 0; + /** * Class lets you say that you need to have the device on. * <p> diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java index 388cfb3..bc38368 100644 --- a/core/java/android/view/WindowManagerPolicy.java +++ b/core/java/android/view/WindowManagerPolicy.java @@ -397,6 +397,9 @@ public interface WindowManagerPolicy { * Creates an input channel that will receive all input from the input dispatcher. */ public InputChannel monitorInput(String name); + + public void shutdown(); + public void rebootSafeMode(); } /** diff --git a/core/jni/Android.mk b/core/jni/Android.mk index cd0959b..c24f6c6 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -66,7 +66,6 @@ LOCAL_SRC_FILES:= \ android_os_MessageQueue.cpp \ android_os_ParcelFileDescriptor.cpp \ android_os_Parcel.cpp \ - android_os_Power.cpp \ android_os_StatFs.cpp \ android_os_SystemClock.cpp \ android_os_SystemProperties.cpp \ @@ -217,8 +216,7 @@ LOCAL_SHARED_LIBRARIES := \ libjpeg \ libusbhost \ libharfbuzz \ - libz \ - libsuspend \ + libz ifeq ($(USE_OPENGL_RENDERER),true) LOCAL_SHARED_LIBRARIES += libhwui diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index b877071..241a905 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -133,7 +133,6 @@ extern int register_android_os_Debug(JNIEnv* env); extern int register_android_os_MessageQueue(JNIEnv* env); extern int register_android_os_Parcel(JNIEnv* env); extern int register_android_os_ParcelFileDescriptor(JNIEnv *env); -extern int register_android_os_Power(JNIEnv *env); extern int register_android_os_StatFs(JNIEnv *env); extern int register_android_os_SystemProperties(JNIEnv *env); extern int register_android_os_SystemClock(JNIEnv* env); @@ -1147,7 +1146,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_os_FileUtils), REG_JNI(register_android_os_MessageQueue), REG_JNI(register_android_os_ParcelFileDescriptor), - REG_JNI(register_android_os_Power), REG_JNI(register_android_os_StatFs), REG_JNI(register_android_os_Trace), REG_JNI(register_android_os_UEventObserver), diff --git a/core/jni/android_os_Power.cpp b/core/jni/android_os_Power.cpp deleted file mode 100644 index 373abd4..0000000 --- a/core/jni/android_os_Power.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* //device/libs/android_runtime/android_os_Power.cpp -** -** Copyright 2006, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -#define LOG_TAG "Power-JNI" - -#include "JNIHelp.h" -#include "jni.h" -#include "android_runtime/AndroidRuntime.h" -#include <utils/misc.h> -#include <hardware/power.h> -#include <hardware_legacy/power.h> -#include <cutils/android_reboot.h> -#include <suspend/autosuspend.h> - -static struct power_module *sPowerModule; - -namespace android -{ - -static void -acquireWakeLock(JNIEnv *env, jobject clazz, jint lock, jstring idObj) -{ - if (idObj == NULL) { - jniThrowNullPointerException(env, "id is null"); - return ; - } - - const char *id = env->GetStringUTFChars(idObj, NULL); - - acquire_wake_lock(lock, id); - - env->ReleaseStringUTFChars(idObj, id); -} - -static void -releaseWakeLock(JNIEnv *env, jobject clazz, jstring idObj) -{ - if (idObj == NULL) { - jniThrowNullPointerException(env, "id is null"); - return ; - } - - const char *id = env->GetStringUTFChars(idObj, NULL); - - release_wake_lock(id); - - env->ReleaseStringUTFChars(idObj, id); - -} - -static int -setLastUserActivityTimeout(JNIEnv *env, jobject clazz, jlong timeMS) -{ - return set_last_user_activity_timeout(timeMS/1000); -} - -static int -setScreenState(JNIEnv *env, jobject clazz, jboolean on) -{ - if (on) { - autosuspend_disable(); - if (sPowerModule) { - sPowerModule->setInteractive(sPowerModule, true); - } - } else { - if (sPowerModule) { - sPowerModule->setInteractive(sPowerModule, false); - } - autosuspend_enable(); - } - - return 0; -} - -static void android_os_Power_shutdown(JNIEnv *env, jobject clazz) -{ - android_reboot(ANDROID_RB_POWEROFF, 0, 0); -} - -static void android_os_Power_reboot(JNIEnv *env, jobject clazz, jstring reason) -{ - if (reason == NULL) { - android_reboot(ANDROID_RB_RESTART, 0, 0); - } else { - const char *chars = env->GetStringUTFChars(reason, NULL); - android_reboot(ANDROID_RB_RESTART2, 0, (char *) chars); - env->ReleaseStringUTFChars(reason, chars); // In case it fails. - } - jniThrowIOException(env, errno); -} - -static int android_os_Power_init(JNIEnv *env, jobject clazz) -{ - status_t err = hw_get_module(POWER_HARDWARE_MODULE_ID, - (hw_module_t const**)&sPowerModule); - ALOGE_IF(err, "couldn't load %s module (%s)", - POWER_HARDWARE_MODULE_ID, strerror(-err)); - - if (!err) - sPowerModule->init(sPowerModule); - - return err; -} - -static JNINativeMethod method_table[] = { - { "acquireWakeLock", "(ILjava/lang/String;)V", (void*)acquireWakeLock }, - { "releaseWakeLock", "(Ljava/lang/String;)V", (void*)releaseWakeLock }, - { "setLastUserActivityTimeout", "(J)I", (void*)setLastUserActivityTimeout }, - { "setScreenState", "(Z)I", (void*)setScreenState }, - { "shutdown", "()V", (void*)android_os_Power_shutdown }, - { "powerInitNative", "()I", (void*)android_os_Power_init }, - { "rebootNative", "(Ljava/lang/String;)V", (void*)android_os_Power_reboot }, -}; - -int register_android_os_Power(JNIEnv *env) -{ - return AndroidRuntime::registerNativeMethods( - env, "android/os/Power", - method_table, NELEM(method_table)); -} - -}; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessController.java index 72fdfad..3ba36af 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessController.java @@ -31,8 +31,8 @@ import android.widget.CompoundButton; public class BrightnessController implements ToggleSlider.Listener { private static final String TAG = "StatusBar.BrightnessController"; - private static final int MINIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_DIM; - private static final int MAXIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_ON; + private static final int MINIMUM_BACKLIGHT = android.os.PowerManager.BRIGHTNESS_DIM; + private static final int MAXIMUM_BACKLIGHT = android.os.PowerManager.BRIGHTNESS_ON; private Context mContext; private ToggleSlider mControl; diff --git a/policy/src/com/android/internal/policy/impl/GlobalActions.java b/policy/src/com/android/internal/policy/impl/GlobalActions.java index 3fa79b6..aa73de4 100644 --- a/policy/src/com/android/internal/policy/impl/GlobalActions.java +++ b/policy/src/com/android/internal/policy/impl/GlobalActions.java @@ -16,14 +16,12 @@ package com.android.internal.policy.impl; -import com.android.internal.app.ShutdownThread; import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyProperties; import com.android.internal.R; import android.app.ActivityManagerNative; import android.app.AlertDialog; -import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; @@ -48,6 +46,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.view.WindowManagerPolicy.WindowManagerFuncs; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; @@ -68,6 +67,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac private static final boolean SHOW_SILENT_TOGGLE = true; private final Context mContext; + private final WindowManagerFuncs mWindowManagerFuncs; private final AudioManager mAudioManager; private ArrayList<Action> mItems; @@ -88,8 +88,9 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac /** * @param context everything needs a context :( */ - public GlobalActions(Context context) { + public GlobalActions(Context context, WindowManagerFuncs windowManagerFuncs) { mContext = context; + mWindowManagerFuncs = windowManagerFuncs; mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); // receive broadcasts @@ -186,11 +187,11 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac public void onPress() { // shutdown by making sure radio and power are handled accordingly. - ShutdownThread.shutdown(mContext, true); + mWindowManagerFuncs.shutdown(); } public boolean onLongPress() { - ShutdownThread.rebootSafeMode(mContext, true); + mWindowManagerFuncs.rebootSafeMode(); return true; } diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 794ed15..8e187cd 100755 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -60,7 +60,6 @@ import android.os.Vibrator; import android.provider.Settings; import com.android.internal.R; -import com.android.internal.app.ShutdownThread; import com.android.internal.policy.PolicyManager; import com.android.internal.statusbar.IStatusBarService; import com.android.internal.telephony.ITelephony; @@ -727,7 +726,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { mPowerKeyHandled = true; performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); - ShutdownThread.shutdown(mContext, true); + mWindowManagerFuncs.shutdown(); break; } } @@ -741,7 +740,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { void showGlobalActionsDialog() { if (mGlobalActions == null) { - mGlobalActions = new GlobalActions(mContext); + mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); } final boolean keyguardShowing = keyguardIsShowingTq(); mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java index 289ab2a..2cc2704 100644 --- a/services/java/com/android/server/PowerManagerService.java +++ b/services/java/com/android/server/PowerManagerService.java @@ -17,8 +17,8 @@ package com.android.server; import com.android.internal.app.IBatteryStats; -import com.android.internal.app.ShutdownThread; import com.android.server.am.BatteryStatsService; +import com.android.server.pm.ShutdownThread; import android.app.ActivityManagerNative; import android.app.IActivityManager; @@ -47,7 +47,6 @@ import android.os.IBinder; import android.os.IPowerManager; import android.os.LocalPowerManager; import android.os.Message; -import android.os.Power; import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; @@ -71,6 +70,7 @@ import static android.provider.Settings.System.WINDOW_ANIMATION_SCALE; import static android.provider.Settings.System.TRANSITION_ANIMATION_SCALE; import java.io.FileDescriptor; +import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; @@ -84,6 +84,12 @@ public class PowerManagerService extends IPowerManager.Stub private static final String TAG = "PowerManagerService"; static final String PARTIAL_NAME = "PowerManagerService"; + // Wake lock that ensures that the CPU is running. The screen might not be on. + private static final int PARTIAL_WAKE_LOCK_ID = 1; + + // Wake lock that ensures that the screen is on. + private static final int FULL_WAKE_LOCK_ID = 2; + static final boolean DEBUG_SCREEN_ON = false; private static final boolean LOG_PARTIAL_WL = false; @@ -134,6 +140,10 @@ public class PowerManagerService extends IPowerManager.Stub // Screen brightness should always have a value, but just in case... private static final int DEFAULT_SCREEN_BRIGHTNESS = 192; + // Threshold for BRIGHTNESS_LOW_BATTERY (percentage) + // Screen will stay dim if battery level is <= LOW_BATTERY_THRESHOLD + private static final int LOW_BATTERY_THRESHOLD = 10; + // flags for setPowerState private static final int ALL_LIGHTS_OFF = 0x00000000; private static final int SCREEN_ON_BIT = 0x00000001; @@ -175,8 +185,8 @@ public class PowerManagerService extends IPowerManager.Stub // we should read them from the driver, but our current hardware returns 0 // for the initial value. Oops! static final int INITIAL_SCREEN_BRIGHTNESS = 255; - static final int INITIAL_BUTTON_BRIGHTNESS = Power.BRIGHTNESS_OFF; - static final int INITIAL_KEYBOARD_BRIGHTNESS = Power.BRIGHTNESS_OFF; + static final int INITIAL_BUTTON_BRIGHTNESS = PowerManager.BRIGHTNESS_OFF; + static final int INITIAL_KEYBOARD_BRIGHTNESS = PowerManager.BRIGHTNESS_OFF; private final int MY_UID; private final int MY_PID; @@ -296,6 +306,11 @@ public class PowerManagerService extends IPowerManager.Stub private native void nativeInit(); private native void nativeSetPowerState(boolean screenOn, boolean screenBright); private native void nativeStartSurfaceFlingerAnimation(int mode); + private static native void nativeAcquireWakeLock(int lock, String id); + private static native void nativeReleaseWakeLock(String id); + private static native int nativeSetScreenState(boolean on); + private static native void nativeShutdown(); + private static native void nativeReboot(String reason) throws IOException; /* static PrintStream mLog; @@ -515,14 +530,13 @@ public class PowerManagerService extends IPowerManager.Stub MY_PID = Process.myPid(); Binder.restoreCallingIdentity(token); - // XXX remove this when the kernel doesn't timeout wake locks - Power.setLastUserActivityTimeout(7*24*3600*1000); // one week - // assume nothing is on yet mUserState = mPowerState = 0; // Add ourself to the Watchdog monitors. Watchdog.getInstance().addMonitor(this); + + nativeInit(); } private ContentQueryMap mSettings; @@ -541,11 +555,6 @@ public class PowerManagerService extends IPowerManager.Stub mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION); mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0")); - nativeInit(); - synchronized (mLocks) { - updateNativePowerStateLocked(); - } - mInitComplete = false; mScreenBrightnessAnimator = new ScreenBrightnessAnimator("mScreenBrightnessUpdaterThread", Process.THREAD_PRIORITY_DISPLAY); @@ -581,8 +590,6 @@ public class PowerManagerService extends IPowerManager.Stub } } - nativeInit(); - Power.powerInitNative(); synchronized (mLocks) { updateNativePowerStateLocked(); // We make sure to start out with the screen on due to user activity. @@ -686,6 +693,26 @@ public class PowerManagerService extends IPowerManager.Stub } } + /** + * Low-level function turn the device off immediately, without trying + * to be clean. Most people should use + * {@link com.android.server.pm.internal.app.ShutdownThread} for a clean shutdown. + */ + public static void lowLevelShutdown() { + nativeShutdown(); + } + + /** + * Low-level function to reboot the device. + * + * @param reason code to pass to the kernel (e.g. "recovery"), or null. + * @throws IOException if reboot fails for some reason (eg, lack of + * permission) + */ + public static void lowLevelReboot(String reason) throws IOException { + nativeReboot(reason); + } + private class WakeLock implements IBinder.DeathRecipient { WakeLock(int f, IBinder b, String t, int u, int p) { @@ -926,7 +953,7 @@ public class PowerManagerService extends IPowerManager.Stub if (LOG_PARTIAL_WL) EventLog.writeEvent(EventLogTags.POWER_PARTIAL_WAKE_STATE, 1, tag); } } - Power.acquireWakeLock(Power.PARTIAL_WAKE_LOCK,PARTIAL_NAME); + nativeAcquireWakeLock(PARTIAL_WAKE_LOCK_ID, PARTIAL_NAME); } if (diffsource) { @@ -1010,7 +1037,7 @@ public class PowerManagerService extends IPowerManager.Stub mPartialCount--; if (mPartialCount == 0) { if (LOG_PARTIAL_WL) EventLog.writeEvent(EventLogTags.POWER_PARTIAL_WAKE_STATE, 0, wl.tag); - Power.releaseWakeLock(PARTIAL_NAME); + nativeReleaseWakeLock(PARTIAL_NAME); } } // Unlink the lock from the binder. @@ -1719,10 +1746,10 @@ public class PowerManagerService extends IPowerManager.Stub + " mSkippedScreenOn=" + mSkippedScreenOn); } mScreenBrightnessHandler.removeMessages(ScreenBrightnessAnimator.ANIMATE_LIGHTS); - mScreenBrightnessAnimator.animateTo(Power.BRIGHTNESS_OFF, SCREEN_BRIGHT_BIT, 0); + mScreenBrightnessAnimator.animateTo(PowerManager.BRIGHTNESS_OFF, SCREEN_BRIGHT_BIT, 0); } } - int err = Power.setScreenState(on); + int err = nativeSetScreenState(on); if (err == 0) { mLastScreenOnTime = (on ? SystemClock.elapsedRealtime() : 0); if (mUseSoftwareAutoBrightness) { @@ -1934,7 +1961,7 @@ public class PowerManagerService extends IPowerManager.Stub private boolean batteryIsLow() { return (!mIsPowered && - mBatteryService.getBatteryLevel() <= Power.LOW_BATTERY_THRESHOLD); + mBatteryService.getBatteryLevel() <= LOW_BATTERY_THRESHOLD); } private boolean shouldDeferScreenOnLocked() { @@ -2024,7 +2051,7 @@ public class PowerManagerService extends IPowerManager.Stub nominalCurrentValue = mScreenBrightnessDim; break; case 0: - nominalCurrentValue = Power.BRIGHTNESS_OFF; + nominalCurrentValue = PowerManager.BRIGHTNESS_OFF; break; case SCREEN_BRIGHT_BIT: default: @@ -2050,7 +2077,7 @@ public class PowerManagerService extends IPowerManager.Stub // was dim steps = (int)(ANIM_STEPS*ratio*scale); } - brightness = Power.BRIGHTNESS_OFF; + brightness = PowerManager.BRIGHTNESS_OFF; } else { if ((oldState & SCREEN_ON_BIT) != 0) { // was bright @@ -2101,13 +2128,13 @@ public class PowerManagerService extends IPowerManager.Stub if (offMask != 0) { if (mSpew) Slog.i(TAG, "Setting brightess off: " + offMask); - setLightBrightness(offMask, Power.BRIGHTNESS_OFF); + setLightBrightness(offMask, PowerManager.BRIGHTNESS_OFF); } if (dimMask != 0) { int brightness = mScreenBrightnessDim; if ((newState & BATTERY_LOW_BIT) != 0 && - brightness > Power.BRIGHTNESS_LOW_BATTERY) { - brightness = Power.BRIGHTNESS_LOW_BATTERY; + brightness > PowerManager.BRIGHTNESS_LOW_BATTERY) { + brightness = PowerManager.BRIGHTNESS_LOW_BATTERY; } if (mSpew) Slog.i(TAG, "Setting brightess dim " + brightness + ": " + dimMask); setLightBrightness(dimMask, brightness); @@ -2115,8 +2142,8 @@ public class PowerManagerService extends IPowerManager.Stub if (onMask != 0) { int brightness = getPreferredBrightness(); if ((newState & BATTERY_LOW_BIT) != 0 && - brightness > Power.BRIGHTNESS_LOW_BATTERY) { - brightness = Power.BRIGHTNESS_LOW_BATTERY; + brightness > PowerManager.BRIGHTNESS_LOW_BATTERY) { + brightness = PowerManager.BRIGHTNESS_LOW_BATTERY; } if (mSpew) Slog.i(TAG, "Setting brightess on " + brightness + ": " + onMask); setLightBrightness(onMask, brightness); @@ -2198,8 +2225,8 @@ public class PowerManagerService extends IPowerManager.Stub if (elapsed < duration) { int delta = endValue - startValue; newValue = startValue + delta * elapsed / duration; - newValue = Math.max(Power.BRIGHTNESS_OFF, newValue); - newValue = Math.min(Power.BRIGHTNESS_ON, newValue); + newValue = Math.max(PowerManager.BRIGHTNESS_OFF, newValue); + newValue = Math.min(PowerManager.BRIGHTNESS_ON, newValue); } else { newValue = endValue; mInitialAnimation = false; @@ -2249,7 +2276,7 @@ public class PowerManagerService extends IPowerManager.Stub if (target != currentValue) { final boolean doScreenAnim = (mask & (SCREEN_BRIGHT_BIT | SCREEN_ON_BIT)) != 0; - final boolean turningOff = endValue == Power.BRIGHTNESS_OFF; + final boolean turningOff = endValue == PowerManager.BRIGHTNESS_OFF; if (turningOff && doScreenAnim) { // Cancel all pending animations since we're turning off mScreenBrightnessHandler.removeCallbacksAndMessages(null); @@ -2353,7 +2380,7 @@ public class PowerManagerService extends IPowerManager.Stub private boolean isScreenTurningOffLocked() { return (mScreenBrightnessAnimator.isAnimating() - && mScreenBrightnessAnimator.endValue == Power.BRIGHTNESS_OFF); + && mScreenBrightnessAnimator.endValue == PowerManager.BRIGHTNESS_OFF); } private boolean shouldLog(long time) { diff --git a/services/java/com/android/server/ShutdownActivity.java b/services/java/com/android/server/ShutdownActivity.java index c9d4d01..d85abe6 100644 --- a/services/java/com/android/server/ShutdownActivity.java +++ b/services/java/com/android/server/ShutdownActivity.java @@ -22,7 +22,8 @@ import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.util.Slog; -import com.android.internal.app.ShutdownThread; + +import com.android.server.pm.ShutdownThread; public class ShutdownActivity extends Activity { diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 849281d..d9833ab 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -46,7 +46,6 @@ import android.util.Log; import android.util.Slog; import android.view.WindowManager; -import com.android.internal.app.ShutdownThread; import com.android.internal.os.BinderInternal; import com.android.internal.os.SamplingProfilerIntegration; import com.android.internal.widget.LockSettingsService; @@ -56,6 +55,7 @@ import com.android.server.input.InputManagerService; import com.android.server.net.NetworkPolicyManagerService; import com.android.server.net.NetworkStatsService; import com.android.server.pm.PackageManagerService; +import com.android.server.pm.ShutdownThread; import com.android.server.usb.UsbService; import com.android.server.wm.WindowManagerService; diff --git a/core/java/com/android/internal/app/ShutdownThread.java b/services/java/com/android/server/pm/ShutdownThread.java index d867ff9..1d6e068 100644 --- a/core/java/com/android/internal/app/ShutdownThread.java +++ b/services/java/com/android/server/pm/ShutdownThread.java @@ -15,7 +15,7 @@ */ -package com.android.internal.app; +package com.android.server.pm; import android.app.ActivityManagerNative; import android.app.AlertDialog; @@ -32,7 +32,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.os.Handler; -import android.os.Power; import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; @@ -44,6 +43,8 @@ import android.os.storage.IMountService; import android.os.storage.IMountShutdownObserver; import com.android.internal.telephony.ITelephony; +import com.android.server.PowerManagerService; + import android.util.Log; import android.view.WindowManager; @@ -456,7 +457,7 @@ public final class ShutdownThread extends Thread { if (reboot) { Log.i(TAG, "Rebooting, reason: " + reason); try { - Power.reboot(reason); + PowerManagerService.lowLevelReboot(reason); } catch (Exception e) { Log.e(TAG, "Reboot failed, will attempt shutdown instead", e); } @@ -479,6 +480,6 @@ public final class ShutdownThread extends Thread { // Shutdown power Log.i(TAG, "Performing low-level shutdown..."); - Power.shutdown(); + PowerManagerService.lowLevelShutdown(); } } diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java index 2efcb8e..c90c0c7 100755 --- a/services/java/com/android/server/wm/WindowManagerService.java +++ b/services/java/com/android/server/wm/WindowManagerService.java @@ -34,7 +34,6 @@ import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; import com.android.internal.app.IBatteryStats; -import com.android.internal.app.ShutdownThread; import com.android.internal.policy.PolicyManager; import com.android.internal.policy.impl.PhoneWindowManager; import com.android.internal.view.IInputContext; @@ -48,6 +47,7 @@ import com.android.server.Watchdog; import com.android.server.am.BatteryStatsService; import com.android.server.input.InputFilter; import com.android.server.input.InputManagerService; +import com.android.server.pm.ShutdownThread; import android.Manifest; import android.app.ActivityManagerNative; @@ -82,7 +82,6 @@ import android.os.Looper; import android.os.Message; import android.os.Parcel; import android.os.ParcelFileDescriptor; -import android.os.Power; import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; @@ -5025,6 +5024,18 @@ public class WindowManagerService extends IWindowManager.Stub return mInputManager.monitorInput(inputChannelName); } + // Called by window manager policy. Not exposed externally. + @Override + public void shutdown() { + ShutdownThread.shutdown(mContext, true); + } + + // Called by window manager policy. Not exposed externally. + @Override + public void rebootSafeMode() { + ShutdownThread.rebootSafeMode(mContext, true); + } + public void setInputFilter(InputFilter filter) { mInputManager.setInputFilter(filter); } @@ -8700,13 +8711,13 @@ public class WindowManagerService extends IWindowManager.Stub mPowerManager.setScreenBrightnessOverride(-1); } else { mPowerManager.setScreenBrightnessOverride((int) - (mInnerFields.mScreenBrightness * Power.BRIGHTNESS_ON)); + (mInnerFields.mScreenBrightness * PowerManager.BRIGHTNESS_ON)); } if (mInnerFields.mButtonBrightness < 0 || mInnerFields.mButtonBrightness > 1.0f) { mPowerManager.setButtonBrightnessOverride(-1); } else { mPowerManager.setButtonBrightnessOverride((int) - (mInnerFields.mButtonBrightness * Power.BRIGHTNESS_ON)); + (mInnerFields.mButtonBrightness * PowerManager.BRIGHTNESS_ON)); } } if (mInnerFields.mHoldScreen != mHoldingScreenOn) { diff --git a/services/jni/Android.mk b/services/jni/Android.mk index e2bd622..e0a14af 100644 --- a/services/jni/Android.mk +++ b/services/jni/Android.mk @@ -23,7 +23,10 @@ LOCAL_C_INCLUDES += \ frameworks/base/services \ frameworks/base/core/jni \ external/skia/include/core \ - libcore/include + libcore/include \ + libcore/include/libsuspend \ + $(call include-path-for, libhardware)/hardware \ + $(call include-path-for, libhardware_legacy)/hardware_legacy \ LOCAL_SHARED_LIBRARIES := \ libandroid_runtime \ @@ -38,7 +41,8 @@ LOCAL_SHARED_LIBRARIES := \ libinput \ libskia \ libgui \ - libusbhost + libusbhost \ + libsuspend ifeq ($(WITH_MALLOC_LEAK_CHECK),true) LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK diff --git a/services/jni/com_android_server_PowerManagerService.cpp b/services/jni/com_android_server_PowerManagerService.cpp index ce80c1f..2077469 100644 --- a/services/jni/com_android_server_PowerManagerService.cpp +++ b/services/jni/com_android_server_PowerManagerService.cpp @@ -24,8 +24,14 @@ #include <limits.h> #include <android_runtime/AndroidRuntime.h> -#include <utils/Timers.h> #include <gui/ISurfaceComposer.h> +#include <utils/Timers.h> +#include <utils/misc.h> +#include <utils/String8.h> +#include <hardware/power.h> +#include <hardware_legacy/power.h> +#include <cutils/android_reboot.h> +#include <suspend/autosuspend.h> #include <private/gui/ComposerService.h> @@ -43,6 +49,7 @@ static struct { // ---------------------------------------------------------------------------- static jobject gPowerManagerServiceObj; +static struct power_module* gPowerModule; static Mutex gPowerManagerLock; static bool gScreenOn; @@ -112,33 +119,115 @@ void android_server_PowerManagerService_goToSleep(nsecs_t eventTime) { // ---------------------------------------------------------------------------- -static void android_server_PowerManagerService_nativeInit(JNIEnv* env, jobject obj) { +static void nativeInit(JNIEnv* env, jobject obj) { gPowerManagerServiceObj = env->NewGlobalRef(obj); + + status_t err = hw_get_module(POWER_HARDWARE_MODULE_ID, + (hw_module_t const**)&gPowerModule); + if (err) { + String8 msg; + msg.appendFormat("Couldn't load %s module (%s)", + POWER_HARDWARE_MODULE_ID, strerror(-err)); + ALOGE("%s", msg.string()); + jniThrowRuntimeException(env, msg.string()); + return; + } + + gPowerModule->init(gPowerModule); } -static void android_server_PowerManagerService_nativeSetPowerState(JNIEnv* env, +static void nativeSetPowerState(JNIEnv* env, jobject serviceObj, jboolean screenOn, jboolean screenBright) { AutoMutex _l(gPowerManagerLock); gScreenOn = screenOn; gScreenBright = screenBright; } -static void android_server_PowerManagerService_nativeStartSurfaceFlingerAnimation(JNIEnv* env, +static void nativeStartSurfaceFlingerAnimation(JNIEnv* env, jobject obj, jint mode) { sp<ISurfaceComposer> s(ComposerService::getComposerService()); s->turnElectronBeamOff(mode); } +static void nativeAcquireWakeLock(JNIEnv *env, jobject clazz, jint lock, jstring idObj) { + if (idObj == NULL) { + jniThrowNullPointerException(env, "id is null"); + return; + } + + const char *id = env->GetStringUTFChars(idObj, NULL); + + acquire_wake_lock(lock, id); + + env->ReleaseStringUTFChars(idObj, id); +} + +static void nativeReleaseWakeLock(JNIEnv *env, jobject clazz, jstring idObj) { + if (idObj == NULL) { + jniThrowNullPointerException(env, "id is null"); + return ; + } + + const char *id = env->GetStringUTFChars(idObj, NULL); + + release_wake_lock(id); + + env->ReleaseStringUTFChars(idObj, id); + +} + +static int nativeSetScreenState(JNIEnv *env, jobject clazz, jboolean on) { + if (on) { + autosuspend_disable(); + if (gPowerModule) { + gPowerModule->setInteractive(gPowerModule, true); + } + } else { + if (gPowerModule) { + gPowerModule->setInteractive(gPowerModule, false); + } + autosuspend_enable(); + } + + return 0; +} + +static void nativeShutdown(JNIEnv *env, jobject clazz) { + android_reboot(ANDROID_RB_POWEROFF, 0, 0); +} + +static void nativeReboot(JNIEnv *env, jobject clazz, jstring reason) { + if (reason == NULL) { + android_reboot(ANDROID_RB_RESTART, 0, 0); + } else { + const char *chars = env->GetStringUTFChars(reason, NULL); + android_reboot(ANDROID_RB_RESTART2, 0, (char *) chars); + env->ReleaseStringUTFChars(reason, chars); // In case it fails. + } + jniThrowIOException(env, errno); +} + + // ---------------------------------------------------------------------------- static JNINativeMethod gPowerManagerServiceMethods[] = { /* name, signature, funcPtr */ { "nativeInit", "()V", - (void*) android_server_PowerManagerService_nativeInit }, + (void*) nativeInit }, { "nativeSetPowerState", "(ZZ)V", - (void*) android_server_PowerManagerService_nativeSetPowerState }, + (void*) nativeSetPowerState }, { "nativeStartSurfaceFlingerAnimation", "(I)V", - (void*) android_server_PowerManagerService_nativeStartSurfaceFlingerAnimation }, + (void*) nativeStartSurfaceFlingerAnimation }, + { "nativeAcquireWakeLock", "(ILjava/lang/String;)V", + (void*) nativeAcquireWakeLock }, + { "nativeReleaseWakeLock", "(Ljava/lang/String;)V", + (void*) nativeReleaseWakeLock }, + { "nativeSetScreenState", "(Z)I", + (void*) nativeSetScreenState }, + { "nativeShutdown", "()V", + (void*) nativeShutdown }, + { "nativeReboot", "(Ljava/lang/String;)V", + (void*) nativeReboot }, }; #define FIND_CLASS(var, className) \ diff --git a/telephony/java/com/android/internal/telephony/IccCard.java b/telephony/java/com/android/internal/telephony/IccCard.java index 92024cd..d738d7b 100644 --- a/telephony/java/com/android/internal/telephony/IccCard.java +++ b/telephony/java/com/android/internal/telephony/IccCard.java @@ -26,7 +26,6 @@ import android.content.res.Resources; import android.os.AsyncResult; import android.os.Handler; import android.os.Message; -import android.os.Power; import android.os.PowerManager; import android.os.Registrant; import android.os.RegistrantList; |