blob: ec9acdf26c8a9458f8d1e660591a12ee1caada11 [file] [log] [blame]
jackqdyulei8443dd02017-08-24 16:14:34 -07001/*
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.systemui.doze;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import android.provider.Settings;
jackqdyulei8443dd02017-08-24 16:14:34 -070022import android.text.format.DateUtils;
23
Brett Chabot84151d92019-02-27 15:37:59 -080024import androidx.test.filters.SmallTest;
25import androidx.test.runner.AndroidJUnit4;
26
jackqdyulei8443dd02017-08-24 16:14:34 -070027import com.android.systemui.R;
28import com.android.systemui.SysuiTestCase;
29
30import org.junit.After;
31import org.junit.Before;
32import org.junit.Test;
33import org.junit.runner.RunWith;
34
35@RunWith(AndroidJUnit4.class)
36@SmallTest
37public 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
47 public void setUp() {
48 mPreviousConfig = Settings.Global.getString(mContext.getContentResolver(),
49 Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS);
50 }
51
52 @After
53 public void tearDown() {
54 Settings.Global.putString(mContext.getContentResolver(),
55 Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS, mPreviousConfig);
56 }
57
58 @Test
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
Adrian Roosc2189122017-09-04 15:39:50 +000065 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);
jackqdyulei8443dd02017-08-24 16:14:34 -070068 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
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}