http://blog.chinaunix.net/uid-13995546-id-2850215.html
1) power management api :
public void goToSleep(long time) |
public void setBacklightBrightness(int brightness) |
public int getSupportedWakeLockFlags() |
public boolean isScreenOn() |
public void reboot(String reason) |
power = new PowerManagerService(); |
ServiceManager.addService(Context.POWER_SERVICE, power); |
// only initialize the power service after we have started the |
private final BrightnessState mScreenBrightness |
- void NativeInputManager::interceptKeyBeforeQueueing(nsecs_t when,
- int32_t deviceId, int32_t action, int32_t &flags,
- int32_t keyCode, int32_t scanCode, uint32_t& policyFlags) {
- #if DEBUG_INPUT_DISPATCHER_POLICY
- LOGD("interceptKeyBeforeQueueing - when=%lld, deviceId=%d, action=%d, flags=%d, "
- "keyCode=%d, scanCode=%d, policyFlags=0x%x",
- when, deviceId, action, flags, keyCode, scanCode, policyFlags);
- #endif
-
- if ((policyFlags & POLICY_FLAG_VIRTUAL) || (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY)) {
- policyFlags |= POLICY_FLAG_VIRTUAL;
- flags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY;
- }
-
- // Policy:
- // - Ignore untrusted events and pass them along.
- // - Ask the window manager what to do with normal events and trusted injected events.
- // - For normal events wake and brighten the screen if currently off or dim.
- if ((policyFlags & POLICY_FLAG_TRUSTED)) {
- const int32_t WM_ACTION_PASS_TO_USER = 1;
- const int32_t WM_ACTION_POKE_USER_ACTIVITY = 2;
- const int32_t WM_ACTION_GO_TO_SLEEP = 4;
-
- bool isScreenOn = this->isScreenOn();
- bool isScreenBright = this->isScreenBright();
-
- JNIEnv* env = jniEnv();
- jint wmActions = env->CallIntMethod(mCallbacksObj,
- gCallbacksClassInfo.interceptKeyBeforeQueueing,
- when, action, flags, keyCode, scanCode, policyFlags, isScreenOn);
- if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
- wmActions = 0;
- }
-
- if (!(flags & POLICY_FLAG_INJECTED)) {
- if (!isScreenOn) {
- policyFlags |= POLICY_FLAG_WOKE_HERE;
- flags |= AKEY_EVENT_FLAG_WOKE_HERE;
- }
-
- if (!isScreenBright) {
- policyFlags |= POLICY_FLAG_BRIGHT_HERE;
- }
- }
-
- if (wmActions & WM_ACTION_GO_TO_SLEEP) {
- android_server_PowerManagerService_goToSleep(when);
- }
-
- if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
- android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
- }
-
- if (wmActions & WM_ACTION_PASS_TO_USER) {
- policyFlags |= POLICY_FLAG_PASS_TO_USER;
- }
- } else {
- policyFlags |= POLICY_FLAG_PASS_TO_USER;
- }
- }