From 145b0157b9f9f418800d38157e87e25a9a8a1d33 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 5 Jan 2021 16:20:38 -0800 Subject: [PATCH] Revert "Revert "Defer FGS notifications from legacy apps by default"" This reverts commit 33de1a2d4c0578d9a9b43755cf4712407ff939cf. Re-establishing this behavior now that the unit test failure has been isolated and fixed. Reason for revert: test/app fix Bug: 175764941 Bug: 176849372 Test: atest TraceurUiTests:com.android.traceur.uitest.TraceurAppTests#testSuccessfulTracing Test: ApiDemos Change-Id: I3fa20e1a37eade5ee8de6f7e10d7eed851d877d1 --- .../core/java/com/android/server/am/ActiveServices.java | 8 +++++++- .../com/android/server/am/ActivityManagerConstants.java | 8 ++++---- 2 files changed, 11 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 5fde046bda0a9..6a52266dfe404 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -1700,12 +1700,13 @@ public final class ActiveServices { // TODO: remove as part of fixing b/173627642 @SuppressWarnings("AndroidFrameworkCompatChange") private void postFgsNotificationLocked(ServiceRecord r) { + final boolean isLegacyApp = (r.appInfo.targetSdkVersion < Build.VERSION_CODES.S); boolean showNow = !mAm.mConstants.mFlagFgsNotificationDeferralEnabled; if (!showNow) { // Legacy apps' FGS notifications are not deferred unless the relevant // DeviceConfig element has been set showNow = mAm.mConstants.mFlagFgsNotificationDeferralApiGated - && r.appInfo.targetSdkVersion < Build.VERSION_CODES.S; + && isLegacyApp; } if (!showNow) { // is the notification such that it should show right away? @@ -1760,6 +1761,11 @@ public final class ActiveServices { Slog.d(TAG_SERVICE, "FGS " + r + " notification in " + (when - now) + " ms"); } + if (isLegacyApp) { + Slog.i(TAG_SERVICE, "Deferring FGS notification in legacy app " + + r.appInfo.packageName + "/" + UserHandle.formatUid(r.appInfo.uid) + + " : " + r.foregroundNoti); + } mAm.mHandler.postAtTime(mPostDeferredFGSNotifications, when); } diff --git a/services/core/java/com/android/server/am/ActivityManagerConstants.java b/services/core/java/com/android/server/am/ActivityManagerConstants.java index b0f296f68a471..6892ef770901d 100644 --- a/services/core/java/com/android/server/am/ActivityManagerConstants.java +++ b/services/core/java/com/android/server/am/ActivityManagerConstants.java @@ -370,9 +370,9 @@ final class ActivityManagerConstants extends ContentObserver { volatile boolean mFlagFgsNotificationDeferralEnabled = true; // Restrict FGS notification deferral policy to only those apps that target - // API version S or higher. Enabled by default; set to "false" to defer FGS - // notifications from legacy apps as well. - volatile boolean mFlagFgsNotificationDeferralApiGated = true; + // API version S or higher. Disabled by default; set to "true" to force + // legacy app FGS notifications to display immediately in all cases. + volatile boolean mFlagFgsNotificationDeferralApiGated = false; // Time in milliseconds to defer FGS notifications after their transition to // the foreground state. @@ -806,7 +806,7 @@ final class ActivityManagerConstants extends ContentObserver { mFlagFgsNotificationDeferralApiGated = DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_DEFERRED_FGS_NOTIFICATIONS_API_GATED, - /*default value*/ true); + /*default value*/ false); } private void updateFgsNotificationDeferralInterval() {