blob: d7b391ff03e497e712b96f43d22eead8797769de [file] [log] [blame]
Evan Laird367b6142019-08-30 14:40:34 -04001/*
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
17package com.android.systemui.statusbar.notification
18
19import android.content.Context
20import android.provider.DeviceConfig
21
22import com.android.internal.annotations.VisibleForTesting
23import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING
24import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_ALERTING
Steve Elliott49671e02020-05-12 13:51:28 -040025import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_FOREGROUND_SERVICE
Steve Elliottb0940382020-02-20 14:24:02 -050026import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_HEADS_UP
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040027import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_MEDIA_CONTROLS
Evan Laird367b6142019-08-30 14:40:34 -040028import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE
29import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT
30import com.android.systemui.util.DeviceConfigProxy
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040031import com.android.systemui.util.Utils
Evan Laird367b6142019-08-30 14:40:34 -040032
33import javax.inject.Inject
34
35private var sUsePeopleFiltering: Boolean? = null
36
37/**
38 * Feature controller for the NOTIFICATIONS_USE_PEOPLE_FILTERING config.
39 */
40class NotificationSectionsFeatureManager @Inject constructor(
41 val proxy: DeviceConfigProxy,
42 val context: Context
43) {
44
45 fun isFilteringEnabled(): Boolean {
46 return usePeopleFiltering(proxy)
47 }
48
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040049 fun isMediaControlsEnabled(): Boolean {
50 return Utils.useQsMediaPlayer(context)
51 }
52
Evan Laird367b6142019-08-30 14:40:34 -040053 fun getNotificationBuckets(): IntArray {
54 return when {
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040055 isFilteringEnabled() && isMediaControlsEnabled() ->
Steve Elliott49671e02020-05-12 13:51:28 -040056 intArrayOf(BUCKET_HEADS_UP, BUCKET_FOREGROUND_SERVICE, BUCKET_MEDIA_CONTROLS,
57 BUCKET_PEOPLE, BUCKET_ALERTING, BUCKET_SILENT)
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040058 !isFilteringEnabled() && isMediaControlsEnabled() ->
Steve Elliott49671e02020-05-12 13:51:28 -040059 intArrayOf(BUCKET_HEADS_UP, BUCKET_FOREGROUND_SERVICE, BUCKET_MEDIA_CONTROLS,
60 BUCKET_ALERTING, BUCKET_SILENT)
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040061 isFilteringEnabled() && !isMediaControlsEnabled() ->
Steve Elliott49671e02020-05-12 13:51:28 -040062 intArrayOf(BUCKET_HEADS_UP, BUCKET_FOREGROUND_SERVICE, BUCKET_PEOPLE,
63 BUCKET_ALERTING, BUCKET_SILENT)
Evan Laird367b6142019-08-30 14:40:34 -040064 NotificationUtils.useNewInterruptionModel(context) ->
65 intArrayOf(BUCKET_ALERTING, BUCKET_SILENT)
66 else ->
67 intArrayOf(BUCKET_ALERTING)
68 }
69 }
70
71 fun getNumberOfBuckets(): Int {
72 return getNotificationBuckets().size
73 }
74
75 @VisibleForTesting
76 fun clearCache() {
77 sUsePeopleFiltering = null
78 }
79}
80
81private fun usePeopleFiltering(proxy: DeviceConfigProxy): Boolean {
82 if (sUsePeopleFiltering == null) {
83 sUsePeopleFiltering = proxy.getBoolean(
Steve Elliott58adc212019-10-15 11:07:54 -040084 DeviceConfig.NAMESPACE_SYSTEMUI, NOTIFICATIONS_USE_PEOPLE_FILTERING, true)
Evan Laird367b6142019-08-30 14:40:34 -040085 }
86
87 return sUsePeopleFiltering!!
88}