CVE-2026-58837 AI-generated analysis
platform/frameworks/base, Companion Device Manager service (services/companion, CompanionDeviceManagerService)
Adds a foreground check to CompanionDeviceManagerImpl.associate(). Callers that are not system, are not making a self-managed request and do not hold MANAGE_COMPANION_DEVICES must be in PROCESS_STATE_TOP; otherwise a SecurityException is thrown before the association request is processed.
Root cause
In services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java, CompanionDeviceManagerImpl.associate() called only enforceCallerCanManageAssociationsForPackage() and then passed the request directly to mAssociationRequestsProcessor.processNewAssociationRequest(). Nothing checked that the calling UID was in the foreground. Per the commit message, this allowed Companion Device Manager to be used to get around background activity launch restrictions.
How the fix works
- services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java:CompanionDeviceManagerImpl.associate(): the new check sits after enforceCallerCanManageAssociationsForPackage() and before mAssociationRequestsProcessor.processNewAssociationRequest(). It reads Binder.getCallingUid(). Unless the caller is SYSTEM_UID, the request isSelfManaged(), or the caller holds MANAGE_COMPANION_DEVICES (checkCallingPermission == PERMISSION_GRANTED), it queries ActivityManagerInternal.getUidProcessState(callingUid) through LocalServices.
- If the UID process state is not ActivityManager.PROCESS_STATE_TOP, it throws SecurityException("Caller must be in foreground to associate"), so the association request is never processed for background callers.
- The commit message says the change combines a short-term mitigation with unconditional enforcement, with no feature-flag gating (Flag: EXEMPT FLAG_REMOVAL). The diff contains only the service-side check. The CTS test (AssociateTest) is referenced but not included.
Completeness
- Covers only the associate() Binder entry point. The gate runs once: before processNewAssociationRequest() on 14 and 15, and before the isSkipRoleGrant() branch (createAssociation()) on 16 and 17. Everything that follows in associate() is therefore behind the check.
- The code has three exemptions: SYSTEM_UID callers, requests with isSelfManaged() set, and holders of MANAGE_COMPANION_DEVICES. Self-managed association requests are therefore not subject to the foreground check.
- The check is a strict equality test against PROCESS_STATE_TOP at the UID level. It does not use a BAL-specific allowlist or a time-bounded window for recently foregrounded apps.
- This commit does not change other ICompanionDeviceManager methods that call enforceCallerCanManageAssociationsForPackage(), for example buildAssociationCancellationIntent(), which is partly visible in the surrounding context. The material does not show whether they are relevant to the same issue.
Behavior changes
- associate() now throws SecurityException (propagated over Binder) for callers that are not in PROCESS_STATE_TOP, unless they are system, the request is self-managed, or they hold MANAGE_COMPANION_DEVICES. Before the fix, such calls went on to processNewAssociationRequest().
- For non-self-managed requests, apps calling associate() from any process state other than top (including foreground-service and background states) now fail instead of starting the association flow.
- The CDM associate path now depends on ActivityManagerInternal, obtained through LocalServices.
Per major
- Android 14: Same fix: platform/frameworks/base e7028d348ee5 ([udc-staging]) in android-security-14.0.0_r29 inserts the identical 15-line block in associate() before processNewAssociationRequest(). 4/4 lines of the patched region are present at android-security-14.0.0_r31.
- Android 15: Same fix: platform/frameworks/base 35a55a523145 ([24Q3]) in android-security-15.0.0_r17, with the identical block before processNewAssociationRequest(). 4/4 lines of the patched region are present at android-security-15.0.0_r19.
- Android 16: Same fix, different surrounding code: platform/frameworks/base a5fd26078dba ([25Q2]) in android-security-16.0.0_r8 inserts the identical block before the request.isSkipRoleGrant()/checkCallerCanSkipRoleGrant() branch. 5/5 lines of the patched region are present at android-security-16.0.0_r10.
- Android 17: Same fix, same surrounding code as 16: platform/frameworks/base f064617cb9cc ([26Q2]) in android-security-17.0.0_r1. 5/5 lines of the patched region are present at android-security-17.0.0_r3.
Unknowns
- How an association request made from the background led to a background activity launch: the material does not show what processNewAssociationRequest() or the association UI does.
- What enforceCallerCanManageAssociationsForPackage() checks exactly; its body is not shown.
- What the 'short-term mitigation' in the commit message consisted of as a separate item, and whether any companion change exists outside this file. The CTS AssociateTest change is referenced but not included.
- Whether other CDM entry points that call enforceCallerCanManageAssociationsForPackage() were evaluated for the same issue.