Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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; |
| 18 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 19 | import android.app.ActivityTaskManager; |
Christine Franks | d154fe5 | 2019-01-04 17:17:45 -0800 | [diff] [blame] | 20 | import android.hardware.display.ColorDisplayManager; |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 21 | import android.opengl.Matrix; |
| 22 | import android.os.IBinder; |
| 23 | import android.os.Parcel; |
| 24 | import android.os.RemoteException; |
| 25 | import android.os.ServiceManager; |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 26 | import android.os.SystemProperties; |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 27 | import android.util.Slog; |
| 28 | import android.util.SparseArray; |
Christine Franks | 39b0311 | 2018-07-03 14:46:07 -0700 | [diff] [blame] | 29 | |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 30 | import com.android.internal.annotations.GuardedBy; |
Christine Franks | 39b0311 | 2018-07-03 14:46:07 -0700 | [diff] [blame] | 31 | |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 32 | import java.util.Arrays; |
| 33 | |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Manager for applying color transformations to the display. |
| 36 | */ |
| 37 | public class DisplayTransformManager { |
| 38 | |
| 39 | private static final String TAG = "DisplayTransformManager"; |
| 40 | |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 41 | private static final String SURFACE_FLINGER = "SurfaceFlinger"; |
| 42 | |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Color transform level used by Night display to tint the display red. |
| 45 | */ |
| 46 | public static final int LEVEL_COLOR_MATRIX_NIGHT_DISPLAY = 100; |
| 47 | /** |
Christine Franks | 245ffd4 | 2018-11-16 13:45:14 -0800 | [diff] [blame] | 48 | * Color transform level used by display white balance to adjust the display's white point. |
| 49 | */ |
| 50 | public static final int LEVEL_COLOR_MATRIX_DISPLAY_WHITE_BALANCE = 125; |
| 51 | /** |
Bryan Mawhinney | 462e29d | 2018-03-22 15:52:41 +0000 | [diff] [blame] | 52 | * Color transform level used to adjust the color saturation of the display. |
| 53 | */ |
| 54 | public static final int LEVEL_COLOR_MATRIX_SATURATION = 150; |
| 55 | /** |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 56 | * Color transform level used by A11y services to make the display monochromatic. |
| 57 | */ |
| 58 | public static final int LEVEL_COLOR_MATRIX_GRAYSCALE = 200; |
| 59 | /** |
| 60 | * Color transform level used by A11y services to invert the display colors. |
| 61 | */ |
| 62 | public static final int LEVEL_COLOR_MATRIX_INVERT_COLOR = 300; |
| 63 | |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 64 | private static final int SURFACE_FLINGER_TRANSACTION_COLOR_MATRIX = 1015; |
| 65 | private static final int SURFACE_FLINGER_TRANSACTION_DALTONIZER = 1014; |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 66 | /** |
| 67 | * SurfaceFlinger global saturation factor. |
| 68 | */ |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 69 | private static final int SURFACE_FLINGER_TRANSACTION_SATURATION = 1022; |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 70 | /** |
| 71 | * SurfaceFlinger display color (managed, unmanaged, etc.). |
| 72 | */ |
| 73 | private static final int SURFACE_FLINGER_TRANSACTION_DISPLAY_COLOR = 1023; |
Christine Franks | 87e681b | 2018-11-29 15:03:42 -0800 | [diff] [blame] | 74 | private static final int SURFACE_FLINGER_TRANSACTION_QUERY_COLOR_MANAGED = 1030; |
Christine Franks | 39b0311 | 2018-07-03 14:46:07 -0700 | [diff] [blame] | 75 | |
| 76 | private static final String PERSISTENT_PROPERTY_SATURATION = "persist.sys.sf.color_saturation"; |
| 77 | private static final String PERSISTENT_PROPERTY_DISPLAY_COLOR = "persist.sys.sf.native_mode"; |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 78 | |
| 79 | private static final float COLOR_SATURATION_NATURAL = 1.0f; |
| 80 | private static final float COLOR_SATURATION_BOOSTED = 1.1f; |
| 81 | |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 82 | private static final int DISPLAY_COLOR_MANAGED = 0; |
| 83 | private static final int DISPLAY_COLOR_UNMANAGED = 1; |
| 84 | private static final int DISPLAY_COLOR_ENHANCED = 2; |
| 85 | |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Map of level -> color transformation matrix. |
| 88 | */ |
| 89 | @GuardedBy("mColorMatrix") |
Christine Franks | c7fb945 | 2019-02-04 08:45:33 -0800 | [diff] [blame] | 90 | private final SparseArray<float[]> mColorMatrix = new SparseArray<>(5); |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Temporary matrix used internally by {@link #computeColorMatrixLocked()}. |
| 93 | */ |
| 94 | @GuardedBy("mColorMatrix") |
| 95 | private final float[][] mTempColorMatrix = new float[2][16]; |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 96 | |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 97 | /** |
| 98 | * Lock used for synchronize access to {@link #mDaltonizerMode}. |
| 99 | */ |
| 100 | private final Object mDaltonizerModeLock = new Object(); |
| 101 | @GuardedBy("mDaltonizerModeLock") |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 102 | private int mDaltonizerMode = -1; |
| 103 | |
| 104 | /* package */ DisplayTransformManager() { |
| 105 | } |
| 106 | |
| 107 | /** |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 108 | * Returns a copy of the color transform matrix set for a given level. |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 109 | */ |
| 110 | public float[] getColorMatrix(int key) { |
| 111 | synchronized (mColorMatrix) { |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 112 | final float[] value = mColorMatrix.get(key); |
| 113 | return value == null ? null : Arrays.copyOf(value, value.length); |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Sets and applies a current color transform matrix for a given level. |
| 119 | * <p> |
| 120 | * Note: all color transforms are first composed to a single matrix in ascending order based |
| 121 | * on level before being applied to the display. |
| 122 | * |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 123 | * @param level the level used to identify and compose the color transform (low -> high) |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 124 | * @param value the 4x4 color transform matrix (in column-major order), or {@code null} to |
| 125 | * remove the color transform matrix associated with the provided level |
| 126 | */ |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 127 | public void setColorMatrix(int level, float[] value) { |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 128 | if (value != null && value.length != 16) { |
| 129 | throw new IllegalArgumentException("Expected length: 16 (4x4 matrix)" |
| 130 | + ", actual length: " + value.length); |
| 131 | } |
| 132 | |
| 133 | synchronized (mColorMatrix) { |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 134 | final float[] oldValue = mColorMatrix.get(level); |
| 135 | if (!Arrays.equals(oldValue, value)) { |
| 136 | if (value == null) { |
| 137 | mColorMatrix.remove(level); |
| 138 | } else if (oldValue == null) { |
| 139 | mColorMatrix.put(level, Arrays.copyOf(value, value.length)); |
| 140 | } else { |
| 141 | System.arraycopy(value, 0, oldValue, 0, value.length); |
| 142 | } |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 143 | |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 144 | // Update the current color transform. |
| 145 | applyColorMatrix(computeColorMatrixLocked()); |
| 146 | } |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | /** |
Christine Franks | c7fb945 | 2019-02-04 08:45:33 -0800 | [diff] [blame] | 151 | * Sets the current Daltonization mode. This adjusts the color space to correct for or simulate |
| 152 | * various types of color blindness. |
| 153 | * |
| 154 | * @param mode the new Daltonization mode, or -1 to disable |
| 155 | */ |
| 156 | public void setDaltonizerMode(int mode) { |
| 157 | synchronized (mDaltonizerModeLock) { |
| 158 | if (mDaltonizerMode != mode) { |
| 159 | mDaltonizerMode = mode; |
| 160 | applyDaltonizerMode(mode); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /** |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 166 | * Returns the composition of all current color matrices, or {@code null} if there are none. |
| 167 | */ |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 168 | @GuardedBy("mColorMatrix") |
| 169 | private float[] computeColorMatrixLocked() { |
| 170 | final int count = mColorMatrix.size(); |
| 171 | if (count == 0) { |
| 172 | return null; |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 173 | } |
Justin Klaassen | 639214e | 2016-07-14 21:00:06 -0700 | [diff] [blame] | 174 | |
| 175 | final float[][] result = mTempColorMatrix; |
| 176 | Matrix.setIdentityM(result[0], 0); |
| 177 | for (int i = 0; i < count; i++) { |
| 178 | float[] rhs = mColorMatrix.valueAt(i); |
| 179 | Matrix.multiplyMM(result[(i + 1) % 2], 0, result[i % 2], 0, rhs, 0); |
| 180 | } |
| 181 | return result[count % 2]; |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /** |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 185 | * Propagates the provided color transformation matrix to the SurfaceFlinger. |
| 186 | */ |
| 187 | private static void applyColorMatrix(float[] m) { |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 188 | final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER); |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 189 | if (flinger != null) { |
| 190 | final Parcel data = Parcel.obtain(); |
| 191 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 192 | if (m != null) { |
| 193 | data.writeInt(1); |
| 194 | for (int i = 0; i < 16; i++) { |
| 195 | data.writeFloat(m[i]); |
| 196 | } |
| 197 | } else { |
| 198 | data.writeInt(0); |
| 199 | } |
| 200 | try { |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 201 | flinger.transact(SURFACE_FLINGER_TRANSACTION_COLOR_MATRIX, data, null, 0); |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 202 | } catch (RemoteException ex) { |
| 203 | Slog.e(TAG, "Failed to set color transform", ex); |
| 204 | } finally { |
| 205 | data.recycle(); |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Propagates the provided Daltonization mode to the SurfaceFlinger. |
| 212 | */ |
| 213 | private static void applyDaltonizerMode(int mode) { |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 214 | final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER); |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 215 | if (flinger != null) { |
| 216 | final Parcel data = Parcel.obtain(); |
| 217 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 218 | data.writeInt(mode); |
| 219 | try { |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 220 | flinger.transact(SURFACE_FLINGER_TRANSACTION_DALTONIZER, data, null, 0); |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 221 | } catch (RemoteException ex) { |
| 222 | Slog.e(TAG, "Failed to set Daltonizer mode", ex); |
| 223 | } finally { |
| 224 | data.recycle(); |
| 225 | } |
| 226 | } |
| 227 | } |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 228 | |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 229 | /** |
Chia-I Wu | 9ec9ea7 | 2018-05-07 13:17:04 -0700 | [diff] [blame] | 230 | * Return true when the color matrix works in linear space. |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 231 | */ |
Chia-I Wu | 9ec9ea7 | 2018-05-07 13:17:04 -0700 | [diff] [blame] | 232 | public static boolean needsLinearColorMatrix() { |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 233 | return SystemProperties.getInt(PERSISTENT_PROPERTY_DISPLAY_COLOR, |
Chia-I Wu | 9ec9ea7 | 2018-05-07 13:17:04 -0700 | [diff] [blame] | 234 | DISPLAY_COLOR_UNMANAGED) != DISPLAY_COLOR_UNMANAGED; |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** |
Chia-I Wu | 9ec9ea7 | 2018-05-07 13:17:04 -0700 | [diff] [blame] | 238 | * Return true when the specified colorMode requires the color matrix to |
| 239 | * work in linear space. |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 240 | */ |
Chia-I Wu | 9ec9ea7 | 2018-05-07 13:17:04 -0700 | [diff] [blame] | 241 | public static boolean needsLinearColorMatrix(int colorMode) { |
Christine Franks | d154fe5 | 2019-01-04 17:17:45 -0800 | [diff] [blame] | 242 | return colorMode != ColorDisplayManager.COLOR_MODE_SATURATED; |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Christine Franks | 218e656 | 2017-11-27 10:20:14 -0800 | [diff] [blame] | 245 | public boolean setColorMode(int colorMode, float[] nightDisplayMatrix) { |
Christine Franks | d154fe5 | 2019-01-04 17:17:45 -0800 | [diff] [blame] | 246 | if (colorMode == ColorDisplayManager.COLOR_MODE_NATURAL) { |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 247 | applySaturation(COLOR_SATURATION_NATURAL); |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 248 | setDisplayColor(DISPLAY_COLOR_MANAGED); |
Christine Franks | d154fe5 | 2019-01-04 17:17:45 -0800 | [diff] [blame] | 249 | } else if (colorMode == ColorDisplayManager.COLOR_MODE_BOOSTED) { |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 250 | applySaturation(COLOR_SATURATION_BOOSTED); |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 251 | setDisplayColor(DISPLAY_COLOR_MANAGED); |
Christine Franks | d154fe5 | 2019-01-04 17:17:45 -0800 | [diff] [blame] | 252 | } else if (colorMode == ColorDisplayManager.COLOR_MODE_SATURATED) { |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 253 | applySaturation(COLOR_SATURATION_NATURAL); |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 254 | setDisplayColor(DISPLAY_COLOR_UNMANAGED); |
Christine Franks | d154fe5 | 2019-01-04 17:17:45 -0800 | [diff] [blame] | 255 | } else if (colorMode == ColorDisplayManager.COLOR_MODE_AUTOMATIC) { |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 256 | applySaturation(COLOR_SATURATION_NATURAL); |
| 257 | setDisplayColor(DISPLAY_COLOR_ENHANCED); |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 258 | } |
Christine Franks | 218e656 | 2017-11-27 10:20:14 -0800 | [diff] [blame] | 259 | setColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY, nightDisplayMatrix); |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 260 | |
| 261 | updateConfiguration(); |
| 262 | |
| 263 | return true; |
| 264 | } |
| 265 | |
| 266 | /** |
Christine Franks | 87e681b | 2018-11-29 15:03:42 -0800 | [diff] [blame] | 267 | * Returns whether the screen is color managed via SurfaceFlinger's |
| 268 | * {@link #SURFACE_FLINGER_TRANSACTION_QUERY_COLOR_MANAGED}. |
Christine Franks | 39b0311 | 2018-07-03 14:46:07 -0700 | [diff] [blame] | 269 | */ |
| 270 | public boolean isDeviceColorManaged() { |
| 271 | final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER); |
| 272 | if (flinger != null) { |
| 273 | final Parcel data = Parcel.obtain(); |
| 274 | final Parcel reply = Parcel.obtain(); |
| 275 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 276 | try { |
Christine Franks | 87e681b | 2018-11-29 15:03:42 -0800 | [diff] [blame] | 277 | flinger.transact(SURFACE_FLINGER_TRANSACTION_QUERY_COLOR_MANAGED, data, reply, 0); |
Christine Franks | 39b0311 | 2018-07-03 14:46:07 -0700 | [diff] [blame] | 278 | return reply.readBoolean(); |
| 279 | } catch (RemoteException ex) { |
Christine Franks | 87e681b | 2018-11-29 15:03:42 -0800 | [diff] [blame] | 280 | Slog.e(TAG, "Failed to query wide color support", ex); |
Christine Franks | 39b0311 | 2018-07-03 14:46:07 -0700 | [diff] [blame] | 281 | } finally { |
| 282 | data.recycle(); |
| 283 | reply.recycle(); |
| 284 | } |
| 285 | } |
| 286 | return false; |
| 287 | } |
| 288 | |
| 289 | /** |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 290 | * Propagates the provided saturation to the SurfaceFlinger. |
| 291 | */ |
| 292 | private void applySaturation(float saturation) { |
| 293 | SystemProperties.set(PERSISTENT_PROPERTY_SATURATION, Float.toString(saturation)); |
| 294 | final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER); |
| 295 | if (flinger != null) { |
| 296 | final Parcel data = Parcel.obtain(); |
| 297 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 298 | data.writeFloat(saturation); |
| 299 | try { |
| 300 | flinger.transact(SURFACE_FLINGER_TRANSACTION_SATURATION, data, null, 0); |
| 301 | } catch (RemoteException ex) { |
Christine Franks | 87e681b | 2018-11-29 15:03:42 -0800 | [diff] [blame] | 302 | Slog.e(TAG, "Failed to set saturation", ex); |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 303 | } finally { |
| 304 | data.recycle(); |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Toggles native mode on/off in SurfaceFlinger. |
| 311 | */ |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 312 | private void setDisplayColor(int color) { |
| 313 | SystemProperties.set(PERSISTENT_PROPERTY_DISPLAY_COLOR, Integer.toString(color)); |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 314 | final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER); |
| 315 | if (flinger != null) { |
| 316 | final Parcel data = Parcel.obtain(); |
| 317 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 318 | data.writeInt(color); |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 319 | try { |
Chia-I Wu | 1e0e717 | 2018-03-14 15:45:29 -0700 | [diff] [blame] | 320 | flinger.transact(SURFACE_FLINGER_TRANSACTION_DISPLAY_COLOR, data, null, 0); |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 321 | } catch (RemoteException ex) { |
Christine Franks | 87e681b | 2018-11-29 15:03:42 -0800 | [diff] [blame] | 322 | Slog.e(TAG, "Failed to set display color", ex); |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 323 | } finally { |
| 324 | data.recycle(); |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | private void updateConfiguration() { |
| 330 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 331 | ActivityTaskManager.getService().updateConfiguration(null); |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 332 | } catch (RemoteException e) { |
Christine Franks | 87e681b | 2018-11-29 15:03:42 -0800 | [diff] [blame] | 333 | Slog.e(TAG, "Could not update configuration", e); |
Christine Franks | 8ad7149 | 2017-10-24 19:04:22 -0700 | [diff] [blame] | 334 | } |
| 335 | } |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 336 | } |