Christine Franks | dacbb2d3 | 2019-04-05 18:33:55 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2019 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.server.display.color; |
| 18 | |
| 19 | import static com.android.server.display.color.DisplayTransformManager.LEVEL_COLOR_MATRIX_NIGHT_DISPLAY; |
| 20 | import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_DISPLAY_COLOR; |
| 21 | import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_SATURATION; |
| 22 | |
| 23 | import static com.google.common.truth.Truth.assertThat; |
| 24 | |
| 25 | import android.hardware.display.ColorDisplayManager; |
| 26 | import android.os.SystemProperties; |
| 27 | |
| 28 | import androidx.test.runner.AndroidJUnit4; |
| 29 | |
| 30 | import org.junit.Before; |
| 31 | import org.junit.Test; |
| 32 | import org.junit.runner.RunWith; |
| 33 | |
| 34 | @RunWith(AndroidJUnit4.class) |
| 35 | public class DisplayTransformManagerTest { |
| 36 | |
| 37 | private DisplayTransformManager mDtm; |
| 38 | private float[] mNightDisplayMatrix; |
| 39 | |
| 40 | @Before |
| 41 | public void setUp() { |
| 42 | mDtm = new DisplayTransformManager(); |
| 43 | mNightDisplayMatrix = mDtm.getColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY); |
| 44 | |
| 45 | SystemProperties.set(PERSISTENT_PROPERTY_DISPLAY_COLOR, null); |
| 46 | SystemProperties.set(PERSISTENT_PROPERTY_SATURATION, null); |
| 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void setColorMode_natural() { |
| 51 | mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_NATURAL, mNightDisplayMatrix); |
| 52 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null)) |
| 53 | .isEqualTo("0" /* managed */); |
| 54 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null)) |
| 55 | .isEqualTo("1.0" /* natural */); |
| 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void setColorMode_boosted() { |
| 60 | mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_BOOSTED, mNightDisplayMatrix); |
| 61 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null)) |
| 62 | .isEqualTo("0" /* managed */); |
| 63 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null)) |
| 64 | .isEqualTo("1.1" /* boosted */); |
| 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void setColorMode_saturated() { |
| 69 | mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_SATURATED, mNightDisplayMatrix); |
| 70 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null)) |
| 71 | .isEqualTo("1" /* unmanaged */); |
| 72 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null)) |
| 73 | .isEqualTo("1.0" /* natural */); |
| 74 | } |
| 75 | |
| 76 | @Test |
| 77 | public void setColorMode_automatic() { |
| 78 | mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_AUTOMATIC, mNightDisplayMatrix); |
| 79 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null)) |
| 80 | .isEqualTo("2" /* enhanced */); |
| 81 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null)) |
| 82 | .isEqualTo("1.0" /* natural */); |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void setColorMode_vendor() { |
| 87 | mDtm.setColorMode(0x100, mNightDisplayMatrix); |
| 88 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null)) |
| 89 | .isEqualTo(Integer.toString(0x100) /* pass-through */); |
| 90 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null)) |
| 91 | .isEqualTo("1.0" /* default */); |
| 92 | } |
| 93 | |
| 94 | @Test |
| 95 | public void setColorMode_outOfBounds() { |
| 96 | mDtm.setColorMode(0x50, mNightDisplayMatrix); |
| 97 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null)) |
| 98 | .isEqualTo("" /* default */); |
| 99 | assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null)) |
| 100 | .isEqualTo("" /* default */); |
| 101 | } |
| 102 | } |