diff options
author | Jeff Brown <jeffbrown@google.com> | 2012-05-11 18:42:42 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2012-05-11 18:42:42 -0700 |
commit | 7304c343821309dd15f769b18f1de2fa43751573 (patch) | |
tree | 37a1b20d78ee47ed7356c39d00bd1529989cea22 /services/jni | |
parent | 888da152ece9a8cfe62fad9e7d1a43e792c41e2f (diff) | |
download | frameworks_base-7304c343821309dd15f769b18f1de2fa43751573.zip frameworks_base-7304c343821309dd15f769b18f1de2fa43751573.tar.gz frameworks_base-7304c343821309dd15f769b18f1de2fa43751573.tar.bz2 |
Move power HAL interactions to PowerManagerService.
This refactoring sets the stage for a follow-on change that
will make use additional functions of the power HAL.
Moved functionality from android.os.Power into PowerManagerService.
None of these functions make sense being called outside of the
system server. Moving them to the PowerManagerService makes it
easier to ensure that the power HAL is initialized exactly once.
Similarly, moved ShutdownThread out of the policy package and into
the services package where it can tie into the PowerManagerService
as needed.
Bug: 6435382
Change-Id: I958241bb124fb4410d96f5d5eb00ed68d60b29e5
Diffstat (limited to 'services/jni')
-rw-r--r-- | services/jni/Android.mk | 8 | ||||
-rw-r--r-- | services/jni/com_android_server_PowerManagerService.cpp | 103 |
2 files changed, 102 insertions, 9 deletions
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) \ |