From 8b6431878a114532bfef12fa61c7374f0af55b3c Mon Sep 17 00:00:00 2001 From: Yining Liu Date: Wed, 28 Aug 2024 23:34:29 +0000 Subject: [PATCH] Show the Tangor Unseen Notification Toggle when notification_minimalism is Enabled Show the Tangor unseen notification toggle in the Notification settings when notification_minimalism flag is enabled on both phones and large screen devices. Bug: 330387368 Bug: 354047572 Flag: com.android.server.notification.notification_minimalism Test: atest ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest Change-Id: Ic126b7885eb29897b55c4acdc1a2f73b4bc7841e --- ...cationsOnLockscreenPreferenceController.java | 14 ++++++++++++++ ...onsOnLockscreenPreferenceControllerTest.java | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceController.java b/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceController.java index a37e29d2347..9534483d25f 100644 --- a/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceController.java +++ b/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceController.java @@ -16,6 +16,7 @@ package com.android.settings.notification; +import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS; import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS; import android.content.Context; @@ -23,6 +24,7 @@ import android.provider.Settings; import androidx.annotation.VisibleForTesting; +import com.android.server.notification.Flags; import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; @@ -55,6 +57,13 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceController @Override public int getAvailabilityStatus() { + if (Flags.notificationMinimalism()) { + if (!isNotifOnLockScreenEnabled()) { + return DISABLED_DEPENDENT_SETTING; + } + // We want to show the switch when the lock screen notification minimalism flag is on. + return AVAILABLE; + } int setting = Settings.Secure.getInt(mContext.getContentResolver(), LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET); if (setting == UNSET) { @@ -68,4 +77,9 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceController public int getSliceHighlightMenuRes() { return R.string.menu_key_notifications; } + + private boolean isNotifOnLockScreenEnabled() { + return Settings.Secure.getInt(mContext.getContentResolver(), + LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) == 1; + } } diff --git a/tests/robotests/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest.java index cc26e542dc4..8877f300e22 100644 --- a/tests/robotests/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest.java @@ -29,12 +29,16 @@ import static org.mockito.Mockito.when; import android.app.admin.DevicePolicyManager; import android.content.Context; +import android.platform.test.annotations.DisableFlags; +import android.platform.test.annotations.EnableFlags; +import android.platform.test.flag.junit.SetFlagsRule; import android.provider.Settings; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -53,6 +57,8 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest { private ShowOnlyUnseenNotificationsOnLockscreenPreferenceController mController; private Preference mPreference; + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Before public void setUp() { @@ -67,12 +73,14 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest { } @Test + @DisableFlags(com.android.server.notification.Flags.FLAG_NOTIFICATION_MINIMALISM) public void display_configUnset_shouldNotDisplay() { mController.displayPreference(mScreen); assertThat(mPreference.isVisible()).isFalse(); } @Test + @DisableFlags(com.android.server.notification.Flags.FLAG_NOTIFICATION_MINIMALISM) public void display_configSet_showDisplay() { Settings.Secure.putInt(mContext.getContentResolver(), LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, OFF); @@ -80,6 +88,15 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest { assertThat(mPreference.isVisible()).isTrue(); } + @Test + @EnableFlags(com.android.server.notification.Flags.FLAG_NOTIFICATION_MINIMALISM) + public void display_configUnset_minimalismEnabled_shouldDisplay() { + Settings.Secure.putInt(mContext.getContentResolver(), + LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, ON); + mController.displayPreference(mScreen); + assertThat(mPreference.isVisible()).isTrue(); + } + @Test public void isChecked_settingIsOff_shouldReturnFalse() { Settings.Secure.putInt(mContext.getContentResolver(),