1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.notification; 18 19 import static android.provider.Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM; 20 import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS; 21 22 import android.content.Context; 23 import android.provider.Settings; 24 25 import androidx.annotation.VisibleForTesting; 26 27 import com.android.server.notification.Flags; 28 import com.android.settings.R; 29 import com.android.settings.core.TogglePreferenceController; 30 31 public class LockscreenNotificationMinimalismPreferenceController 32 extends TogglePreferenceController { 33 34 @VisibleForTesting 35 static final int ON = 1; 36 @VisibleForTesting 37 static final int OFF = 0; 38 LockscreenNotificationMinimalismPreferenceController( Context context, String preferenceKey)39 public LockscreenNotificationMinimalismPreferenceController( 40 Context context, 41 String preferenceKey) { 42 super(context, preferenceKey); 43 } 44 45 @Override isChecked()46 public boolean isChecked() { 47 return Settings.Secure.getInt(mContext.getContentResolver(), 48 LOCK_SCREEN_NOTIFICATION_MINIMALISM, ON) == ON; 49 } 50 51 @Override setChecked(boolean isChecked)52 public boolean setChecked(boolean isChecked) { 53 return Settings.Secure.putInt(mContext.getContentResolver(), 54 LOCK_SCREEN_NOTIFICATION_MINIMALISM, isChecked ? ON : OFF); 55 } 56 57 @Override getAvailabilityStatus()58 public int getAvailabilityStatus() { 59 // Hide when the notifications on lock screen settings page flag is enabled. 60 if (Flags.notificationLockScreenSettings()) { 61 return CONDITIONALLY_UNAVAILABLE; 62 } 63 if (!Flags.notificationMinimalism()) { 64 return CONDITIONALLY_UNAVAILABLE; 65 } 66 int lockScreenNotif = Settings.Secure.getInt(mContext.getContentResolver(), 67 LOCK_SCREEN_SHOW_NOTIFICATIONS, 0); 68 if (lockScreenNotif == 0) { 69 return DISABLED_DEPENDENT_SETTING; 70 } 71 return AVAILABLE; 72 } 73 74 @Override getSliceHighlightMenuRes()75 public int getSliceHighlightMenuRes() { 76 return R.string.menu_key_notifications; 77 } 78 } 79