Evan Laird | 367b614 | 2019-08-30 14:40:34 -0400 | [diff] [blame] | 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.provider.DeviceConfig |
| 20 | import android.provider.Settings |
| 21 | import android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL |
| 22 | import android.testing.AndroidTestingRunner |
| 23 | |
| 24 | import androidx.test.filters.SmallTest |
| 25 | |
| 26 | import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING |
| 27 | import com.android.systemui.SysuiTestCase |
| 28 | import com.android.systemui.util.DeviceConfigProxyFake |
| 29 | |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 30 | import org.junit.After |
Evan Laird | 367b614 | 2019-08-30 14:40:34 -0400 | [diff] [blame] | 31 | import org.junit.Assert.assertFalse |
| 32 | import org.junit.Assert.assertTrue |
| 33 | import org.junit.Before |
| 34 | import org.junit.Test |
| 35 | import org.junit.runner.RunWith |
| 36 | |
| 37 | @RunWith(AndroidTestingRunner::class) |
| 38 | @SmallTest |
| 39 | class NotificationSectionsFeatureManagerTest : SysuiTestCase() { |
| 40 | var manager: NotificationSectionsFeatureManager? = null |
| 41 | val proxyFake = DeviceConfigProxyFake() |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 42 | var originalQsMediaPlayer: Int = 0 |
Evan Laird | 367b614 | 2019-08-30 14:40:34 -0400 | [diff] [blame] | 43 | |
| 44 | @Before |
| 45 | public fun setup() { |
| 46 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 47 | NOTIFICATION_NEW_INTERRUPTION_MODEL, 1) |
| 48 | manager = NotificationSectionsFeatureManager(proxyFake, mContext) |
| 49 | manager!!.clearCache() |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 50 | originalQsMediaPlayer = Settings.System.getInt(context.getContentResolver(), |
| 51 | "qs_media_player", 1) |
Selim Cinek | 6eec7f2 | 2020-05-08 22:18:07 -0700 | [diff] [blame] | 52 | Settings.Global.putInt(context.getContentResolver(), "qs_media_player", 0) |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @After |
| 56 | public fun teardown() { |
Selim Cinek | 6eec7f2 | 2020-05-08 22:18:07 -0700 | [diff] [blame] | 57 | Settings.Global.putInt(context.getContentResolver(), "qs_media_player", |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 58 | originalQsMediaPlayer) |
Evan Laird | 367b614 | 2019-08-30 14:40:34 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public fun testPeopleFilteringOff_newInterruptionModelOn() { |
| 63 | proxyFake.setProperty( |
| 64 | DeviceConfig.NAMESPACE_SYSTEMUI, NOTIFICATIONS_USE_PEOPLE_FILTERING, "false", false) |
| 65 | |
| 66 | assertFalse("People filtering should be disabled", manager!!.isFilteringEnabled()) |
| 67 | assertTrue("Expecting 2 buckets when people filtering is disabled", |
| 68 | manager!!.getNumberOfBuckets() == 2) |
| 69 | } |
| 70 | |
| 71 | @Test |
| 72 | public fun testPeopleFilteringOn_newInterruptionModelOn() { |
| 73 | proxyFake.setProperty( |
| 74 | DeviceConfig.NAMESPACE_SYSTEMUI, NOTIFICATIONS_USE_PEOPLE_FILTERING, "true", false) |
| 75 | |
| 76 | assertTrue("People filtering should be enabled", manager!!.isFilteringEnabled()) |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 77 | assertTrue("Expecting 4 buckets when people filtering is enabled", |
| 78 | manager!!.getNumberOfBuckets() == 4) |
Evan Laird | 367b614 | 2019-08-30 14:40:34 -0400 | [diff] [blame] | 79 | } |
| 80 | } |