From 0db51114286d322e1f41f36375ee4374bc38494d Mon Sep 17 00:00:00 2001 From: Jason Chang Date: Thu, 5 Nov 2020 18:29:38 +0800 Subject: [PATCH] Fix screen should not automatically leave one-handed mode when the TalkBack user is exploring Use AccessibilityStateChangeListener to listening Accessibility state changes then align One-Handed timeout with A11y's timeout settings. Bug: 170360730 Test: manual Test: atest WMShellUnitTests Change-Id: Ie0debd157a170388e10ce7508316111697922f78 --- .../shell/onehanded/OneHandedController.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java index e8c6cb74af0c0..86cfa568c190b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java @@ -32,6 +32,7 @@ import android.os.ServiceManager; import android.os.SystemProperties; import android.provider.Settings; import android.util.Slog; +import android.view.accessibility.AccessibilityManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -74,6 +75,7 @@ public class OneHandedController implements OneHanded { private final Handler mMainHandler = new Handler(Looper.getMainLooper()); private OneHandedDisplayAreaOrganizer mDisplayAreaOrganizer; + private final AccessibilityManager mAccessibilityManager; /** * Handle rotation based on OnDisplayChangingListener callback @@ -163,6 +165,26 @@ public class OneHandedController implements OneHanded { } }; + private AccessibilityManager.AccessibilityStateChangeListener + mAccessibilityStateChangeListener = + new AccessibilityManager.AccessibilityStateChangeListener() { + @Override + public void onAccessibilityStateChanged(boolean enabled) { + if (enabled) { + final int mOneHandedTimeout = OneHandedSettingsUtil + .getSettingsOneHandedModeTimeout(mContext.getContentResolver()); + final int timeout = mAccessibilityManager + .getRecommendedTimeoutMillis(mOneHandedTimeout * 1000 + /* align with A11y timeout millis */, + AccessibilityManager.FLAG_CONTENT_CONTROLS); + mTimeoutHandler.setTimeout(timeout / 1000); + } else { + mTimeoutHandler.setTimeout(OneHandedSettingsUtil + .getSettingsOneHandedModeTimeout(mContext.getContentResolver())); + } + } + }; + /** * Creates {@link OneHandedController}, returns {@code null} if the feature is not supported. */ @@ -238,6 +260,11 @@ public class OneHandedController implements OneHanded { stopOneHanded(OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_APP_TAPS_OUT); } }); + + mAccessibilityManager = (AccessibilityManager) + context.getSystemService(Context.ACCESSIBILITY_SERVICE); + mAccessibilityManager.addAccessibilityStateChangeListener( + mAccessibilityStateChangeListener); } /**