From 5c8ceade92cdaf369c17295ff135d17d505cb144 Mon Sep 17 00:00:00 2001 From: Hui Yu Date: Fri, 21 Feb 2020 18:11:18 -0800 Subject: [PATCH] Exempt callingUid that has START_ACTIVITIES_FROM_BACKGROUND permission. From background FGS while-in-use permission restriction. Bug: 149835015, 136219221 Test: adb shell dumpsys activity -a Change-Id: I1a23689a2939d15101a1d8bb21a85fc9a9cca31f (cherry picked from commit d731201cac67f925a324aec8662ae907d90deedd) --- .../com/android/server/am/ActiveServices.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 7f98c7f2ba85f..c18d7e38bdd12 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -16,6 +16,7 @@ package com.android.server.am; +import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION; import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST; @@ -685,8 +686,8 @@ public final class ActiveServices { if (!r.mAllowWhileInUsePermissionInFgs) { r.mAllowWhileInUsePermissionInFgs = - shouldAllowWhileInUsePermissionInFgsLocked(callingPackage, callingUid, - service, r, allowBackgroundActivityStarts); + shouldAllowWhileInUsePermissionInFgsLocked(callingPackage, callingPid, + callingUid, service, r, allowBackgroundActivityStarts); } return cmp; @@ -1865,9 +1866,9 @@ public final class ActiveServices { } if (!s.mAllowWhileInUsePermissionInFgs) { - final int callingUid = Binder.getCallingUid(); s.mAllowWhileInUsePermissionInFgs = - shouldAllowWhileInUsePermissionInFgsLocked(callingPackage, callingUid, + shouldAllowWhileInUsePermissionInFgsLocked(callingPackage, + Binder.getCallingPid(), Binder.getCallingUid(), service, s, false); } @@ -4625,7 +4626,8 @@ public final class ActiveServices { * @return true if allow, false otherwise. */ private boolean shouldAllowWhileInUsePermissionInFgsLocked(String callingPackage, - int callingUid, Intent intent, ServiceRecord r, boolean allowBackgroundActivityStarts) { + int callingPid, int callingUid, Intent intent, ServiceRecord r, + boolean allowBackgroundActivityStarts) { // Is the background FGS start restriction turned on? if (!mAm.mConstants.mFlagBackgroundFgsStartRestrictionEnabled) { return true; @@ -4635,13 +4637,6 @@ public final class ActiveServices { return true; } - // Is the service in a whitelist? - final boolean hasAllowBackgroundActivityStartsToken = r.app != null - ? r.app.mAllowBackgroundActivityStartsTokens.contains(r) : false; - if (hasAllowBackgroundActivityStartsToken) { - return true; - } - boolean isCallerSystem = false; final int callingAppId = UserHandle.getAppId(callingUid); switch (callingAppId) { @@ -4660,6 +4655,11 @@ public final class ActiveServices { return true; } + if (mAm.checkPermission(START_ACTIVITIES_FROM_BACKGROUND, callingPid, callingUid) + == PERMISSION_GRANTED) { + return true; + } + // Is the calling UID at PROCESS_STATE_TOP or above? final boolean isCallingUidTopApp = appIsTopLocked(callingUid); if (isCallingUidTopApp) {