Avoid Screen Overlay Detected for service that use

2019-06-04 18:01发布

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.

2条回答
爷、活的狠高调
2楼-- · 2019-06-04 18:35

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"

  • Once detected in this class, we send Intent to "duck", and when we're out, we send another intent that we're back on.

  • The service handles those calls by:

    [ourView].setVisibility(View.INVISIBLE); // when permission settings shown

    [ourView].setVisibility(View.VISIBLE); // when normal flow

查看更多
一纸荒年 Trace。
3楼-- · 2019-06-04 18:42

As long as Android 6.x is buggy on some devices where this "overlay alert" is displayed without any reason (on 2 to 5% of the devices according to my analytics data), the best solution is to avoid the whole permission process by defining the targetSdk to 22. Take care that you can't downgrade the target sdk for a new version or this will induce a INSTALL_FAILED_PERMISSION_DOWNGRADE error when the user updates requiring an unisntall/install of the app.

查看更多
登录 后发表回答