Preserve calling UID for HeavyWeightSwitcherActivity

When an activity launch from an app with cantSaveState="true"
conflicts with an existing heavy-weight process, ActivityStarter
intercepts the request in resolveToHeavyWeightSwitcherIfNeeded()
and reroutes the intent to HeavyWeightSwitcherActivity.

Previously, resolveToHeavyWeightSwitcherIfNeeded() overwrote
mRequest.callingUid and callingPid with Binder.getCallingUid()
and Binder.getCallingPid() after Binder.clearCallingIdentity().
This caused the calling UID to be replaced with SYSTEM_UID (1000).
Because Background Activity Launch (BAL) evaluation in
checkBackgroundActivityStart() evaluates permissions against
mRequest.callingUid, this overwrite allowed untrusted background
apps to bypass BAL restrictions (via BAL_ALLOW_ALLOWLISTED_UID)
and launch the switcher activity over any foreground app.

This change prevents the BAL bypass while ensuring the switcher
activity can still be launched:
1. Preserve the original app Calling UID and PID in mRequest when
   rerouting to HeavyWeightSwitcherActivity so BAL and Intent
   Firewall checks are evaluated against the true caller.
2. Set mRequest.ignoreTargetSecurity = true when rerouting to
   HeavyWeightSwitcherActivity so that component permission and
   exported checks in checkStartAnyActivityPermission permit
   starting the non-exported system activity.
3. Add unit test coverage in ActivityStarterTests to verify
   UID/PID preservation, ignoreTargetSecurity assignment, and
   BAL blocking behavior.

Bug: 527036967
Test: atest WmTests:ActivityStarterTests#testHeavyWeightSwitcher_preservesCallingUid_setsFlag,testHeavyWeightSwitcher_blockedByBal_whenCallerInBackground
Flag: EXEMPT CVE_FIX
TAG=agy
CONV=8361c3cf-3e81-46e5-bfae-2a1df0f05a55
(cherry picked from commit 038570272e1bffb436ba462a17019ee1591e6ea2)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:fd53cee662011b8c941ed128c46da310c01d5625
Merged-In: I00fed9cda203a06ae47089ed8d959ee372aecec7
Change-Id: I00fed9cda203a06ae47089ed8d959ee372aecec7
1 file changed