When looking at the Android source code, I noticed that the account manager service sets the caller's pid and uid on the Bundle as AccountManager.KEY_CALLER_PID
and AccountManager.KEY_CALLER_UID
.
You can use getInt()
on the bundle to find out the real caller's pid and uid in your getAppToken method.
One other useful bit of information that can be hard to find. The getAppToken
method is often only called once since the account manager service caches the result. If you want to be able to manage the token more actively, you can disable caching by adding meta-data to your manifest entry:
<service android:name=".authenticator.AccountAuthenticatorService">
<meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator"/>
<meta-data android:name="android.accounts.AccountAuthenticator.customTokens" android:value="1"/>
</service>
Here is what the authenticator xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.your.account.type"
android:customTokens="true"
android:icon="@drawable/logo"
android:smallIcon="@drawable/logo"
android:label="@string/app_name_long"/>