I have implemented SyncAdapter to perform sync of items in application. This adapter is invoked correctly by Android when sync is requested either programmatically or automatically.
When I try to cancel the sync operation manually by deselecting the check box under Accounts and sync setting >{myappccount} > Data and Synchronisation > {app item} , my sync adapters onSyncCanceled is also get called correctly.
But when I my app try to read some internal setting through content provider query , it receives “java.lang.SecurityException: Permission Denial”. Although same query works well during normal execution of application or during sync .
Below is stack trace.
java.lang.SecurityException: Permission Denial: reading com.my.applications.sync.content.MySettingProvider uri content://com.my.applications.sync.provider.mysetting/currentstateid from pid=0, uid=1000 requires null
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:307)
at android.content.ContentProvider$Transport.query(ContentProvider.java:186)
at android.content.ContentResolver.query(ContentResolver.java:262)
at com.my.applications.sync.service.MysyncService.getCurrentServiceUri(MysyncService.java:442)
at com.my.applications.sync.service.MysyncService.cancelSync(MysyncService.java:1723)
at com.my.applications.sync.syncadapter.OtherSyncAdapter.onSyncCanceled(OtherSyncAdapter.java:51)
at android.content.AbstractThreadedSyncAdapter$ISyncAdapterImpl.cancelSync(AbstractThreadedSyncAdapter.java:121)
at android.content.ISyncAdapter$Stub.onTransact(ISyncAdapter.java:78)
at android.os.Binder.execTransact(Binder.java:320)
at dalvik.system.NativeStart.run(Native Method)
Do I need to add any permission for my internal content provider?
It looks from your stack trace that you’ve declared a
readPermissionon yourContentProvider. WhenonSyncCanceled(..)is called on your app it’s an RPC call from the sync manager (typically) – and the Sync manager is not likely to hold thereadPermission.Try the following in
#onCancelSync(..)to run your cancel code without the callers pid/uid involved:Br,
Jens