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

Commit 07c51731 authored by Julia Tuttle's avatar Julia Tuttle
Browse files

HeadsUpManager: Log reasons for updates and auto remove cancels

The logic for updating AlertEntry display times is somewhat hairy, so
add some logging to explain why we schedule (using updateEntry) or
deschedule (using removeAutoRemovalCallback) dismissal.

Bug: 284418902
Test: presubmit
Change-Id: I9c47b75e0da92954a3f131e472430d55bcb3f531
parent 6a548f64
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ public abstract class AlertingNotificationManager {

        alertEntry.mEntry.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
        if (alert) {
            alertEntry.updateEntry(true /* updatePostTime */);
            alertEntry.updateEntry(true /* updatePostTime */, "updateNotification");
        }
    }

@@ -273,15 +273,15 @@ public abstract class AlertingNotificationManager {
            mRemoveAlertRunnable = removeAlertRunnable;

            mPostTime = calculatePostTime();
            updateEntry(true /* updatePostTime */);
            updateEntry(true /* updatePostTime */, "setEntry");
        }

        /**
         * Updates an entry's removal time.
         * @param updatePostTime whether or not to refresh the post time
         */
        public void updateEntry(boolean updatePostTime) {
            mLogger.logUpdateEntry(mEntry, updatePostTime);
        public void updateEntry(boolean updatePostTime, @Nullable String reason) {
            mLogger.logUpdateEntry(mEntry, updatePostTime, reason);

            final long now = mClock.currentTimeMillis();
            mEarliestRemovaltime = now + mMinimumDisplayTime;
@@ -289,7 +289,7 @@ public abstract class AlertingNotificationManager {
            if (updatePostTime) {
                mPostTime = Math.max(mPostTime, now);
            }
            removeAutoRemovalCallbacks();
            removeAutoRemovalCallbacks("updateEntry (will be rescheduled)");

            if (!isSticky()) {
                final long finishTime = calculateFinishTime();
@@ -330,15 +330,16 @@ public abstract class AlertingNotificationManager {

        public void reset() {
            mEntry = null;
            removeAutoRemovalCallbacks();
            removeAutoRemovalCallbacks("reset()");
            mRemoveAlertRunnable = null;
        }

        /**
         * Clear any pending removal runnables.
         */
        public void removeAutoRemovalCallbacks() {
        public void removeAutoRemovalCallbacks(@Nullable String reason) {
            if (mRemoveAlertRunnable != null) {
                mLogger.logAutoRemoveCanceled(mEntry, reason);
                mHandler.removeCallbacks(mRemoveAlertRunnable);
            }
        }
@@ -348,7 +349,7 @@ public abstract class AlertingNotificationManager {
         */
        public void removeAsSoonAsPossible() {
            if (mRemoveAlertRunnable != null) {
                removeAutoRemovalCallbacks();
                removeAutoRemovalCallbacks("removeAsSoonAsPossible (will be rescheduled)");

                final long timeLeft = mEarliestRemovaltime - mClock.currentTimeMillis();
                mHandler.postDelayed(mRemoveAlertRunnable, timeLeft);
+10 −10
Original line number Diff line number Diff line
@@ -263,9 +263,9 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
        if (headsUpEntry != null && headsUpEntry.remoteInputActive != remoteInputActive) {
            headsUpEntry.remoteInputActive = remoteInputActive;
            if (remoteInputActive) {
                headsUpEntry.removeAutoRemovalCallbacks();
                headsUpEntry.removeAutoRemovalCallbacks("setRemoteInputActive(true)");
            } else {
                headsUpEntry.updateEntry(false /* updatePostTime */);
                headsUpEntry.updateEntry(false /* updatePostTime */, "setRemoteInputActive(false)");
            }
        }
    }
@@ -446,8 +446,8 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
        }

        @Override
        public void updateEntry(boolean updatePostTime) {
            super.updateEntry(updatePostTime);
        public void updateEntry(boolean updatePostTime, String reason) {
            super.updateEntry(updatePostTime, reason);

            if (mEntriesToRemoveAfterExpand.contains(mEntry)) {
                mEntriesToRemoveAfterExpand.remove(mEntry);
@@ -465,9 +465,9 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,

            this.expanded = expanded;
            if (expanded) {
                removeAutoRemovalCallbacks();
                removeAutoRemovalCallbacks("setExpanded(true)");
            } else {
                updateEntry(false /* updatePostTime */);
                updateEntry(false /* updatePostTime */, "setExpanded(false)");
            }
        }

@@ -478,9 +478,9 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,

            mGutsShownPinned = gutsShownPinned;
            if (gutsShownPinned) {
                removeAutoRemovalCallbacks();
                removeAutoRemovalCallbacks("setGutsShownPinned(true)");
            } else {
                updateEntry(false /* updatePostTime */);
                updateEntry(false /* updatePostTime */, "setGutsShownPinned(false)");
            }
        }

@@ -494,7 +494,7 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
        private void extendPulse() {
            if (!extended) {
                extended = true;
                updateEntry(false);
                updateEntry(false, "extendPulse()");
            }
        }

@@ -544,7 +544,7 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
                // Let's make sure all huns we got while dozing time out within the normal timeout
                // duration. Otherwise they could get stuck for a very long time
                for (AlertEntry entry : mAlertEntries.values()) {
                    entry.updateEntry(true /* updatePostTime */);
                    entry.updateEntry(true /* updatePostTime */, "onDozingChanged(false)");
                }
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -343,7 +343,7 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
            HeadsUpEntry entry = getHeadsUpEntry(key);
            setEntryPinned(entry, false /* isPinned */);
            // maybe it got un sticky
            entry.updateEntry(false /* updatePostTime */);
            entry.updateEntry(false /* updatePostTime */, "unpinAll");

            // when the user unpinned all of HUNs by moving one HUN, all of HUNs should not stay
            // on the screen.
+13 −3
Original line number Diff line number Diff line
@@ -66,6 +66,15 @@ class HeadsUpManagerLogger @Inject constructor(
        })
    }

    fun logAutoRemoveCanceled(entry: NotificationEntry, reason: String?) {
        buffer.log(TAG, INFO, {
            str1 = entry.logKey
            str2 = reason ?: "unknown"
        }, {
            "cancel auto remove of $str1 reason: $str2"
        })
    }

    fun logRemoveNotification(key: String, releaseImmediately: Boolean) {
        buffer.log(TAG, INFO, {
            str1 = logKey(key)
@@ -89,16 +98,17 @@ class HeadsUpManagerLogger @Inject constructor(
            bool1 = alert
            bool2 = hasEntry
        }, {
            "update notification $str1 alert: $bool1 hasEntry: $bool2"
            "update notification $str1 alert: $bool1 hasEntry: $bool2 reason: $str2"
        })
    }

    fun logUpdateEntry(entry: NotificationEntry, updatePostTime: Boolean) {
    fun logUpdateEntry(entry: NotificationEntry, updatePostTime: Boolean, reason: String?) {
        buffer.log(TAG, INFO, {
            str1 = entry.logKey
            bool1 = updatePostTime
            str2 = reason ?: "unknown"
        }, {
            "update entry $str1 updatePostTime: $bool1"
            "update entry $str1 updatePostTime: $bool1 reason: $str2"
        })
    }