1

I am trying to use the new Android 6's permission model for

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

but i get the exception

java.lang.SecurityException: uid 10153 does not have android.permission.UPDATE_APP_OPS_STATS

in the onDataSetChanged() of my RemoteViewsFactory when I call

Settings.canDrawOverlays(mContext))

Log:

java.lang.SecurityException: uid 10153 does not have android.permission.UPDATE_APP_OPS_STATS. at android.os.Parcel.readException(Parcel.java:1599) at android.os.Parcel.readException(Parcel.java:1552) at com.android.internal.app.IAppOpsService$Stub$Proxy.checkOperation(IAppOpsService.java:327) at android.app.AppOpsManager.checkOpNoThrow(AppOpsManager.java:1523) at android.provider.Settings.isCallingPackageAllowedToPerformAppOpsProtectedOperation(Settings.java:8425) at android.provider.Settings.isCallingPackageAllowedToDrawOverlays(Settings.java:8385) at android.provider.Settings.canDrawOverlays(Settings.java:1432)

Can someone explain to me this exception?

UPDATE

Temporarily solved calling canDrawOverlays() from a service started from inside onDataSetChanged() of the RemoteViewsFactory

GPack
  • 2,494
  • 4
  • 19
  • 50
  • That's odd. Is your app uid 10153? What device or emulator are you using to test this? – CommonsWare Oct 05 '15 at 18:39
  • I get this on real device Nexus 5 with the M Preview, and the same on emulator Nexus 5 with API 23. – GPack Oct 05 '15 at 18:42
  • The images for 6.0 final [were released today](https://developers.google.com/android/nexus/images), so you might try updating to 6.0 final on the Nexus 5 and see what happens. – CommonsWare Oct 05 '15 at 18:46
  • Another thing that you might try is calling `canDrawOverlays()` from someplace else (e.g., launcher activity) and see what happens. I haven't used the method yet myself, though I need to soonish. – CommonsWare Oct 05 '15 at 18:57
  • In the same app calling canDrawOverlays() from an Activity works fine. I will try on final release of Android 6 soon. – GPack Oct 06 '15 at 07:41
  • skipped the exception calling canDrawOverlays() from a service started from inside onDataSetChanged() of the RemoteViewsFactory – GPack Oct 06 '15 at 10:40
  • @GPack i call this method inside my service but still have exception. In your case calling from service doesn't produce exception? – x90 Mar 14 '16 at 13:53
  • @x90 yes moving the call inside a service doesnt get the exception for me – GPack Mar 14 '16 at 15:08

1 Answers1

0

Settings.canDrawOverlays,AppOpsManager.checkOpNoThrow and Setting.System.canWrite can cause this kind of crashes in various cases (probably only on Android 6.x) , as reported here:

The workaround I've found is to run them all on the UI thread using a handler, and wait for the result on the thread you are working on. Here's an example for the case of extending of NotificationListenerService :

public void onNotificationPosted(StatusBarNotification sbn) {
   final Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            //do the check of Settings.canDrawOverlays here.
            // notify that the result of the check was done
        }
    });
    //wait for result of the handler
android developer
  • 114,585
  • 152
  • 739
  • 1,270