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.systemui.statusbar.notification 18 19 import android.content.Context 20 import android.provider.DeviceConfig 21 22 import com.android.internal.annotations.VisibleForTesting 23 import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING 24 import com.android.systemui.dagger.SysUISingleton 25 import com.android.systemui.statusbar.notification.stack.BUCKET_ALERTING 26 import com.android.systemui.statusbar.notification.stack.BUCKET_FOREGROUND_SERVICE 27 import com.android.systemui.statusbar.notification.stack.BUCKET_HEADS_UP 28 import com.android.systemui.statusbar.notification.stack.BUCKET_MEDIA_CONTROLS 29 import com.android.systemui.statusbar.notification.stack.BUCKET_PEOPLE 30 import com.android.systemui.statusbar.notification.stack.BUCKET_SILENT 31 import com.android.systemui.util.DeviceConfigProxy 32 import com.android.systemui.util.Utils 33 34 import javax.inject.Inject 35 36 private var sUsePeopleFiltering: Boolean? = null 37 38 /** 39 * Feature controller for the NOTIFICATIONS_USE_PEOPLE_FILTERING config. 40 */ 41 @SysUISingleton 42 class NotificationSectionsFeatureManager @Inject constructor( 43 val proxy: DeviceConfigProxy, 44 val context: Context 45 ) { 46 47 fun isFilteringEnabled(): Boolean { 48 return usePeopleFiltering(proxy) 49 } 50 51 fun isMediaControlsEnabled(): Boolean { 52 return Utils.useQsMediaPlayer(context) 53 } 54 55 fun getNotificationBuckets(): IntArray { 56 return when { 57 isFilteringEnabled() && isMediaControlsEnabled() -> 58 intArrayOf(BUCKET_HEADS_UP, BUCKET_FOREGROUND_SERVICE, BUCKET_MEDIA_CONTROLS, 59 BUCKET_PEOPLE, BUCKET_ALERTING, BUCKET_SILENT) 60 !isFilteringEnabled() && isMediaControlsEnabled() -> 61 intArrayOf(BUCKET_HEADS_UP, BUCKET_FOREGROUND_SERVICE, BUCKET_MEDIA_CONTROLS, 62 BUCKET_ALERTING, BUCKET_SILENT) 63 isFilteringEnabled() && !isMediaControlsEnabled() -> 64 intArrayOf(BUCKET_HEADS_UP, BUCKET_FOREGROUND_SERVICE, BUCKET_PEOPLE, 65 BUCKET_ALERTING, BUCKET_SILENT) 66 else -> 67 intArrayOf(BUCKET_ALERTING, BUCKET_SILENT) 68 } 69 } 70 71 fun getNumberOfBuckets(): Int { 72 return getNotificationBuckets().size 73 } 74 75 @VisibleForTesting 76 fun clearCache() { 77 sUsePeopleFiltering = null 78 } 79 } 80 81 private fun usePeopleFiltering(proxy: DeviceConfigProxy): Boolean { 82 if (sUsePeopleFiltering == null) { 83 sUsePeopleFiltering = proxy.getBoolean( 84 DeviceConfig.NAMESPACE_SYSTEMUI, NOTIFICATIONS_USE_PEOPLE_FILTERING, true) 85 } 86 87 return sUsePeopleFiltering!! 88 } 89