在通过读取系统闹铃的provider获取闹铃时间列表时,出现了这个异常:
Caused by: java.lang.SecurityException: Permission Denial:
opening provider com.android.deskclock.provider.ClockProvider from
ProcessRecord{65f49190 8676:com.wisesean.heartbeat.alarm/u0a185}
(pid=8676, uid=10185) that is not exported from uid 10014
at
android.os.Parcel.readException(Parcel.java:1465)
at
android.os.Parcel.readException(Parcel.java:1419)
at
android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2848)
at
android.app.ActivityThread.acquireProvider(ActivityThread.java:4415)
at
android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2207)
at
android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1425)
at
android.content.ContentResolver.query(ContentResolver.java:445)
at
android.content.ContentResolver.query(ContentResolver.java:404)
看到异常以为是某个权限没有,经过查证发现是系统闹铃数据并不允许,其他的进程读取。
AlarmProvider在定义时有android:exported="false"这个标签:
android:exported
Whether the content provider is available for
other applications to use:
true:
The provider is available to other applications. Any application
can use the provider's content URI to access it, subject to the
permissions specified for the provider.
false:
The provider is not available to other applications.
Set android:exported="false" to
limit access to the provider to your applications. Only
applications that have the same user ID (UID) as the provider will
have access to it.
The default value is "true" for
applications that set either orto "16" or
lower. For applications that set either of these attributes
to"17" or
higher, the default is "false".
You can set android:exported="false" and
still limit access to your provider by setting permissions with
the attribute.
看了这里我再到源码里查看了,Alarm的AndroidManifest.xml中的定义,Provider定义如下:
android:authorities="com.android.deskclock"
android:exported="false"
/>
设置为不允许其他应用使用AlarmProvider,因此才报了这个异常,