2 * Copyright (C) 2019 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.server.display.color;
19 import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyString;
20 import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
21 import static com.android.server.display.color.DisplayTransformManager.LEVEL_COLOR_MATRIX_NIGHT_DISPLAY;
22 import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_DISPLAY_COLOR;
23 import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_SATURATION;
25 import static com.google.common.truth.Truth.assertThat;
27 import static org.mockito.ArgumentMatchers.any;
29 import android.hardware.display.ColorDisplayManager;
30 import android.os.SystemProperties;
32 import androidx.test.runner.AndroidJUnit4;
34 import com.android.dx.mockito.inline.extended.ExtendedMockito;
36 import org.junit.After;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.mockito.MockitoSession;
41 import org.mockito.quality.Strictness;
42 import org.mockito.stubbing.Answer;
44 import java.util.HashMap;
46 @RunWith(AndroidJUnit4.class)
47 public class DisplayTransformManagerTest {
49 private MockitoSession mSession;
50 private DisplayTransformManager mDtm;
51 private float[] mNightDisplayMatrix;
52 private HashMap<String, String> mSystemProperties;
56 mDtm = new DisplayTransformManager();
57 mNightDisplayMatrix = mDtm.getColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY);
59 mSession = ExtendedMockito.mockitoSession()
61 .strictness(Strictness.LENIENT)
62 .spyStatic(SystemProperties.class)
64 mSystemProperties = new HashMap<>();
66 doAnswer((Answer<Void>) invocationOnMock -> {
67 mSystemProperties.put(invocationOnMock.getArgument(0),
68 invocationOnMock.getArgument(1));
71 ).when(() -> SystemProperties.set(anyString(), any()));
75 public void tearDown() throws Exception {
76 mSession.finishMocking();
77 mSystemProperties.clear();
81 public void setColorMode_natural() {
82 mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_NATURAL, mNightDisplayMatrix);
83 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
84 .isEqualTo("0" /* managed */);
85 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
86 .isEqualTo("1.0" /* natural */);
90 public void setColorMode_boosted() {
91 mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_BOOSTED, mNightDisplayMatrix);
93 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
94 .isEqualTo("0" /* managed */);
95 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
96 .isEqualTo("1.1" /* boosted */);
100 public void setColorMode_saturated() {
101 mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_SATURATED, mNightDisplayMatrix);
102 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
103 .isEqualTo("1" /* unmanaged */);
104 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
105 .isEqualTo("1.0" /* natural */);
109 public void setColorMode_automatic() {
110 mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_AUTOMATIC, mNightDisplayMatrix);
111 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
112 .isEqualTo("2" /* enhanced */);
113 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
114 .isEqualTo("1.0" /* natural */);
118 public void setColorMode_vendor() {
119 mDtm.setColorMode(0x100, mNightDisplayMatrix);
120 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
121 .isEqualTo(Integer.toString(0x100) /* pass-through */);
122 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
123 .isEqualTo("1.0" /* natural */);
127 public void setColorMode_outOfBounds() {
128 mDtm.setColorMode(0x50, mNightDisplayMatrix);
129 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
131 assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))