SecurityException异常:来电者的uid XXXX是不是认证的UID不同 [英] SecurityException: caller uid XXXX is different than the authenticator's uid

查看:161
本文介绍了SecurityException异常:来电者的uid XXXX是不是认证的UID不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现样品同步适配器的应用程序,当收到上述异常。我已经看到了与此相关的问题,但没有满意的答复无数的帖子。

I received the above exception when trying to implement Sample Sync Adapter application. I have seen numerous posts related to this issue but no satisfactory response.

所以,我会记下<一href="http://stackoverflow.com/questions/3774282/securityexception-caller-uid-xxxx-is-different-than-the-authenticators-uid/5329490#5329490">my解决方案的位置,以防其他​​人进入了同样的问题。

So I will jot down my solution here in case anyone else gets into the same issue.

推荐答案

首先,检查的这个帖子

[...]如果你看到一个错误的 AccountManagerService 表格来电UID XXXX是不是认证的uid不同的,它可能是一个有点误导。该消息中的身份验证是不是你的验证器类,它就是Android的理解是该帐户的类型注册的身份验证。中发生的检查 AccountManagerService 是这样的:

[...] If you see an error from the AccountManagerService of the form caller uid XXXX is different than the authenticator's uid, it might be a bit misleading. The ‘authenticator’ in that message is not your authenticator class, it’s what Android understands to be the registered authenticator for the account’s type. The check that happens within the AccountManagerService looks like this:

 private void checkCallingUidAgainstAuthenticator(Account account) {
     final int uid = Binder.getCallingUid();
     if (account == null || !hasAuthenticatorUid(account.type, uid)) {
         String msg = "caller uid " + uid + " is different than the authenticator's uid";
         Log.w(TAG, msg);
         throw new SecurityException(msg);
     }
     if (Log.isLoggable(TAG, Log.VERBOSE)) {
         Log.v(TAG, "caller uid " + uid + " is the same as the authenticator's uid");
     }
 }

注意 hasAuthenticatorUid() account.type 。这是我会搞砸了。我创建我的帐户由一个常量指定类型:

Note that hasAuthenticatorUid() takes the account.type. This is where I’d screwed up. I was creating my Account with a type specified by a constant:

 class LoginTask {
     Account account = new Account(userId, AuthenticatorService.ACCOUNT_TYPE);
     ...
 }

 class AuthenticatorService extends Service {
     public static final String ACCOUNT_TYPE = "com.joelapenna.foursquared";
     ...
 }

但这个常数没有XML定义匹配我的身份验证:

but this constant did not match the XML definition for my authenticator:

 <account-authenticator xmlns:android="/web/20150729061818/http://schemas.android.com/apk/res/android"
        android:accountType="com.joelapenna.foursquared.account" ... />

其次,如果你和我一样,想用这个样本嵌入到测试现有的应用程序,然后,请确保您使用常量类,它是这个例子中的一部分,不在 android.provider.SyncStateContract 包。因为这两个类使用相同的属性名称 ACCOUNT_TYPE 正在创建帐户对象。

Second, if you are like me and want to embed the sample into your existing app for testing then, make sure you use Constants class that is part of this example and not under android.provider.SyncStateContract package. Because both classes use the same attribute name ACCOUNT_TYPE that is used when creating Account object.

这篇关于SecurityException异常:来电者的uid XXXX是不是认证的UID不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆