From 890202bde486ca47ceb5daf4955038352384558e Mon Sep 17 00:00:00 2001 From: Phil Weaver Date: Thu, 14 Jul 2016 15:11:09 -0700 Subject: [PATCH] Suppress exceptions for corner-case a11y events. Apps are told to query AccessibilityManager#isEnabled before calling sendAccessibilityEvent. If accessibility is disabled between the two calls, an app can crash. We can guarantee that this won't happen on a process's main thread, but guaranteeing it for all threads is messier. Rather than add the complexity of tracking the state for all threads, only log an error in the corner case that an accessibility event is requested on a thread that doesn't have the process's main looper. Bug: 28985452 Change-Id: I8369deefd83b0a6b04936ddfce55c53147756f1f --- .../android/view/accessibility/AccessibilityManager.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java index 81ec3306c4c7..2dfa8cdd3db9 100644 --- a/core/java/android/view/accessibility/AccessibilityManager.java +++ b/core/java/android/view/accessibility/AccessibilityManager.java @@ -305,7 +305,18 @@ public final class AccessibilityManager { return; } if (!mIsEnabled) { - throw new IllegalStateException("Accessibility off. Did you forget to check that?"); + Looper myLooper = Looper.myLooper(); + if (myLooper == Looper.getMainLooper()) { + throw new IllegalStateException( + "Accessibility off. Did you forget to check that?"); + } else { + // If we're not running on the thread with the main looper, it's possible for + // the state of accessibility to change between checking isEnabled and + // calling this method. So just log the error rather than throwing the + // exception. + Log.e(LOG_TAG, "AccessibilityEvent sent with accessibility disabled"); + return; + } } userId = mUserId; } -- 2.11.0