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

Commit caed15cd authored by Gus Prevas's avatar Gus Prevas
Browse files

Fixes NotificationInfo for demoted notifications.

This change modifies NotificationInfo such that the choice to display
"alert" vs. "keep alerting" and "silence" vs. "stay silent" buttons is
based on the same criteria used to determine whether the notification is
in the "high priority" or "low priority" section of the shade.  In
particular this affects notifications whose channel is marked as high
priority but which are displayed as low priority due to demotion by an
assistant service adjustment.  NotificationMenuRow is also modified to
use the same logic for which icon to use for the button that launches
the NotificationInfo UI.

Change-Id: Id7534ca5133e51d636e41baba9404108ee216467
Fixes: 121334699
Test: atest SystemUITests, manual
parent 57406a7e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -333,6 +333,7 @@ public class NotificationData {
                        mGroupManager.onEntryUpdated(entry, oldSbn);
                    }
                    entry.populateFromRanking(mTmpRanking);
                    entry.setIsHighPriority(isHighPriority(entry.notification));
                }
            }
        }
+14 −0
Original line number Diff line number Diff line
@@ -153,6 +153,12 @@ public final class NotificationEntry {
     */
    private boolean mUserDismissedBubble;

    /**
     * Whether this notification is shown to the user as a high priority notification: visible on
     * the lock screen/status bar and in the top section in the shade.
     */
    private boolean mHighPriority;

    public NotificationEntry(StatusBarNotification n) {
        this(n, null);
    }
@@ -191,6 +197,14 @@ public final class NotificationEntry {
        return interruption;
    }

    public boolean isHighPriority() {
        return mHighPriority;
    }

    public void setIsHighPriority(boolean highPriority) {
        this.mHighPriority = highPriority;
    }

    public void setIsBubble(boolean bubbleable) {
        mIsBubble = bubbleable;
    }
+2 −1
Original line number Diff line number Diff line
@@ -298,7 +298,8 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
                row.getIsNonblockable(),
                isForBlockingHelper,
                row.getEntry().userSentiment == USER_SENTIMENT_NEGATIVE,
                row.getEntry().importance);
                row.getEntry().importance,
                row.getEntry().isHighPriority());

    }

+36 −26
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -97,8 +96,12 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
    private int mNumUniqueChannelsInRow;
    private NotificationChannel mSingleNotificationChannel;
    private int mStartingChannelImportance;
    private int mStartingChannelOrNotificationImportance;
    private int mChosenImportance;
    private boolean mWasShownHighPriority;
    /**
     * The last importance level chosen by the user.  Null if the user has not chosen an importance
     * level; non-null once the user takes an action which indicates an explicit preference.
     */
    @Nullable private Integer mChosenImportance;
    private boolean mIsSingleDefaultChannel;
    private boolean mIsNonblockable;
    private StatusBarNotification mSbn;
@@ -195,13 +198,14 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            final OnAppSettingsClickListener onAppSettingsClick,
            boolean isDeviceProvisioned,
            boolean isNonblockable,
            int importance)
            int importance,
            boolean wasShownHighPriority)
            throws RemoteException {
        bindNotification(pm, iNotificationManager, pkg, notificationChannel,
                numUniqueChannelsInRow, sbn, checkSaveListener, onSettingsClick,
                onAppSettingsClick, isDeviceProvisioned, isNonblockable,
                false /* isBlockingHelper */, false /* isUserSentimentNegative */,
                importance);
                importance, wasShownHighPriority);
    }

    public void bindNotification(
@@ -218,7 +222,8 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            boolean isNonblockable,
            boolean isForBlockingHelper,
            boolean isUserSentimentNegative,
            int importance)
            int importance,
            boolean wasShownHighPriority)
            throws RemoteException {
        mINotificationManager = iNotificationManager;
        mMetricsLogger = Dependency.get(MetricsLogger.class);
@@ -231,10 +236,8 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        mCheckSaveListener = checkSaveListener;
        mOnSettingsClickListener = onSettingsClick;
        mSingleNotificationChannel = notificationChannel;
        int channelImportance = mSingleNotificationChannel.getImportance();
        mStartingChannelImportance = mChosenImportance = channelImportance;
        mStartingChannelOrNotificationImportance =
                channelImportance == IMPORTANCE_UNSPECIFIED ? importance : channelImportance;
        mStartingChannelImportance = mSingleNotificationChannel.getImportance();
        mWasShownHighPriority = wasShownHighPriority;
        mNegativeUserSentiment = isUserSentimentNegative;
        mIsNonblockable = isNonblockable;
        mIsForeground =
@@ -400,19 +403,27 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
     * @return new LogMaker
     */
    private LogMaker importanceChangeLogMaker() {
        Integer chosenImportance =
                mChosenImportance != null ? mChosenImportance : mStartingChannelImportance;
        return new LogMaker(MetricsEvent.ACTION_SAVE_IMPORTANCE)
                .setType(MetricsEvent.TYPE_ACTION)
                .setSubtype(mChosenImportance - mStartingChannelImportance);
                .setSubtype(chosenImportance - mStartingChannelImportance);
    }

    private boolean hasImportanceChanged() {
        return mSingleNotificationChannel != null
                && mStartingChannelImportance != mChosenImportance;
                && mChosenImportance != null
                && (mStartingChannelImportance != mChosenImportance
                || (mWasShownHighPriority && mChosenImportance < IMPORTANCE_DEFAULT)
                || (!mWasShownHighPriority && mChosenImportance >= IMPORTANCE_DEFAULT));
    }

    private void saveImportance() {
        if (!mIsNonblockable
                || mExitReason != NotificationCounters.BLOCKING_HELPER_STOP_NOTIFICATIONS) {
            if (mChosenImportance == null) {
                mChosenImportance = mStartingChannelImportance;
            }
            updateImportance();
        }
    }
@@ -421,13 +432,16 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
     * Commits the updated importance values on the background thread.
     */
    private void updateImportance() {
        if (mChosenImportance != null) {
            mMetricsLogger.write(importanceChangeLogMaker());

            Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
        bgHandler.post(new UpdateImportanceRunnable(mINotificationManager, mPackageName, mAppUid,
            bgHandler.post(
                    new UpdateImportanceRunnable(mINotificationManager, mPackageName, mAppUid,
                            mNumUniqueChannelsInRow == 1 ? mSingleNotificationChannel : null,
                            mStartingChannelImportance, mChosenImportance));
        }
    }

    private void bindButtons() {
        findViewById(R.id.undo).setOnClickListener(mOnUndo);
@@ -444,11 +458,8 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            TextView silent = findViewById(R.id.int_silent);
            TextView alert = findViewById(R.id.int_alert);

            boolean isCurrentlyAlerting =
                    mStartingChannelOrNotificationImportance >= IMPORTANCE_DEFAULT;

            block.setOnClickListener(mOnStopOrMinimizeNotifications);
            if (isCurrentlyAlerting) {
            if (mWasShownHighPriority) {
                silent.setOnClickListener(mOnToggleSilent);
                silent.setText(R.string.inline_silent_button_silent);
                alert.setOnClickListener(mOnKeepShowing);
@@ -517,7 +528,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
                break;
            case ACTION_TOGGLE_SILENT:
                mExitReason = NotificationCounters.BLOCKING_HELPER_TOGGLE_SILENT;
                if (mStartingChannelOrNotificationImportance >= IMPORTANCE_DEFAULT) {
                if (mWasShownHighPriority) {
                    mChosenImportance = IMPORTANCE_LOW;
                    confirmationText.setText(R.string.notification_channel_silenced);
                } else {
@@ -584,9 +595,8 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G

    @Override
    public void onFinishedClosing() {
        if (mChosenImportance != null) {
            mStartingChannelImportance = mChosenImportance;
        if (mChosenImportance != IMPORTANCE_UNSPECIFIED) {
            mStartingChannelOrNotificationImportance = mChosenImportance;
        }
        mExitReason = NotificationCounters.BLOCKING_HELPER_DISMISSED;

+1 −7
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
@@ -250,12 +249,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
        }
        mAppOpsItem = createAppOpsItem(mContext);
        if (NotificationUtils.useNewInterruptionModel(mContext)) {
            int channelImportance = mParent.getEntry().channel.getImportance();
            int effectiveImportance =
                    channelImportance == NotificationManager.IMPORTANCE_UNSPECIFIED
                            ? mParent.getEntry().importance : channelImportance;
            mInfoItem = createInfoItem(mContext,
                    effectiveImportance < NotificationManager.IMPORTANCE_DEFAULT);
            mInfoItem = createInfoItem(mContext, !mParent.getEntry().isHighPriority());
        } else {
            mInfoItem = createInfoItem(mContext);
        }
Loading