Security Research Center
Obscure touch detection
Guardsquare recommended technique
Technique summary | |
Technique | Obscure touch detection |
Against | View injections |
Limitations | FLAG_WINDOW_IS_OBSCURED API Level ≥9 (Android ≥2) |
FLAG_WINDOW_IS_PARTIALLY_OBSCURED API Level ≥29 (Android ≥10) |
|
Does not protect against activity injections or opaque view injections | |
Side effects | None |
Recommendations | Usually redundant |
Android API 9 (Android 2) added three valuable methods for detecting overlays based on touch events. The methods onTouch
, onFilterTouchEventForSecurity
, and setFilterTouchesWhenObscured
are made available in API 9 and higher and can be used to detect obscured touch events.
There are two types of obscured touches, named 'partially obscured' and 'obscured'; the latter is true if an overlay is located at the touch location. When an overlay is present, but does not cover a touch, this will be seen as a partially-obscured touch.
The setFilterTouchesWhenObscured
can be used as a method to filter obscured touches specifically. Another way to apply this method to a view is by adding the 'android:filterTouchesWhenObscured'
to the layout attribute.
The onFilterTouchEventForSecurity
can also be used to filter specific MotionEvents
to prevent obscure touches.
Furthermore, the onTouch
can use the FLAG_WINDOW_IS_OBSCURED
flag to detect obscured touches in a specified view. Another onTouch
flag has been added in API 29 (Android 10), introducing FLAG_WINDOW_IS_PARTIALLY_OBSCURED
for more precise detection of partially-obscured touches.