summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/am/ActiveServices.java59
1 files changed, 42 insertions, 17 deletions
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 125824c3f37e..fdadaaf9654e 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -387,6 +387,15 @@ public final class ActiveServices {
@Overridable
public static final long FGS_SAW_RESTRICTIONS = 319471980L;
+ /**
+ * Allows system to manage foreground state of service with type
+ * <li>{@link android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK}</li>
+ */
+ @ChangeId
+ @EnabledSince(targetSdkVersion = VERSION_CODES.VANILLA_ICE_CREAM)
+ @Overridable
+ public static final long MEDIA_FGS_STATE_TRANSITION = 281762171L;
+
final ActivityManagerService mAm;
// Maximum number of services that we allow to start in the background
@@ -9341,20 +9350,25 @@ public final class ActiveServices {
== ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE
&& sr.foregroundId == notificationId) {
// check if service is explicitly requested by app to not be in foreground.
- if (sr.systemRequestedFgToBg) {
- Slog.d(TAG,
- "System initiated service transition to foreground "
- + "for package "
- + packageName);
+ if (sr.systemRequestedFgToBg && CompatChanges.isChangeEnabled(
+ MEDIA_FGS_STATE_TRANSITION, sr.appInfo.uid)) {
+ if (DEBUG_FOREGROUND_SERVICE) {
+ Slog.d(TAG,
+ "System initiated service transition to foreground "
+ + "for package "
+ + packageName);
+ }
setServiceForegroundInnerLocked(sr, sr.foregroundId,
sr.foregroundNoti, /* flags */ 0,
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK,
/* callingUidStart */ 0, /* systemRequestedTransition */ true);
} else {
- Slog.d(TAG,
- "Ignoring system initiated foreground service transition for "
- + "package"
- + packageName);
+ if (DEBUG_FOREGROUND_SERVICE) {
+ Slog.d(TAG,
+ "Ignoring system initiated foreground service transition for "
+ + "package "
+ + packageName);
+ }
}
}
}
@@ -9388,14 +9402,25 @@ public final class ActiveServices {
if (sr.foregroundServiceType
== ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
&& sr.foregroundId == notificationId) {
- Slog.d(TAG,
- "System initiated transition of foreground service(type:media) to bg "
- + "for package"
- + packageName);
- setServiceForegroundInnerLocked(sr, /* id */ 0,
- /* notification */ null, /* flags */ 0,
- /* foregroundServiceType */ 0, /* callingUidStart */ 0,
- /* systemRequestedTransition */ true);
+ if (CompatChanges.isChangeEnabled(MEDIA_FGS_STATE_TRANSITION, sr.appInfo.uid)) {
+ if (DEBUG_FOREGROUND_SERVICE) {
+ Slog.d(TAG,
+ "System initiated transition of foreground service"
+ + "(type:media) to"
+ + " bg "
+ + "for package "
+ + packageName);
+ }
+ setServiceForegroundInnerLocked(sr, /* id */ 0,
+ /* notification */ null, /* flags */ 0,
+ /* foregroundServiceType */ 0, /* callingUidStart */ 0,
+ /* systemRequestedTransition */ true);
+ } else {
+ if (DEBUG_FOREGROUND_SERVICE) {
+ Slog.d(TAG, "Ignoring system initiated transition of foreground"
+ + " service(type:media)to bg for package " + packageName);
+ }
+ }
}
}
}