您的位置:首页 > 其它

GT9xx系列------gesture mode在framework里的实现

2016-04-19 10:56 369 查看
首先到了inputreader.cpp里的

void KeyboardInputMapper::process(const RawEvent* rawEvent) {

switch (rawEvent->type) {

case EV_KEY: { //走的是这里

int32_t scanCode = rawEvent->code;

int32_t usageCode = mCurrentHidUsage; //这里是0,如果是手势c的话

mCurrentHidUsage = 0;

if (isKeyboardOrGamepadKey(scanCode)) {

processKey(rawEvent->when, rawEvent->value != 0, scanCode, usageCode); //然后走这里

}

break;

}

case EV_MSC: {

if (rawEvent->code == MSC_SCAN) {

mCurrentHidUsage = rawEvent->value;

}

break;

}

case EV_SYN: {

if (rawEvent->code == SYN_REPORT) {

mCurrentHidUsage = 0;

}

}

}

}

然后到了

void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode,

int32_t usageCode) {

int32_t keyCode;

int32_t keyMetaState;

uint32_t policyFlags;

if (getEventHub()->mapKey(getDeviceId(), scanCode, usageCode, mMetaState,

&keyCode, &keyMetaState, &policyFlags)) {

keyCode = AKEYCODE_UNKNOWN;

keyMetaState = mMetaState;

policyFlags = 0;

}

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) { //如果是手势唤醒的话,touch是不上报的,只是报了对应的key而已

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 not down. "

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

// If global meta state changed send it along with the key.

// If it has not changed then we'll use what keymap gave us,

// since key replacement logic might temporarily reset a few

// meta bits for given key.

keyMetaState = newMetaState;

}

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 waking up in your pocket.

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

// each wake key individually.

// TODO: Use the input device configuration to control this behavior more 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();

}

NotifyKeyArgs args(when, getDeviceId(), mSource, policyFlags,

down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,

AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, keyMetaState, downTime);

getListener()->notifyKey(&args); /然后到了inputdispatcher.cpp里的

}

inputdispatcher.cpp里的

void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {

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); //看这个函数

}

在PhoneWindowManager.java里

public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {

case KeyEvent.KEYCODE_GESTURE_C:

case KeyEvent.KEYCODE_GESTURE_E:

case KeyEvent.KEYCODE_GESTURE_S:

case KeyEvent.KEYCODE_GESTURE_V:

case KeyEvent.KEYCODE_GESTURE_W:

case KeyEvent.KEYCODE_GESTURE_Z:{

if(down){

sendGestureBroadcast(keyCode);

}

result &= ~ACTION_PASS_TO_USER;

break;

}

}

但是有个问题

正确的log是

01-02 05:24:51.575 1440 1613 E InputReader: matt-scanCode=46

01-02 05:24:51.575 1440 1613 E InputReader: matt-keyCode=821 ,scanCode=46

01-02 05:24:51.576 1440 1613 E InputReader: matt-scanCode=46

01-02 05:24:51.576 1440 1613 E InputReader: matt-keyCode=821 ,scanCode=46

01-02 05:24:51.576 1440 1613 D InputDispatcher: matt-mPolicy->interceptKeyBeforeQueueing

01-02 05:24:51.576 1440 1613 D WindowManager: matt-interceptKeyTq keycode=821 interactive=false keyguardActive=true policyFlags=2000003

01-02 05:24:51.576 1440 1613 D WindowManager: matt-KEYCODE_GESTURE_C

01-02 05:24:51.586 1440 1613 D InputDispatcher: matt-mPolicy->interceptKeyBeforeQueueing

01-02 05:24:51.586 1440 1613 D WindowManager: matt-interceptKeyTq keycode=821 interactive=true keyguardActive=true policyFlags=22000003

01-02 05:24:51.586 1440 1613 D WindowManager: matt-KEYCODE_GESTURE_C

这里的interactive如果在kl文件里没有在后面加wake的话就两个都是false,policyFlags也是不同就无法唤醒系统

key 46 GESTURE_C VIRTUAL WAKE 所以 这里的后面两个VIRTUAL WAKE 不能缺

在哪里解析了这两个呢,继续看

void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode,

int32_t usageCode) {

uint32_t policyFlags;

if (getEventHub()->mapKey(getDeviceId(), scanCode, usageCode, mMetaState,

&keyCode, &keyMetaState, &policyFlags)) { //这里第一次policyFlags

keyCode = AKEYCODE_UNKNOWN;

keyMetaState = mMetaState;

policyFlags = 0;

}

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

policyFlags |= POLICY_FLAG_WAKE;

}

if (mParameters.handlesKeyRepeat) {

policyFlags |= POLICY_FLAG_DISABLE_KEY_REPEAT;

}

NotifyKeyArgs args(when, getDeviceId(), mSource, policyFlags,

down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,

AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, keyMetaState, downTime); //拼接起来

getListener()->notifyKey(&args);

}

到了status_t EventHub::mapKey(int32_t deviceId,

int32_t scanCode, int32_t usageCode, int32_t metaState,

int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const {

if (!device->keyMap.keyLayoutMap->mapKey(

scanCode, usageCode, outKeycode, outFlags)) {

status = NO_ERROR;

}

}

然后到了

status_t KeyLayoutMap::mapKey(int32_t scanCode, int32_t usageCode,

int32_t* outKeyCode, uint32_t* outFlags) const {

const Key* key = getKey(scanCode, usageCode);

*outFlags = key->flags;

}

然后到了

void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {

uint32_t policyFlags = args->policyFlags;

mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags);

}

public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {

final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;

policyFlags= Integer.toHexString(policyFlags)

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: