Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 871b04e2 authored by Christopher Tate's avatar Christopher Tate
Browse files

Defer FGS notifications from legacy apps by default

Also write to logcat about the deferral, for developer & triage
visibility in bugreports.

Bug: 171499612
Test: ApiDemos
Change-Id: I643bb33f840053c2080a687a4634b59d33582cbf
parent 7e16c27a
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -1672,12 +1672,13 @@ public final class ActiveServices {
    // TODO: remove as part of fixing b/173627642
    // TODO: remove as part of fixing b/173627642
    @SuppressWarnings("AndroidFrameworkCompatChange")
    @SuppressWarnings("AndroidFrameworkCompatChange")
    private void postFgsNotificationLocked(ServiceRecord r) {
    private void postFgsNotificationLocked(ServiceRecord r) {
        final boolean isLegacyApp = (r.appInfo.targetSdkVersion < Build.VERSION_CODES.S);
        boolean showNow = !mAm.mConstants.mFlagFgsNotificationDeferralEnabled;
        boolean showNow = !mAm.mConstants.mFlagFgsNotificationDeferralEnabled;
        if (!showNow) {
        if (!showNow) {
            // Legacy apps' FGS notifications are not deferred unless the relevant
            // Legacy apps' FGS notifications are not deferred unless the relevant
            // DeviceConfig element has been set
            // DeviceConfig element has been set
            showNow = mAm.mConstants.mFlagFgsNotificationDeferralApiGated
            showNow = mAm.mConstants.mFlagFgsNotificationDeferralApiGated
                    && r.appInfo.targetSdkVersion < Build.VERSION_CODES.S;
                    && isLegacyApp;
        }
        }
        if (!showNow) {
        if (!showNow) {
            // is the notification such that it should show right away?
            // is the notification such that it should show right away?
@@ -1732,6 +1733,11 @@ public final class ActiveServices {
            Slog.d(TAG_SERVICE, "FGS " + r
            Slog.d(TAG_SERVICE, "FGS " + r
                    + " notification in " + (when - now) + " ms");
                    + " 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);
        mAm.mHandler.postAtTime(mPostDeferredFGSNotifications, when);
    }
    }


+4 −4
Original line number Original line Diff line number Diff line
@@ -370,9 +370,9 @@ final class ActivityManagerConstants extends ContentObserver {
    volatile boolean mFlagFgsNotificationDeferralEnabled = true;
    volatile boolean mFlagFgsNotificationDeferralEnabled = true;


    // Restrict FGS notification deferral policy to only those apps that target
    // 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
    // API version S or higher.  Disabled by default; set to "true" to force
    // notifications from legacy apps as well.
    // legacy app FGS notifications to display immediately in all cases.
    volatile boolean mFlagFgsNotificationDeferralApiGated = true;
    volatile boolean mFlagFgsNotificationDeferralApiGated = false;


    // Time in milliseconds to defer FGS notifications after their transition to
    // Time in milliseconds to defer FGS notifications after their transition to
    // the foreground state.
    // the foreground state.
@@ -806,7 +806,7 @@ final class ActivityManagerConstants extends ContentObserver {
        mFlagFgsNotificationDeferralApiGated = DeviceConfig.getBoolean(
        mFlagFgsNotificationDeferralApiGated = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
                DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
                KEY_DEFERRED_FGS_NOTIFICATIONS_API_GATED,
                KEY_DEFERRED_FGS_NOTIFICATIONS_API_GATED,
                /*default value*/ true);
                /*default value*/ false);
    }
    }


    private void updateFgsNotificationDeferralInterval() {
    private void updateFgsNotificationDeferralInterval() {