From 00aabf7d187bc05408199bd687a538b2e68bdc17 Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Thu, 21 Jul 2011 11:35:03 -0700 Subject: Touch exploration state set to clients asynchronously and depended on talking service being enabled. 1. Upon registration of an accessibility client the latter received only the accessiiblity state and waiting for the touch exploration state to be sent by the system in async manner. This led the very first check of touch exploration state is checked a wrong value to be reported. Now a state of the accessibility layer is returned to the client upon registration. 2. Removing the dependency on talking accessibility service to be enabled for getting into touch exploration mode. What if the user wants to use an accessibility service that shows a dialog with the text of the touched view? bug:5051546 Change-Id: Ib377babb3f560929ee73bd3d8b0d277341ba23f7 --- api/current.txt | 3 +- .../AccessibilityServiceInfo.java | 11 +++ core/java/android/provider/Settings.java | 6 +- .../view/accessibility/AccessibilityManager.java | 44 +++++----- .../view/accessibility/AccessibilityNodeInfo.java | 4 +- .../view/accessibility/IAccessibilityManager.aidl | 2 +- .../accessibility/IAccessibilityManagerClient.aidl | 4 +- core/res/res/values/attrs.xml | 2 + .../RecycleAccessibilityEventTest.java | 8 +- .../accessibility/AccessibilityManagerService.java | 95 ++++++++++------------ .../server/AccessibilityManagerServiceTest.java | 26 ++++-- .../android/server/AccessibilityManagerTest.java | 16 ++-- 12 files changed, 121 insertions(+), 100 deletions(-) diff --git a/api/current.txt b/api/current.txt index d821c8e..eb3bb58 100644 --- a/api/current.txt +++ b/api/current.txt @@ -1828,6 +1828,7 @@ package android.accessibilityservice { method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; field public static final int DEFAULT = 1; // 0x1 + field public static final int FEEDBACK_ALL_MASK = -1; // 0xffffffff field public static final int FEEDBACK_AUDIBLE = 4; // 0x4 field public static final int FEEDBACK_GENERIC = 16; // 0x10 field public static final int FEEDBACK_HAPTIC = 2; // 0x2 @@ -16709,7 +16710,7 @@ package android.provider { field public static final java.lang.String SELECTED_INPUT_METHOD_SUBTYPE = "selected_input_method_subtype"; field public static final java.lang.String SETTINGS_CLASSNAME = "settings_classname"; field public static final java.lang.String SYS_PROP_SETTING_VERSION = "sys.settings_secure_version"; - field public static final java.lang.String TOUCH_EXPLORATION_REQUESTED = "touch_exploration_requested"; + field public static final java.lang.String TOUCH_EXPLORATION_ENABLED = "touch_exploration_enabled"; field public static final java.lang.String TTS_DEFAULT_COUNTRY = "tts_default_country"; field public static final java.lang.String TTS_DEFAULT_LANG = "tts_default_lang"; field public static final java.lang.String TTS_DEFAULT_PITCH = "tts_default_pitch"; diff --git a/core/java/android/accessibilityservice/AccessibilityServiceInfo.java b/core/java/android/accessibilityservice/AccessibilityServiceInfo.java index a09607a..41a3eac 100644 --- a/core/java/android/accessibilityservice/AccessibilityServiceInfo.java +++ b/core/java/android/accessibilityservice/AccessibilityServiceInfo.java @@ -75,6 +75,17 @@ public class AccessibilityServiceInfo implements Parcelable { public static final int FEEDBACK_GENERIC = 0x0000010; /** + * Mask for all feedback types. + * + * @see #FEEDBACK_SPOKEN + * @see #FEEDBACK_HAPTIC + * @see #FEEDBACK_AUDIBLE + * @see #FEEDBACK_VISUAL + * @see #FEEDBACK_GENERIC + */ + public static final int FEEDBACK_ALL_MASK = 0xFFFFFFFF; + + /** * If an {@link AccessibilityService} is the default for a given type. * Default service is invoked only if no package specific one exists. In case of * more than one package specific service only the earlier registered is notified. diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index cb87e94..e48c858 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -2691,11 +2691,9 @@ public final class Settings { public static final String ACCESSIBILITY_ENABLED = "accessibility_enabled"; /** - * If touch exploration is requested. Touch exploration is enabled if it is - * requested by this setting, accessibility is enabled and there is at least - * one enabled accessibility serivce that provides spoken feedback. + * If touch exploration is enabled. */ - public static final String TOUCH_EXPLORATION_REQUESTED = "touch_exploration_requested"; + public static final String TOUCH_EXPLORATION_ENABLED = "touch_exploration_enabled"; /** * List of the enabled accessibility providers. diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java index 83c73cb..a80c2a7 100644 --- a/core/java/android/view/accessibility/AccessibilityManager.java +++ b/core/java/android/view/accessibility/AccessibilityManager.java @@ -67,13 +67,17 @@ public final class AccessibilityManager { private static final String LOG_TAG = "AccessibilityManager"; + /** @hide */ + public static final int STATE_FLAG_ACCESSIBILITY_ENABLED = 0x00000001; + + /** @hide */ + public static final int STATE_FLAG_TOUCH_EXPLORATION_ENABLED = 0x00000002; + static final Object sInstanceSync = new Object(); private static AccessibilityManager sInstance; - private static final int DO_SET_ACCESSIBILITY_ENABLED = 10; - - private static final int DO_SET_TOUCH_EXPLORATION_ENABLED = 20; + private static final int DO_SET_STATE = 10; final IAccessibilityManager mService; @@ -100,13 +104,8 @@ public final class AccessibilityManager { } final IAccessibilityManagerClient.Stub mClient = new IAccessibilityManagerClient.Stub() { - public void setEnabled(boolean enabled) { - mHandler.obtainMessage(DO_SET_ACCESSIBILITY_ENABLED, enabled ? 1 : 0, 0).sendToTarget(); - } - - public void setTouchExplorationEnabled(boolean enabled) { - mHandler.obtainMessage(DO_SET_TOUCH_EXPLORATION_ENABLED, - enabled ? 1 : 0, 0).sendToTarget(); + public void setState(int state) { + mHandler.obtainMessage(DO_SET_STATE, state, 0).sendToTarget(); } }; @@ -119,14 +118,8 @@ public final class AccessibilityManager { @Override public void handleMessage(Message message) { switch (message.what) { - case DO_SET_ACCESSIBILITY_ENABLED : - final boolean isAccessibilityEnabled = (message.arg1 == 1); - setAccessibilityState(isAccessibilityEnabled); - return; - case DO_SET_TOUCH_EXPLORATION_ENABLED : - synchronized (mHandler) { - mIsTouchExplorationEnabled = (message.arg1 == 1); - } + case DO_SET_STATE : + setState(message.arg1); return; default : Log.w(LOG_TAG, "Unknown message type: " + message.what); @@ -163,8 +156,8 @@ public final class AccessibilityManager { mService = service; try { - final boolean isEnabled = mService.addClient(mClient); - setAccessibilityState(isEnabled); + final int stateFlags = mService.addClient(mClient); + setState(stateFlags); } catch (RemoteException re) { Log.e(LOG_TAG, "AccessibilityManagerService is dead", re); } @@ -341,6 +334,17 @@ public final class AccessibilityManager { } /** + * Sets the current state. + * + * @param stateFlags The state flags. + */ + private void setState(int stateFlags) { + final boolean accessibilityEnabled = (stateFlags & STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; + setAccessibilityState(accessibilityEnabled); + mIsTouchExplorationEnabled = (stateFlags & STATE_FLAG_TOUCH_EXPLORATION_ENABLED) != 0; + } + + /** * Sets the enabled state. * * @param isEnabled The accessibility state. diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.java b/core/java/android/view/accessibility/AccessibilityNodeInfo.java index 0e04471..6469b35 100644 --- a/core/java/android/view/accessibility/AccessibilityNodeInfo.java +++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.java @@ -294,14 +294,14 @@ public class AccessibilityNodeInfo implements Parcelable { } /** - * Gets the unique id identifying this node's parent. + * Gets the parent. *

* Note: It is a client responsibility to recycle the * received info by calling {@link AccessibilityNodeInfo#recycle()} * to avoid creating of multiple instances. *

* - * @return The node's patent id. + * @return The parent. */ public AccessibilityNodeInfo getParent() { enforceSealed(); diff --git a/core/java/android/view/accessibility/IAccessibilityManager.aidl b/core/java/android/view/accessibility/IAccessibilityManager.aidl index b14f02a..c621ff6 100644 --- a/core/java/android/view/accessibility/IAccessibilityManager.aidl +++ b/core/java/android/view/accessibility/IAccessibilityManager.aidl @@ -34,7 +34,7 @@ import android.view.IWindow; */ interface IAccessibilityManager { - boolean addClient(IAccessibilityManagerClient client); + int addClient(IAccessibilityManagerClient client); boolean sendAccessibilityEvent(in AccessibilityEvent uiEvent); diff --git a/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl b/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl index 4e69692..5e7e813 100644 --- a/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl +++ b/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl @@ -24,7 +24,5 @@ package android.view.accessibility; */ oneway interface IAccessibilityManagerClient { - void setEnabled(boolean enabled); - - void setTouchExplorationEnabled(boolean enabled); + void setState(int stateFlags); } diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 082284a..e307c17 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2281,6 +2281,8 @@ + +