diff options
Diffstat (limited to 'services/jni/com_android_server_PowerManagerService.cpp')
| -rw-r--r-- | services/jni/com_android_server_PowerManagerService.cpp | 112 |
1 files changed, 105 insertions, 7 deletions
diff --git a/services/jni/com_android_server_PowerManagerService.cpp b/services/jni/com_android_server_PowerManagerService.cpp index ce80c1f..a47f8fd 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; @@ -76,6 +83,13 @@ bool android_server_PowerManagerService_isScreenBright() { } void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType) { + if (gPowerModule) { + // Tell the power HAL when user activity occurs. + if (gPowerModule->powerHint) { + gPowerModule->powerHint(gPowerModule, POWER_HINT_INTERACTION, NULL); + } + } + if (gPowerManagerServiceObj) { // Throttle calls into user activity by event type. // We're a little conservative about argument checking here in case the caller @@ -112,33 +126,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) \ @@ -175,6 +271,8 @@ int register_android_server_PowerManagerService(JNIEnv* env) { } gScreenOn = true; gScreenBright = true; + gPowerManagerServiceObj = NULL; + gPowerModule = NULL; return 0; } |
