1 /*
2  * Copyright (C) 2017 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.doze;
18 
19 import static org.mockito.ArgumentMatchers.anyInt;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.when;
22 import static org.mockito.Mockito.withSettings;
23 
24 import android.hardware.display.AmbientDisplayConfiguration;
25 
26 import com.android.systemui.statusbar.phone.DozeParameters;
27 import com.android.systemui.util.sensors.FakeSensorManager;
28 
29 import org.mockito.Answers;
30 import org.mockito.MockSettings;
31 
32 public class DozeConfigurationUtil {
createMockParameters()33     public static DozeParameters createMockParameters() {
34         boolean[] doneHolder = new boolean[1];
35         DozeParameters params = mock(DozeParameters.class, noDefaultAnswer(doneHolder));
36 
37         when(params.getPulseOnSigMotion()).thenReturn(false);
38         when(params.getPickupVibrationThreshold()).thenReturn(0);
39         when(params.getProxCheckBeforePulse()).thenReturn(true);
40         when(params.doubleTapReportsTouchCoordinates()).thenReturn(false);
41         when(params.getDisplayNeedsBlanking()).thenReturn(false);
42         when(params.getSelectivelyRegisterSensorsUsingProx()).thenReturn(false);
43         when(params.singleTapUsesProx(anyInt())).thenReturn(true);
44         when(params.longPressUsesProx()).thenReturn(true);
45         when(params.getQuickPickupAodDuration()).thenReturn(500);
46 
47         doneHolder[0] = true;
48         return params;
49     }
50 
createMockConfig()51     public static AmbientDisplayConfiguration createMockConfig() {
52         boolean[] doneHolder = new boolean[1];
53         AmbientDisplayConfiguration config = mock(AmbientDisplayConfiguration.class,
54                 noDefaultAnswer(doneHolder));
55         when(config.doubleTapGestureEnabled(anyInt())).thenReturn(false);
56         when(config.pickupGestureEnabled(anyInt())).thenReturn(false);
57         when(config.pulseOnNotificationEnabled(anyInt())).thenReturn(true);
58         when(config.alwaysOnEnabled(anyInt())).thenReturn(false);
59         when(config.dozeSuppressed(anyInt())).thenReturn(false);
60         when(config.enabled(anyInt())).thenReturn(true);
61         when(config.getWakeLockScreenDebounce()).thenReturn(0L);
62 
63         when(config.doubleTapSensorType()).thenReturn(null);
64         when(config.longPressSensorType()).thenReturn(null);
65         when(config.udfpsLongPressSensorType()).thenReturn(null);
66         when(config.quickPickupSensorType()).thenReturn(null);
67 
68         when(config.tapGestureEnabled(anyInt())).thenReturn(true);
69         when(config.tapSensorAvailable()).thenReturn(true);
70         when(config.tapSensorTypeMapping()).thenReturn(
71                 new String[]{FakeSensorManager.TAP_SENSOR_TYPE});
72 
73         when(config.dozePickupSensorAvailable()).thenReturn(false);
74         when(config.wakeScreenGestureAvailable()).thenReturn(false);
75         when(config.quickPickupSensorEnabled(anyInt())).thenReturn(false);
76         when(config.screenOffUdfpsEnabled(anyInt())).thenReturn(false);
77 
78         doneHolder[0] = true;
79         return config;
80     }
81 
noDefaultAnswer(boolean[] setupDoneHolder)82     private static MockSettings noDefaultAnswer(boolean[] setupDoneHolder) {
83         return withSettings().defaultAnswer((i) -> {
84             if (setupDoneHolder[0]) {
85                 throw new IllegalArgumentException("not defined");
86             } else {
87                 return Answers.RETURNS_DEFAULTS.answer(i);
88             }
89         });
90     }
91 
92 }
93