From 7d80fc90a218f09405241bf36c6a3679c53bd7bb Mon Sep 17 00:00:00 2001 From: Bernardo Rufino Date: Tue, 6 Jul 2021 16:21:21 +0100 Subject: [PATCH] Also check for home activity in BAL This is a CP from ag/15216475, see b/189896361#comment25 for details -- Original message Since checking for home process can fail if lancher has been killed but we still want to allow launcher to start activities. Bug: 189896361 Test: 1. Set app 1 as launcher, give PI for random activity to app 2 2. With app 2 in fg, kill app 1 3. Launch PI, verify it launches Change-Id: Ia5eb5bfcf239b6dd2f732516edeac29a77c8a478 Merged-In: Ia5eb5bfcf239b6dd2f732516edeac29a77c8a478 (cherry picked from commit 6771862788360b6f2c9d91792840fc1cb4158efc) --- .../com/android/server/wm/ActivityStarter.java | 17 ++++++++++++++++- .../android/server/wm/ActivityStarterTests.java | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index e2ef82b81a184..a9a25fc2d2727 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -86,6 +86,7 @@ import android.app.IApplicationThread; import android.app.PendingIntent; import android.app.ProfilerInfo; import android.app.WaitResult; +import android.content.ComponentName; import android.content.IIntentSender; import android.content.Intent; import android.content.IntentSender; @@ -1221,6 +1222,20 @@ class ActivityStarter { mController.onExecutionComplete(this); } + private boolean isHomeApp(int uid, @Nullable String packageName) { + if (mService.mHomeProcess != null) { + // Fast check + return uid == mService.mHomeProcess.mUid; + } + if (packageName == null) { + return false; + } + ComponentName activity = + mService.getPackageManagerInternalLocked().getDefaultHomeActivity( + UserHandle.getUserId(uid)); + return activity != null && packageName.equals(activity.getPackageName()); + } + boolean shouldAbortBackgroundActivityStart(int callingUid, int callingPid, final String callingPackage, int realCallingUid, int realCallingPid, WindowProcessController callerApp, PendingIntentRecord originatingPendingIntent, @@ -1236,7 +1251,7 @@ class ActivityStarter { } // Always allow home application to start activities. - if (mService.mHomeProcess != null && callingUid == mService.mHomeProcess.mUid) { + if (isHomeApp(callingUid, callingPackage)) { if (DEBUG_ACTIVITY_STARTS) { Slog.d(TAG, "Activity start allowed for home app callingUid (" + callingUid + ")"); } diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java index 0a36af2d586ac..d0588a30ca673 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java @@ -348,6 +348,7 @@ public class ActivityStarterTests extends WindowTestsBase { invocation -> { throw new RuntimeException("Not stubbed"); }); + doReturn(null).when(mMockPackageManager).getDefaultHomeActivity(anyInt()); doReturn(mMockPackageManager).when(mAtm).getPackageManagerInternalLocked(); doReturn(false).when(mMockPackageManager).isInstantAppInstallerComponent(any()); doReturn(null).when(mMockPackageManager).resolveIntent(any(), any(), anyInt(), anyInt(),