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