From 8b6431878a114532bfef12fa61c7374f0af55b3c Mon Sep 17 00:00:00 2001 From: Yining Liu Date: Wed, 28 Aug 2024 23:34:29 +0000 Subject: [PATCH 1/2] 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(), From 41cd514fb3792607ab31f73d79c2bc9bb36ef2fc Mon Sep 17 00:00:00 2001 From: Yining Liu Date: Thu, 5 Sep 2024 15:11:45 +0000 Subject: [PATCH 2/2] Notification Minimalism Settings Main Switch Add a main preference switch for the lockscreen notification minimalism feature Bug: 330387368 Bug: 354047572 Flag: com.android.server.notification.notification_minimalism Test: atest LockscreenNotificationMinimalismPreferenceControllerTest Change-Id: I9aa4c51f9e316dd0dd1529d712b5e9486e43453b --- res/values/strings.xml | 7 ++ res/xml/configure_notification_settings.xml | 24 ++-- ...icationMinimalismPreferenceController.java | 74 ++++++++++++ ...ionMinimalismPreferenceControllerTest.java | 105 ++++++++++++++++++ 4 files changed, 202 insertions(+), 8 deletions(-) create mode 100644 src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceController.java create mode 100644 tests/robotests/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceControllerTest.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 0392bfc52b3..cf0e112a15f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -8657,6 +8657,13 @@ When work profile is locked + + Lock screen notification minimalism + + + Show fewer notifications on lock screen + Show only new notifications on lock screen diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml index b673a0839b0..c88b7bace8a 100644 --- a/res/xml/configure_notification_settings.xml +++ b/res/xml/configure_notification_settings.xml @@ -136,8 +136,16 @@ /> + + diff --git a/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceController.java b/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceController.java new file mode 100644 index 00000000000..7b48ba7ff5a --- /dev/null +++ b/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceController.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2024 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.settings.notification; + +import static android.provider.Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM; +import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS; + +import android.content.Context; +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; + +public class LockscreenNotificationMinimalismPreferenceController + extends TogglePreferenceController { + + @VisibleForTesting + static final int ON = 1; + @VisibleForTesting + static final int OFF = 0; + + public LockscreenNotificationMinimalismPreferenceController( + Context context, + String preferenceKey) { + super(context, preferenceKey); + } + + @Override + public boolean isChecked() { + return Settings.Secure.getInt(mContext.getContentResolver(), + LOCK_SCREEN_NOTIFICATION_MINIMALISM, ON) == ON; + } + + @Override + public boolean setChecked(boolean isChecked) { + return Settings.Secure.putInt(mContext.getContentResolver(), + LOCK_SCREEN_NOTIFICATION_MINIMALISM, isChecked ? ON : OFF); + } + + @Override + public int getAvailabilityStatus() { + if (!Flags.notificationMinimalism()) { + return CONDITIONALLY_UNAVAILABLE; + } + int lockScreenNotif = Settings.Secure.getInt(mContext.getContentResolver(), + LOCK_SCREEN_SHOW_NOTIFICATIONS, 0); + if (lockScreenNotif == 0) { + return DISABLED_DEPENDENT_SETTING; + } + return AVAILABLE; + } + + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_notifications; + } +} diff --git a/tests/robotests/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceControllerTest.java new file mode 100644 index 00000000000..86dc06fc4d1 --- /dev/null +++ b/tests/robotests/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceControllerTest.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2024 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.settings.notification; + +import static android.provider.Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +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; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; + +@RunWith(RobolectricTestRunner.class) +public class LockscreenNotificationMinimalismPreferenceControllerTest { + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Context mContext; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private PreferenceScreen mScreen; + + private LockscreenNotificationMinimalismPreferenceController mController; + private Preference mPreference; + static final int ON = 1; + static final int OFF = 0; + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + doReturn(mock(DevicePolicyManager.class)).when(mContext) + .getSystemService(Context.DEVICE_POLICY_SERVICE); + mController = new LockscreenNotificationMinimalismPreferenceController(mContext, + "key"); + mPreference = new Preference(RuntimeEnvironment.application); + mPreference.setKey(mController.getPreferenceKey()); + when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference); + } + + @Test + @DisableFlags(com.android.server.notification.Flags.FLAG_NOTIFICATION_MINIMALISM) + public void display_featureFlagOff_shouldNotDisplay() { + mController.displayPreference(mScreen); + assertThat(mPreference.isVisible()).isFalse(); + } + + @Test + @EnableFlags(com.android.server.notification.Flags.FLAG_NOTIFICATION_MINIMALISM) + public void display_featureFlagOn_shouldDisplay() { + mController.displayPreference(mScreen); + assertThat(mPreference.isVisible()).isTrue(); + } + + @Test + @EnableFlags(com.android.server.notification.Flags.FLAG_NOTIFICATION_MINIMALISM) + public void isChecked_settingIsOff_shouldReturnFalse() { + Settings.Secure.putInt(mContext.getContentResolver(), + LOCK_SCREEN_NOTIFICATION_MINIMALISM, OFF); + + assertThat(mController.isChecked()).isFalse(); + } + + @Test + @EnableFlags(com.android.server.notification.Flags.FLAG_NOTIFICATION_MINIMALISM) + public void isChecked_settingIsOn_shouldReturnTrue() { + Settings.Secure.putInt(mContext.getContentResolver(), + LOCK_SCREEN_NOTIFICATION_MINIMALISM, ON); + + assertThat(mController.isChecked()).isTrue(); + } +}