• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.preference.Preference;
24 
25 import com.android.settings.R;
26 import com.android.settings.core.PreferenceControllerMixin;
27 import com.android.settings.notification.NotificationBackend;
28 import com.android.settingslib.utils.StringUtil;
29 
30 public class DeletedChannelsPreferenceController extends NotificationPreferenceController
31         implements PreferenceControllerMixin {
32 
33     private static final String  KEY_DELETED = "deleted";
34 
DeletedChannelsPreferenceController(Context context, NotificationBackend backend)35     public DeletedChannelsPreferenceController(Context context, NotificationBackend backend) {
36         super(context, backend);
37     }
38 
39     @Override
getPreferenceKey()40     public String getPreferenceKey() {
41         return KEY_DELETED;
42     }
43 
44     @Override
isAvailable()45     public boolean isAvailable() {
46         if (!super.isAvailable()) {
47             return false;
48         }
49         if (notificationHideUnusedChannels()) {
50             return false;
51         }
52         // only visible on app screen
53         if (mChannel != null || hasValidGroup()) {
54             return false;
55         }
56 
57         return mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid) > 0;
58     }
59 
60     @Override
isIncludedInFilter()61     boolean isIncludedInFilter() {
62         return false;
63     }
64 
updateState(Preference preference)65     public void updateState(Preference preference) {
66         if (preference.getParent() != null) {
67             preference.getParent().setVisible(true);
68         }
69         if (mAppRow != null) {
70             int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
71             preference.setTitle(StringUtil.getIcuPluralsString(mContext, deletedChannelCount,
72                     R.string.deleted_channels));
73         }
74         preference.setSelectable(false);
75     }
76 }
77