Android 11 SYSTEM_ALERT_WINDOW behaviour changes with SurfaceView

491 Views Asked by At

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?

2

There are 2 best solutions below

1
Harsh Patel On

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.

0
Muhammad Tahir Qaiser On

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