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.platform.test.annotations.DisableFlags 20 import android.provider.DeviceConfig 21 import android.provider.Settings 22 import androidx.test.ext.junit.runners.AndroidJUnit4 23 import androidx.test.filters.SmallTest 24 import com.android.dx.mockito.inline.extended.ExtendedMockito 25 import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING 26 import com.android.systemui.SysuiTestCase 27 import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype 28 import com.android.systemui.statusbar.notification.shared.PriorityPeopleSection 29 import com.android.systemui.util.DeviceConfigProxyFake 30 import com.android.systemui.util.Utils 31 import com.android.systemui.util.mockito.any 32 import org.junit.After 33 import org.junit.Assert.assertFalse 34 import org.junit.Assert.assertTrue 35 import org.junit.Before 36 import org.junit.Test 37 import org.junit.runner.RunWith 38 import org.mockito.MockitoSession 39 import org.mockito.kotlin.whenever 40 import org.mockito.quality.Strictness 41 42 @RunWith(AndroidJUnit4::class) 43 @SmallTest 44 // this class has no testable logic with either of these flags enabled 45 @DisableFlags(PriorityPeopleSection.FLAG_NAME, NotificationMinimalismPrototype.V2.FLAG_NAME) 46 class NotificationSectionsFeatureManagerTest : SysuiTestCase() { 47 lateinit var manager: NotificationSectionsFeatureManager 48 private val proxyFake = DeviceConfigProxyFake() 49 private lateinit var staticMockSession: MockitoSession 50 51 @Before setupnull52 fun setup() { 53 manager = NotificationSectionsFeatureManager(proxyFake, mContext) 54 manager.clearCache() 55 staticMockSession = 56 ExtendedMockito.mockitoSession() 57 .mockStatic(Utils::class.java) 58 .strictness(Strictness.LENIENT) 59 .startMocking() 60 whenever(Utils.useQsMediaPlayer(any())).thenReturn(false) 61 Settings.Global.putInt( 62 context.getContentResolver(), 63 Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 64 0 65 ) 66 } 67 68 @After teardownnull69 fun teardown() { 70 staticMockSession.finishMocking() 71 } 72 73 @Test testPeopleFilteringOff_newInterruptionModelOnnull74 fun testPeopleFilteringOff_newInterruptionModelOn() { 75 proxyFake.setProperty( 76 DeviceConfig.NAMESPACE_SYSTEMUI, 77 NOTIFICATIONS_USE_PEOPLE_FILTERING, 78 "false", 79 false 80 ) 81 82 assertFalse("People filtering should be disabled", manager.isFilteringEnabled()) 83 assertTrue( 84 "Expecting 2 buckets when people filtering is disabled", 85 manager.getNumberOfBuckets() == 2 86 ) 87 } 88 89 @Test testPeopleFilteringOn_newInterruptionModelOnnull90 fun testPeopleFilteringOn_newInterruptionModelOn() { 91 proxyFake.setProperty( 92 DeviceConfig.NAMESPACE_SYSTEMUI, 93 NOTIFICATIONS_USE_PEOPLE_FILTERING, 94 "true", 95 false 96 ) 97 98 assertTrue("People filtering should be enabled", manager.isFilteringEnabled()) 99 assertTrue( 100 "Expecting 5 buckets when people filtering is enabled", 101 manager.getNumberOfBuckets() == 5 102 ) 103 } 104 } 105