From d23ba7d4f8b551d369c91ebbb184fa1c34609d0a Mon Sep 17 00:00:00 2001 From: huiyu Date: Wed, 27 Apr 2022 15:00:58 -0700 Subject: [PATCH] Persistent process is ProcessRecord.isPersistent(). Persistent process does not propagate BG-FGS-start capability down to service over binding, the "persistent process" here is ProcessRecord.isPersistent() (manifest file has android:persistent="true") instead of the process's procstate is PROCESS_STATE_PERSISTENT, because app could also get procstate PROCESS_STATE_PERSISTENT when it is bound by system_server. Bug: 226461824 Test: b/226461824 reproduce steps. Change-Id: If892ffaa2fe296aad334e71644ef22571a7d3e91 --- .../java/com/android/server/am/ActiveServices.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 730907c7d049e..235dbeeb9e27f 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -21,7 +21,6 @@ import static android.Manifest.permission.REQUEST_COMPANION_START_FOREGROUND_SER import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND; import static android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND; import static android.app.ActivityManager.PROCESS_STATE_HEAVY_WEIGHT; -import static android.app.ActivityManager.PROCESS_STATE_PERSISTENT_UI; import static android.app.ActivityManager.PROCESS_STATE_RECEIVER; import static android.app.ActivityManager.PROCESS_STATE_TOP; import static android.content.pm.PackageManager.PERMISSION_GRANTED; @@ -6527,10 +6526,14 @@ public final class ActiveServices { for (int con = 0; con < crs.size(); con++) { final ConnectionRecord cr = crs.get(con); final ProcessRecord clientPr = cr.binding.client; - // Persistent process does not propagate BG-FGS-start capability - // down to service over binding. - if (clientPr.mState.getCurProcState() - <= PROCESS_STATE_PERSISTENT_UI) { + // If a binding is from a persistent process, we don't automatically + // always allow the bindee to allow FGS BG starts. In this case, + // the binder will have to explicitly make sure the bindee's + // procstate will be BFGS or above. Otherwise, for example, even if + // the system server binds to an app with BIND_NOT_FOREGROUND, + // the binder would have to be able to start FGS, which is not what + // we want. (e.g. job services shouldn't be allowed BG-FGS.) + if (clientPr.isPersistent()) { continue; } final int clientPid = clientPr.mPid;