Dave Mankoff | 84c07e9 | 2019-06-21 14:24:43 -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.classifier; |
| 18 | |
| 19 | import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_MANAGER_ENABLED; |
| 20 | |
| 21 | import static org.hamcrest.CoreMatchers.instanceOf; |
| 22 | import static org.junit.Assert.assertThat; |
| 23 | |
| 24 | import android.os.Handler; |
| 25 | import android.provider.DeviceConfig; |
| 26 | import android.testing.AndroidTestingRunner; |
| 27 | import android.testing.TestableLooper; |
| 28 | |
| 29 | import androidx.test.filters.SmallTest; |
| 30 | |
| 31 | import com.android.systemui.SysuiTestCase; |
| 32 | import com.android.systemui.classifier.brightline.BrightLineFalsingManager; |
| 33 | import com.android.systemui.shared.plugins.PluginManager; |
Dave Mankoff | 46b9d68 | 2019-09-12 13:39:42 -0400 | [diff] [blame] | 34 | import com.android.systemui.util.ProximitySensor; |
Dave Mankoff | 84c07e9 | 2019-06-21 14:24:43 -0400 | [diff] [blame] | 35 | |
| 36 | import org.junit.After; |
| 37 | import org.junit.Before; |
| 38 | import org.junit.Test; |
| 39 | import org.junit.runner.RunWith; |
| 40 | import org.mockito.Mock; |
| 41 | import org.mockito.MockitoAnnotations; |
| 42 | |
| 43 | @SmallTest |
| 44 | @RunWith(AndroidTestingRunner.class) |
| 45 | @TestableLooper.RunWithLooper |
| 46 | public class FalsingManagerProxyTest extends SysuiTestCase { |
Dave Mankoff | 46b9d68 | 2019-09-12 13:39:42 -0400 | [diff] [blame] | 47 | @Mock(stubOnly = true) |
Dave Mankoff | 84c07e9 | 2019-06-21 14:24:43 -0400 | [diff] [blame] | 48 | PluginManager mPluginManager; |
Dave Mankoff | 46b9d68 | 2019-09-12 13:39:42 -0400 | [diff] [blame] | 49 | @Mock(stubOnly = true) |
| 50 | ProximitySensor mProximitySensor; |
Dave Mankoff | 84c07e9 | 2019-06-21 14:24:43 -0400 | [diff] [blame] | 51 | private boolean mDefaultConfigValue; |
| 52 | private Handler mHandler; |
| 53 | private TestableLooper mTestableLooper; |
| 54 | |
| 55 | @Before |
| 56 | public void setup() { |
| 57 | MockitoAnnotations.initMocks(this); |
| 58 | mTestableLooper = TestableLooper.get(this); |
| 59 | mHandler = new Handler(mTestableLooper.getLooper()); |
| 60 | mDefaultConfigValue = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 61 | BRIGHTLINE_FALSING_MANAGER_ENABLED, false); |
Dave Mankoff | 1b80884 | 2019-07-18 17:20:11 -0400 | [diff] [blame] | 62 | // In case it runs on a device where it's been set to true, set it to false by hand. |
| 63 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 64 | BRIGHTLINE_FALSING_MANAGER_ENABLED, "false", false); |
Dave Mankoff | 84c07e9 | 2019-06-21 14:24:43 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @After |
| 68 | public void tearDown() { |
| 69 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 70 | BRIGHTLINE_FALSING_MANAGER_ENABLED, mDefaultConfigValue ? "true" : "false", false); |
| 71 | } |
| 72 | |
| 73 | @Test |
| 74 | public void test_brightLineFalsingManagerDisabled() { |
Dave Mankoff | 46b9d68 | 2019-09-12 13:39:42 -0400 | [diff] [blame] | 75 | FalsingManagerProxy proxy = new FalsingManagerProxy( |
| 76 | getContext(), mPluginManager, mHandler, mProximitySensor); |
Dave Mankoff | 84c07e9 | 2019-06-21 14:24:43 -0400 | [diff] [blame] | 77 | |
| 78 | assertThat(proxy.getInternalFalsingManager(), instanceOf(FalsingManagerImpl.class)); |
| 79 | } |
| 80 | |
| 81 | @Test |
| 82 | public void test_brightLineFalsingManagerEnabled() { |
| 83 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 84 | BRIGHTLINE_FALSING_MANAGER_ENABLED, "true", false); |
Dave Mankoff | 46b9d68 | 2019-09-12 13:39:42 -0400 | [diff] [blame] | 85 | FalsingManagerProxy proxy = new FalsingManagerProxy( |
| 86 | getContext(), mPluginManager, mHandler, mProximitySensor); |
Dave Mankoff | 84c07e9 | 2019-06-21 14:24:43 -0400 | [diff] [blame] | 87 | |
| 88 | assertThat(proxy.getInternalFalsingManager(), instanceOf(BrightLineFalsingManager.class)); |
| 89 | } |
| 90 | |
| 91 | @Test |
| 92 | public void test_brightLineFalsingManagerToggled() { |
Dave Mankoff | 46b9d68 | 2019-09-12 13:39:42 -0400 | [diff] [blame] | 93 | FalsingManagerProxy proxy = new FalsingManagerProxy( |
| 94 | getContext(), mPluginManager, mHandler, mProximitySensor); |
Dave Mankoff | 84c07e9 | 2019-06-21 14:24:43 -0400 | [diff] [blame] | 95 | assertThat(proxy.getInternalFalsingManager(), instanceOf(FalsingManagerImpl.class)); |
| 96 | |
| 97 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 98 | BRIGHTLINE_FALSING_MANAGER_ENABLED, "true", false); |
| 99 | mTestableLooper.processAllMessages(); |
| 100 | proxy.setupFalsingManager(getContext()); |
| 101 | assertThat(proxy.getInternalFalsingManager(), instanceOf(BrightLineFalsingManager.class)); |
| 102 | |
| 103 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 104 | BRIGHTLINE_FALSING_MANAGER_ENABLED, "false", false); |
| 105 | mTestableLooper.processAllMessages(); |
| 106 | proxy.setupFalsingManager(getContext()); |
| 107 | assertThat(proxy.getInternalFalsingManager(), instanceOf(FalsingManagerImpl.class)); |
| 108 | } |
| 109 | } |