安卓4.2 ACTION_OUTSIDE MotionEvent X和Y返回0自己的应用程序之外 [英] Android 4.2 ACTION_OUTSIDE MotionEvent X and Y return 0 outside of own application

查看:314
本文介绍了安卓4.2 ACTION_OUTSIDE MotionEvent X和Y返回0自己的应用程序之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个TYPE_SYSTEM_ALERT视图,设置标志FLAG_NOT_TOUCH_MODAL和FLAG_WATCH_OUTSIDE_TOUCH,并与WindowManager.addView()把它添加;

I created a TYPE_SYSTEM_ALERT view, set the flags FLAG_NOT_TOUCH_MODAL and FLAG_WATCH_OUTSIDE_TOUCH, and added it with WindowManager.addView();

在我的观点之外触摸到自己的活动,一切工作和MotionEvent.getY()返回正确的值。

When I touch outside of the view onto my own activity, everything works and MotionEvent.getY() returns the correct value.

不过,如果我离开我的活动,并触摸到另一个应用程序,MotionEvent.getY()总是返回0。

However, if I exit my activity and and touch onto another application, MotionEvent.getY() always returns 0.

我不知道,如果这只是发生在4.2与否。

I'm not sure if this only happens on 4.2 or not.

任何帮助将是AP preciated!

Any help would be appreciated!

推荐答案

这是不幸的,这个问题一直悬而未决。5年,但我遇到了你做同样的事情,并找到了原因!

It's unfortunate that this question has remained unanswered for 1.5 years, but I ran into the same thing you did and found out why!

淘源$ C ​​$ C后,我找到了问题的根源:

After scouring the source code, I found the source of the issue:

<一个href="https://github.com/android/platform_frameworks_base/blob/79e0206ef3203a1842949242e58fa8f3c25eb129/services/input/InputDispatcher.cpp#L1417" rel="nofollow">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。这肯定是出于安全方面的工作要做,但我不知道我看到它的设计以减轻威胁的全部范围。而这位先生的here (SO)报告,可以检索2.3.6定位数据,但似乎至少4.x版不会透露给你听(我试过4.1.2,它不工作)。

If the "outside touch" lands in a view that doesn't share its UID (read about it here) with the view that's listening for outside touches, the event dispatcher sets its coordinates to 0,0. This was definitely done for security purposes, but I'm not sure I see the full scope of the threat it's designed to mitigate. And this gentleman here (SO) reports that you can retrieve location data on 2.3.6, but it seems that at least 4.x won't reveal it to you (I tried 4.1.2, it didn't work).

我打开了这个错误票,如果你想跟着它。最起码,文档需要包含此信息...我也想知道,如果这个安全功能实在是有必要的。

I opened up a bug ticket about this if you'd like to follow it. At the very least, the documentation needs to include this information... I would also like to know if this security feature is really necessary.

问题72746:FLAG_WATCH_OUTSIDE_TOUCH没有为ACTION_OUTSIDE返回位置在4.2+ 事件

这篇关于安卓4.2 ACTION_OUTSIDE MotionEvent X和Y返回0自己的应用程序之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆