Avoid Screen Overlay Detected for service that uses SYSTEM_ALERT_WINDOW

 ̄綄美尐妖づ 提交于 2020-01-03 03:21:15

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/40475670/avoid-screen-overlay-detected-for-service-that-uses-system-alert-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!