blob: 32cf8429cf62077a2bc758b913e276ddae873281 [file] [log] [blame]
Dave Mankoff84c07e92019-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;
Dave Mankoff46b9d682019-09-12 13:39:42 -040034import com.android.systemui.util.ProximitySensor;
Dave Mankoff84c07e92019-06-21 14:24:43 -040035
36import org.junit.After;
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40import org.mockito.Mock;
41import org.mockito.MockitoAnnotations;
42
43@SmallTest
44@RunWith(AndroidTestingRunner.class)
45@TestableLooper.RunWithLooper
46public class FalsingManagerProxyTest extends SysuiTestCase {
Dave Mankoff46b9d682019-09-12 13:39:42 -040047 @Mock(stubOnly = true)
Dave Mankoff84c07e92019-06-21 14:24:43 -040048 PluginManager mPluginManager;
Dave Mankoff46b9d682019-09-12 13:39:42 -040049 @Mock(stubOnly = true)
50 ProximitySensor mProximitySensor;
Dave Mankoff84c07e92019-06-21 14:24:43 -040051 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 Mankoff1b808842019-07-18 17:20:11 -040062 // 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 Mankoff84c07e92019-06-21 14:24:43 -040065 }
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 Mankoff46b9d682019-09-12 13:39:42 -040075 FalsingManagerProxy proxy = new FalsingManagerProxy(
76 getContext(), mPluginManager, mHandler, mProximitySensor);
Dave Mankoff84c07e92019-06-21 14:24:43 -040077
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 Mankoff46b9d682019-09-12 13:39:42 -040085 FalsingManagerProxy proxy = new FalsingManagerProxy(
86 getContext(), mPluginManager, mHandler, mProximitySensor);
Dave Mankoff84c07e92019-06-21 14:24:43 -040087
88 assertThat(proxy.getInternalFalsingManager(), instanceOf(BrightLineFalsingManager.class));
89 }
90
91 @Test
92 public void test_brightLineFalsingManagerToggled() {
Dave Mankoff46b9d682019-09-12 13:39:42 -040093 FalsingManagerProxy proxy = new FalsingManagerProxy(
94 getContext(), mPluginManager, mHandler, mProximitySensor);
Dave Mankoff84c07e92019-06-21 14:24:43 -040095 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}