Introduce a new process state for location fg service
A foreground service of type "location" gets a higher
process state PROCESS_STATE_FOREGROUND_SERVICE_LOCATION,
which is then propagated to AppOpsService, allowing it
to grant "while-in-use" permission to the process.
This changes the minimum bar for no-restriction to
UID_STATE_FOREGROUND_SERVICE_LOCATION.
Bug: 111453223
Test: atest CtsAppTestCases:ActivityManagerProcessStateTest
Change-Id: I25333bb2d524a6ae6d39efee088e6c94971b5db2
diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
index 054c830..7e52463 100644
--- a/services/core/java/com/android/server/am/ProcessRecord.java
+++ b/services/core/java/com/android/server/am/ProcessRecord.java
@@ -31,6 +31,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.ServiceInfo;
import android.content.res.CompatibilityInfo;
import android.os.Binder;
import android.os.Debug;
@@ -169,6 +170,7 @@
private boolean mHasClientActivities; // Are there any client services with activities?
boolean hasStartedServices; // Are there any started services running in this process?
private boolean mHasForegroundServices; // Running any services that are foreground?
+ private int mFgServiceTypes; // Type of foreground service, if there is a foreground service.
private boolean mHasForegroundActivities; // Running any activities that are foreground?
boolean repForegroundActivities; // Last reported foreground activities.
boolean systemNoUi; // This is a system process, but not currently showing UI.
@@ -1051,8 +1053,9 @@
return mRequiredAbi;
}
- void setHasForegroundServices(boolean hasForegroundServices) {
+ void setHasForegroundServices(boolean hasForegroundServices, int fgServiceTypes) {
mHasForegroundServices = hasForegroundServices;
+ mFgServiceTypes = fgServiceTypes;
mWindowProcessController.setHasForegroundServices(hasForegroundServices);
}
@@ -1060,6 +1063,11 @@
return mHasForegroundServices;
}
+ boolean hasLocationForegroundServices() {
+ return mHasForegroundServices
+ && (mFgServiceTypes & ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION) != 0;
+ }
+
void setHasForegroundActivities(boolean hasForegroundActivities) {
mHasForegroundActivities = hasForegroundActivities;
mWindowProcessController.setHasForegroundActivities(hasForegroundActivities);