Why in Android O method Settings.canDrawOverlays() returns "false" when user has granted permission to draw overlays and returns to my application? -


i have mdm app parents control child's devices , uses permission system_alert_window display warnings on child's device when forbidden action performed. on devices m+ during installation app checks permission using method:

settings.candrawoverlays(getapplicationcontext())  

and if method return false app opens system dialog user can grant permission:

intent intent = new intent(settings.action_manage_overlay_permission,                     uri.parse("package:" + getpackagename())); startactivityforresult(intent, request_code); 

in android o, when user grant permission , return app pressing button, method candrawoverlays() still return false, until user don't close app , open again or choose in recent apps dialog. tested on latest version of virtual device android o in android studio because haven't real device.

i did little research , additionally check permission appopsmanager:

appopsmanager appopsmgr = (appopsmanager) getsystemservice(context.app_ops_service); int mode = appopsmgr.checkopnothrow("android:system_alert_window", android.os.process.myuid(), getpackagename()); log.d(tag, "android:system_alert_window: mode=" + mode); 

and so:

  • when application not have permission, mode "2" (mode_errored) (candrawoverlays() returns false) when user
  • granted permission , returned application, mode "1" (mode_ignored) (candrawoverlays() returns false)
  • and if reopen app, mode "0" (mode_allowed) (candrawoverlays() returns true)

please, can explain behavior me? can rely on mode == 1 of operation "android:system_alert_window" , assume user has granted permission?

i've found problems checkop too. in case have flow allows redirect settings when permission not set. , appops set when redirecting settings.

assuming appops callback called when changed , there 1 switch, can changed. means, if callback called, user has grant permission.

if (version.sdk_int >= version_codes.o &&                 (appopsmanager.opstr_system_alert_window.equals(op) &&                       packagename.equals(mcontext.getpackagename()))) {     // proceed app } 

after app restored, checking candrawoverlays() starts worked me. sure restart app , check if permission granted via standard way.

it's not perfect solution, should work, till know more google.

edit asked google: https://issuetracker.google.com/issues/66072795


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -