AccountManager.addAccountExplicitly()上的SecurityException用于共享的android模块

时间:2015-08-10 10:52:14

标签: android android-authenticator android-securityexception

我一直在关注Android的Creating a Sync Adapter (BasicSyncAdapter)以开始我自己的同步服务逻辑。

问题:在调用AccountManager.addAccountExplicitly()时,会引发SecurityException,声称来电者与身份验证员UID之间不匹配:

java.lang.SecurityException: caller uid 10048 is different than the authenticator's uid
        at android.os.Parcel.readException(Parcel.java:1425)
        at android.os.Parcel.readException(Parcel.java:1379)
        at android.accounts.IAccountManager$Stub$Proxy.addAccount(IAccountManager.java:580)
        at android.accounts.AccountManager.addAccountExplicitly(AccountManager.java:565)

应用程序/库结构:我的应用程序分为两个模块(gradle / android studio项目):

  • Android库(com.example.mylib),其中包含定义同步服务,适配器,身份验证器等所需的源和xml。
  • Android应用程序:测试/演示库功能(com.example.mylib.app)。

这似乎很相关,因为这两个应用程序是不同的包。出于这个原因我在两个项目清单中设置了sharedUserId属性(根据下面的packages.xml代码段,它似乎设置正确)

所有必需的权限似乎都设置正确(即:READ_SYNC_SETTINGSWRITE_SYNC_SETTINGSAUTHENTICATE_ACCOUNTSUSE_CREDENTIALS,{{1} }和GET_ACCOUNTS)。

我还为清单属性设置了显式值(而不是通过MANAGE_ACCOUNTS扩展) - 见下文。

还尝试了干净的构建,干净的安装,重新启动等。

技术细节/转储如下。

环境/设置

  • 使用Android Studio(版本1.3)
  • @string/...为22(两个项目)
  • 在模拟器上运行(genymotion)

系统logcat转储

根据this question中提到的建议,我已检查 Android系统Logcat 似乎也没问题(直到遇到异常):

之前(干净安装):

targetSdkVersion

单步执行08-10 10:43:39.375 9015-9031/system_process D/PackageManager﹕ New package installed in /data/app/example.mylib.app-1.apk 08-10 10:43:39.387 9015-9027/system_process D/PackageManager﹕ generateServicesMap(android.accounts.AccountAuthenticator): 3 services unchanged 08-10 10:43:39.387 9015-9027/system_process D/PackageManager﹕ generateServicesMap(android.content.SyncAdapter): 6 services: New service added: ServiceInfo: SyncAdapterType {name=com.example.mylib.provider, type=com.example.mylib.provider.ACCOUNT, userVisible=false, supportsUploading=false, isAlwaysSyncable=true, allowParallelSyncs=false, settingsActivity=null}, ComponentInfo{com.example.mylib.app/com.example.mylib.service.SyncService}, uid 10048 08-10 10:43:39.739 9015-9015/system_process I/ActivityManager﹕ START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.mylib.app/.MyActivity u=0} from pid 19237 08-10 10:43:39.791 9015-9025/system_process I/ActivityManager﹕ Start proc com.example.mylib.app for activity com.example.mylib.app/.MyActivity: pid=19247 uid=10048 gids={3003, 1028}

addAccountExplicitly()

包转储

来自08-10 10:45:56.479 9015-9270/system_process V/AccountManagerService﹕ addAccount: Account {name=100, type=com.example.mylib.provider.ACCOUNT}, caller's uid 10048, pid 19247 08-10 10:45:56.479 9015-9270/system_process V/AccountManagerService﹕ caller uid 10048 has android.permission.AUTHENTICATE_ACCOUNTS 08-10 10:45:56.479 9015-9270/system_process W/AccountManagerService﹕ caller uid 10048 is different than the authenticator's uid 的有趣片段似乎没问题:

/data/system/packages.xml

项目清单

图书馆计划... <package name="com.example.mylib.app" codePath="/data/app/com.example.mylib.app-1.apk" nativeLibraryPath="/data/data/com.example.mylib.app/lib" flags="0" ft="14f170308d8" it="14f16d8b51b" ut="14f17030a42" version="1" sharedUserId="10048"> <sigs count="1"> <cert index="4" /> </sigs> <perms /> </package> ... <shared-user name="com.example.mylib" userId="10048"> <sigs count="1"> <cert index="4" /> </sigs> <perms> <item name="android.permission.READ_SYNC_SETTINGS" /> <item name="android.permission.MANAGE_ACCOUNTS" /> <item name="android.permission.USE_CREDENTIALS" /> <item name="android.permission.WRITE_SYNC_SETTINGS" /> <item name="android.permission.GET_ACCOUNTS" /> <item name="android.permission.INTERNET" /> <item name="android.permission.AUTHENTICATE_ACCOUNTS" /> </perms> </shared-user>

mylib_authenticator.xml

图书馆计划<?xml version="1.0" encoding="utf-8"?> <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android" android:sharedUserId="com.example.mylib" android:accountType="com.example.mylib.provider.ACCOUNT" android:exported="true" android:label="@string/service_name"/>

mylib_syncadapter.xml

来自图书馆项目<?xml version="1.0" encoding="utf-8"?> <sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" android:sharedUserId="com.example.mylib" android:contentAuthority="com.example.mylib.provider" android:accountType="com.example.mylib.provider.ACCOUNT" android:userVisible="false" android:exported="true" android:supportsUploading="false" android:allowParallelSyncs="false" android:isAlwaysSyncable="true" /> 的有趣位:

AndroidManifest.xml

来自应用项目<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mylib" android:sharedUserId="com.example.mylib"> <application> <provider android:name="com.example.mylib.provider.MyContentProvider" android:authorities="com.example.mylib.provider" android:exported="true" android:syncable="true"/> <service android:name="com.example.mylib.service.SyncService" android:exported="true" android:process=":sync"> <intent-filter> <action android:name="android.content.SyncAdapter"/> </intent-filter> <meta-data android:name="android.content.SyncAdapter" android:resource="@xml/mylib_syncadapter" /> </service> <service android:name="com.example.mylib.service.AccountService" android:exported="true"> <intent-filter> <action android:name="android.content.AccountAuthenticator"/> </intent-filter> <meta-data android:name="android.content.AccountAuthenticator" android:resource="@xml/mylib_authenticator" /> </service> </application> 的有趣位:

AndroidManifest.xml

0 个答案:

没有答案