The question
Two of our apps run side by side on a classroom panel: a whiteboard the teacher signs in to, and an AI assistant that should act as the same teacher. The question is old and well documented: how do two Android apps share one sign-in?
The documented answers assume something our devices don’t have.
My initial mental model
The textbook toolkit for this is:
AccountManagerwith a custom authenticator, so the system stores the account and other apps request tokens from it.protectionLevel="signature"on whatever you expose, so only apps signed with your key can call it.- Or the simplest version: the signed-in app shares its session with the other one.
All three are reasonable on a phone where you ship every app with one release key and from one store.
What actually happens
Signature permissions need one signing key
protectionLevel="signature" grants a permission only to apps signed with the same certificate as
the app that defines it. Our assistant ships four builds, each signed with a different OEM platform
key, because it’s preinstalled as a system app on different manufacturers’ panels. The whiteboard is
signed by CI with its own key.
So a signature permission would deny every real build. The kernel-level guarantee everyone relies on simply didn’t apply. Any check had to happen at runtime.
Sharing the session breaks twice
The first working version exported the whiteboard’s saved accounts and session through a read-only
ContentProvider. Two things ended it within days:
- It failed silently. Some time after sign-in, the assistant went “unauthorized”. The token request returned HTTP 200 with a failure flag in the body: the session was no good. The replayed cookie still looked valid on the device, with a far-future expiry date, so nothing local knew it was dead.
- It was the wrong model. Security guidance made it explicit that the assistant must never read, copy or store the whiteboard’s credentials. “Carefully” exporting a cookie is still exporting it.
Let’s look at the implementation
Step 1: verify the caller at runtime
Every exported entry point, whether the Binder service, the provider or the login activity, runs one fail-closed check:
// Simplified. Order matters: cheapest and unspoofable first.
fun isTrustedCaller(
context: Context,
uid: Int = Binder.getCallingUid(),
): Boolean {
val sameUser = UserHandle.getUserHandleForUid(uid) == Process.myUserHandle()
if (!sameUser) return false
val pkg = context.packageManager.getPackagesForUid(uid)
?.singleOrNull { it in ALLOWED_PACKAGES } ?: return false
return signingCertSha256(context, pkg) in PINNED_CERTS.getValue(pkg)
}
The Binder calling uid is supplied by the kernel and can’t be forged. From it you get the caller’s package and its signing certificate, which you compare against a pinned set: one entry per OEM key the assistant is legitimately signed with. It’s what a signature permission would have done, done by hand, for several keys.
Step 2: give the other app a code, not a credential
Instead of a session, the whiteboard acts as an authorization server on the device, using the OAuth authorization-code flow with PKCE:
assistant: generate code_verifier, send code_challenge = SHA-256(verifier)
whiteboard: verify caller → mint a one-time code bound to that challenge (60 s)
assistant: exchange code + code_verifier with the backend → its own session
The code is useless to anyone who intercepts it, because they don’t have the verifier. It expires in a minute, and redeeming it gives the assistant its own session, with its own lifetime and revocation, rather than a copy of the whiteboard’s.
Step 3: say “something changed” without saying what
The assistant has to follow account switches on a shared panel. The whiteboard broadcasts a change signal that carries no data: no account, no user id, nothing. A forged broadcast can only make the assistant re-query a channel that authenticates it anyway. Accounts are shown to it with opaque ids from an Android Keystore HMAC, never raw user ids.
Step 4: borrow the real login screen
If no one is signed in, the assistant doesn’t get a login form of its own. That would put Teachmint credentials into a second app. It starts the whiteboard’s login in a transparent activity over itself. Two details matter for any exported activity like this:
- Gate it with the same caller check. An exported login screen anyone can launch is a phishing surface.
- Keep
launchMode="standard".startActivityForResultonly delivers a result when the activity runs in the caller’s task. WithsingleTaskyou getRESULT_CANCELEDimmediately, andgetCallingPackage()returns null, which quietly disables your caller check.
The surprising part
Most of the work wasn’t the protocol. It was the edges of Android’s IPC components:
ContentProvider.onCreateruns beforeApplication.onCreate. Touch your DI graph there and it crashes, so storage has to be reached lazily insidequery().getType()isn’t covered by provider permissions. If it answers differently depending on the data, it becomes an unauthenticated “is a teacher signed in?” check for every app on the device. Return a constant.- Every request needs exactly one terminal callback. A crash or teardown mid-request would otherwise leave the caller waiting forever. The broker tracks pending requests and answers them all on destroy.
- Re-read state after the network call, not before. Otherwise an account switch during the request mints a code for the wrong teacher.
Practical consequences
If your apps don’t share one signing key, which is common for preinstalled or OEM-signed apps:
- Don’t rely on
protectionLevel="signature". Verify callers at runtime from the Binder uid, and pin certificates. - Don’t share sessions between apps. Share a short-lived, bound code, and let each app hold its own session.
- Treat every exported component as a public API, including its launch mode and
getType(). - Check the response body, not just the status code, when your API reports failure inside a 200.
AccountManager still has its place. It’s a good fit when one company ships every app with one key and
wants accounts to appear in system settings. It just isn’t a security boundary by itself when the callers
are signed with keys you don’t control.
What I would remember
- Signature permissions mean “same certificate”. With several signing keys, check at runtime.
- The Binder calling uid is the one identity a caller can’t lie about.
- PKCE works between apps on one device as well as between an app and a server.
- A change signal should carry no data.
- Exported activities and providers have sharp edges:
singleTask,getType()andonCreateorder.
Further reading
- Permissions and
protectionLevel. - RFC 7636: Proof Key for Code Exchange.
Binder.getCallingUidandPackageManager.getPackagesForUid.- Android Keystore.