SecurityException when trying to add an account
Asked Answered
M

4

5

I'm experimenting with Android AccountManager.

I have an Account authentication service that shows UI to enter username/password.

I go to Settings/Accounts/Add Account, choose my new account type and I'm presented with the UI.

When I click OK I get the following error

04-24 14:48:29.334: E/AndroidRuntime(386): java.lang.SecurityException: 
    caller uid 10035 is different than the authenticator's uid

The only method of MyAccountAuthenticationService:

@Override
public IBinder onBind(Intent intent) {
    return new MyAccountAuthenticator(this).getIBinder();
}

MyAccountAuthenticator:

@Override
public Bundle addAccount(AccountAuthenticatorResponse response, 
    String accountType, String authTokenType, String[] requiredFeatures, 
    Bundle options) throws NetworkErrorException {

    final Intent intent = new Intent(context, MyAccountCreatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}

Fragment of MyAccountCreatorActivity's onClick

AccountManager accManager = AccountManager.get(this);
Account newAccount = new Account(email, MyAccountAuthenticator.ACCOUNT_TYPE);
accManager.setPassword(newAccount, password);

Exception is thrown on setPassword. I already required all the accounting permissions. I'm not sure about what could be causing this. If you need more code/information please ask.

Thank you.

Mendelian answered 24/4, 2012 at 14:56 Comment(3)
see this loganandandy.tumblr.com/post/613041897/caller-uid-is-different maybe helpfulTadtada
Possible duplicate of SecurityException: caller uid XXXX is different than the authenticator's uidFurunculosis
@Furunculosis sorry it's not a dupe. The original XML had a typo, however Android will not explain you exactly the real nature of the problemUpanchor
M
4

Thanks to @imran khan, I discovered that my constant value didn't match "exactly" what was in the authenticator XML definition

Mendelian answered 24/4, 2012 at 15:10 Comment(2)
I don't understand how your "authenticator XML definition" is different from the answer about the AndroidManifest. Did you have to match your AndroidManifest or was the answer elsewhere?Berserk
if I mistype org.zighinetto.myapp.account as org.zighinetto.myap.account it won't work. It was simply defined one way in the XML and another way in the code (public static final String... you know...)Upanchor
P
16

Seems obvious, but you will also see this error if your authenticator service has not been defined in AndroidManifest.xml. For example:

<service android:name="your.AuthService">
    <intent-filter>
        <action android:name="android.accounts.AccountAuthenticator" />
    </intent-filter>
    <meta-data android:name="android.accounts.AccountAuthenticator"
         android:resource="@xml/authenticator" />
</service>
Pure answered 6/6, 2013 at 20:57 Comment(1)
Thanks for the answer. The question didn't state that I already wrote the XML, in that case with a syntax glitchUpanchor
M
4

Thanks to @imran khan, I discovered that my constant value didn't match "exactly" what was in the authenticator XML definition

Mendelian answered 24/4, 2012 at 15:10 Comment(2)
I don't understand how your "authenticator XML definition" is different from the answer about the AndroidManifest. Did you have to match your AndroidManifest or was the answer elsewhere?Berserk
if I mistype org.zighinetto.myapp.account as org.zighinetto.myap.account it won't work. It was simply defined one way in the XML and another way in the code (public static final String... you know...)Upanchor
A
4

In my case, I got this error when I ran two different flavors on the same device. The second one was trying to access the same account as the first, which caused the error.

Algoid answered 5/8, 2016 at 21:55 Comment(1)
I had the same problem on an Android 5 phone, which I fixed by changing the flavor dimension name, thanks to your answer :)Sweptwing
A
1

In my case I accidently defined AuthenticatorService in the Manifest outside the <application> tags. Moving the declaration inside <application> fixed the issue. Hope will help someone.

Alodi answered 8/5, 2016 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.