2019년 3월 25일 월요일

[Android] KeyEvent.KEYCODE_NOTIFICATION 을 Application으로 전달하지 않기

 #Android   KeyEvent.KEYCODE_NOTIFICATION 을 Application으로 전달하지 않기

1. 특정 KeyCode에 대해 POLICY_FLAG_PASS_TO_USER  flag 제거

1.1 Flag 정의
path : frameworks/native/include/input/input.h
    // Indicates that the event should be dispatched to applications.
    // The input event should still be sent to the InputDispatcher so that it can see all
    // input events received include those that it will not deliver.
    POLICY_FLAG_PASS_TO_USER = 0x40000000,


1.2 수정사항
path : rk3066/frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp
void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) {
    ......
        handleInterceptActions(wmActions, when, /byref/ policyFlags);
    ......
    if (keyEvent->getKeyCode() == /KeyEvent.KEYCODE_NOTIFICATION/83 )
        policyFlags &= ~POLICY_FLAG_PASS_TO_USER;
}

void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
        uint32_t& policyFlags) {
    if (wmActions & WM_ACTION_GO_TO_SLEEP) {
#if DEBUG_INPUT_DISPATCHER_POLICY
        ALOGD("handleInterceptActions: Going to sleep.");
#endif
        android_server_PowerManagerService_goToSleep(when);
    }

    if (wmActions & WM_ACTION_WAKE_UP) {
#if DEBUG_INPUT_DISPATCHER_POLICY
        ALOGD("handleInterceptActions: Waking up.");
#endif
        android_server_PowerManagerService_wakeUp(when);
    }

    if (wmActions & WM_ACTION_PASS_TO_USER) {
        policyFlags |= POLICY_FLAG_PASS_TO_USER;
    } else {
#if DEBUG_INPUT_DISPATCHER_POLICY
        ALOGD("handleInterceptActions: Not passing key to user.");
#endif
    }
}

2. Error case
- 현상 : KeyEvent 제거 -> Wakeup 불가.

path : rk3066/frameworks/base/core/jni/android_view_KeyEvent.cpp
jobject android_view_KeyEvent_fromNative(JNIEnv* env, const KeyEvent* event) {
    if ( event->getKeyCode() == XXX )
        return NULL;
}

댓글 없음:

댓글 쓰기