Adrian Roos | d35d4ca | 2017-04-19 14:31:03 -0700 | [diff] [blame] | 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 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 19 | import android.hardware.display.AmbientDisplayConfiguration; |
| 20 | |
Adrian Roos | d35d4ca | 2017-04-19 14:31:03 -0700 | [diff] [blame] | 21 | import static org.mockito.ArgumentMatchers.anyInt; |
| 22 | import static org.mockito.Mockito.mock; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | import static org.mockito.Mockito.withSettings; |
| 25 | |
Adrian Roos | d35d4ca | 2017-04-19 14:31:03 -0700 | [diff] [blame] | 26 | import com.android.systemui.statusbar.phone.DozeParameters; |
| 27 | |
| 28 | import org.mockito.Answers; |
| 29 | import org.mockito.MockSettings; |
| 30 | |
| 31 | public class DozeConfigurationUtil { |
| 32 | public static DozeParameters createMockParameters() { |
| 33 | boolean[] doneHolder = new boolean[1]; |
| 34 | DozeParameters params = mock(DozeParameters.class, noDefaultAnswer(doneHolder)); |
| 35 | |
| 36 | when(params.getPulseOnSigMotion()).thenReturn(false); |
Adrian Roos | d35d4ca | 2017-04-19 14:31:03 -0700 | [diff] [blame] | 37 | when(params.getPickupVibrationThreshold()).thenReturn(0); |
| 38 | when(params.getProxCheckBeforePulse()).thenReturn(true); |
| 39 | when(params.getPickupSubtypePerformsProxCheck(anyInt())).thenReturn(true); |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 40 | when(params.getPolicy()).thenReturn(mock(AlwaysOnDisplayPolicy.class)); |
| 41 | when(params.doubleTapReportsTouchCoordinates()).thenReturn(false); |
Adrian Roos | d35d4ca | 2017-04-19 14:31:03 -0700 | [diff] [blame] | 42 | |
| 43 | doneHolder[0] = true; |
| 44 | return params; |
| 45 | } |
| 46 | |
| 47 | public static AmbientDisplayConfiguration createMockConfig() { |
| 48 | boolean[] doneHolder = new boolean[1]; |
| 49 | AmbientDisplayConfiguration config = mock(AmbientDisplayConfiguration.class, |
| 50 | noDefaultAnswer(doneHolder)); |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 51 | when(config.doubleTapGestureEnabled(anyInt())).thenReturn(false); |
| 52 | when(config.pickupGestureEnabled(anyInt())).thenReturn(false); |
Adrian Roos | d35d4ca | 2017-04-19 14:31:03 -0700 | [diff] [blame] | 53 | when(config.pulseOnNotificationEnabled(anyInt())).thenReturn(true); |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 54 | when(config.alwaysOnEnabled(anyInt())).thenReturn(false); |
Adrian Roos | d35d4ca | 2017-04-19 14:31:03 -0700 | [diff] [blame] | 55 | |
| 56 | when(config.doubleTapSensorType()).thenReturn(null); |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 57 | when(config.tapSensorType()).thenReturn(null); |
| 58 | when(config.longPressSensorType()).thenReturn(null); |
| 59 | |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 60 | when(config.dozePickupSensorAvailable()).thenReturn(false); |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 61 | when(config.wakeScreenGestureAvailable()).thenReturn(false); |
Adrian Roos | d35d4ca | 2017-04-19 14:31:03 -0700 | [diff] [blame] | 62 | |
| 63 | doneHolder[0] = true; |
| 64 | return config; |
| 65 | } |
| 66 | |
| 67 | private static MockSettings noDefaultAnswer(boolean[] setupDoneHolder) { |
| 68 | return withSettings().defaultAnswer((i) -> { |
| 69 | if (setupDoneHolder[0]) { |
| 70 | throw new IllegalArgumentException("not defined"); |
| 71 | } else { |
| 72 | return Answers.RETURNS_DEFAULTS.answer(i); |
| 73 | } |
| 74 | }); |
| 75 | } |
| 76 | |
| 77 | } |