1 /*
2  * Copyright (C) 2016 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 com.android.settings.notification.ChannelListPreferenceController.ARG_FROM_SETTINGS;
20 
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.os.Bundle;
25 import android.preference.PreferenceManager;
26 import android.text.TextUtils;
27 import android.util.Log;
28 
29 import androidx.preference.PreferenceScreen;
30 
31 import com.android.internal.widget.LockPatternUtils;
32 import com.android.settings.R;
33 import com.android.settingslib.core.AbstractPreferenceController;
34 
35 import java.util.ArrayList;
36 import java.util.List;
37 
38 public class ChannelNotificationSettings extends NotificationSettingsBase {
39     private static final String TAG = "ChannelSettings";
40 
41     @Override
getMetricsCategory()42     public int getMetricsCategory() {
43         return SettingsEnums.NOTIFICATION_TOPIC_NOTIFICATION;
44     }
45 
46     @Override
onCreate(Bundle savedInstanceState)47     public void onCreate(Bundle savedInstanceState) {
48         super.onCreate(savedInstanceState);
49         final PreferenceScreen screen = getPreferenceScreen();
50         Bundle args = getArguments();
51         // If linking to this screen from an external app, expand settings
52         if (screen != null && args != null) {
53             if (!args.getBoolean(ARG_FROM_SETTINGS, false)) {
54                 screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
55             }
56         }
57     }
58 
59     @Override
onResume()60     public void onResume() {
61         super.onResume();
62         if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) {
63             Log.w(TAG, "Missing package or uid or packageinfo or channel");
64             finish();
65             return;
66         }
67 
68         for (NotificationPreferenceController controller : mControllers) {
69             controller.onResume(mAppRow, mChannel, mChannelGroup, mSuspendedAppsAdmin);
70             controller.displayPreference(getPreferenceScreen());
71         }
72         updatePreferenceStates();
73     }
74 
75     @Override
onActivityResult(int requestCode, int resultCode, Intent data)76     public void onActivityResult(int requestCode, int resultCode, Intent data) {
77         for (NotificationPreferenceController controller : mControllers) {
78             if (controller instanceof PreferenceManager.OnActivityResultListener) {
79                 ((PreferenceManager.OnActivityResultListener) controller)
80                         .onActivityResult(requestCode, resultCode, data);
81             }
82         }
83     }
84 
85     @Override
getLogTag()86     protected String getLogTag() {
87         return TAG;
88     }
89 
90     @Override
getPreferenceScreenResId()91     protected int getPreferenceScreenResId() {
92         return  R.xml.channel_notification_settings;
93     }
94 
95     @Override
createPreferenceControllers(Context context)96     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
97         mControllers = new ArrayList<>();
98         mControllers.add(new HeaderPreferenceController(context, this));
99         mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
100         mControllers.add(new ImportancePreferenceController(
101                 context, mImportanceListener, mBackend));
102         mControllers.add(new MinImportancePreferenceController(
103                 context, mImportanceListener, mBackend));
104         mControllers.add(new HighImportancePreferenceController(
105                 context, mImportanceListener, mBackend));
106         mControllers.add(new AllowSoundPreferenceController(
107                 context, mImportanceListener, mBackend));
108         mControllers.add(new SoundPreferenceController(context, this,
109                 mImportanceListener, mBackend));
110         mControllers.add(new VibrationPreferenceController(context, mBackend));
111         mControllers.add(new AppLinkPreferenceController(context));
112         mControllers.add(new DescriptionPreferenceController(context));
113         mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
114                 mBackend));
115         mControllers.add(new LightsPreferenceController(context, mBackend));
116         mControllers.add(new BadgePreferenceController(context, mBackend));
117         mControllers.add(new DndPreferenceController(context, mBackend));
118         mControllers.add(new NotificationsOffPreferenceController(context));
119         mControllers.add(new BubblePreferenceController(context, getChildFragmentManager(),
120                 mBackend, false /* isAppPage */));
121         return new ArrayList<>(mControllers);
122     }
123 }
124