androidandroid-permissionssystem-alert-window

Avoid Screen Overlay Detected for service that uses SYSTEM_ALERT_WINDOW


My app main usage is overlay, the overlay is running from a service.

Android Security add the nice "Screen Overlay Detected"

I want to avoid "Screen Overlay Detected" when user tries to change permissions. so... I've add an AccessiblityService that detects:

if ( event.getPackageName().equals("com.google.android.packageinstaller") ){
    stopService(myServiceIntent);
}

However, even now I see this message popping. (when my service is stopped...).

I saw Twilight does it without problem.

What am I missing?

p.s. - I've also tried building a signed apk but saw exact same behavior.


Solution

  • It seems I've been able to resolve this.

    a) stopService isn't assured your service will be stopped. as described here :

    It will not be destroyed until all of these bindings are removed. See > the Service documentation for more details on a service's lifecycle.

    b) I was able to kill my service by sending intent that called stopSelf(). However process killing/starting can be slow.

    c) Best resolution: so it seems Android checks for view visibility. no need to kill services or do anything more complicated.

    Current way I'm doing it: - AccessibilityService (already used by my app) monitor "com.google.android.packageinstaller" though it can be refined to class: "com.android.packageinstaller.permission.ui.ManagePermissionsActivity"