Add the new settings page for lock screen notifs

Add a new empty settings page, which is flag-guarded. When the flag
is disabled, show the original Notifications on lock screen
tri-state switch, otherwise show the new page.

Bug: 367455695
Flag: com.android.server.notification.notification_lock_screen_settings
Test: atest LockScreenNotificationsPreferenceControllerTest

Change-Id: I8a81ad651626f39380767b2c9cfa2f1c19d0e7c5
This commit is contained in:
Yining Liu
2024-09-27 17:16:50 +00:00
parent 226c6392ef
commit 9836d6a69a
10 changed files with 233 additions and 17 deletions

View File

@@ -92,23 +92,31 @@
android:singleLineTitle="false" android:singleLineTitle="false"
android:summary="@string/summary_placeholder" /> android:summary="@string/summary_placeholder" />
<Preference
android:key="lock_screen_notifications_page"
android:order="14"
android:persistent="false"
android:title="@string/lock_screen_notifs_title"
android:fragment="com.android.settings.notification.LockScreenNotificationsPreferencePageFragment"
settings:controller="com.android.settings.notification.LockScreenNotificationsPreferencePageController" />
<com.android.settingslib.RestrictedSwitchPreference <com.android.settingslib.RestrictedSwitchPreference
android:key="lock_screen_redact" android:key="lock_screen_redact"
android:order="14" android:order="15"
android:title="@string/lock_screen_notifs_redact" android:title="@string/lock_screen_notifs_redact"
android:summary="@string/lock_screen_notifs_redact_summary" android:summary="@string/lock_screen_notifs_redact_summary"
settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" /> settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" />
<com.android.settingslib.RestrictedSwitchPreference <com.android.settingslib.RestrictedSwitchPreference
android:key="lock_screen_work_redact" android:key="lock_screen_work_redact"
android:order="15" android:order="16"
android:title="@string/lock_screen_notifs_redact_work" android:title="@string/lock_screen_notifs_redact_work"
android:summary="@string/lock_screen_notifs_redact_work_summary" android:summary="@string/lock_screen_notifs_redact_work_summary"
settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" /> settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="notification_lockscreen_bypass" android:key="notification_lockscreen_bypass"
android:order="16" android:order="17"
android:title="@string/lockscreen_bypass_title" android:title="@string/lockscreen_bypass_title"
android:summary="@string/lockscreen_bypass_summary" android:summary="@string/lockscreen_bypass_summary"
settings:searchable="false" settings:searchable="false"
@@ -129,14 +137,14 @@
<Preference <Preference
android:fragment="com.android.settings.notification.PoliteNotificationsPreferenceFragment" android:fragment="com.android.settings.notification.PoliteNotificationsPreferenceFragment"
android:key="polite_notifications_preference" android:key="polite_notifications_preference"
android:order="17" android:order="18"
android:persistent="false" android:persistent="false"
android:title="@string/notification_polite_title" android:title="@string/notification_polite_title"
settings:controller="com.android.settings.notification.PoliteNotificationsPreferenceController" /> settings:controller="com.android.settings.notification.PoliteNotificationsPreferenceController" />
<com.android.settingslib.RestrictedPreference <com.android.settingslib.RestrictedPreference
android:key="zen_mode_notifications" android:key="zen_mode_notifications"
android:order="18" android:order="19"
android:title="@string/zen_mode_settings_title" android:title="@string/zen_mode_settings_title"
settings:useAdminDisabledSummary="true" settings:useAdminDisabledSummary="true"
android:fragment="com.android.settings.notification.zen.ZenModeSettings" android:fragment="com.android.settings.notification.zen.ZenModeSettings"
@@ -145,7 +153,7 @@
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="lock_screen_notif_minimalism" android:key="lock_screen_notif_minimalism"
android:order="19" android:order="20"
android:title="@string/lock_screen_notif_minimalism" android:title="@string/lock_screen_notif_minimalism"
android:summary="@string/lock_screen_notif_minimalism_summary" android:summary="@string/lock_screen_notif_minimalism_summary"
settings:controller="com.android.settings.notification.LockscreenNotificationMinimalismPreferenceController" settings:controller="com.android.settings.notification.LockscreenNotificationMinimalismPreferenceController"
@@ -153,7 +161,7 @@
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="lock_screen_show_only_unseen_notifs" android:key="lock_screen_show_only_unseen_notifs"
android:order="20" android:order="21"
android:title="@string/unseen_notifs_lock_screen" android:title="@string/unseen_notifs_lock_screen"
android:summary="@string/unseen_notifs_lock_screen_summary" android:summary="@string/unseen_notifs_lock_screen_summary"
settings:controller="com.android.settings.notification.ShowOnlyUnseenNotificationsOnLockscreenPreferenceController" settings:controller="com.android.settings.notification.ShowOnlyUnseenNotificationsOnLockscreenPreferenceController"
@@ -162,7 +170,7 @@
<Preference <Preference
android:fragment="com.android.settings.accessibility.FlashNotificationsPreferenceFragment" android:fragment="com.android.settings.accessibility.FlashNotificationsPreferenceFragment"
android:key="flash_notifications_preference" android:key="flash_notifications_preference"
android:order="21" android:order="22"
android:persistent="false" android:persistent="false"
android:title="@string/flash_notifications_title" android:title="@string/flash_notifications_title"
settings:searchable="false" settings:searchable="false"
@@ -170,7 +178,7 @@
<com.android.settingslib.RestrictedPreference <com.android.settingslib.RestrictedPreference
android:key="app_and_notif_cell_broadcast_settings" android:key="app_and_notif_cell_broadcast_settings"
android:order="22" android:order="23"
android:title="@string/cell_broadcast_settings" android:title="@string/cell_broadcast_settings"
settings:useAdminDisabledSummary="true"> settings:useAdminDisabledSummary="true">
<intent <intent
@@ -181,33 +189,33 @@
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="silent_icons" android:key="silent_icons"
android:order="23" android:order="24"
android:title="@string/silent_notifications_status_bar" android:title="@string/silent_notifications_status_bar"
settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController"/> settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController"/>
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="show_snooze_options" android:key="show_snooze_options"
android:order="24" android:order="25"
android:title="@string/snooze_options_title" android:title="@string/snooze_options_title"
settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" /> settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
<!-- Notification badging --> <!-- Notification badging -->
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="notification_badging" android:key="notification_badging"
android:order="25" android:order="26"
android:title="@string/notification_badging_title" android:title="@string/notification_badging_title"
settings:controller="com.android.settings.notification.BadgingNotificationPreferenceController"/> settings:controller="com.android.settings.notification.BadgingNotificationPreferenceController"/>
<!-- Pulse notification light, on devices that support it --> <!-- Pulse notification light, on devices that support it -->
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="notification_pulse" android:key="notification_pulse"
android:order="26" android:order="27"
android:title="@string/notification_pulse_title" android:title="@string/notification_pulse_title"
settings:controller="com.android.settings.notification.PulseNotificationPreferenceController"/> settings:controller="com.android.settings.notification.PulseNotificationPreferenceController"/>
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="notification_assistant" android:key="notification_assistant"
android:order="27" android:order="28"
android:title="@string/notification_assistant_title" android:title="@string/notification_assistant_title"
android:summary="@string/notification_assistant_summary" android:summary="@string/notification_assistant_summary"
settings:controller="com.android.settings.notification.NotificationAssistantPreferenceController"/> settings:controller="com.android.settings.notification.NotificationAssistantPreferenceController"/>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/lock_screen_notifs_title"
xmlns:settings="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto">
</PreferenceScreen>

View File

@@ -0,0 +1,40 @@
/*
* 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 android.content.Context;
import com.android.server.notification.Flags;
import com.android.settings.core.BasePreferenceController;
// TODO(b/367455695): remove controller when the feature flag is removed!
/**
* Controller for lock screen notifications settings page.
*/
public class LockScreenNotificationsPreferencePageController extends BasePreferenceController {
public LockScreenNotificationsPreferencePageController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return Flags.notificationLockScreenSettings() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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 android.app.settings.SettingsEnums;
import android.content.Context;
import com.android.server.notification.Flags;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
/**
* Fragment for notifications on lock screen preference page.
*/
@SearchIndexable
public class LockScreenNotificationsPreferencePageFragment extends DashboardFragment {
@Override
public int getMetricsCategory() {
//TODO(b/367455695): create a new metrics category
return SettingsEnums.SETTINGS_LOCK_SCREEN_PREFERENCES;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.lock_screen_notifications_settings;
}
@Override
protected String getLogTag() {
return "LockScreenNotificationsPreferenceFragment";
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.lock_screen_notifications_settings) {
@Override
protected boolean isPageSearchEnabled(Context context) {
return Flags.notificationLockScreenSettings();
}
};
}

View File

@@ -56,6 +56,10 @@ public class LockscreenNotificationMinimalismPreferenceController
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
// Hide when the notifications on lock screen settings page flag is enabled.
if (Flags.notificationLockScreenSettings()) {
return CONDITIONALLY_UNAVAILABLE;
}
if (!Flags.notificationMinimalism()) { if (!Flags.notificationMinimalism()) {
return CONDITIONALLY_UNAVAILABLE; return CONDITIONALLY_UNAVAILABLE;
} }

View File

@@ -18,16 +18,19 @@ package com.android.settings.notification;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull;
import com.android.server.notification.Flags; import com.android.server.notification.Flags;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
// TODO: b/291897570 - remove controller when the feature flag is removed! // TODO(b/330606963): remove controller when the feature flag is removed!
/** /**
* Controller for polite notifications settings page. * Controller for polite notifications settings page.
*/ */
public class PoliteNotificationsPreferenceController extends BasePreferenceController { public class PoliteNotificationsPreferenceController extends BasePreferenceController {
public PoliteNotificationsPreferenceController(Context context, String preferenceKey) { public PoliteNotificationsPreferenceController(@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey); super(context, preferenceKey);
} }

View File

@@ -33,6 +33,7 @@ import android.provider.Settings;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.server.notification.Flags;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController; import com.android.settings.core.TogglePreferenceController;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
@@ -120,6 +121,11 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
// Hide when the notifications on lock screen settings page flag is enabled.
if (Flags.notificationLockScreenSettings()) {
return CONDITIONALLY_UNAVAILABLE;
}
// hide work profile setting if no work profile // hide work profile setting if no work profile
if (KEY_LOCKSCREEN_WORK_PROFILE_REDACT.equals(getPreferenceKey()) if (KEY_LOCKSCREEN_WORK_PROFILE_REDACT.equals(getPreferenceKey())
&& mProfileUserId == UserHandle.myUserId()) { && mProfileUserId == UserHandle.myUserId()) {

View File

@@ -26,6 +26,7 @@ import android.provider.Settings;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.server.notification.Flags;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.RestrictedListPreference; import com.android.settings.RestrictedListPreference;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
@@ -63,7 +64,8 @@ public class ShowOnLockScreenNotificationPreferenceController extends AbstractPr
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {
return true; // When notificationLockScreenSettings is enabled, show the lock screen notif settings page
return !Flags.notificationLockScreenSettings();
} }
@Override @Override

View File

@@ -57,6 +57,10 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceController
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
// Hide when the notifications on lock screen page flag is enabled.
if (Flags.notificationLockScreenSettings()) {
return CONDITIONALLY_UNAVAILABLE;
}
if (Flags.notificationMinimalism()) { if (Flags.notificationMinimalism()) {
if (!isNotifOnLockScreenEnabled()) { if (!isNotifOnLockScreenEnabled()) {
return DISABLED_DEPENDENT_SETTING; return DISABLED_DEPENDENT_SETTING;

View File

@@ -0,0 +1,69 @@
/*
* 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 com.google.common.truth.Truth.assertThat;
import android.platform.test.flag.junit.SetFlagsRule;
import com.android.server.notification.Flags;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
// TODO(b/367455695): remove test when feature flag is cleaned
@RunWith(RobolectricTestRunner.class)
public class LockScreenNotificationsPreferencePageControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final String PREFERENCE_KEY = "lock_screen_notifications_page";
private LockScreenNotificationsPreferencePageController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new LockScreenNotificationsPreferencePageController(
RuntimeEnvironment.application,
PREFERENCE_KEY);
}
@Test
public void isAvailable_flagEnabled_shouldReturnTrue() {
mSetFlagsRule.enableFlags(Flags.FLAG_NOTIFICATION_LOCK_SCREEN_SETTINGS);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void isAvailable_flagDisabled_shouldReturnFalse() {
mSetFlagsRule.disableFlags(Flags.FLAG_NOTIFICATION_LOCK_SCREEN_SETTINGS);
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
}