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 com.google.common.truth.Truth.assertThat; 20 21 import android.provider.Settings; 22 import android.text.format.DateUtils; 23 24 import androidx.test.filters.SmallTest; 25 import androidx.test.runner.AndroidJUnit4; 26 27 import com.android.systemui.R; 28 import com.android.systemui.SysuiTestCase; 29 30 import org.junit.After; 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 @RunWith(AndroidJUnit4.class) 36 @SmallTest 37 public class AlwaysOnDisplayPolicyTest extends SysuiTestCase { 38 private static final String ALWAYS_ON_DISPLAY_CONSTANTS_VALUE = "prox_screen_off_delay=1000" 39 + ",prox_cooldown_trigger=2000" 40 + ",prox_cooldown_period=3000" 41 + ",screen_brightness_array=1:2:3:4:5" 42 + ",dimming_scrim_array=5:4:3:2:1"; 43 44 private String mPreviousConfig; 45 46 @Before setUp()47 public void setUp() { 48 mPreviousConfig = Settings.Global.getString(mContext.getContentResolver(), 49 Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS); 50 } 51 52 @After tearDown()53 public void tearDown() { 54 Settings.Global.putString(mContext.getContentResolver(), 55 Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS, mPreviousConfig); 56 } 57 58 @Test testPolicy_valueNull_containsDefaultValue()59 public void testPolicy_valueNull_containsDefaultValue() throws Exception { 60 Settings.Global.putString(mContext.getContentResolver(), 61 Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS, null); 62 63 AlwaysOnDisplayPolicy policy = new AlwaysOnDisplayPolicy(mContext); 64 65 assertThat(policy.proxScreenOffDelayMs).isEqualTo(10 * DateUtils.SECOND_IN_MILLIS); 66 assertThat(policy.proxCooldownTriggerMs).isEqualTo(2 * DateUtils.SECOND_IN_MILLIS); 67 assertThat(policy.proxCooldownPeriodMs).isEqualTo(5 * DateUtils.SECOND_IN_MILLIS); 68 assertThat(policy.screenBrightnessArray).isEqualTo(mContext.getResources().getIntArray( 69 R.array.config_doze_brightness_sensor_to_brightness)); 70 assertThat(policy.dimmingScrimArray).isEqualTo(mContext.getResources().getIntArray( 71 R.array.config_doze_brightness_sensor_to_scrim_opacity)); 72 } 73 74 @Test testPolicy_valueNotNull_containsValue()75 public void testPolicy_valueNotNull_containsValue() throws Exception { 76 Settings.Global.putString(mContext.getContentResolver(), 77 Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS, ALWAYS_ON_DISPLAY_CONSTANTS_VALUE); 78 79 AlwaysOnDisplayPolicy policy = new AlwaysOnDisplayPolicy(mContext); 80 81 assertThat(policy.proxScreenOffDelayMs).isEqualTo(1000); 82 assertThat(policy.proxCooldownTriggerMs).isEqualTo(2000); 83 assertThat(policy.proxCooldownPeriodMs).isEqualTo(3000); 84 assertThat(policy.screenBrightnessArray).isEqualTo(new int[]{1, 2, 3, 4, 5}); 85 assertThat(policy.dimmingScrimArray).isEqualTo(new int[]{5, 4, 3, 2, 1}); 86 } 87 } 88