• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.app;
18 
19 import static com.android.server.notification.Flags.notificationHideUnusedChannels;
20 
21 import android.content.Context;
22 
23 import androidx.annotation.NonNull;
24 import androidx.preference.Preference;
25 import androidx.preference.PreferenceScreen;
26 
27 import com.android.settings.notification.NotificationBackend;
28 
29 import org.jetbrains.annotations.NotNull;
30 
31 public class ShowMorePreferenceController extends NotificationPreferenceController {
32 
33     private static final String KEY = "more";
34     private NotificationSettings.DependentFieldListener mDependentFieldListener;
35 
ShowMorePreferenceController(Context context, NotificationSettings.DependentFieldListener dependentFieldListener, NotificationBackend backend)36     public ShowMorePreferenceController(Context context,
37             NotificationSettings.DependentFieldListener dependentFieldListener,
38             NotificationBackend backend) {
39         super(context, backend);
40         mDependentFieldListener = dependentFieldListener;
41     }
42 
43     @Override
getPreferenceKey()44     public String getPreferenceKey() {
45         return KEY;
46     }
47 
48     @Override
isAvailable()49     public boolean isAvailable() {
50         if (!notificationHideUnusedChannels()) {
51             return false;
52         }
53         if (mAppRow == null) {
54             return false;
55         }
56         if (mAppRow.banned || mAppRow.showAllChannels) {
57             return false;
58         }
59         if (mBackend.getChannelCount(mAppRow.pkg, mAppRow.uid) == 0) {
60             return false;
61         }
62         return true;
63     }
64 
65     @Override
isIncludedInFilter()66     boolean isIncludedInFilter() {
67         return false;
68     }
69 
70     @Override
updateState(Preference preference)71     public void updateState(Preference preference) {
72         preference.setOnPreferenceClickListener(preference1 -> {
73             mAppRow.showAllChannels = true;
74             mDependentFieldListener.onFieldValueChanged();
75             return true;
76         });
77     }
78 }
79