上一篇《Android AccessibilityService拦截不到VR眼镜BACK键分析》我们拦截VR返回键出现了问题,这一篇我们从源码中进行分析。
《Android 源码分析鼠标事件传递》介绍了鼠标事件从底层到View的传递过程,那么我们直接从View的源码中分析
public boolean dispatchKeyEvent(KeyEvent event) {
if (mInputEventConsistencyVerifier != null) {
mInputEventConsistencyVerifier.onKeyEvent(event, 0);
}
// Give any attached key listener a first crack at the event.
//noinspection SimplifiableIfStatement
ListenerInfo li = mListenerInfo;
if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED
&& li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) {
return true;
}
if (event.dispatch(this, mAttachInfo != null
? mAttachInfo.mKeyDispatchState : null, this)) {
return true;
}
if (mInputEventConsistencyVerifier != null) {
mInputEventConsistencyVerifier.onUnhandledEvent(event, 0);
}
return false;
}
public final boolean dispatch(Callback receiver, DispatcherState state,
Object target) {
switch (mAction) {
case ACTION_DOWN: {
mFlags &= ~FLAG_START_TRACKING;
if (DEBUG) Log.v(TAG, "Key down to " + target + " in " + state
+ ": " + this);
boolean res = receiver.onKeyDown(mKeyCode, this);
if (state != null) {
if (res && mRepeatCount == 0 && (mFlags&FLAG_START_TRACKING) != 0) {
if (DEBUG) Log.v(TAG, " Start tracking!");
state.startTracking(this, target);
} else if (isLongPress() && state.isTracking(this)) {
try {
if (receiver.onKeyLongPress(mKeyCode, this)) {
if (DEBUG) L

本文深入探讨了Android AccessibilityService在处理VR眼镜Key事件时遇到的问题,通过源码分析发现,BACK键在VR模式下有特殊处理。在View体系中,onKeyUp事件触发performClick,但VR的BACK键并未通过常规方式被AccessibilityService捕获,说明存在独立的处理机制。同时,文章指出AccessibilityEvent主要关注View焦点、点击和窗口变化,而非Key事件。
最低0.47元/天 解锁文章
557

被折叠的 条评论
为什么被折叠?



