blob: e2b01ffe59b8d0fe19e3334a91be34b30b7e31d2 [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 Elliottb0940382020-02-20 14:24:02 -050025import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_HEADS_UP
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040026import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_MEDIA_CONTROLS
Evan Laird367b6142019-08-30 14:40:34 -040027import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE
28import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT
29import com.android.systemui.util.DeviceConfigProxy
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040030import com.android.systemui.util.Utils
Evan Laird367b6142019-08-30 14:40:34 -040031
32import javax.inject.Inject
33
34private var sUsePeopleFiltering: Boolean? = null
35
36/**
37 * Feature controller for the NOTIFICATIONS_USE_PEOPLE_FILTERING config.
38 */
39class NotificationSectionsFeatureManager @Inject constructor(
40 val proxy: DeviceConfigProxy,
41 val context: Context
42) {
43
44 fun isFilteringEnabled(): Boolean {
45 return usePeopleFiltering(proxy)
46 }
47
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040048 fun isMediaControlsEnabled(): Boolean {
49 return Utils.useQsMediaPlayer(context)
50 }
51
Evan Laird367b6142019-08-30 14:40:34 -040052 fun getNotificationBuckets(): IntArray {
53 return when {
Robert Snoebergerb6464ea2020-03-20 11:56:22 -040054 isFilteringEnabled() && isMediaControlsEnabled() ->
55 intArrayOf(BUCKET_HEADS_UP, BUCKET_MEDIA_CONTROLS, BUCKET_PEOPLE, BUCKET_ALERTING,
56 BUCKET_SILENT)
57 !isFilteringEnabled() && isMediaControlsEnabled() ->
58 intArrayOf(BUCKET_HEADS_UP, BUCKET_MEDIA_CONTROLS, BUCKET_ALERTING, BUCKET_SILENT)
59 isFilteringEnabled() && !isMediaControlsEnabled() ->
Steve Elliottb0940382020-02-20 14:24:02 -050060 intArrayOf(BUCKET_HEADS_UP, BUCKET_PEOPLE, BUCKET_ALERTING, BUCKET_SILENT)
Evan Laird367b6142019-08-30 14:40:34 -040061 NotificationUtils.useNewInterruptionModel(context) ->
62 intArrayOf(BUCKET_ALERTING, BUCKET_SILENT)
63 else ->
64 intArrayOf(BUCKET_ALERTING)
65 }
66 }
67
68 fun getNumberOfBuckets(): Int {
69 return getNotificationBuckets().size
70 }
71
72 @VisibleForTesting
73 fun clearCache() {
74 sUsePeopleFiltering = null
75 }
76}
77
78private fun usePeopleFiltering(proxy: DeviceConfigProxy): Boolean {
79 if (sUsePeopleFiltering == null) {
80 sUsePeopleFiltering = proxy.getBoolean(
Steve Elliott58adc212019-10-15 11:07:54 -040081 DeviceConfig.NAMESPACE_SYSTEMUI, NOTIFICATIONS_USE_PEOPLE_FILTERING, true)
Evan Laird367b6142019-08-30 14:40:34 -040082 }
83
84 return sUsePeopleFiltering!!
85}