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

Commit b74dae92 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Transition NotificationInterruptStateProviderImpl to use NotifHeadsUpLog LogBuffer

Fixes: 205284674
Test: dumpsysui NotifHeadsUpLog
Change-Id: I45bd2e2a0cd7a4fdc83f68ef4221e5ebfdbaf001
parent c7a8dea9
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -46,4 +46,5 @@ class HeadsUpViewBinderLogger @Inject constructor(@NotificationHeadsUpLog val bu
        })
    }
}
const val TAG = "HeadsUpViewBinder"
 No newline at end of file

private const val TAG = "HeadsUpViewBinder"
+216 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.interruption

import android.service.notification.StatusBarNotification
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel.DEBUG
import com.android.systemui.log.LogLevel.INFO
import com.android.systemui.log.dagger.NotificationHeadsUpLog
import com.android.systemui.log.dagger.NotificationLog
import javax.inject.Inject

class NotificationInterruptLogger @Inject constructor(
    @NotificationLog val notifBuffer: LogBuffer,
    @NotificationHeadsUpLog val hunBuffer: LogBuffer
) {
    fun logHeadsUpFeatureChanged(useHeadsUp: Boolean) {
        hunBuffer.log(TAG, INFO, {
            bool1 = useHeadsUp
        }, {
            "heads up is enabled=$bool1"
        })
    }

    fun logWillDismissAll() {
        hunBuffer.log(TAG, INFO, {
        }, {
            "dismissing any existing heads up notification on disable event"
        })
    }

    fun logNoBubbleNotAllowed(sbn: StatusBarNotification) {
        notifBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No bubble up: not allowed to bubble: $str1"
        })
    }

    fun logNoBubbleNoMetadata(sbn: StatusBarNotification) {
        notifBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No bubble up: notification: $str1 doesn't have valid metadata"
        })
    }

    fun logNoHeadsUpFeatureDisabled() {
        hunBuffer.log(TAG, DEBUG, {
        }, {
            "No heads up: no huns"
        })
    }

    fun logNoHeadsUpPackageSnoozed(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No alerting: snoozed package: $str1"
        })
    }

    fun logNoHeadsUpAlreadyBubbled(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No heads up: in unlocked shade where notification is shown as a bubble: $str1"
        })
    }

    fun logNoHeadsUpSuppressedByDnd(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No heads up: suppressed by DND: $str1"
        })
    }

    fun logNoHeadsUpNotImportant(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No heads up: unimportant notification: $str1"
        })
    }

    fun logNoHeadsUpNotInUse(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No heads up: not in use: $str1"
        })
    }

    fun logNoHeadsUpSuppressedBy(
        sbn: StatusBarNotification,
        suppressor: NotificationInterruptSuppressor
    ) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
            str2 = suppressor.name
        }, {
            "No heads up: aborted by suppressor: $str2 sbnKey=$str1"
        })
    }

    fun logHeadsUp(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "Heads up: $str1"
        })
    }

    fun logNoAlertingFilteredOut(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No alerting: filtered notification: $str1"
        })
    }

    fun logNoAlertingGroupAlertBehavior(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No alerting: suppressed due to group alert behavior: $str1"
        })
    }

    fun logNoAlertingSuppressedBy(
        sbn: StatusBarNotification,
        suppressor: NotificationInterruptSuppressor,
        awake: Boolean
    ) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
            str2 = suppressor.name
            bool1 = awake
        }, {
            "No alerting: aborted by suppressor: $str2 awake=$bool1 sbnKey=$str1"
        })
    }

    fun logNoAlertingRecentFullscreen(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No alerting: recent fullscreen: $str1"
        })
    }

    fun logNoPulsingSettingDisabled(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No pulsing: disabled by setting: $str1"
        })
    }

    fun logNoPulsingBatteryDisabled(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No pulsing: disabled by battery saver: $str1"
        })
    }

    fun logNoPulsingNoAlert(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No pulsing: notification shouldn't alert: $str1"
        })
    }

    fun logNoPulsingNoAmbientEffect(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No pulsing: ambient effect suppressed: $str1"
        })
    }

    fun logNoPulsingNotImportant(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "No pulsing: not important enough: $str1"
        })
    }

    fun logPulsing(sbn: StatusBarNotification) {
        hunBuffer.log(TAG, DEBUG, {
            str1 = sbn.key
        }, {
            "Pulsing: $str1"
        })
    }
}

private const val TAG = "InterruptionStateProvider"
+27 −69
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import com.android.systemui.statusbar.notification.NotificationFilter;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.util.Compile;

import java.util.ArrayList;
import java.util.List;
@@ -53,8 +52,6 @@ import javax.inject.Inject;
@SysUISingleton
public class NotificationInterruptStateProviderImpl implements NotificationInterruptStateProvider {
    private static final String TAG = "InterruptionStateProvider";
    private static final boolean DEBUG = Compile.IS_DEBUG;
    private static final boolean DEBUG_HEADS_UP = Compile.IS_DEBUG;
    private static final boolean ENABLE_HEADS_UP = true;
    private static final String SETTING_HEADS_UP_TICKER = "ticker_gets_heads_up";

@@ -67,7 +64,8 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
    private final AmbientDisplayConfiguration mAmbientDisplayConfiguration;
    private final BatteryController mBatteryController;
    private final ContentObserver mHeadsUpObserver;
    private HeadsUpManager mHeadsUpManager;
    private final HeadsUpManager mHeadsUpManager;
    private final NotificationInterruptLogger mLogger;

    @VisibleForTesting
    protected boolean mUseHeadsUp = false;
@@ -82,6 +80,7 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
            BatteryController batteryController,
            StatusBarStateController statusBarStateController,
            HeadsUpManager headsUpManager,
            NotificationInterruptLogger logger,
            @Main Handler mainHandler) {
        mContentResolver = contentResolver;
        mPowerManager = powerManager;
@@ -91,6 +90,7 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
        mNotificationFilter = notificationFilter;
        mStatusBarStateController = statusBarStateController;
        mHeadsUpManager = headsUpManager;
        mLogger = logger;
        mHeadsUpObserver = new ContentObserver(mainHandler) {
            @Override
            public void onChange(boolean selfChange) {
@@ -100,11 +100,10 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
                        mContentResolver,
                        Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED,
                        Settings.Global.HEADS_UP_OFF);
                Log.d(TAG, "heads up is " + (mUseHeadsUp ? "enabled" : "disabled"));
                mLogger.logHeadsUpFeatureChanged(mUseHeadsUp);
                if (wasUsing != mUseHeadsUp) {
                    if (!mUseHeadsUp) {
                        Log.d(TAG, "dismissing any existing heads up notification on "
                                + "disable event");
                        mLogger.logWillDismissAll();
                        mHeadsUpManager.releaseAllImmediately();
                    }
                }
@@ -141,19 +140,14 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
        }

        if (!entry.canBubble()) {
            if (DEBUG) {
                Log.d(TAG, "No bubble up: not allowed to bubble: " + sbn.getKey());
            }
            mLogger.logNoBubbleNotAllowed(sbn);
            return false;
        }

        if (entry.getBubbleMetadata() == null
                || (entry.getBubbleMetadata().getShortcutId() == null
                    && entry.getBubbleMetadata().getIntent() == null)) {
            if (DEBUG) {
                Log.d(TAG, "No bubble up: notification: " + sbn.getKey()
                        + " doesn't have valid metadata");
            }
            mLogger.logNoBubbleNoMetadata(sbn);
            return false;
        }

@@ -185,9 +179,7 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
        StatusBarNotification sbn = entry.getSbn();

        if (!mUseHeadsUp) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No heads up: no huns");
            }
            mLogger.logNoHeadsUpFeatureDisabled();
            return false;
        }

@@ -200,32 +192,23 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
        }

        if (isSnoozedPackage(sbn)) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No alerting: snoozed package: " + sbn.getKey());
            }
            mLogger.logNoHeadsUpPackageSnoozed(sbn);
            return false;
        }

        boolean inShade = mStatusBarStateController.getState() == SHADE;
        if (entry.isBubble() && inShade) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No heads up: in unlocked shade where notification is shown as a "
                        + "bubble: " + sbn.getKey());
            }
            mLogger.logNoHeadsUpAlreadyBubbled(sbn);
            return false;
        }

        if (entry.shouldSuppressPeek()) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No heads up: suppressed by DND: " + sbn.getKey());
            }
            mLogger.logNoHeadsUpSuppressedByDnd(sbn);
            return false;
        }

        if (entry.getImportance() < NotificationManager.IMPORTANCE_HIGH) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No heads up: unimportant notification: " + sbn.getKey());
            }
            mLogger.logNoHeadsUpNotImportant(sbn);
            return false;
        }

@@ -238,21 +221,17 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
        boolean inUse = mPowerManager.isScreenOn() && !isDreaming;

        if (!inUse) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No heads up: not in use: " + sbn.getKey());
            }
            mLogger.logNoHeadsUpNotInUse(sbn);
            return false;
        }

        for (int i = 0; i < mSuppressors.size(); i++) {
            if (mSuppressors.get(i).suppressAwakeHeadsUp(entry)) {
                if (DEBUG_HEADS_UP) {
                    Log.d(TAG, "No heads up: aborted by suppressor: "
                            + mSuppressors.get(i).getName() + " sbnKey=" + sbn.getKey());
                }
                mLogger.logNoHeadsUpSuppressedBy(sbn, mSuppressors.get(i));
                return false;
            }
        }
        mLogger.logHeadsUp(sbn);
        return true;
    }

@@ -267,39 +246,30 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
        StatusBarNotification sbn = entry.getSbn();

        if (!mAmbientDisplayConfiguration.pulseOnNotificationEnabled(UserHandle.USER_CURRENT)) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No pulsing: disabled by setting: " + sbn.getKey());
            }
            mLogger.logNoPulsingSettingDisabled(sbn);
            return false;
        }

        if (mBatteryController.isAodPowerSave()) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No pulsing: disabled by battery saver: " + sbn.getKey());
            }
            mLogger.logNoPulsingBatteryDisabled(sbn);
            return false;
        }

        if (!canAlertCommon(entry)) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No pulsing: notification shouldn't alert: " + sbn.getKey());
            }
            mLogger.logNoPulsingNoAlert(sbn);
            return false;
        }

        if (entry.shouldSuppressAmbient()) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No pulsing: ambient effect suppressed: " + sbn.getKey());
            }
            mLogger.logNoPulsingNoAmbientEffect(sbn);
            return false;
        }

        if (entry.getImportance() < NotificationManager.IMPORTANCE_DEFAULT) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No pulsing: not important enough: " + sbn.getKey());
            }
            mLogger.logNoPulsingNotImportant(sbn);
            return false;
        }
        mLogger.logPulsing(sbn);
        return true;
    }

@@ -313,34 +283,25 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
        StatusBarNotification sbn = entry.getSbn();

        if (mNotificationFilter.shouldFilterOut(entry)) {
            if (DEBUG || DEBUG_HEADS_UP) {
                Log.d(TAG, "No alerting: filtered notification: " + sbn.getKey());
            }
            mLogger.logNoAlertingFilteredOut(sbn);
            return false;
        }

        // Don't alert notifications that are suppressed due to group alert behavior
        if (sbn.isGroup() && sbn.getNotification().suppressAlertingDueToGrouping()) {
            if (DEBUG || DEBUG_HEADS_UP) {
                Log.d(TAG, "No alerting: suppressed due to group alert behavior");
            }
            mLogger.logNoAlertingGroupAlertBehavior(sbn);
            return false;
        }

        for (int i = 0; i < mSuppressors.size(); i++) {
            if (mSuppressors.get(i).suppressInterruptions(entry)) {
                if (DEBUG_HEADS_UP) {
                    Log.d(TAG, "No alerting: aborted by suppressor: "
                            + mSuppressors.get(i).getName() + " sbnKey=" + sbn.getKey());
                }
                mLogger.logNoAlertingSuppressedBy(sbn, mSuppressors.get(i), /* awake */ false);
                return false;
            }
        }

        if (entry.hasJustLaunchedFullScreenIntent()) {
            if (DEBUG_HEADS_UP) {
                Log.d(TAG, "No alerting: recent fullscreen: " + sbn.getKey());
            }
            mLogger.logNoAlertingRecentFullscreen(sbn);
            return false;
        }

@@ -358,10 +319,7 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter

        for (int i = 0; i < mSuppressors.size(); i++) {
            if (mSuppressors.get(i).suppressAwakeInterruptions(entry)) {
                if (DEBUG_HEADS_UP) {
                    Log.d(TAG, "No alerting: aborted by suppressor: "
                            + mSuppressors.get(i).getName() + " sbnKey=" + sbn.getKey());
                }
                mLogger.logNoAlertingSuppressedBy(sbn, mSuppressors.get(i), /* awake */ true);
                return false;
            }
        }
+3 −0
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {
    @Mock
    HeadsUpManager mHeadsUpManager;
    @Mock
    NotificationInterruptLogger mLogger;
    @Mock
    BatteryController mBatteryController;
    @Mock
    Handler mMockHandler;
@@ -101,6 +103,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {
                        mBatteryController,
                        mStatusBarStateController,
                        mHeadsUpManager,
                        mLogger,
                        mMockHandler);

        mNotifInterruptionStateProvider.mUseHeadsUp = true;
+4 −1
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ import com.android.systemui.statusbar.notification.collection.legacy.VisualStabi
import com.android.systemui.statusbar.notification.collection.render.NotifShadeEventSource;
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
import com.android.systemui.statusbar.notification.init.NotificationsController;
import com.android.systemui.statusbar.notification.interruption.NotificationInterruptLogger;
import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderImpl;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.logging.NotificationPanelLoggerFake;
@@ -309,6 +310,7 @@ public class StatusBarTest extends SysuiTestCase {
                        mPowerManager,
                        mDreamManager, mAmbientDisplayConfiguration, mNotificationFilter,
                        mStatusBarStateController, mBatteryController, mHeadsUpManager,
                        mock(NotificationInterruptLogger.class),
                        new Handler(TestableLooper.get(this).getLooper()));

        mContext.addMockSystemService(TrustManager.class, mock(TrustManager.class));
@@ -994,9 +996,10 @@ public class StatusBarTest extends SysuiTestCase {
                StatusBarStateController controller,
                BatteryController batteryController,
                HeadsUpManager headsUpManager,
                NotificationInterruptLogger logger,
                Handler mainHandler) {
            super(contentResolver, powerManager, dreamManager, ambientDisplayConfiguration, filter,
                    batteryController, controller, headsUpManager, mainHandler);
                    batteryController, controller, headsUpManager, logger, mainHandler);
            mUseHeadsUp = true;
        }
    }
Loading