Merge "Revert "Use calling package name for CompatChange."" into udc-dev
diff --git a/services/core/java/com/android/server/am/PendingIntentRecord.java b/services/core/java/com/android/server/am/PendingIntentRecord.java
index 04db6c0..cb26c13 100644
--- a/services/core/java/com/android/server/am/PendingIntentRecord.java
+++ b/services/core/java/com/android/server/am/PendingIntentRecord.java
@@ -348,22 +348,21 @@
* use caller's BAL permission.
*/
public static BackgroundStartPrivileges getBackgroundStartPrivilegesAllowedByCaller(
- @Nullable ActivityOptions activityOptions, int callingUid,
- @Nullable String callingPackage) {
+ @Nullable ActivityOptions activityOptions, int callingUid) {
if (activityOptions == null) {
// since the ActivityOptions were not created by the app itself, determine the default
// for the app
- return getDefaultBackgroundStartPrivileges(callingUid, callingPackage);
+ return getDefaultBackgroundStartPrivileges(callingUid);
}
return getBackgroundStartPrivilegesAllowedByCaller(activityOptions.toBundle(),
- callingUid, callingPackage);
+ callingUid);
}
private static BackgroundStartPrivileges getBackgroundStartPrivilegesAllowedByCaller(
- @Nullable Bundle options, int callingUid, @Nullable String callingPackage) {
+ @Nullable Bundle options, int callingUid) {
if (options == null || !options.containsKey(
ActivityOptions.KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED)) {
- return getDefaultBackgroundStartPrivileges(callingUid, callingPackage);
+ return getDefaultBackgroundStartPrivileges(callingUid);
}
return options.getBoolean(ActivityOptions.KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED)
? BackgroundStartPrivileges.ALLOW_BAL
@@ -382,10 +381,8 @@
android.Manifest.permission.LOG_COMPAT_CHANGE
})
public static BackgroundStartPrivileges getDefaultBackgroundStartPrivileges(
- int callingUid, @Nullable String callingPackage) {
- boolean isChangeEnabledForApp = callingPackage != null ? CompatChanges.isChangeEnabled(
- DEFAULT_RESCIND_BAL_PRIVILEGES_FROM_PENDING_INTENT_SENDER, callingPackage,
- UserHandle.getUserHandleForUid(callingUid)) : CompatChanges.isChangeEnabled(
+ int callingUid) {
+ boolean isChangeEnabledForApp = CompatChanges.isChangeEnabled(
DEFAULT_RESCIND_BAL_PRIVILEGES_FROM_PENDING_INTENT_SENDER, callingUid);
if (isChangeEnabledForApp) {
return BackgroundStartPrivileges.ALLOW_FGS;
@@ -641,7 +638,7 @@
// temporarily allow receivers and services to open activities from background if the
// PendingIntent.send() caller was foreground at the time of sendInner() call
if (uid != callingUid && controller.mAtmInternal.isUidForeground(callingUid)) {
- return getBackgroundStartPrivilegesAllowedByCaller(options, callingUid, null);
+ return getBackgroundStartPrivilegesAllowedByCaller(options, callingUid);
}
return BackgroundStartPrivileges.NONE;
}
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index b8ae330..cff6554 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -5337,54 +5337,15 @@
return null;
}
- /**
- * Returns the {@link WindowProcessController} for the app process for the given uid and pid.
- *
- * If no such {@link WindowProcessController} is found, it does not belong to an app, or the
- * pid does not match the uid {@code null} is returned.
- */
- @Nullable WindowProcessController getProcessController(int pid, int uid) {
- return UserHandle.isApp(uid) ? getProcessControllerInternal(pid, uid) : null;
- }
-
- /**
- * Returns the {@link WindowProcessController} for the given uid and pid.
- *
- * If no such {@link WindowProcessController} is found or the pid does not match the uid
- * {@code null} is returned.
- */
- private @Nullable WindowProcessController getProcessControllerInternal(int pid, int uid) {
+ WindowProcessController getProcessController(int pid, int uid) {
final WindowProcessController proc = mProcessMap.getProcess(pid);
- if (proc == null) {
- return null;
- }
- if (proc.mUid == uid) {
+ if (proc == null) return null;
+ if (UserHandle.isApp(uid) && proc.mUid == uid) {
return proc;
}
return null;
}
- /**
- * Returns the package name if (and only if) the package name can be uniquely determined.
- * Otherwise returns {@code null}.
- *
- * The provided pid must match the provided uid, otherwise this also returns null.
- */
- @Nullable String getPackageNameIfUnique(int uid, int pid) {
- WindowProcessController processController = getProcessControllerInternal(pid, uid);
- if (processController == null) {
- Slog.w(TAG, "callingPackage for (uid=" + uid + ", pid=" + pid + ") has no WPC");
- return null;
- }
- List<String> realCallingPackages = processController.getPackageList();
- if (realCallingPackages.size() == 1) {
- return realCallingPackages.get(0);
- }
- Slog.w(TAG, "callingPackage for (uid=" + uid + ", pid=" + pid + ") is ambiguous: "
- + realCallingPackages);
- return null;
- }
-
/** A uid is considered to be foreground if it has a visible non-toast window. */
@HotPath(caller = HotPath.START_SERVICE)
boolean hasActiveVisibleWindow(int uid) {
diff --git a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
index b216578..dc49e8c 100644
--- a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
+++ b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
@@ -180,8 +180,7 @@
Intent intent,
ActivityOptions checkedOptions) {
return checkBackgroundActivityStart(callingUid, callingPid, callingPackage,
- realCallingUid, realCallingPid,
- callerApp, originatingPendingIntent,
+ realCallingUid, realCallingPid, callerApp, originatingPendingIntent,
backgroundStartPrivileges, intent, checkedOptions) == BAL_BLOCK;
}
@@ -289,13 +288,11 @@
}
}
- String realCallingPackage = mService.getPackageNameIfUnique(realCallingUid, realCallingPid);
-
// Legacy behavior allows to use caller foreground state to bypass BAL restriction.
// The options here are the options passed by the sender and not those on the intent.
final BackgroundStartPrivileges balAllowedByPiSender =
PendingIntentRecord.getBackgroundStartPrivilegesAllowedByCaller(
- checkedOptions, realCallingUid, realCallingPackage);
+ checkedOptions, realCallingUid);
final boolean logVerdictChangeByPiDefaultChange = checkedOptions == null
|| checkedOptions.getPendingIntentBackgroundActivityStartMode()
@@ -463,11 +460,8 @@
// If we are here, it means all exemptions not based on PI sender failed, so we'll block
// unless resultIfPiSenderAllowsBal is an allow and the PI sender allows BAL
- if (realCallingPackage == null) {
- realCallingPackage = (callingUid == realCallingUid ? callingPackage :
- mService.mContext.getPackageManager().getNameForUid(realCallingUid))
- + "[debugOnly]";
- }
+ String realCallingPackage = callingUid == realCallingUid ? callingPackage :
+ mService.mContext.getPackageManager().getNameForUid(realCallingUid);
String stateDumpLog = " [callingPackage: " + callingPackage
+ "; callingUid: " + callingUid
diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java
index 3672820..dbd9e4b 100644
--- a/services/core/java/com/android/server/wm/WindowProcessController.java
+++ b/services/core/java/com/android/server/wm/WindowProcessController.java
@@ -721,12 +721,6 @@
}
}
- List<String> getPackageList() {
- synchronized (mPkgList) {
- return new ArrayList<>(mPkgList);
- }
- }
-
void addActivityIfNeeded(ActivityRecord r) {
// even if we already track this activity, note down that it has been launched
setLastActivityLaunchTime(r);
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 2b589bf..2671e77 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
@@ -944,7 +944,7 @@
anyInt(), anyInt()));
doReturn(BackgroundStartPrivileges.allowBackgroundActivityStarts(null)).when(
() -> PendingIntentRecord.getBackgroundStartPrivilegesAllowedByCaller(
- anyObject(), anyInt(), anyObject()));
+ anyObject(), anyInt()));
runAndVerifyBackgroundActivityStartsSubtest(
"allowed_notAborted", false,
UNIMPORTANT_UID, false, PROCESS_STATE_BOUND_TOP,