Home | History | Annotate | Download | only in doze
      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 com.android.internal.hardware.AmbientDisplayConfiguration;
     25 import com.android.systemui.statusbar.phone.DozeParameters;
     26 
     27 import org.mockito.Answers;
     28 import org.mockito.MockSettings;
     29 
     30 public class DozeConfigurationUtil {
     31     public static DozeParameters createMockParameters() {
     32         boolean[] doneHolder = new boolean[1];
     33         DozeParameters params = mock(DozeParameters.class, noDefaultAnswer(doneHolder));
     34 
     35         when(params.getPulseOnSigMotion()).thenReturn(false);
     36         when(params.getPickupVibrationThreshold()).thenReturn(0);
     37         when(params.getProxCheckBeforePulse()).thenReturn(true);
     38         when(params.getPickupSubtypePerformsProxCheck(anyInt())).thenReturn(true);
     39 
     40         doneHolder[0] = true;
     41         return params;
     42     }
     43 
     44     public static AmbientDisplayConfiguration createMockConfig() {
     45         boolean[] doneHolder = new boolean[1];
     46         AmbientDisplayConfiguration config = mock(AmbientDisplayConfiguration.class,
     47                 noDefaultAnswer(doneHolder));
     48         when(config.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
     49         when(config.pulseOnPickupEnabled(anyInt())).thenReturn(false);
     50         when(config.pulseOnNotificationEnabled(anyInt())).thenReturn(true);
     51 
     52         when(config.doubleTapSensorType()).thenReturn(null);
     53         when(config.pulseOnPickupAvailable()).thenReturn(false);
     54 
     55         doneHolder[0] = true;
     56         return config;
     57     }
     58 
     59     private static MockSettings noDefaultAnswer(boolean[] setupDoneHolder) {
     60         return withSettings().defaultAnswer((i) -> {
     61             if (setupDoneHolder[0]) {
     62                 throw new IllegalArgumentException("not defined");
     63             } else {
     64                 return Answers.RETURNS_DEFAULTS.answer(i);
     65             }
     66         });
     67     }
     68 
     69 }
     70