inputreader是如何将事件传递到inputdispathnotifykey里面去的

inputreader是如何将事件传递到inputdispath::notifykey里面去的?在inputdispatcher按键的派发的step6中遗留下了这个问题,现在回过头来学习下:

STEP6

voidKeyboardInputMapper::processKey(nsecs_twhen, bool down, int32_t keyCode,

       int32_tscanCode, uint32_t policyFlags) {

。。。。。。

 

   NotifyKeyArgsargs(when, getDeviceId(), mSource, policyFlags,

           down? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,

           AKEY_EVENT_FLAG_FROM_SYSTEM,keyCode, scanCode, newMetaState, downTime);

getListener()->notifyKey(&args);

//这个notifyKey 应该是对应InputDispatcher.cpp中的notifykey(),具体如何通讯的,待学习。

   ALOGD_READER("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);

}

 

getListener()->notifyKey(&args);这里我们继续往里面看看。

 

STEP 1:

\frameworks\native\services\inputflinger\ InputReader.cpp

 

voidKeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,

       int32_t scanCode, uint32_t policyFlags) {

 

   if (down) {

       // Rotate key codes according to orientation if needed.

       if (mParameters.orientationAware && mParameters.hasAssociatedDisplay){

           keyCode = rotateKeyCode(keyCode, mOrientation);

       }

 

       // Add key down.

       ssize_t keyDownIndex = findKeyDown(scanCode);

       if (keyDownIndex >= 0) {

           // key repeat, be sure to use same keycode as before in case of rotation

           keyCode = mKeyDowns.itemAt(keyDownIndex).keyCode;

       } else {

           // key down

           if ((policyFlags & POLICY_FLAG_VIRTUAL)

                    &&mContext->shouldDropVirtualKey(when,

                            getDevice(),keyCode, scanCode)) {

                return;

           }

           if (policyFlags & POLICY_FLAG_GESTURE) {

                mDevice->cancelTouch(when);

           }

 

           mKeyDowns.push();

           KeyDown& keyDown = mKeyDowns.editTop();

           keyDown.keyCode = keyCode;

           keyDown.scanCode = scanCode;

       }

 

       mDownTime = when;

    }else {

       // Remove key down.

       ssize_t keyDownIndex = findKeyDown(scanCode);

       if (keyDownIndex >= 0) {

           // key up, be sure to use same keycode as before in case of rotation

           keyCode = mKeyDowns.itemAt(keyDownIndex).keyCode;

           mKeyDowns.removeAt(size_t(keyDownIndex));

       } else {

            // key was not actually down

           ALOGI("Dropping key up from device %s because the key was notdown.  "

                    "keyCode=%d,scanCode=%d",

                    getDeviceName().string(),keyCode, scanCode);

           return;

       }

    }

 

   int32_t oldMetaState = mMetaState;

   int32_t newMetaState = updateMetaState(keyCode, down, oldMetaState);

   bool metaStateChanged = oldMetaState != newMetaState;

   if (metaStateChanged) {

       mMetaState = newMetaState;

       updateLedState(false);

    }

 

   nsecs_t downTime = mDownTime;

 

   // Key down on external an keyboard should wake the device.

   // We don't do this for internal keyboards to prevent them from wakingup in your pocket.

   // For internal keyboards, the key layout file should specify the policyflags for

   // each wake key individually.

   // TODO: Use the input device configuration to control this behaviormore finely.

   if (down && getDevice()->isExternal()) {

        policyFlags |= POLICY_FLAG_WAKE;

    }

 

   if (mParameters.handlesKeyRepeat) {

       policyFlags |= POLICY_FLAG_DISABLE_KEY_REPEAT;

    }

 

   if (metaStateChanged) {

       getContext()->updateGlobalMetaState();

    }

 

   if (down && !isMetaKey(keyCode)) {

       getContext()->fadePointer();

    }

 

    NotifyKeyArgsargs(when, getDeviceId(), mSource, policyFlags,

            down ? AKEY_EVENT_ACTION_DOWN :AKEY_EVENT_ACTION_UP,

            AKEY_EVENT_FLAG_FROM_SYSTEM,keyCode, scanCode, newMetaState, downTime);

    getListener()->notifyKey(&args);/*主要是把这个getListener 搞清楚,起对应的notifykey就知道是哪里了。*/

   ALOGD_READER("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);

}

 

 

STEP 2:

\frameworks\native\services\inputflinger\ InputReader.cpp

 

InputListenerInterface*InputReader::ContextImpl::getListener() {

   return mReader->mQueuedListener.get();

}

 

 

/*

mQueuedListener是从哪里来的呢?在mReader的构造函数中,通过参数的形式传进来。

*/

STEP 3:

 

 

   InputReader(const sp<EventHubInterface>& eventHub,

           const sp<InputReaderPolicyInterface>& policy,

           constsp<InputListenerInterface>& listener);

/*

mReader创建的的时候,通过参数的形式传递进来的。

*/

STEP 4:

\frameworks\native\services\inputflinger\ InputManager.cpp

/*mReader的创建*/

InputManager::InputManager(

       constsp<EventHubInterface>& eventHub,

       const sp<InputReaderPolicyInterface>& readerPolicy,

       const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) {

   mDispatcher = new InputDispatcher(dispatcherPolicy);

    mReader = new InputReader(eventHub,readerPolicy, mDispatcher);/*就是这里传进去的*/

   initialize();

}

 

/*

所以这个mQueuedListener就是mDispatcher。自然也就是调用的是mDispatchernotifykey了。后面的就不继续分析了。这里只是说明标题的问题“inputreader是如何将事件传递到inputdispath::notifykey里面去的

*/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值