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

Commit 587acbbc authored by Chris Tate's avatar Chris Tate Committed by Automerger Merge Worker
Browse files

Merge "Fix FGS enter/exit statslog semantics" into sc-dev am: d3a0befe

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14823656

Change-Id: I0690cb6e354fa1a6dc8a58286bc717ef6ad77b6b
parents f2afc741 d3a0befe
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -486,11 +486,11 @@ public abstract class ActivityManagerInternal {

    /**
     * Callback from the notification subsystem that the given FGS notification has
     * been shown or updated.  This can happen after either Service.startForeground()
     * or NotificationManager.notify().
     * been evaluated, and either shown or explicitly overlooked.  This can happen
     * after either Service.startForeground() or NotificationManager.notify().
     */
    public abstract void onForegroundServiceNotificationUpdate(Notification notification,
            int id, String pkg, @UserIdInt int userId);
    public abstract void onForegroundServiceNotificationUpdate(boolean shown,
            Notification notification, int id, String pkg, @UserIdInt int userId);

    /**
     * If the given app has any FGSs whose notifications are in the given channel,
+20 −10
Original line number Diff line number Diff line
@@ -2221,8 +2221,9 @@ public final class ActiveServices {
     * visibility, starting with both Service.startForeground() and
     * NotificationManager.notify().
     */
    public void onForegroundServiceNotificationUpdateLocked(Notification notification,
            final int id, final String pkg, @UserIdInt final int userId) {
    public void onForegroundServiceNotificationUpdateLocked(boolean shown,
            Notification notification, final int id, final String pkg,
            @UserIdInt final int userId) {
        // If this happens to be a Notification for an FGS still in its deferral period,
        // drop the deferral and make sure our content bookkeeping is up to date.
        for (int i = mPendingFgsNotifications.size() - 1; i >= 0; i--) {
@@ -2230,17 +2231,26 @@ public final class ActiveServices {
            if (userId == sr.userId
                    && id == sr.foregroundId
                    && sr.appInfo.packageName.equals(pkg)) {
                // Found it.  If 'shown' is false, it means that the notification
                // subsystem will not be displaying it yet, so all we do is log
                // the "fgs entered" transition noting deferral, then we're done.
                maybeLogFGSStateEnteredLocked(sr);
                if (shown) {
                    if (DEBUG_FOREGROUND_SERVICE) {
                        Slog.d(TAG_SERVICE, "Notification shown; canceling deferral of "
                                + sr);
                    }
                maybeLogFGSStateEnteredLocked(sr);
                    sr.mFgsNotificationShown = true;
                    sr.mFgsNotificationDeferred = false;
                    mPendingFgsNotifications.remove(i);
                } else {
                    if (DEBUG_FOREGROUND_SERVICE) {
                        Slog.d(TAG_SERVICE, "FGS notification deferred for " + sr);
                    }
                }
            }
        }
        // And make sure to retain the latest notification content for the FGS
        // In all cases, make sure to retain the latest notification content for the FGS
        ServiceMap smap = mServiceMap.get(userId);
        if (smap != null) {
            for (int i = 0; i < smap.mServicesByInstanceName.size(); i++) {
+4 −6
Original line number Diff line number Diff line
@@ -350,8 +350,6 @@ import com.android.internal.util.Preconditions;
import com.android.internal.util.function.DecFunction;
import com.android.internal.util.function.HeptFunction;
import com.android.internal.util.function.HexFunction;
import com.android.internal.util.function.NonaFunction;
import com.android.internal.util.function.OctFunction;
import com.android.internal.util.function.QuadFunction;
import com.android.internal.util.function.QuintFunction;
import com.android.internal.util.function.TriFunction;
@@ -16093,11 +16091,11 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        @Override
        public void onForegroundServiceNotificationUpdate(Notification notification,
                int id, String pkg, @UserIdInt int userId) {
        public void onForegroundServiceNotificationUpdate(boolean shown,
                Notification notification, int id, String pkg, @UserIdInt int userId) {
            synchronized (ActivityManagerService.this) {
                mServices.onForegroundServiceNotificationUpdateLocked(notification,
                        id, pkg, userId);
                mServices.onForegroundServiceNotificationUpdateLocked(shown,
                        notification, id, pkg, userId);
            }
        }
+12 −9
Original line number Diff line number Diff line
@@ -3052,17 +3052,19 @@ public class NotificationManagerService extends SystemService {
        }
    }

    protected void maybeReportForegroundServiceUpdate(final NotificationRecord r) {
    protected void reportForegroundServiceUpdate(boolean shown,
            final Notification notification, final int id, final String pkg, final int userId) {
        mHandler.post(() -> {
            mAmi.onForegroundServiceNotificationUpdate(shown, notification, id, pkg, userId);
        });
    }

    protected void maybeReportForegroundServiceUpdate(final NotificationRecord r, boolean shown) {
        if (r.isForegroundService()) {
            // snapshot live state for the asynchronous operation
            final StatusBarNotification sbn = r.getSbn();
            final Notification notification = sbn.getNotification();
            final int id = sbn.getId();
            final String pkg = sbn.getPackageName();
            final int userId = sbn.getUser().getIdentifier();
            mHandler.post(() -> {
                mAmi.onForegroundServiceNotificationUpdate(notification, id, pkg, userId);
            });
            reportForegroundServiceUpdate(shown, sbn.getNotification(), sbn.getId(),
                    sbn.getPackageName(), sbn.getUser().getIdentifier());
        }
    }

@@ -6194,6 +6196,7 @@ public class NotificationManagerService extends SystemService {
            // because the service lifecycle logic has retained responsibility for its
            // handling.
            if (!isNotificationShownInternal(pkg, tag, id, userId)) {
                reportForegroundServiceUpdate(false, notification, id, pkg, userId);
                return;
            }
        }
@@ -7121,7 +7124,7 @@ public class NotificationManagerService extends SystemService {

                    maybeRecordInterruptionLocked(r);
                    maybeRegisterMessageSent(r);
                    maybeReportForegroundServiceUpdate(r);
                    maybeReportForegroundServiceUpdate(r, true);

                    // Log event to statsd
                    mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position,