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