OSDN Git Service

Allow color matrix to be controlled by secure setting
authorJason Monk <jmonk@google.com>
Tue, 8 Dec 2015 01:05:08 +0000 (20:05 -0500)
committerJason Monk <jmonk@google.com>
Tue, 8 Dec 2015 12:27:15 +0000 (07:27 -0500)
Change-Id: Ia5518ad79fae502e814034edd7ae8d7a57b3eaeb

core/java/android/provider/Settings.java
services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
services/accessibility/java/com/android/server/accessibility/DisplayAdjustmentUtils.java

index dad3c67..7c24e9c 100644 (file)
@@ -4912,6 +4912,15 @@ public final class Settings {
                 "accessibility_display_daltonizer";
 
         /**
+         * Float list that specifies the color matrix to apply to
+         * the display. Valid values are defined in AccessibilityManager.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISPLAY_COLOR_MATRIX =
+                "accessibility_display_color_matrix";
+
+        /**
          * Setting that specifies whether automatic click when the mouse pointer stops moving is
          * enabled.
          *
index 11fdbb5..8cf25b3 100644 (file)
@@ -3987,6 +3987,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
         private final Uri mDisplayDaltonizerUri = Settings.Secure.getUriFor(
                 Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER);
 
+        private final Uri mDisplayColorMatrixUri = Settings.Secure.getUriFor(
+                Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX);
+
         private final Uri mHighTextContrastUri = Settings.Secure.getUriFor(
                 Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED);
 
@@ -4017,6 +4020,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
             contentResolver.registerContentObserver(
                     mDisplayDaltonizerUri, false, this, UserHandle.USER_ALL);
             contentResolver.registerContentObserver(
+                    mDisplayColorMatrixUri, false, this, UserHandle.USER_ALL);
+            contentResolver.registerContentObserver(
                     mHighTextContrastUri, false, this, UserHandle.USER_ALL);
         }
 
@@ -4066,6 +4071,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                     if (readDisplayColorAdjustmentSettingsLocked(userState)) {
                         updateDisplayColorAdjustmentSettingsLocked(userState);
                     }
+                } else if (mDisplayColorMatrixUri.equals(uri)) {
+                    updateDisplayColorAdjustmentSettingsLocked(userState);
                 } else if (mHighTextContrastUri.equals(uri)) {
                     if (readHighTextContrastEnabledSettingLocked(userState)) {
                         onUserStateChangedLocked(userState);
index d0b5898..1a7de25 100644 (file)
@@ -107,9 +107,24 @@ class DisplayAdjustmentUtils {
             setDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED);
         }
 
+        String matrix = Settings.Secure.getStringForUser(cr,
+                Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, userId);
+        if (matrix != null) {
+            colorMatrix = multiply(colorMatrix, getMatrix(matrix));
+        }
+
         setColorTransform(colorMatrix);
     }
 
+    private static float[] getMatrix(String matrix) {
+        String[] strValues = matrix.split(",");
+        float[] values = new float[strValues.length];
+        for (int i = 0; i < values.length; i++) {
+            values[i] = Float.parseFloat(strValues[i]);
+        }
+        return values;
+    }
+
     private static float[] multiply(float[] matrix, float[] other) {
         if (matrix == null) {
             return other;