android power键流程

来源:互联网 发布:最小公倍数 c语言 编辑:程序博客网 时间:2024/05/29 16:56

1. InputDispatcher.cpp

首先void InputDispatcher::notifyKey(const NotifyKeyArgs* args)

void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {#if DEBUG_INBOUND_EVENT_DETAILS    ALOGD("notifyKey - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, action=0x%x, "            "flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, downTime=%lld",            args->eventTime, args->deviceId, args->source, args->policyFlags,            args->action, args->flags, args->keyCode, args->scanCode,            args->metaState, args->downTime);#endif    if (!validateKeyEvent(args->action)) {        return;    }    uint32_t policyFlags = args->policyFlags;    int32_t flags = args->flags;    int32_t metaState = args->metaState;    if ((policyFlags & POLICY_FLAG_VIRTUAL) || (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY)) {        policyFlags |= POLICY_FLAG_VIRTUAL;        flags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY;    }    if (policyFlags & POLICY_FLAG_FUNCTION) {        metaState |= AMETA_FUNCTION_ON;    }    policyFlags |= POLICY_FLAG_TRUSTED;    int32_t keyCode = args->keyCode;    if (metaState & AMETA_META_ON && args->action == AKEY_EVENT_ACTION_DOWN) {        int32_t newKeyCode = AKEYCODE_UNKNOWN;        if (keyCode == AKEYCODE_DEL) {            newKeyCode = AKEYCODE_BACK;        } else if (keyCode == AKEYCODE_ENTER) {            newKeyCode = AKEYCODE_HOME;        }        if (newKeyCode != AKEYCODE_UNKNOWN) {            AutoMutex _l(mLock);            struct KeyReplacement replacement = {keyCode, args->deviceId};            mReplacedKeys.add(replacement, newKeyCode);            keyCode = newKeyCode;            metaState &= ~AMETA_META_ON;        }    } else if (args->action == AKEY_EVENT_ACTION_UP) {        // In order to maintain a consistent stream of up and down events, check to see if the key        // going up is one we've replaced in a down event and haven't yet replaced in an up event,        // even if the modifier was released between the down and the up events.        AutoMutex _l(mLock);        struct KeyReplacement replacement = {keyCode, args->deviceId};        ssize_t index = mReplacedKeys.indexOfKey(replacement);        if (index >= 0) {            keyCode = mReplacedKeys.valueAt(index);            mReplacedKeys.removeItemsAt(index);            metaState &= ~AMETA_META_ON;        }    }    KeyEvent event;    event.initialize(args->deviceId, args->source, args->action,            flags, keyCode, args->scanCode, metaState, 0,            args->downTime, args->eventTime);    mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags);    bool needWake;    { // acquire lock        mLock.lock();        if (shouldSendKeyToInputFilterLocked(args)) {            mLock.unlock();            policyFlags |= POLICY_FLAG_FILTERED;            if (!mPolicy->filterInputEvent(&event, policyFlags)) {                return; // event was consumed by the filter            }            mLock.lock();        }        int32_t repeatCount = 0;        KeyEntry* newEntry = new KeyEntry(args->eventTime,                args->deviceId, args->source, policyFlags,                args->action, flags, keyCode, args->scanCode,                metaState, repeatCount, args->downTime);        needWake = enqueueInboundEventLocked(newEntry);        mLock.unlock();    } // release lock    if (needWake) {        mLooper->wake();    }}

2.com_android_server_input_InputManagerService.cpp


void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,        uint32_t& policyFlags) {    // 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.    bool interactive = mInteractive.load();    if (interactive) {        policyFlags |= POLICY_FLAG_INTERACTIVE;    }    if ((policyFlags & POLICY_FLAG_TRUSTED)) {        nsecs_t when = keyEvent->getEventTime();        JNIEnv* env = jniEnv();        jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);        jint wmActions;        if (keyEventObj) {            wmActions = env->CallIntMethod(mServiceObj,                    gServiceClassInfo.interceptKeyBeforeQueueing,                    keyEventObj, policyFlags);            if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {                wmActions = 0;            }            android_view_KeyEvent_recycle(env, keyEventObj);            env->DeleteLocalRef(keyEventObj);        } else {            ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");            wmActions = 0;        }        handleInterceptActions(wmActions, when, /*byref*/ policyFlags);    } else {        if (interactive) {            policyFlags |= POLICY_FLAG_PASS_TO_USER;        }    }}


0 0
原创粉丝点击