Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
762 views
in Technique[技术] by (71.8m points)

android - SecurityException when trying to add an account

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...