4

Some time ago with Android 11 SYSTEM_ALERT_WINDOW draw-over-applications touch behaviour was limited with a number of exceptions.

  • Interactions within your app.
  • Accessibility windows
  • Input method editor (IME) windows
  • Assistant windows
  • Completely transparent windows. The alpha property is 0.0 for the window.
  • Sufficiently translucent system alert windows. (0.8)

If I set my view opacity to be <0.8 it passes-through touches as expected - except for SurfaceView. Because my application uses a full-screen surface view drawn over other apps (overlay), the limitation basically blocks any pass-through touches.

Is this a technical limitation or is there a workaround for this new Untrusted touch events are blocked policy when SurfaceView is used?

Arturs Vancans
  • 4,531
  • 14
  • 47
  • 76
  • Can you please at least share the code sample of how do you instantiate your overlay? Like LayoutParams and adding view to the WindowManager? Also sharing the logs like "Untrusted touch ...." from logcat would really help to understand what's going on. Lastly, what device are you testing on? Some nuances of surface flinger interactions may differ across devices. – Amaksoft Jun 14 '23 at 09:04

2 Answers2

0

Yes, this is a technical limitation. SurfaceView is a view that provides direct access to the underlying Surface object, which allows it to render its content without going through the normal view hierarchy. This makes it possible for SurfaceView to draw its content on top of other apps, but it also means that SurfaceView cannot receive touch events from other apps.

There is no workaround for this limitation. The only way to get touch events from other apps on a SurfaceView is to use a different view that does not have this limitation, such as a LinearLayout or a FrameLayout.

If you need to use SurfaceView, you can work around the limitation by using a different view to receive touch events. For example, you could create a LinearLayout or a FrameLayout that contains the SurfaceView, and then use the LinearLayout or FrameLayout to receive touch events.

Harsh Patel
  • 688
  • 2
  • 5
  • 16
  • That's what I did. The problem is, because of the nature of my app, my `SurfaceView` is full screen. And then I apply an invisible `FrameLayout` over a small portion of `SurfaceView` to catch user touch input. It was working well, but the new Android limitation doesn't let touch events pass through SurfaceView anymore. Now this full-screen SurfaceView is blocking the whole screen. – Arturs Vancans Jun 17 '23 at 05:09
  • @Harsh Patel -- Please provide some references for your statements. – Krokomot Jun 30 '23 at 12:53
  • 2
    Asked ChatGPT: "*Apologies for the confusion. Upon reviewing my previous responses, I can confirm that I did write the paragraph you provided.*" So, whether that is correct or not -- without any references your answer is neither traceable nor comprehensible, and therefore not adequate https://stackoverflow.com/help/referencing. The usage of AIs like ChatGPT is with good reasons not allowed on StackOverflow https://stackoverflow.com/help/gpt-policy. – Krokomot Jun 30 '23 at 13:30
  • I don't use chat GPT. Even I haven't created account on it yet. @Krokomot – Harsh Patel Jun 30 '23 at 15:27
  • Super! I tend to mistrust machines, they are so insidious! Remains a question -- Could you please refer to the sources of your insights? Or elaborate on your experience? – Krokomot Jun 30 '23 at 18:20
  • I understand the concern, I have total 7 years of experience in Android and almost 4 years of experience in React Native. In these time, I came across many problems like this. And some problems and solution not on internet. I knew this things as I worked with Accessibility feature in few apps for the clients, So I shared what I knew. @Krokomot – Harsh Patel Jul 01 '23 at 03:15
-1

Android 11 made changes to SYSTEM_ALERT_WINDOW's touch behaviour, affecting SurfaceView overlays. As a workaround, consider using TextureView, which doesn't have the same limitations. Alternatively, try using WindowManager.LayoutParams's FLAG_NOT_TOUCHABLE flag to block touch events.

Please check official docs if you want to know more https://developer.android.com/reference/android/view/SurfaceView https://developer.android.com/reference/android/view/TextureView