Implement the Hide seen notifications toggle
Implement the Hide seen notifications toggle on the notifications on lock screen page. The toggle will become invisible when the main toggle is unset or when the lock screen notification minimalism feature flag is disabled. Bug: 367455695 Flag: com.android.server.notification.notification_lock_screen_settings Test: adb shell settings get secure \ lock_screen_show_notifications <1|0> Change-Id: I6f94be3295dfbaa978d145d113e03cacc1a232fc
This commit is contained in:
@@ -8851,6 +8851,12 @@
|
||||
<!-- Security > Choose PIN/PW/Pattern > Notification redaction interstitial: Message asking the user how they want their profile notifications to appear when the device is locked [CHAR LIMIT=NONE] -->
|
||||
<string name="lock_screen_notifications_interstitial_message_profile">When your device is locked, how do you want profile notifications to show?</string>
|
||||
|
||||
<!-- Notification Settings > Notifications on lock screen > Title for hiding seen notifications toggle. [CHAR LIMIT=30] -->
|
||||
<string name="lock_screen_notification_hide_seen_title">Hide seen notifications</string>
|
||||
|
||||
<!-- Notification Settings > Notifications on lock screen > Summary for hiding seen notifications toggle. [CHAR LIMIT=30] -->
|
||||
<string name="lock_screen_notification_hide_seen_summary">Seen notifications are removed from the lock screen.</string>
|
||||
|
||||
<!-- Notification Settings > Notifications on lock screen > Title for hiding silent notifications toggle. [CHAR LIMIT=30] -->
|
||||
<string name="lock_screen_notification_hide_silent_title">Hide silent notifications</string>
|
||||
|
||||
|
||||
@@ -35,6 +35,12 @@
|
||||
android:title="@string/lock_screen_notifications_summary_hide_profile"
|
||||
settings:controller="com.android.settings.notification.LockScreenNotificationShowSensitiveToggleController" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="lock_screen_notification_hide_seen_toggle"
|
||||
android:title="@string/lock_screen_notification_hide_seen_title"
|
||||
android:summary="@string/lock_screen_notification_hide_seen_summary"
|
||||
settings:controller="com.android.settings.notification.LockScreenNotificationHideSeenToggleController" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="lock_screen_notification_hide_silent_toggle"
|
||||
android:title="@string/lock_screen_notification_hide_silent_title"
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleEventObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.server.notification.Flags;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* Controls the toggle that determines whether to hide seen notifications from the lock screen.
|
||||
* Toggle for setting: Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS
|
||||
*/
|
||||
public class LockScreenNotificationHideSeenToggleController extends TogglePreferenceController
|
||||
implements LifecycleEventObserver {
|
||||
|
||||
private static final int UNSET = 0;
|
||||
static final int ON = 1;
|
||||
static final int OFF = 2;
|
||||
@Nullable private Preference mPreference;
|
||||
private final ContentResolver mContentResolver;
|
||||
|
||||
final ContentObserver mContentObserver = new ContentObserver(
|
||||
new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
||||
if (mPreference == null) return;
|
||||
updateState(mPreference);
|
||||
}
|
||||
};
|
||||
|
||||
public LockScreenNotificationHideSeenToggleController(@NonNull Context context,
|
||||
@NonNull String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mContentResolver = context.getContentResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner,
|
||||
@NonNull Lifecycle.Event event) {
|
||||
if (event == Lifecycle.Event.ON_RESUME) {
|
||||
mContentResolver.registerContentObserver(
|
||||
Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS),
|
||||
/* notifyForDescendants= */ false, mContentObserver);
|
||||
mContentResolver.registerContentObserver(
|
||||
Settings.Secure.getUriFor(
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS),
|
||||
/* notifyForDescendants= */ false,
|
||||
mContentObserver
|
||||
);
|
||||
} else if (event == Lifecycle.Event.ON_PAUSE) {
|
||||
mContentResolver.unregisterContentObserver(mContentObserver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(@NonNull Preference preference) {
|
||||
super.updateState(preference);
|
||||
setChecked(lockScreenShowOnlyUnseenNotifications());
|
||||
preference.setVisible(isAvailable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!Flags.notificationMinimalism()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
if (!lockScreenShowNotification()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether showing notifications on the lockscreen is enabled.
|
||||
*/
|
||||
private boolean lockScreenShowNotification() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, OFF) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return lockScreenShowOnlyUnseenNotifications();
|
||||
}
|
||||
|
||||
private boolean lockScreenShowOnlyUnseenNotifications() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, (isChecked ? ON : OFF));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
// not needed because Sliceable is deprecated
|
||||
return NO_RES;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user