OSDN Git Service

DO NOT MERGE Wear Fwk: Disable Animations for A11y
authorVinod Krishnan <vinodkrishnan@google.com>
Wed, 26 Oct 2016 22:12:25 +0000 (15:12 -0700)
committerVinod Krishnan <vinodkrishnan@google.com>
Fri, 28 Oct 2016 23:56:25 +0000 (16:56 -0700)
- When Accessibility is turned on, Android Wear devices become unusable.
Add an option to disable animations, will be disabled in an overlay.

Bug: 24985771

Change-Id: If5fc44705d56579b305abd48a0d820f306b9be10

core/java/android/provider/Settings.java
packages/SettingsProvider/res/values/defaults.xml
packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
services/core/java/com/android/server/wm/WindowManagerService.java

index 3f1789b..ee2596b 100755 (executable)
@@ -5164,6 +5164,16 @@ public final class Settings {
                 "accessibility_soft_keyboard_mode";
 
         /**
+         * Should we disable all animations when accessibility is turned on. On low-power devices
+         * like Android Wear, the performance makes the device unusable. Turning off animations
+         * is a partial fix.
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_DISABLE_ANIMATIONS =
+                "accessibility_disable_animations";
+
+        /**
          * Default soft keyboard behavior.
          *
          * @hide
@@ -6441,6 +6451,7 @@ public final class Settings {
             ACCESSIBILITY_CAPTIONING_TYPEFACE,
             ACCESSIBILITY_CAPTIONING_FONT_SCALE,
             ACCESSIBILITY_CAPTIONING_WINDOW_COLOR,
+            ACCESSIBILITY_DISABLE_ANIMATIONS,
             TTS_USE_DEFAULTS,
             TTS_DEFAULT_RATE,
             TTS_DEFAULT_PITCH,
index a536874..c459571 100644 (file)
 
     <!-- Default setting for ability to add users from the lock screen -->
     <bool name="def_add_users_from_lockscreen">false</bool>
+
+    <!-- Default setting for disable animations when accessibility is turned on. -->
+    <bool name="def_accessibility_disable_animations">false</bool>
 </resources>
index d55bb4f..07bcce6 100644 (file)
@@ -2484,6 +2484,9 @@ class DatabaseHelper extends SQLiteOpenHelper {
             loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
                     R.string.def_accessibility_screen_reader_url);
 
+            loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISABLE_ANIMATIONS,
+                    R.bool.def_accessibility_disable_animations);
+
             if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) {
                 loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1");
             } else {
index ca2610a..5dad9c4 100644 (file)
@@ -350,11 +350,13 @@ public class WindowManagerService extends IWindowManager.Stub
 
     // Enums for animation scale update types.
     @Retention(RetentionPolicy.SOURCE)
-    @IntDef({WINDOW_ANIMATION_SCALE, TRANSITION_ANIMATION_SCALE, ANIMATION_DURATION_SCALE})
+    @IntDef({WINDOW_ANIMATION_SCALE, TRANSITION_ANIMATION_SCALE, ANIMATION_DURATION_SCALE,
+            ACCESSIBILITY_CHANGED})
     private @interface UpdateAnimationScaleMode {};
     private static final int WINDOW_ANIMATION_SCALE = 0;
     private static final int TRANSITION_ANIMATION_SCALE = 1;
     private static final int ANIMATION_DURATION_SCALE = 2;
+    private static final int ACCESSIBILITY_CHANGED = 3;
 
     final private KeyguardDisableHandler mKeyguardDisableHandler;
 
@@ -669,6 +671,8 @@ public class WindowManagerService extends IWindowManager.Stub
                 Settings.Global.getUriFor(Settings.Global.TRANSITION_ANIMATION_SCALE);
         private final Uri mAnimationDurationScaleUri =
                 Settings.Global.getUriFor(Settings.Global.ANIMATOR_DURATION_SCALE);
+        private final Uri mAccessibilityEnabledUri =
+                Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_ENABLED);
 
         public SettingsObserver() {
             super(new Handler());
@@ -681,6 +685,8 @@ public class WindowManagerService extends IWindowManager.Stub
                     UserHandle.USER_ALL);
             resolver.registerContentObserver(mAnimationDurationScaleUri, false, this,
                     UserHandle.USER_ALL);
+            resolver.registerContentObserver(mAccessibilityEnabledUri, false, this,
+                    UserHandle.USER_ALL);
         }
 
         @Override
@@ -700,6 +706,9 @@ public class WindowManagerService extends IWindowManager.Stub
                     mode = TRANSITION_ANIMATION_SCALE;
                 } else if (mAnimationDurationScaleUri.equals(uri)) {
                     mode = ANIMATION_DURATION_SCALE;
+                } else if (mAccessibilityEnabledUri.equals(uri)) {
+                    // Change all of them.
+                    mode = ACCESSIBILITY_CHANGED;
                 } else {
                     // Ignoring unrecognized content changes
                     return;
@@ -998,13 +1007,12 @@ public class WindowManagerService extends IWindowManager.Stub
             public void onLowPowerModeChanged(boolean enabled) {
                 synchronized (mWindowMap) {
                     if (mAnimationsDisabled != enabled && !mAllowAnimationsInLowPowerMode) {
-                        mAnimationsDisabled = enabled;
-                        dispatchNewAnimatorScaleLocked(null);
+                        setShouldAnimationsDisabled(enabled);
                     }
                 }
             }
         });
-        mAnimationsDisabled = mPowerManagerInternal.getLowPowerModeEnabled();
+        setShouldAnimationsDisabled(mPowerManagerInternal.getLowPowerModeEnabled());
         mScreenFrozenLock = mPowerManager.newWakeLock(
                 PowerManager.PARTIAL_WAKE_LOCK, "SCREEN_FROZEN");
         mScreenFrozenLock.setReferenceCounted(false);
@@ -1087,6 +1095,18 @@ public class WindowManagerService extends IWindowManager.Stub
         }
     }
 
+    private void setShouldAnimationsDisabled(boolean isLowPowerEnabled) {
+        boolean accessibilityEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
+        boolean disableAnimationsWhenAccessibility = Settings.Secure.getInt(
+                mContext.getContentResolver(),
+                Settings.Secure.ACCESSIBILITY_DISABLE_ANIMATIONS, 0) == 1;
+
+        mAnimationsDisabled = isLowPowerEnabled ||
+                (accessibilityEnabled && disableAnimationsWhenAccessibility);
+        dispatchNewAnimatorScaleLocked(null);
+    }
+
     private void placeWindowAfter(WindowState pos, WindowState window) {
         final WindowList windows = pos.getWindowList();
         final int i = windows.indexOf(pos);
@@ -8590,6 +8610,11 @@ public class WindowManagerService extends IWindowManager.Stub
                             dispatchNewAnimatorScaleLocked(null);
                             break;
                         }
+                        case ACCESSIBILITY_CHANGED: {
+                            setShouldAnimationsDisabled(
+                                    mPowerManagerInternal.getLowPowerModeEnabled());
+                        }
+                        break;
                     }
                     break;
                 }