+++ /dev/null
-/*
- * 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();
-}
* 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>
* Creates an input channel that will receive all input from the input dispatcher.
*/
public InputChannel monitorInput(String name);
+
+ public void shutdown();
+ public void rebootSafeMode();
}
/**
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 \
libjpeg \
libusbhost \
libharfbuzz \
- libz \
- libsuspend \
+ libz
ifeq ($(USE_OPENGL_RENDERER),true)
LOCAL_SHARED_LIBRARIES += libhwui
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);
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),
+++ /dev/null
-/* //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));
-}
-
-};
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;
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;
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;
private static final boolean SHOW_SILENT_TOGGLE = true;
private final Context mContext;
+ private final WindowManagerFuncs mWindowManagerFuncs;
private final AudioManager mAudioManager;
private ArrayList<Action> mItems;
/**
* @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
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;
}
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;
mPowerKeyHandled = true;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
- ShutdownThread.shutdown(mContext, true);
+ mWindowManagerFuncs.shutdown();
break;
}
}
void showGlobalActionsDialog() {
if (mGlobalActions == null) {
- mGlobalActions = new GlobalActions(mContext);
+ mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
}
final boolean keyguardShowing = keyguardIsShowingTq();
mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
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;
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;
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;
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;
// 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;
// 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;
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;
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;
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);
}
}
- nativeInit();
- Power.powerInitNative();
synchronized (mLocks) {
updateNativePowerStateLocked();
// We make sure to start out with the screen on due to user activity.
}
}
+ /**
+ * 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) {
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) {
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.
+ " 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) {
private boolean batteryIsLow() {
return (!mIsPowered &&
- mBatteryService.getBatteryLevel() <= Power.LOW_BATTERY_THRESHOLD);
+ mBatteryService.getBatteryLevel() <= LOW_BATTERY_THRESHOLD);
}
private boolean shouldDeferScreenOnLocked() {
nominalCurrentValue = mScreenBrightnessDim;
break;
case 0:
- nominalCurrentValue = Power.BRIGHTNESS_OFF;
+ nominalCurrentValue = PowerManager.BRIGHTNESS_OFF;
break;
case SCREEN_BRIGHT_BIT:
default:
// 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
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);
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);
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;
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);
private boolean isScreenTurningOffLocked() {
return (mScreenBrightnessAnimator.isAnimating()
- && mScreenBrightnessAnimator.endValue == Power.BRIGHTNESS_OFF);
+ && mScreenBrightnessAnimator.endValue == PowerManager.BRIGHTNESS_OFF);
}
private boolean shouldLog(long time) {
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 {
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;
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;
*/
-package com.android.internal.app;
+package com.android.server.pm;
import android.app.ActivityManagerNative;
import android.app.AlertDialog;
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;
import android.os.storage.IMountShutdownObserver;
import com.android.internal.telephony.ITelephony;
+import com.android.server.PowerManagerService;
+
import android.util.Log;
import android.view.WindowManager;
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);
}
// Shutdown power
Log.i(TAG, "Performing low-level shutdown...");
- Power.shutdown();
+ PowerManagerService.lowLevelShutdown();
}
}
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;
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;
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;
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);
}
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) {
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 \
libinput \
libskia \
libgui \
- libusbhost
+ libusbhost \
+ libsuspend
ifeq ($(WITH_MALLOC_LEAK_CHECK),true)
LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK
#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>
// ----------------------------------------------------------------------------
static jobject gPowerManagerServiceObj;
+static struct power_module* gPowerModule;
static Mutex gPowerManagerLock;
static bool gScreenOn;
// ----------------------------------------------------------------------------
-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) \
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;