1 /*
2  * Copyright (C) 2014 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 android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.text.TextUtils;
23 import android.util.Log;
24 
25 import com.android.internal.widget.LockPatternUtils;
26 import com.android.settings.R;
27 import com.android.settingslib.core.AbstractPreferenceController;
28 
29 import java.util.ArrayList;
30 import java.util.List;
31 
32 import androidx.preference.Preference;
33 import androidx.preference.PreferenceGroup;
34 import androidx.preference.PreferenceScreen;
35 
36 /** These settings are per app, so should not be returned in global search results. */
37 public class AppNotificationSettings extends NotificationSettingsBase {
38     private static final String TAG = "AppNotificationSettings";
39     private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
40 
41     private static String KEY_ADVANCED_CATEGORY = "app_advanced";
42     private static String KEY_BADGE = "badge";
43     private static String KEY_APP_LINK = "app_link";
44     private static String KEY_BUBBLE = "bubble_link_pref";
45     private static String[] LEGACY_NON_ADVANCED_KEYS = {KEY_BADGE, KEY_APP_LINK, KEY_BUBBLE};
46 
47     @Override
getMetricsCategory()48     public int getMetricsCategory() {
49         return SettingsEnums.NOTIFICATION_APP_NOTIFICATION;
50     }
51 
52     @Override
onCreate(Bundle savedInstanceState)53     public void onCreate(Bundle savedInstanceState) {
54         super.onCreate(savedInstanceState);
55         final PreferenceScreen screen = getPreferenceScreen();
56         if (mShowLegacyChannelConfig && screen != null) {
57             // if showing legacy settings, pull advanced settings out of the advanced category
58             PreferenceGroup advanced = (PreferenceGroup) findPreference(KEY_ADVANCED_CATEGORY);
59             removePreference(KEY_ADVANCED_CATEGORY);
60             if (advanced != null) {
61                 for (String key : LEGACY_NON_ADVANCED_KEYS) {
62                     Preference pref = advanced.findPreference(key);
63                     advanced.removePreference(pref);
64                     if (pref != null) {
65                         screen.addPreference(pref);
66                     }
67                 }
68             }
69         }
70     }
71 
72     @Override
onResume()73     public void onResume() {
74         super.onResume();
75 
76         if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
77             Log.w(TAG, "Missing package or uid or packageinfo");
78             finish();
79             return;
80         }
81 
82         for (NotificationPreferenceController controller : mControllers) {
83             controller.onResume(mAppRow, mChannel, mChannelGroup, mSuspendedAppsAdmin);
84             controller.displayPreference(getPreferenceScreen());
85         }
86         updatePreferenceStates();
87     }
88 
89     @Override
getLogTag()90     protected String getLogTag() {
91         return TAG;
92     }
93 
94     @Override
getPreferenceScreenResId()95     protected int getPreferenceScreenResId() {
96         return R.xml.app_notification_settings;
97     }
98 
99     @Override
createPreferenceControllers(Context context)100     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
101         mControllers = new ArrayList<>();
102         mControllers.add(new HeaderPreferenceController(context, this));
103         mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
104         mControllers.add(new BadgePreferenceController(context, mBackend));
105         mControllers.add(new AllowSoundPreferenceController(
106                 context, mImportanceListener, mBackend));
107         mControllers.add(new ImportancePreferenceController(
108                 context, mImportanceListener, mBackend));
109         mControllers.add(new MinImportancePreferenceController(
110                 context, mImportanceListener, mBackend));
111         mControllers.add(new HighImportancePreferenceController(
112                 context, mImportanceListener, mBackend));
113         mControllers.add(new SoundPreferenceController(context, this,
114                 mImportanceListener, mBackend));
115         mControllers.add(new LightsPreferenceController(context, mBackend));
116         mControllers.add(new VibrationPreferenceController(context, mBackend));
117         mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
118                 mBackend));
119         mControllers.add(new DndPreferenceController(context, mBackend));
120         mControllers.add(new AppLinkPreferenceController(context));
121         mControllers.add(new DescriptionPreferenceController(context));
122         mControllers.add(new NotificationsOffPreferenceController(context));
123         mControllers.add(new DeletedChannelsPreferenceController(context, mBackend));
124         mControllers.add(new BubbleSummaryPreferenceController(context, mBackend));
125         mControllers.add(new ChannelListPreferenceController(context, mBackend));
126         return new ArrayList<>(mControllers);
127     }
128 }
129