Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eeee4d2c authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Final polish of the interrogation feature.

1. Added a new event type for notifying client accessibilitiy
   services for changes in the layout. The event is fired at
   most once for a given time frame and is delivered to clients
   only if it originates from the window that can be interrogated.

2. Exposed the findByText functionality in AccessibilityNodeInfo.
   This is very useful for an accessibility service since it allows
   searching for something the user knows is on the screen thus
   avoiding touch exploring the content. Touch exploring is
   excellent for learning the apps but knowing them search is
   much faster.

3. Fixed a bug causing an accessibiliby service not to receive
   the event source in case of more than one service is registered
   and one of them does not have paermission to interrogate the window.
   The same event was dispatched to multiple services but if one
   of them does not have interrogation permission the event is
   modified to remove the source causing subsequent serivices not
   to get the later.

4. Moved the getSource setSource methods to AccessibilityRecord
   instead in AccessibilityEvent.

5. Hiden some protected members in AccessibilityRecod which should
   not be made public since getters exist.

6. Added the View absolute coordinates in the screen to AccessibilityNodeInfo.
   This is needed for fast computation of relative positions of
   views from accessibility - common use case for the later.

7. Fixed a couple of marshalling bugs.

8. Added a test for the object contract of AccessibilityNodeInfo.

Change-Id: Id9dc50c33aff441e4c93d25ea316c9bbc4bd7a35
parent eaf7ce60
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -22239,7 +22239,6 @@ package android.view.accessibility {
  }
  public class AccessibilityRecord {
    ctor protected AccessibilityRecord();
    method public int getAddedCount();
    method public java.lang.CharSequence getBeforeText();
    method public java.lang.CharSequence getClassName();
@@ -22269,17 +22268,6 @@ package android.view.accessibility {
    method public void setParcelableData(android.os.Parcelable);
    method public void setPassword(boolean);
    method public void setRemovedCount(int);
    field protected int mAddedCount;
    field protected java.lang.CharSequence mBeforeText;
    field protected int mBooleanProperties;
    field protected java.lang.CharSequence mClassName;
    field protected java.lang.CharSequence mContentDescription;
    field protected int mCurrentItemIndex;
    field protected int mFromIndex;
    field protected int mItemCount;
    field protected android.os.Parcelable mParcelableData;
    field protected int mRemovedCount;
    field protected final java.util.List mText;
  }
}
+10 −18
Original line number Diff line number Diff line
@@ -22719,13 +22719,11 @@ package android.view.accessibility {
    method public void appendRecord(android.view.accessibility.AccessibilityRecord);
    method public int describeContents();
    method public static java.lang.String eventTypeToString(int);
    method public int getAccessibilityWindowId();
    method public long getEventTime();
    method public int getEventType();
    method public java.lang.CharSequence getPackageName();
    method public android.view.accessibility.AccessibilityRecord getRecord(int);
    method public int getRecordCount();
    method public android.view.accessibility.AccessibilityNodeInfo getSource();
    method public void initFromParcel(android.os.Parcel);
    method public static android.view.accessibility.AccessibilityEvent obtain(int);
    method public static android.view.accessibility.AccessibilityEvent obtain(android.view.accessibility.AccessibilityEvent);
@@ -22733,7 +22731,6 @@ package android.view.accessibility {
    method public void setEventTime(long);
    method public void setEventType(int);
    method public void setPackageName(java.lang.CharSequence);
    method public void setSource(android.view.View);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final int INVALID_POSITION = -1; // 0xffffffff
@@ -22749,6 +22746,7 @@ package android.view.accessibility {
    field public static final int TYPE_VIEW_LONG_CLICKED = 2; // 0x2
    field public static final int TYPE_VIEW_SELECTED = 4; // 0x4
    field public static final int TYPE_VIEW_TEXT_CHANGED = 16; // 0x10
    field public static final int TYPE_WINDOW_CONTENT_CHANGED = 2048; // 0x800
    field public static final int TYPE_WINDOW_STATE_CHANGED = 32; // 0x20
  }
@@ -22776,9 +22774,10 @@ package android.view.accessibility {
    method public void addAction(int);
    method public void addChild(android.view.View);
    method public int describeContents();
    method public int getAccessibilityWindowId();
    method public java.util.List<android.view.accessibility.AccessibilityNodeInfo> findAccessibilityNodeInfosByText(java.lang.String);
    method public int getActions();
    method public void getBounds(android.graphics.Rect);
    method public void getBoundsInParent(android.graphics.Rect);
    method public void getBoundsInScreen(android.graphics.Rect);
    method public android.view.accessibility.AccessibilityNodeInfo getChild(int);
    method public int getChildCount();
    method public java.lang.CharSequence getClassName();
@@ -22786,6 +22785,7 @@ package android.view.accessibility {
    method public java.lang.CharSequence getPackageName();
    method public android.view.accessibility.AccessibilityNodeInfo getParent();
    method public java.lang.CharSequence getText();
    method public int getWindowId();
    method public boolean isCheckable();
    method public boolean isChecked();
    method public boolean isClickable();
@@ -22799,7 +22799,8 @@ package android.view.accessibility {
    method public static android.view.accessibility.AccessibilityNodeInfo obtain();
    method public boolean performAction(int);
    method public void recycle();
    method public void setBounds(android.graphics.Rect);
    method public void setBoundsInParent(android.graphics.Rect);
    method public void setBoundsInScreen(android.graphics.Rect);
    method public void setCheckable(boolean);
    method public void setChecked(boolean);
    method public void setClassName(java.lang.CharSequence);
@@ -22824,7 +22825,6 @@ package android.view.accessibility {
  }
  public class AccessibilityRecord {
    ctor protected AccessibilityRecord();
    method public int getAddedCount();
    method public java.lang.CharSequence getBeforeText();
    method public java.lang.CharSequence getClassName();
@@ -22834,7 +22834,9 @@ package android.view.accessibility {
    method public int getItemCount();
    method public android.os.Parcelable getParcelableData();
    method public int getRemovedCount();
    method public android.view.accessibility.AccessibilityNodeInfo getSource();
    method public java.util.List<java.lang.CharSequence> getText();
    method public int getWindowId();
    method public boolean isChecked();
    method public boolean isEnabled();
    method public boolean isFullScreen();
@@ -22855,17 +22857,7 @@ package android.view.accessibility {
    method public void setParcelableData(android.os.Parcelable);
    method public void setPassword(boolean);
    method public void setRemovedCount(int);
    field protected int mAddedCount;
    field protected java.lang.CharSequence mBeforeText;
    field protected int mBooleanProperties;
    field protected java.lang.CharSequence mClassName;
    field protected java.lang.CharSequence mContentDescription;
    field protected int mCurrentItemIndex;
    field protected int mFromIndex;
    field protected int mItemCount;
    field protected android.os.Parcelable mParcelableData;
    field protected int mRemovedCount;
    field protected final java.util.List mText;
    method public void setSource(android.view.View);
  }
}
+2 −2
Original line number Diff line number Diff line
@@ -190,9 +190,9 @@ public abstract class AccessibilityService extends Service {
     *            <li>
     *              Register for all event types with no notification timeout and keep track
     *              for the active window by calling
     *              {@link AccessibilityEvent#getAccessibilityWindowId()} of the last received
     *              {@link AccessibilityEvent#getWindowId()} of the last received
     *              event and compare this with the
     *              {@link AccessibilityNodeInfo#getAccessibilityWindowId()} before calling
     *              {@link AccessibilityNodeInfo#getWindowId()} before calling
     *              retrieval methods on the latter.
     *            </li>
     *            <li>
+29 −4
Original line number Diff line number Diff line
@@ -47,7 +47,9 @@ interface IAccessibilityServiceConnection {

    /**
     * Finds {@link AccessibilityNodeInfo}s by View text. The match is case
     * insensitive containment.
     * insensitive containment. The search is performed in the window whose
     * id is specified and starts from the View whose accessibility id is
     * specified.
     * <p>
     *   <strong>
     *     It is a client responsibility to recycle the received infos by
@@ -57,12 +59,35 @@ interface IAccessibilityServiceConnection {
     * </p>
     *
     * @param text The searched text.
     * @param accessibilityId The id of the view from which to start searching.
     *        Use {@link android.view.View#NO_ID} to start from the root.
     * @return A list of node info.
     */
    List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewText(String text);
    List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewText(String text,
        int accessibilityWindowId, int accessibilityViewId);

    /**
     * Finds an {@link AccessibilityNodeInfo} by View id.
     * Finds {@link AccessibilityNodeInfo}s by View text. The match is case
     * insensitive containment. The search is performed in the currently
     * active window and start from the root View in the window.
     * <p>
     *   <strong>
     *     It is a client responsibility to recycle the received infos by
     *     calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
     *     of multiple instances.
     *   </strong>
     * </p>
     *
     * @param text The searched text.
     * @param accessibilityId The id of the view from which to start searching.
     *        Use {@link android.view.View#NO_ID} to start from the root.
     * @return A list of node info.
     */
    List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewTextInActiveWindow(String text);

    /**
     * Finds an {@link AccessibilityNodeInfo} by View id. The search is performed
     * in the currently active window and start from the root View in the window.
     * <p>
     *   <strong>
     *     It is a client responsibility to recycle the received info by
@@ -74,7 +99,7 @@ interface IAccessibilityServiceConnection {
     * @param id The id of the node.
     * @return The node info.
     */
    AccessibilityNodeInfo findAccessibilityNodeInfoByViewId(int viewId);
    AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(int viewId);

    /**
     * Performs an accessibility action on an {@link AccessibilityNodeInfo}.
+8 −2
Original line number Diff line number Diff line
@@ -3704,7 +3704,8 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
     * The base implementation sets:
     * <ul>
     *   <li>{@link AccessibilityNodeInfo#setParent(View)},</li>
     *   <li>{@link AccessibilityNodeInfo#setBounds(Rect)},</li>
     *   <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li>
     *   <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li>
     *   <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li>
     *   <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li>
     *   <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li>
@@ -3724,7 +3725,12 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
        Rect bounds = mAttachInfo.mTmpInvalRect;
        getDrawingRect(bounds);
        info.setBounds(bounds);
        info.setBoundsInParent(bounds);

        int[] locationOnScreen = mAttachInfo.mInvalidateChildLocation;
        getLocationOnScreen(locationOnScreen);
        bounds.offset(locationOnScreen[0], locationOnScreen[1]);
        info.setBoundsInScreen(bounds);

        ViewParent parent = getParent();
        if (parent instanceof View) {
Loading