13

Is there a way for an app to:

  1. check if there exists screen overlay(s) on top of it, and
  2. figure out what package name owns the overlay(s)?

I know Android M and above is able to detect screen overlays when in the permissions page and deny permission changes whenever it detects screen overlays, but are developers able to achieve the same things in the app layer?

user1118764
  • 9,255
  • 18
  • 61
  • 113
  • good question! It's especially important for apps that are showing a login screen. See: http://www.androidpolice.com/2017/05/25/recently-revealed-cloak-dagger-android-attack-uses-overlays-accessibility-services-deceive-users/ – Someone Somewhere May 26 '17 at 16:15
  • I know there are ways to detect Activity based overlay attacks, as well as some View based overlays (such as using system overlays, toast notification overlays, etc), but they don't cover all overlay types. – user1118764 May 29 '17 at 01:25
  • @user1364419 pointed out https://github.com/geeksonsecurity/android-overlay-protection – shkschneider Aug 21 '18 at 12:35
  • Possible duplicate of [System Overlay Detector](https://stackoverflow.com/questions/40076758/system-overlay-detector) – Sam Mar 09 '19 at 11:06

1 Answers1

3

You can detect overlays by checking for the MotionEvent.FLAG_WINDOW_IS_OBSCURED flag when the user touches one of your Views.

final View.OnTouchListener filterTouchListener = new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // Filter obscured touches by consuming them.
        if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                Toast.makeText(v.getContext(), "Overlay detected", Toast.LENGTH_SHORT).show();
            }
            return true;
        }
        return false;
    }
};

yourButton.setOnTouchListener(filterTouchListener);

Source: Android M's settings app

However, I don't think it's possible to detect which app owns the overlay.

Sam
  • 40,644
  • 36
  • 176
  • 219