title: Marshmallow: Can't execute Settings.System.canWrite(Context) from a service
body: <p>I have a NotificationListener service running in the background and it throws an exception when I execute Settings.System.canWrite(Settings.java:3742)</p>
  
  <pre><code>12-03 18:25:33.490    2754-2771/? W/System.err﹕ java.lang.SecurityException: uid 10057 does not have android.permission.UPDATE_APP_OPS_STATS.
  12-03 18:25:33.490    2754-2771/? W/System.err﹕ at android.os.Parcel.readException(Parcel.java:1599)
  12-03 18:25:33.490    2754-2771/? W/System.err﹕ at android.os.Parcel.readException(Parcel.java:1552)
  12-03 18:25:33.490    2754-2771/? W/System.err﹕ at com.android.internal.app.IAppOpsService$Stub$Proxy.checkOperation(IAppOpsService.java:327)
  12-03 18:25:33.490    2754-2771/? W/System.err﹕ at android.app.AppOpsManager.checkOpNoThrow(AppOpsManager.java:1536)
  12-03 18:25:33.490    2754-2771/? W/System.err﹕ at android.provider.Settings.isCallingPackageAllowedToPerformAppOpsProtectedOperation(Settings.java:8425)
  12-03 18:25:33.490    2754-2771/? W/System.err﹕ at android.provider.Settings.isCallingPackageAllowedToWriteSettings(Settings.java:8320)
  12-03 18:25:33.490    2754-2771/? W/System.err﹕ at android.provider.Settings$System.canWrite(Settings.java:3742)
  </code></pre>
  
  <p>Is this because the provided Context is a service because this doesn't happen when called from an activity.</p>