Merge changes from topic "lockscreen-notif-settings-page" into main
* changes: Replace the existing notifications on lock screen preferences with new page Implement the preference switch for minimalism on ls settings page Implement the Hide seen notifications toggle Implement the hide silent notifications toggle Implement the show sensitive content toggle Implement the main switch of notifications on lock screen Add the new settings page for lock screen notifs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* Controls the toggle that determines whether to show silent notifications when screen locked.
|
||||
* Toggle for: Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS
|
||||
*/
|
||||
public class LockScreenNotificationHideSilentToggleController extends TogglePreferenceController
|
||||
implements LifecycleEventObserver {
|
||||
|
||||
private static final int ON = 1;
|
||||
private static final int OFF = 0;
|
||||
|
||||
@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 LockScreenNotificationHideSilentToggleController(@NonNull Context context,
|
||||
@NonNull String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mContentResolver = context.getContentResolver();
|
||||
}
|
||||
|
||||
@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_SILENT_NOTIFICATIONS),
|
||||
/* notifyForDescendants= */ false,
|
||||
mContentObserver
|
||||
);
|
||||
} else if (event == Lifecycle.Event.ON_PAUSE) {
|
||||
mContentResolver.unregisterContentObserver(mContentObserver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(@NonNull Preference preference) {
|
||||
super.updateState(preference);
|
||||
setChecked(hideSilentNotificationsWhenLocked());
|
||||
preference.setVisible(isAvailable());
|
||||
}
|
||||
|
||||
private boolean hideSilentNotificationsWhenLocked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, OFF) == OFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
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 hideSilentNotificationsWhenLocked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, (isChecked ? OFF : ON));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
// not needed since it's not sliceable
|
||||
return NO_RES;
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.server.notification.Flags;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.RestrictedListPreference;
|
||||
import com.android.settings.Utils;
|
||||
@@ -94,6 +95,13 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
// Hide the preference when the lock screen notification page shows
|
||||
if (Flags.notificationLockScreenSettings()) {
|
||||
setVisible(screen, mSettingKey, false);
|
||||
setVisible(screen, mWorkSettingKey, false);
|
||||
setVisible(screen, mWorkSettingCategoryKey, false);
|
||||
return;
|
||||
}
|
||||
mLockscreen = screen.findPreference(mSettingKey);
|
||||
if (mLockscreen == null) {
|
||||
Log.i(TAG, "Preference not found: " + mSettingKey);
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* 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.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
|
||||
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleEventObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controls the toggle that determines whether to show sensitive notifications on the lock screen
|
||||
* when locked.
|
||||
* Toggle for: Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS
|
||||
*/
|
||||
public class LockScreenNotificationShowSensitiveToggleController
|
||||
extends TogglePreferenceController implements LifecycleEventObserver {
|
||||
|
||||
private static final int ON = 1;
|
||||
private static final int OFF = 0;
|
||||
@VisibleForTesting
|
||||
static final String KEY_SHOW_SENSITIVE = "lock_screen_notification_show_sensitive_toggle";
|
||||
@VisibleForTesting
|
||||
static final String KEY_SHOW_SENSITIVE_WORK_PROFILE =
|
||||
"work_profile_show_sensitive_notif_toggle";
|
||||
@Nullable private RestrictedSwitchPreference mPreference;
|
||||
private final ContentResolver mContentResolver;
|
||||
private UserManager mUserManager;
|
||||
private KeyguardManager mKeyguardManager;
|
||||
@VisibleForTesting
|
||||
int mWorkProfileUserId;
|
||||
|
||||
final ContentObserver mContentObserver = new ContentObserver(
|
||||
new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
};
|
||||
|
||||
public LockScreenNotificationShowSensitiveToggleController(@NonNull Context context,
|
||||
@NonNull String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mContentResolver = context.getContentResolver();
|
||||
|
||||
mUserManager = context.getSystemService(UserManager.class);
|
||||
mKeyguardManager = context.getSystemService(KeyguardManager.class);
|
||||
mWorkProfileUserId = UserHandle.myUserId();
|
||||
final List<UserInfo> profiles = mUserManager.getProfiles(UserHandle.myUserId());
|
||||
|
||||
for (UserInfo profile: profiles) {
|
||||
if (profile.isManagedProfile()
|
||||
&& profile.getUserHandle().getIdentifier() != UserHandle.myUserId()) {
|
||||
mWorkProfileUserId = profile.getUserHandle().getIdentifier();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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_ALLOW_PRIVATE_NOTIFICATIONS),
|
||||
/* notifyForDescendants= */ false,
|
||||
mContentObserver
|
||||
);
|
||||
} else if (event == Lifecycle.Event.ON_PAUSE) {
|
||||
mContentResolver.unregisterContentObserver(mContentObserver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
int userId = getUserId();
|
||||
|
||||
if (mPreference != null && userId != UserHandle.USER_NULL) {
|
||||
mPreference.setDisabledByAdmin(getEnforcedAdmin(userId));
|
||||
}
|
||||
}
|
||||
|
||||
private RestrictedLockUtils.EnforcedAdmin getEnforcedAdmin(int userId) {
|
||||
RestrictedLockUtils.EnforcedAdmin admin =
|
||||
RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
|
||||
mContext, KEYGUARD_DISABLE_SECURE_NOTIFICATIONS, userId);
|
||||
if (admin != null) {
|
||||
return admin;
|
||||
}
|
||||
admin = RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
|
||||
mContext, KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS, userId);
|
||||
return admin;
|
||||
}
|
||||
|
||||
private int getUserId() {
|
||||
return KEY_SHOW_SENSITIVE.equals(getPreferenceKey())
|
||||
? UserHandle.myUserId() : mWorkProfileUserId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(@Nullable Preference preference) {
|
||||
if (preference == null) return;
|
||||
setChecked(showSensitiveContentOnlyWhenUnlocked());
|
||||
preference.setVisible(isAvailable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// hide setting if no lock screen notification
|
||||
if (!lockScreenShowNotification()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
// hide setting if no screen lock
|
||||
if (!isLockScreenSecure()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
// For the work profile toggle
|
||||
if (KEY_SHOW_SENSITIVE_WORK_PROFILE.equals(getPreferenceKey())) {
|
||||
// hide work profile setting if no work profile
|
||||
if (mWorkProfileUserId == UserHandle.myUserId()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
// specifically the work profile setting requires the work profile to be unlocked
|
||||
if (mKeyguardManager.isDeviceLocked(mWorkProfileUserId)) {
|
||||
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, ON) != OFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return showSensitiveContentOnlyWhenUnlocked();
|
||||
}
|
||||
|
||||
private boolean showSensitiveContentOnlyWhenUnlocked() {
|
||||
int userId = getUserId();
|
||||
if (!isLockScreenSecure()) return false;
|
||||
if (getEnforcedAdmin(userId) != null) return true;
|
||||
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, ON, userId) == OFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putIntForUser(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
|
||||
(isChecked ? OFF : ON), getUserId()
|
||||
);
|
||||
}
|
||||
|
||||
private boolean isLockScreenSecure() {
|
||||
return FeatureFactory.getFeatureFactory()
|
||||
.getSecurityFeatureProvider()
|
||||
.getLockPatternUtils(mContext)
|
||||
.isSecure(UserHandle.myUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
// not needed since it's not sliceable
|
||||
return NO_RES;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.widget.SettingsMainSwitchPreferenceController;
|
||||
|
||||
public class LockScreenNotificationsGlobalPreferenceController
|
||||
extends SettingsMainSwitchPreferenceController
|
||||
implements LifecycleEventObserver {
|
||||
|
||||
public static final int ON = 1;
|
||||
public static final int OFF = 0;
|
||||
private final ContentResolver mContentResolver;
|
||||
private final ContentObserver mContentObserver;
|
||||
@Nullable private Preference mPreference;
|
||||
|
||||
|
||||
public LockScreenNotificationsGlobalPreferenceController(
|
||||
@NonNull Context context,
|
||||
@NonNull String preferenceKey
|
||||
) {
|
||||
super(context, preferenceKey);
|
||||
mContentResolver = context.getContentResolver();
|
||||
mContentObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
||||
if (mPreference == null) return;
|
||||
updateState(mPreference);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(@NonNull Preference preference) {
|
||||
super.updateState(preference);
|
||||
setChecked(lockScreenShowNotifications());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// TODO: b/367455695 - remove this when the feature flag is removed!
|
||||
return Flags.notificationLockScreenSettings() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return lockScreenShowNotifications();
|
||||
}
|
||||
|
||||
private boolean lockScreenShowNotifications() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, OFF) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, (isChecked ? ON : OFF));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
// not needed since it's not sliceable
|
||||
return NO_RES;
|
||||
}
|
||||
|
||||
@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
|
||||
);
|
||||
} else {
|
||||
mContentResolver.unregisterContentObserver(mContentObserver);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -56,6 +56,10 @@ public class LockscreenNotificationMinimalismPreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// Hide when the notifications on lock screen settings page flag is enabled.
|
||||
if (Flags.notificationLockScreenSettings()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
if (!Flags.notificationMinimalism()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@@ -18,16 +18,19 @@ package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.server.notification.Flags;
|
||||
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.
|
||||
*/
|
||||
public class PoliteNotificationsPreferenceController extends BasePreferenceController {
|
||||
|
||||
public PoliteNotificationsPreferenceController(Context context, String preferenceKey) {
|
||||
public PoliteNotificationsPreferenceController(@NonNull Context context,
|
||||
@NonNull String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.provider.Settings;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.server.notification.Flags;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
@@ -120,6 +121,11 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
|
||||
|
||||
@Override
|
||||
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
|
||||
if (KEY_LOCKSCREEN_WORK_PROFILE_REDACT.equals(getPreferenceKey())
|
||||
&& mProfileUserId == UserHandle.myUserId()) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.provider.Settings;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.server.notification.Flags;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.RestrictedListPreference;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
@@ -63,7 +64,8 @@ public class ShowOnLockScreenNotificationPreferenceController extends AbstractPr
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
// When notificationLockScreenSettings is enabled, show the lock screen notif settings page
|
||||
return !Flags.notificationLockScreenSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -57,6 +57,10 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// Hide when the notifications on lock screen page flag is enabled.
|
||||
if (Flags.notificationLockScreenSettings()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
if (Flags.notificationMinimalism()) {
|
||||
if (!isNotifOnLockScreenEnabled()) {
|
||||
return DISABLED_DEPENDENT_SETTING;
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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.lockscreen;
|
||||
|
||||
import static android.provider.Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM;
|
||||
import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS;
|
||||
|
||||
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 android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleEventObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.server.notification.Flags;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.IllustrationPreference;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MinimalismPreferenceController
|
||||
extends BasePreferenceController
|
||||
implements LifecycleEventObserver {
|
||||
|
||||
private static final int LS_SHOW_NOTIF_ON = 1;
|
||||
private static final int LS_SHOW_NOTIF_OFF = 0;
|
||||
private static final int LS_MINIMALISM_OFF = 0;
|
||||
private static final int LS_MINIMALISM_ON = 1;
|
||||
private static final String KEY_MINIMALISM_PREFERENCE = "ls_minimalism";
|
||||
private static final String KEY_FULL_LIST_ILLUSTRATION = "full_list_illustration";
|
||||
private static final String KEY_COMPACT_ILLUSTRATION = "compact_illustration";
|
||||
private static final Uri URI_LOCK_SCREEN_NOTIFICATION_MINIMALISM =
|
||||
Settings.Secure.getUriFor(LOCK_SCREEN_NOTIFICATION_MINIMALISM);
|
||||
private static final Uri URI_LOCK_SCREEN_SHOW_NOTIFICATIONS =
|
||||
Settings.Secure.getUriFor(LOCK_SCREEN_SHOW_NOTIFICATIONS);
|
||||
|
||||
@Nullable private LayoutPreference mPreference;
|
||||
@Nullable private TextView mDescView;
|
||||
private Map<Integer, LinearLayout> mButtons = new HashMap<>();
|
||||
private Map<Integer, IllustrationPreference> mIllustrations = new HashMap<>();
|
||||
private final Map<Integer, Integer> mDescriptionTexts = Map.ofEntries(
|
||||
Map.entry(LS_MINIMALISM_OFF, R.string.lock_screen_notifs_full_list_desc),
|
||||
Map.entry(LS_MINIMALISM_ON, R.string.lock_screen_notifs_compact_desc)
|
||||
);
|
||||
|
||||
private final ContentResolver mContentResolver;
|
||||
|
||||
final ContentObserver mContentObserver = new ContentObserver(
|
||||
new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
||||
refreshState(uri);
|
||||
}
|
||||
};
|
||||
|
||||
public MinimalismPreferenceController(@NonNull Context context, @NonNull String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mContentResolver = context.getContentResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner,
|
||||
@NonNull Lifecycle.Event event) {
|
||||
if (event == Lifecycle.Event.ON_RESUME) {
|
||||
mContentResolver.registerContentObserver(
|
||||
URI_LOCK_SCREEN_NOTIFICATION_MINIMALISM,
|
||||
/* notifyForDescendants= */ false,
|
||||
mContentObserver
|
||||
);
|
||||
mContentResolver.registerContentObserver(
|
||||
URI_LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
||||
/* notifyForDescendants= */ false,
|
||||
mContentObserver
|
||||
);
|
||||
} else if (event == Lifecycle.Event.ON_PAUSE) {
|
||||
mContentResolver.unregisterContentObserver(mContentObserver);
|
||||
}
|
||||
}
|
||||
|
||||
@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,
|
||||
LS_SHOW_NOTIF_OFF
|
||||
) == LS_SHOW_NOTIF_ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(KEY_MINIMALISM_PREFERENCE);
|
||||
mDescView = mPreference.findViewById(R.id.notif_ls_style_desc);
|
||||
|
||||
mButtons = Map.ofEntries(
|
||||
Map.entry(LS_MINIMALISM_OFF,
|
||||
mPreference.findViewById(R.id.button_full)),
|
||||
Map.entry(LS_MINIMALISM_ON,
|
||||
mPreference.findViewById(R.id.button_compact))
|
||||
);
|
||||
|
||||
mIllustrations = Map.ofEntries(
|
||||
Map.entry(LS_MINIMALISM_OFF,
|
||||
screen.findPreference(KEY_FULL_LIST_ILLUSTRATION)),
|
||||
Map.entry(LS_MINIMALISM_ON,
|
||||
screen.findPreference(KEY_COMPACT_ILLUSTRATION))
|
||||
);
|
||||
mButtons.forEach((value, button) -> button.setOnClickListener(v ->
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM,
|
||||
value
|
||||
)
|
||||
));
|
||||
|
||||
refreshState(URI_LOCK_SCREEN_NOTIFICATION_MINIMALISM);
|
||||
}
|
||||
|
||||
private void highlightButton(int currentValue) {
|
||||
mButtons.forEach((value, button) -> button.setSelected(currentValue == value));
|
||||
}
|
||||
|
||||
private void highlightIllustration(int currentValue) {
|
||||
mIllustrations.forEach((value, preference)
|
||||
-> preference.setVisible(currentValue == value));
|
||||
}
|
||||
|
||||
private void highlightDescription(int value) {
|
||||
if (mDescView == null) return;
|
||||
Integer descStringId = mDescriptionTexts.get(value);
|
||||
if (descStringId != null) {
|
||||
mDescView.setText(descStringId);
|
||||
}
|
||||
}
|
||||
|
||||
private int getCurrentMinimalismValue() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
LOCK_SCREEN_NOTIFICATION_MINIMALISM, LS_MINIMALISM_ON);
|
||||
}
|
||||
|
||||
private void refreshState(@Nullable Uri uri) {
|
||||
if (mPreference == null) return;
|
||||
if (URI_LOCK_SCREEN_SHOW_NOTIFICATIONS.equals(uri) && !lockScreenShowNotification()) {
|
||||
// hide all preferences when showing notifications on lock screen is disabled
|
||||
mIllustrations.forEach((value, preference)
|
||||
-> preference.setVisible(false));
|
||||
mPreference.setVisible(false);
|
||||
} else {
|
||||
mPreference.setVisible(isAvailable());
|
||||
int currentValue = getCurrentMinimalismValue();
|
||||
highlightButton(currentValue);
|
||||
highlightIllustration(currentValue);
|
||||
highlightDescription(currentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user