3

我创建了一个TYPE_SYSTEM_ALERT视图,设置了标志FLAG_NOT_TOUCH_MODALFLAG_WATCH_OUTSIDE_TOUCH,并用WindowManager.addView().

当我在视图之外触摸自己的活动时,一切正常并MotionEvent.getY()返回正确的值。

但是,如果我退出我的活动并触摸另一个应用程序,则MotionEvent.getY()始终返回 0。

我不确定这是否只发生在 4.2 上。

任何帮助,将不胜感激!

4

1 回答 1

9

不幸的是,这个问题已经 1.5 年没有答案了,但我遇到了和你一样的事情,并找出了原因!

翻遍了源码,找到了问题的根源:

https://github.com/android/platform_frameworks_base/blob/79e0206ef3203a1842949242e58fa8f3c25eb129/services/input/InputDispatcher.cpp#L1417

// Check whether windows listening for outside touches are owned by the same UID. If it is
// set the policy flag that we will not reveal coordinate information to this window.
if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
    sp<InputWindowHandle> foregroundWindowHandle =
            mTempTouchState.getFirstForegroundWindowHandle();
    const int32_t foregroundWindowUid = foregroundWindowHandle->getInfo()->ownerUid;
    for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
        const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
        if (touchedWindow.targetFlags & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) {
            sp<InputWindowHandle> inputWindowHandle = touchedWindow.windowHandle;
            if (inputWindowHandle->getInfo()->ownerUid != foregroundWindowUid) {
                mTempTouchState.addOrUpdateWindow(inputWindowHandle,
                        InputTarget::FLAG_ZERO_COORDS, BitSet32(0));
            }
        }
    }
}

如果“外部触摸”位于不与正在侦听外部触摸的视图共享其 UID(在此处阅读)的视图中,则事件调度程序将其坐标设置为 0,0。这绝对是出于安全目的,但我不确定我是否看到了它旨在减轻的威胁的全部范围。而这里的这位先生(SO)报告说你可以在2.3.6上检索位置数据,但似乎至少4.x不会向你透露(我试过4.1.2,它没有工作)。

如果您想关注它,我打开了一张关于此的错误票。至少,文档需要包含这些信息......我还想知道这个安全功能是否真的有必要。

问题 72746:FLAG_WATCH_OUTSIDE_TOUCH 在 4.2+ 上不返回 ACTION_OUTSIDE 事件的位置

于 2014-07-01T03:22:39.053 回答