Loading services/accessibility/accessibility.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -183,3 +183,10 @@ flag { purpose: PURPOSE_BUGFIX } } flag { name: "enable_color_correction_saturation" namespace: "accessibility" description: "Feature allows users to change color correction saturation for daltonizer." bug: "322829049" } No newline at end of file services/core/java/com/android/server/display/color/ColorDisplayService.java +26 −5 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ import com.android.internal.util.DumpUtils; import com.android.server.DisplayThread; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.accessibility.Flags; import com.android.server.display.feature.DisplayManagerFlags; import com.android.server.twilight.TwilightListener; import com.android.server.twilight.TwilightManager; Loading Loading @@ -356,6 +357,11 @@ public final class ColorDisplayService extends SystemService { case Secure.ACCESSIBILITY_DISPLAY_DALTONIZER: onAccessibilityDaltonizerChanged(); break; case Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL: if (Flags.enableColorCorrectionSaturation()) { onAccessibilityDaltonizerChanged(); } break; case Secure.DISPLAY_WHITE_BALANCE_ENABLED: updateDisplayWhiteBalanceStatus(); break; Loading Loading @@ -398,6 +404,11 @@ public final class ColorDisplayService extends SystemService { false /* notifyForDescendants */, mContentObserver, mCurrentUser); cr.registerContentObserver(Secure.getUriFor(Secure.REDUCE_BRIGHT_COLORS_LEVEL), false /* notifyForDescendants */, mContentObserver, mCurrentUser); if (Flags.enableColorCorrectionSaturation()) { cr.registerContentObserver( Secure.getUriFor(Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL), false /* notifyForDescendants */, mContentObserver, mCurrentUser); } // Apply the accessibility settings first, since they override most other settings. onAccessibilityInversionChanged(); Loading Loading @@ -597,21 +608,31 @@ public final class ColorDisplayService extends SystemService { if (mCurrentUser == UserHandle.USER_NULL) { return; } var contentResolver = getContext().getContentResolver(); final int daltonizerMode = isAccessiblityDaltonizerEnabled() ? Secure.getIntForUser(getContext().getContentResolver(), ? Secure.getIntForUser(contentResolver, Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, AccessibilityManager.DALTONIZER_CORRECT_DEUTERANOMALY, mCurrentUser) : AccessibilityManager.DALTONIZER_DISABLED; int saturation = NOT_SET; if (Flags.enableColorCorrectionSaturation()) { saturation = Secure.getIntForUser( contentResolver, Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL, NOT_SET, mCurrentUser); } final DisplayTransformManager dtm = getLocalService(DisplayTransformManager.class); if (daltonizerMode == AccessibilityManager.DALTONIZER_SIMULATE_MONOCHROMACY) { // Monochromacy isn't supported by the native Daltonizer implementation; use grayscale. dtm.setColorMatrix(DisplayTransformManager.LEVEL_COLOR_MATRIX_GRAYSCALE, MATRIX_GRAYSCALE); dtm.setDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED); dtm.setDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED, saturation); } else { dtm.setColorMatrix(DisplayTransformManager.LEVEL_COLOR_MATRIX_GRAYSCALE, null); dtm.setDaltonizerMode(daltonizerMode); dtm.setDaltonizerMode(daltonizerMode, saturation); } } Loading services/core/java/com/android/server/display/color/DisplayTransformManager.java +17 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.display.color; import android.annotation.IntRange; import android.app.ActivityTaskManager; import android.hardware.display.ColorDisplayManager; import android.opengl.Matrix; Loading Loading @@ -111,9 +112,15 @@ public class DisplayTransformManager { /** * Lock used for synchronize access to {@link #mDaltonizerMode}. */ private final Object mDaltonizerModeLock = new Object(); @VisibleForTesting final Object mDaltonizerModeLock = new Object(); @VisibleForTesting @GuardedBy("mDaltonizerModeLock") int mDaltonizerMode = -1; @VisibleForTesting @GuardedBy("mDaltonizerModeLock") private int mDaltonizerMode = -1; int mDaltonizerLevel = -1; private static final IBinder sFlinger = ServiceManager.getService(SURFACE_FLINGER); Loading Loading @@ -168,12 +175,15 @@ public class DisplayTransformManager { * various types of color blindness. * * @param mode the new Daltonization mode, or -1 to disable * @param level the level of saturation for color correction [-1,10] inclusive. -1 for when * it is not set. */ public void setDaltonizerMode(int mode) { public void setDaltonizerMode(int mode, @IntRange(from = -1, to = 10) int level) { synchronized (mDaltonizerModeLock) { if (mDaltonizerMode != mode) { if (mDaltonizerMode != mode || mDaltonizerLevel != level) { mDaltonizerMode = mode; applyDaltonizerMode(mode); mDaltonizerLevel = level; applyDaltonizerMode(mode, level); } } } Loading Loading @@ -223,10 +233,11 @@ public class DisplayTransformManager { /** * Propagates the provided Daltonization mode to the SurfaceFlinger. */ private static void applyDaltonizerMode(int mode) { private static void applyDaltonizerMode(int mode, int level) { final Parcel data = Parcel.obtain(); data.writeInterfaceToken("android.ui.ISurfaceComposer"); data.writeInt(mode); data.writeInt(level); try { sFlinger.transact(SURFACE_FLINGER_TRANSACTION_DALTONIZER, data, null, 0); } catch (RemoteException ex) { Loading services/tests/displayservicetests/src/com/android/server/display/color/DisplayTransformManagerTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -161,4 +161,20 @@ public class DisplayTransformManagerTest { .isEqualTo(Integer.toString(testPropertyValue)); } @Test public void daltonizer_defaultValues() { synchronized (mDtm.mDaltonizerModeLock) { assertThat(mDtm.mDaltonizerMode).isEqualTo(-1); assertThat(mDtm.mDaltonizerLevel).isEqualTo(-1); } } @Test public void setDaltonizerMode_newValues_valuesUpdated() { mDtm.setDaltonizerMode(0, 0); synchronized (mDtm.mDaltonizerModeLock) { assertThat(mDtm.mDaltonizerMode).isEqualTo(0); assertThat(mDtm.mDaltonizerLevel).isEqualTo(0); } } } Loading
services/accessibility/accessibility.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -183,3 +183,10 @@ flag { purpose: PURPOSE_BUGFIX } } flag { name: "enable_color_correction_saturation" namespace: "accessibility" description: "Feature allows users to change color correction saturation for daltonizer." bug: "322829049" } No newline at end of file
services/core/java/com/android/server/display/color/ColorDisplayService.java +26 −5 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ import com.android.internal.util.DumpUtils; import com.android.server.DisplayThread; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.accessibility.Flags; import com.android.server.display.feature.DisplayManagerFlags; import com.android.server.twilight.TwilightListener; import com.android.server.twilight.TwilightManager; Loading Loading @@ -356,6 +357,11 @@ public final class ColorDisplayService extends SystemService { case Secure.ACCESSIBILITY_DISPLAY_DALTONIZER: onAccessibilityDaltonizerChanged(); break; case Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL: if (Flags.enableColorCorrectionSaturation()) { onAccessibilityDaltonizerChanged(); } break; case Secure.DISPLAY_WHITE_BALANCE_ENABLED: updateDisplayWhiteBalanceStatus(); break; Loading Loading @@ -398,6 +404,11 @@ public final class ColorDisplayService extends SystemService { false /* notifyForDescendants */, mContentObserver, mCurrentUser); cr.registerContentObserver(Secure.getUriFor(Secure.REDUCE_BRIGHT_COLORS_LEVEL), false /* notifyForDescendants */, mContentObserver, mCurrentUser); if (Flags.enableColorCorrectionSaturation()) { cr.registerContentObserver( Secure.getUriFor(Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL), false /* notifyForDescendants */, mContentObserver, mCurrentUser); } // Apply the accessibility settings first, since they override most other settings. onAccessibilityInversionChanged(); Loading Loading @@ -597,21 +608,31 @@ public final class ColorDisplayService extends SystemService { if (mCurrentUser == UserHandle.USER_NULL) { return; } var contentResolver = getContext().getContentResolver(); final int daltonizerMode = isAccessiblityDaltonizerEnabled() ? Secure.getIntForUser(getContext().getContentResolver(), ? Secure.getIntForUser(contentResolver, Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, AccessibilityManager.DALTONIZER_CORRECT_DEUTERANOMALY, mCurrentUser) : AccessibilityManager.DALTONIZER_DISABLED; int saturation = NOT_SET; if (Flags.enableColorCorrectionSaturation()) { saturation = Secure.getIntForUser( contentResolver, Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL, NOT_SET, mCurrentUser); } final DisplayTransformManager dtm = getLocalService(DisplayTransformManager.class); if (daltonizerMode == AccessibilityManager.DALTONIZER_SIMULATE_MONOCHROMACY) { // Monochromacy isn't supported by the native Daltonizer implementation; use grayscale. dtm.setColorMatrix(DisplayTransformManager.LEVEL_COLOR_MATRIX_GRAYSCALE, MATRIX_GRAYSCALE); dtm.setDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED); dtm.setDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED, saturation); } else { dtm.setColorMatrix(DisplayTransformManager.LEVEL_COLOR_MATRIX_GRAYSCALE, null); dtm.setDaltonizerMode(daltonizerMode); dtm.setDaltonizerMode(daltonizerMode, saturation); } } Loading
services/core/java/com/android/server/display/color/DisplayTransformManager.java +17 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.display.color; import android.annotation.IntRange; import android.app.ActivityTaskManager; import android.hardware.display.ColorDisplayManager; import android.opengl.Matrix; Loading Loading @@ -111,9 +112,15 @@ public class DisplayTransformManager { /** * Lock used for synchronize access to {@link #mDaltonizerMode}. */ private final Object mDaltonizerModeLock = new Object(); @VisibleForTesting final Object mDaltonizerModeLock = new Object(); @VisibleForTesting @GuardedBy("mDaltonizerModeLock") int mDaltonizerMode = -1; @VisibleForTesting @GuardedBy("mDaltonizerModeLock") private int mDaltonizerMode = -1; int mDaltonizerLevel = -1; private static final IBinder sFlinger = ServiceManager.getService(SURFACE_FLINGER); Loading Loading @@ -168,12 +175,15 @@ public class DisplayTransformManager { * various types of color blindness. * * @param mode the new Daltonization mode, or -1 to disable * @param level the level of saturation for color correction [-1,10] inclusive. -1 for when * it is not set. */ public void setDaltonizerMode(int mode) { public void setDaltonizerMode(int mode, @IntRange(from = -1, to = 10) int level) { synchronized (mDaltonizerModeLock) { if (mDaltonizerMode != mode) { if (mDaltonizerMode != mode || mDaltonizerLevel != level) { mDaltonizerMode = mode; applyDaltonizerMode(mode); mDaltonizerLevel = level; applyDaltonizerMode(mode, level); } } } Loading Loading @@ -223,10 +233,11 @@ public class DisplayTransformManager { /** * Propagates the provided Daltonization mode to the SurfaceFlinger. */ private static void applyDaltonizerMode(int mode) { private static void applyDaltonizerMode(int mode, int level) { final Parcel data = Parcel.obtain(); data.writeInterfaceToken("android.ui.ISurfaceComposer"); data.writeInt(mode); data.writeInt(level); try { sFlinger.transact(SURFACE_FLINGER_TRANSACTION_DALTONIZER, data, null, 0); } catch (RemoteException ex) { Loading
services/tests/displayservicetests/src/com/android/server/display/color/DisplayTransformManagerTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -161,4 +161,20 @@ public class DisplayTransformManagerTest { .isEqualTo(Integer.toString(testPropertyValue)); } @Test public void daltonizer_defaultValues() { synchronized (mDtm.mDaltonizerModeLock) { assertThat(mDtm.mDaltonizerMode).isEqualTo(-1); assertThat(mDtm.mDaltonizerLevel).isEqualTo(-1); } } @Test public void setDaltonizerMode_newValues_valuesUpdated() { mDtm.setDaltonizerMode(0, 0); synchronized (mDtm.mDaltonizerModeLock) { assertThat(mDtm.mDaltonizerMode).isEqualTo(0); assertThat(mDtm.mDaltonizerLevel).isEqualTo(0); } } }