diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FeedbackInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FeedbackInfo.java index 2b782b6e3917a..3f4fd50064088 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FeedbackInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FeedbackInfo.java @@ -165,7 +165,7 @@ public class FeedbackInfo extends LinearLayout implements NotificationGuts.GutsC } private void positiveFeedback(View v) { - mGutsContainer.closeControls(v, false); + mGutsContainer.closeControls(v, /* save= */ false); handleFeedback(true); } @@ -176,7 +176,7 @@ public class FeedbackInfo extends LinearLayout implements NotificationGuts.GutsC menuItem = mMenuRowPlugin.getLongpressMenuItem(mContext); } - mGutsContainer.closeControls(v, false); + mGutsContainer.closeControls(v, /* save= */ false); mNotificationGutsManager.openGuts(mExpandableNotificationRow, 0, 0, menuItem); handleFeedback(false); } @@ -203,7 +203,7 @@ public class FeedbackInfo extends LinearLayout implements NotificationGuts.GutsC } private void closeControls(View v) { - mGutsContainer.closeControls(v, false); + mGutsContainer.closeControls(v, /* save= */ false); } @Override @@ -232,7 +232,7 @@ public class FeedbackInfo extends LinearLayout implements NotificationGuts.GutsC } @Override - public boolean shouldBeSaved() { + public boolean shouldBeSavedOnClose() { return false; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java index 7120fe50adb4d..0ce9656a21b52 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java @@ -157,7 +157,7 @@ public class NotificationConversationInfo extends LinearLayout implements mShadeController.animateCollapsePanels(); mPeopleSpaceWidgetManager.requestPinAppWidget(mShortcutInfo, new Bundle()); } - mGutsContainer.closeControls(v, true); + mGutsContainer.closeControls(v, /* save= */ true); }; public NotificationConversationInfo(Context context, AttributeSet attrs) { @@ -186,7 +186,6 @@ public class NotificationConversationInfo extends LinearLayout implements } public void bindNotification( - @Action int selectedAction, ShortcutManager shortcutManager, PackageManager pm, PeopleSpaceWidgetManager peopleSpaceWidgetManager, @@ -205,8 +204,6 @@ public class NotificationConversationInfo extends LinearLayout implements OnConversationSettingsClickListener onConversationSettingsClickListener, Optional bubblesManagerOptional, ShadeController shadeController) { - mPressedApply = false; - mSelectedAction = selectedAction; mINotificationManager = iNotificationManager; mPeopleSpaceWidgetManager = peopleSpaceWidgetManager; mOnUserInteractionCallback = onUserInteractionCallback; @@ -417,9 +414,7 @@ public class NotificationConversationInfo extends LinearLayout implements } @Override - public void onFinishedClosing() { - mSelectedAction = -1; - } + public void onFinishedClosing() { } @Override public boolean needsFalsingProtection() { @@ -564,7 +559,7 @@ public class NotificationConversationInfo extends LinearLayout implements } @Override - public boolean shouldBeSaved() { + public boolean shouldBeSavedOnClose() { return mPressedApply; } @@ -578,6 +573,12 @@ public class NotificationConversationInfo extends LinearLayout implements if (save && mSelectedAction > -1) { updateChannel(); } + + // Clear the selected importance when closing, so when when we open again, + // we starts from a clean state. + mSelectedAction = -1; + mPressedApply = false; + return false; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGuts.java index fc296e1257940..93f08123ab5ac 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGuts.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGuts.java @@ -76,7 +76,7 @@ public class NotificationGuts extends FrameLayout { switch (action) { case AccessibilityNodeInfo.ACTION_LONG_CLICK: - closeControls(host, false); + closeControls(host, /* save= */ false); return true; } @@ -123,7 +123,7 @@ public class NotificationGuts extends FrameLayout { /** * Return whether something changed and needs to be saved, possibly requiring a bouncer. */ - boolean shouldBeSaved(); + boolean shouldBeSavedOnClose(); /** * Called when the guts view has finished its close animation. @@ -259,7 +259,7 @@ public class NotificationGuts extends FrameLayout { if (mGutsContent != null) { if ((mGutsContent.isLeavebehind() && leavebehinds) || (!mGutsContent.isLeavebehind() && controls)) { - closeControls(x, y, mGutsContent.shouldBeSaved(), force); + closeControls(x, y, mGutsContent.shouldBeSavedOnClose(), force); } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java index c4ff2599c2cef..efad6edb7bb71 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java @@ -477,7 +477,6 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx R.dimen.notification_guts_conversation_icon_size)); notificationInfoView.bindNotification( - notificationInfoView.getSelectedAction(), mShortcutManager, pmUser, mPeopleSpaceWidgetManager, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java index 8b01a4790f3c8..ea0060a693b28 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java @@ -158,7 +158,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G // used by standard ui private OnClickListener mOnDismissSettings = v -> { mPressedApply = true; - mGutsContainer.closeControls(v, true); + mGutsContainer.closeControls(v, /* save= */ true); }; public NotificationInfo(Context context, AttributeSet attrs) { @@ -541,10 +541,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G @Override public void onFinishedClosing() { - if (mChosenImportance != null) { - mStartingChannelImportance = mChosenImportance; - } - bindInlineControls(); logUiEvent(NotificationControlsEvent.NOTIFICATION_CONTROLS_CLOSE); @@ -604,7 +600,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G } @Override - public boolean shouldBeSaved() { + public boolean shouldBeSavedOnClose() { return mPressedApply; } @@ -627,6 +623,12 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G if (save) { saveImportance(); } + + // Clear the selected importance when closing, so when when we open again, + // we starts from a clean state. + mChosenImportance = null; + mPressedApply = false; + return false; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationSnooze.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationSnooze.java index 512b049681664..adbfa755b63c1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationSnooze.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationSnooze.java @@ -384,7 +384,7 @@ public class NotificationSnooze extends LinearLayout private void undoSnooze(View v) { mSelectedOption = null; showSnoozeOptions(false); - mGutsContainer.closeControls(v, false); + mGutsContainer.closeControls(v, /* save= */ false); } @Override @@ -433,7 +433,7 @@ public class NotificationSnooze extends LinearLayout } @Override - public boolean shouldBeSaved() { + public boolean shouldBeSavedOnClose() { return true; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java index 186ffa67f046b..ac97e77f84a27 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java @@ -16,22 +16,13 @@ package com.android.systemui.statusbar.notification.row; -import static android.app.Notification.EXTRA_IS_GROUP_CONVERSATION; - -import static java.lang.annotation.RetentionPolicy.SOURCE; - -import android.annotation.IntDef; import android.app.INotificationManager; -import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; -import android.graphics.drawable.Icon; -import android.os.Bundle; -import android.os.Parcelable; import android.os.RemoteException; import android.service.notification.StatusBarNotification; import android.text.TextUtils; @@ -46,8 +37,6 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.R; import com.android.systemui.statusbar.notification.collection.NotificationEntry; -import java.lang.annotation.Retention; -import java.util.List; import java.util.Set; /** @@ -71,8 +60,6 @@ public class PartialConversationInfo extends LinearLayout implements private Set mUniqueChannelsInRow; private Drawable mPkgIcon; - private @Action int mSelectedAction = -1; - private boolean mPressedApply; private boolean mPresentingChannelEditorDialog = false; private NotificationInfo.OnSettingsClickListener mOnSettingsClickListener; @@ -82,14 +69,8 @@ public class PartialConversationInfo extends LinearLayout implements @VisibleForTesting boolean mSkipPost = false; - @Retention(SOURCE) - @IntDef({ACTION_SETTINGS}) - private @interface Action {} - static final int ACTION_SETTINGS = 5; - private OnClickListener mOnDone = v -> { - mPressedApply = true; - mGutsContainer.closeControls(v, true); + mGutsContainer.closeControls(v, /* save= */ false); }; public PartialConversationInfo(Context context, AttributeSet attrs) { @@ -107,7 +88,6 @@ public class PartialConversationInfo extends LinearLayout implements NotificationInfo.OnSettingsClickListener onSettingsClick, boolean isDeviceProvisioned, boolean isNonBlockable) { - mSelectedAction = -1; mINotificationManager = iNotificationManager; mPackageName = pkg; mSbn = entry.getSbn(); @@ -286,8 +266,8 @@ public class PartialConversationInfo extends LinearLayout implements } @Override - public boolean shouldBeSaved() { - return mPressedApply; + public boolean shouldBeSavedOnClose() { + return false; } @Override diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java index 381d72f53d5f2..90adabfadd5d7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java @@ -236,7 +236,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { @Test public void testBindNotification_SetsShortcutIcon() { mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -261,7 +260,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { public void testBindNotification_SetsTextApplicationName() { when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -314,7 +312,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setGroup(group.getId()); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -340,7 +337,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { @Test public void testBindNotification_GroupNameHiddenIfNoGroup() { mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -365,7 +361,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { @Test public void testBindNotification_noDelegate() { mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -401,7 +396,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { .setShortcutInfo(mShortcutInfo) .build(); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -427,7 +421,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { public void testBindNotification_SetsOnClickListenerForSettings() { final CountDownLatch latch = new CountDownLatch(1); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -457,7 +450,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { @Test public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() { mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -482,7 +474,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { public void testBindNotification_SettingsButtonInvisibleWhenDeviceUnprovisioned() { final CountDownLatch latch = new CountDownLatch(1); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -511,7 +502,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportance(IMPORTANCE_LOW); mConversationChannel.setImportantConversation(true); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -540,7 +530,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(false); mConversationChannel.setAllowBubbles(true); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -572,7 +561,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(false); mConversationChannel.setAllowBubbles(true); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -610,7 +598,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(false); mConversationChannel.setAllowBubbles(false); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -639,7 +626,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(false); mConversationChannel.setAllowBubbles(false); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -675,7 +661,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(false); mConversationChannel.setAllowBubbles(true); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -704,7 +689,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(false); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -735,7 +719,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { .isEqualTo(GONE); // no changes until hit done - assertFalse(mNotificationInfo.shouldBeSaved()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), anyInt(), any()); assertFalse(mConversationChannel.isImportantConversation()); @@ -749,7 +733,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportance(IMPORTANCE_LOW); mConversationChannel.setImportantConversation(false); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -779,7 +762,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { .isEqualTo(GONE); // no changes until hit done - assertFalse(mNotificationInfo.shouldBeSaved()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), anyInt(), any()); assertFalse(mConversationChannel.isImportantConversation()); @@ -793,7 +776,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(false); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -825,7 +807,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { .isEqualTo(VISIBLE); // no changes until save - assertFalse(mNotificationInfo.shouldBeSaved()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), anyInt(), any()); assertEquals(IMPORTANCE_DEFAULT, mConversationChannel.getImportance()); @@ -838,7 +820,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(false); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -868,6 +849,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { assertTrue(captor.getValue().isImportantConversation()); assertTrue(captor.getValue().canBubble()); assertEquals(IMPORTANCE_DEFAULT, captor.getValue().getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -876,7 +858,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportance(9); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -913,7 +894,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(true); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -954,7 +934,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { // WHEN we indicate no selected action mNotificationInfo.bindNotification( - -1, // no action selected by default mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -984,8 +963,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(false); // WHEN we indicate the selected action should be "Favorite" + mNotificationInfo.setSelectedAction(NotificationConversationInfo.ACTION_FAVORITE); mNotificationInfo.bindNotification( - NotificationConversationInfo.ACTION_FAVORITE, // "Favorite" selected by default mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -1015,7 +994,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setOriginalImportance(IMPORTANCE_HIGH); mConversationChannel.setImportantConversation(true); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -1044,6 +1022,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { assertFalse(captor.getValue().isImportantConversation()); assertFalse(captor.getValue().canBubble()); assertEquals(IMPORTANCE_HIGH, captor.getValue().getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -1052,7 +1031,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setOriginalImportance(IMPORTANCE_HIGH); mConversationChannel.setImportantConversation(false); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -1089,7 +1067,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setOriginalImportance(IMPORTANCE_HIGH); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -1125,7 +1102,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setAllowBubbles(true); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -1155,12 +1131,46 @@ public class NotificationConversationInfoTest extends SysuiTestCase { assertFalse(captor.getValue().isImportantConversation()); assertFalse(captor.getValue().canBubble()); assertEquals(IMPORTANCE_LOW, captor.getValue().getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); + } + + @Test + public void testSilence_closeGutsThenTryToSave() { + mConversationChannel.setImportance(IMPORTANCE_DEFAULT); + mConversationChannel.setImportantConversation(true); + mConversationChannel.setAllowBubbles(true); + + mNotificationInfo.bindNotification( + mShortcutManager, + mMockPackageManager, + mPeopleSpaceWidgetManager, + mMockINotificationManager, + mOnUserInteractionCallback, + TEST_PACKAGE_NAME, + mNotificationChannel, + mEntry, + mBubbleMetadata, + null, + mIconFactory, + mContext, + true, + mTestHandler, + mTestHandler, null, Optional.of(mBubblesManager), + mShadeController); + + mNotificationInfo.findViewById(R.id.silence).performClick(); + mNotificationInfo.handleCloseControls(false, false); + mNotificationInfo.findViewById(R.id.done).performClick(); + + mTestableLooper.processAllMessages(); + + assertEquals(IMPORTANCE_DEFAULT, mConversationChannel.getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test public void testBindNotification_createsNewChannel() throws Exception { mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -1186,7 +1196,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { public void testBindNotification_doesNotCreateNewChannelIfExists() throws Exception { mNotificationChannel.setConversationId("", CONVERSATION_ID); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -1213,7 +1222,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { //WHEN channel is default importance mNotificationChannel.setImportantConversation(false); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -1244,7 +1252,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { @Test public void testSelectDefaultDoesNotRequestPinPeopleTile() { mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, @@ -1279,7 +1286,6 @@ public class NotificationConversationInfoTest extends SysuiTestCase { mConversationChannel.setImportantConversation(true); mNotificationInfo.bindNotification( - -1, mShortcutManager, mMockPackageManager, mPeopleSpaceWidgetManager, diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsTest.kt new file mode 100644 index 0000000000000..e696c8738d72a --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsTest.kt @@ -0,0 +1,103 @@ +/* + * 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.row + +import android.testing.AndroidTestingRunner +import android.testing.TestableLooper.RunWithLooper +import android.testing.ViewUtils +import android.view.LayoutInflater +import android.view.View +import androidx.test.filters.SmallTest +import com.android.systemui.R +import com.android.systemui.SysuiTestCase +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito.verify +import org.mockito.Mockito.`when` as whenever +import org.mockito.MockitoAnnotations + +@SmallTest +@RunWith(AndroidTestingRunner::class) +@RunWithLooper +class NotificationGutsTest : SysuiTestCase() { + + private lateinit var guts: NotificationGuts + private lateinit var gutsContentView: View + + @Mock + private lateinit var gutsContent: NotificationGuts.GutsContent + + @Mock + private lateinit var gutsClosedListener: NotificationGuts.OnGutsClosedListener + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + + val layoutInflater = LayoutInflater.from(mContext) + guts = layoutInflater.inflate(R.layout.notification_guts, null) as NotificationGuts + gutsContentView = View(mContext) + + whenever(gutsContent.contentView).thenReturn(gutsContentView) + + ViewUtils.attachView(guts) + } + + @After + fun tearDown() { + ViewUtils.detachView(guts) + } + + @Test + fun setGutsContent() { + guts.gutsContent = gutsContent + + verify(gutsContent).setGutsParent(guts) + } + + @Test + fun openControls() { + guts.gutsContent = gutsContent + + guts.openControls(true, 0, 0, false, null) + } + + @Test + fun closeControlsWithSave() { + guts.gutsContent = gutsContent + guts.setClosedListener(gutsClosedListener) + + guts.closeControls(gutsContentView, true) + + verify(gutsContent).handleCloseControls(true, false) + verify(gutsClosedListener).onGutsClosed(guts) + } + + @Test + fun closeControlsWithoutSave() { + guts.gutsContent = gutsContent + guts.setClosedListener(gutsClosedListener) + + guts.closeControls(gutsContentView, false) + + verify(gutsContent).handleCloseControls(false, false) + verify(gutsClosedListener).onGutsClosed(guts) + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java index b1f10751119e9..80a81a5920499 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java @@ -50,6 +50,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; +import android.os.RemoteException; import android.os.UserHandle; import android.service.notification.StatusBarNotification; import android.telecom.TelecomManager; @@ -1090,6 +1091,7 @@ public class NotificationInfoTest extends SysuiTestCase { mUiEventLogger.eventId(0)); assertEquals(NotificationControlsEvent.NOTIFICATION_CONTROLS_SAVE_IMPORTANCE.getId(), mUiEventLogger.eventId(1)); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -1124,6 +1126,7 @@ public class NotificationInfoTest extends SysuiTestCase { assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -1156,6 +1159,7 @@ public class NotificationInfoTest extends SysuiTestCase { verify(mMockINotificationManager, times(1)).unlockNotificationChannel( anyString(), eq(TEST_UID), any()); assertEquals(IMPORTANCE_DEFAULT, mNotificationChannel.getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -1191,6 +1195,7 @@ public class NotificationInfoTest extends SysuiTestCase { assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -1229,6 +1234,37 @@ public class NotificationInfoTest extends SysuiTestCase { anyString(), eq(TEST_UID), updated.capture()); assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); + } + + @Test + public void testSilence_closeGutsThenTryToSave() throws RemoteException { + mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); + mNotificationInfo.bindNotification( + mMockPackageManager, + mMockINotificationManager, + mOnUserInteractionCallback, + mChannelEditorDialogController, + TEST_PACKAGE_NAME, + mNotificationChannel, + mNotificationChannelSet, + mEntry, + null, + null, + mUiEventLogger, + true, + false, + false, + mAssistantFeedbackController); + + mNotificationInfo.findViewById(R.id.silence).performClick(); + mNotificationInfo.handleCloseControls(false, false); + mNotificationInfo.handleCloseControls(true, false); + + mTestableLooper.processAllMessages(); + + assertEquals(IMPORTANCE_DEFAULT, mNotificationChannel.getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -1267,6 +1303,7 @@ public class NotificationInfoTest extends SysuiTestCase { anyString(), eq(TEST_UID), updated.capture()); assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -1294,6 +1331,7 @@ public class NotificationInfoTest extends SysuiTestCase { mNotificationInfo.handleCloseControls(true, false); verify(mOnUserInteractionCallback).onImportanceChanged(mEntry); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -1360,6 +1398,7 @@ public class NotificationInfoTest extends SysuiTestCase { assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test @@ -1450,7 +1489,7 @@ public class NotificationInfoTest extends SysuiTestCase { mNotificationInfo.findViewById(R.id.alert).performClick(); - assertFalse(mNotificationInfo.shouldBeSaved()); + assertFalse(mNotificationInfo.shouldBeSavedOnClose()); } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java index 43aa8fef76a90..12c8fd5db7510 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java @@ -16,7 +16,6 @@ package com.android.systemui.statusbar.notification.row; -import static android.app.Notification.EXTRA_IS_GROUP_CONVERSATION; import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME; import static android.view.View.GONE; @@ -25,7 +24,6 @@ import static android.view.View.VISIBLE; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.anyInt; @@ -36,8 +34,6 @@ import static org.mockito.Mockito.when; import android.app.INotificationManager; import android.app.Notification; import android.app.NotificationChannel; -import android.app.NotificationChannelGroup; -import android.app.Person; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager;