PowerManagerServiceTest.java revision 92681e8cfbbae58b00a80bb1e60f5444cf53fbdd
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 17package com.android.server.power; 18 19import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest; 20import android.os.PowerSaveState; 21import android.test.AndroidTestCase; 22import android.test.suitebuilder.annotation.SmallTest; 23import org.mockito.Mock; 24import org.mockito.MockitoAnnotations; 25 26import static com.google.common.truth.Truth.assertThat; 27import static org.mockito.Matchers.anyBoolean; 28import static org.mockito.Matchers.eq; 29import static org.mockito.Mockito.when; 30 31/** 32 * Tests for {@link com.android.server.power.PowerManagerService} 33 */ 34public class PowerManagerServiceTest extends AndroidTestCase { 35 private static final float PRECISION = 0.001f; 36 private static final float BRIGHTNESS_FACTOR = 0.7f; 37 private static final boolean BATTERY_SAVER_ENABLED = true; 38 39 private @Mock BatterySaverPolicy mBatterySaverPolicy; 40 private PowerManagerService mService; 41 private PowerSaveState mPowerSaveState; 42 private DisplayPowerRequest mDisplayPowerRequest; 43 44 public void setUp() throws Exception { 45 super.setUp(); 46 MockitoAnnotations.initMocks(this); 47 48 mPowerSaveState = new PowerSaveState.Builder() 49 .setBatterySaverEnabled(BATTERY_SAVER_ENABLED) 50 .setBrightnessFactor(BRIGHTNESS_FACTOR) 51 .build(); 52 when(mBatterySaverPolicy.getBatterySaverPolicy( 53 eq(BatterySaverPolicy.ServiceType.SCREEN_BRIGHTNESS), anyBoolean())) 54 .thenReturn(mPowerSaveState); 55 mDisplayPowerRequest = new DisplayPowerRequest(); 56 mService = new PowerManagerService(getContext(), mBatterySaverPolicy); 57 } 58 59 @SmallTest 60 public void testUpdatePowerScreenPolicy_UpdateDisplayPowerRequest() { 61 mService.updatePowerRequestFromBatterySaverPolicy(mDisplayPowerRequest); 62 assertThat(mDisplayPowerRequest.lowPowerMode).isEqualTo(BATTERY_SAVER_ENABLED); 63 assertThat(mDisplayPowerRequest.screenLowPowerBrightnessFactor) 64 .isWithin(PRECISION).of(BRIGHTNESS_FACTOR); 65 } 66} 67