• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.text.TextUtils;
22 import android.util.Log;
23 
24 import com.android.settings.R;
25 import com.android.settings.search.BaseSearchIndexProvider;
26 import com.android.settings.search.Indexable;
27 import com.android.settingslib.core.AbstractPreferenceController;
28 import com.android.settingslib.search.SearchIndexable;
29 
30 import java.util.ArrayList;
31 import java.util.List;
32 
33 @SearchIndexable
34 public class AppBubbleNotificationSettings extends NotificationSettingsBase implements
35         GlobalBubblePermissionObserverMixin.Listener {
36     private static final String TAG = "AppBubNotiSettings";
37     private GlobalBubblePermissionObserverMixin mObserverMixin;
38 
39     @Override
getMetricsCategory()40     public int getMetricsCategory() {
41         return SettingsEnums.APP_BUBBLE_SETTINGS;
42     }
43 
44     @Override
getLogTag()45     protected String getLogTag() {
46         return TAG;
47     }
48 
49     @Override
getPreferenceScreenResId()50     protected int getPreferenceScreenResId() {
51         return R.xml.app_bubble_notification_settings;
52     }
53 
54     @Override
createPreferenceControllers(Context context)55     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
56         mControllers = getPreferenceControllers(context, this);
57         return new ArrayList<>(mControllers);
58     }
59 
getPreferenceControllers( Context context, AppBubbleNotificationSettings fragment)60     protected static List<NotificationPreferenceController> getPreferenceControllers(
61             Context context, AppBubbleNotificationSettings fragment) {
62         List<NotificationPreferenceController> controllers = new ArrayList<>();
63         controllers.add(new HeaderPreferenceController(context, fragment));
64         controllers.add(new BubblePreferenceController(context, fragment != null
65                 ? fragment.getChildFragmentManager()
66                 : null,
67                 new NotificationBackend(), true /* isAppPage */));
68         return controllers;
69     }
70 
71     @Override
onGlobalBubblePermissionChanged()72     public void onGlobalBubblePermissionChanged() {
73         updatePreferenceStates();
74     }
75 
76     @Override
onResume()77     public void onResume() {
78         super.onResume();
79 
80         if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
81             Log.w(TAG, "Missing package or uid or packageinfo");
82             finish();
83             return;
84         }
85 
86         for (NotificationPreferenceController controller : mControllers) {
87             controller.onResume(mAppRow, mChannel, mChannelGroup, mSuspendedAppsAdmin);
88             controller.displayPreference(getPreferenceScreen());
89         }
90         updatePreferenceStates();
91 
92         mObserverMixin = new GlobalBubblePermissionObserverMixin(getContext(), this);
93         mObserverMixin.onStart();
94     }
95 
96     @Override
onPause()97     public void onPause() {
98         mObserverMixin.onStop();
99         super.onPause();
100     }
101 
102     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
103             new BaseSearchIndexProvider() {
104 
105                 @Override
106                 protected boolean isPageSearchEnabled(Context context) {
107                     return false;
108                 }
109 
110                 @Override
111                 public List<AbstractPreferenceController> createPreferenceControllers(Context
112                         context) {
113                     return new ArrayList<>(AppBubbleNotificationSettings.getPreferenceControllers(
114                             context, null));
115                 }
116             };
117 }
118