diff options
Diffstat (limited to 'core/java/android/view')
| -rw-r--r-- | core/java/android/view/InputEventConsistencyVerifier.java | 19 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 44 | ||||
| -rw-r--r-- | core/java/android/view/ViewConfiguration.java | 22 | ||||
| -rw-r--r-- | core/java/android/view/ViewGroup.java | 54 | ||||
| -rw-r--r-- | core/java/android/view/ViewParent.java | 19 | ||||
| -rw-r--r-- | core/java/android/view/ViewRoot.java | 8 | ||||
| -rw-r--r-- | core/java/android/view/accessibility/AccessibilityEvent.java | 470 | ||||
| -rw-r--r-- | core/java/android/view/accessibility/AccessibilityManager.java | 36 | ||||
| -rw-r--r-- | core/java/android/view/accessibility/AccessibilityRecord.java | 415 | ||||
| -rw-r--r-- | core/java/android/view/accessibility/IAccessibilityManager.aidl | 2 |
10 files changed, 359 insertions, 730 deletions
diff --git a/core/java/android/view/InputEventConsistencyVerifier.java b/core/java/android/view/InputEventConsistencyVerifier.java index e14b97558e49..b5ca2c2a8c1c 100644 --- a/core/java/android/view/InputEventConsistencyVerifier.java +++ b/core/java/android/view/InputEventConsistencyVerifier.java @@ -30,6 +30,7 @@ import android.util.Log; * @hide */ public final class InputEventConsistencyVerifier { + private static final String TAG = "InputEventConsistencyVerifier"; private static final boolean IS_ENG_BUILD = "eng".equals(Build.TYPE); // The number of recent events to log when a problem is detected. @@ -43,11 +44,6 @@ public final class InputEventConsistencyVerifier { // Consistency verifier flags. private final int mFlags; - // Tag for logging which a client can set to help distinguish the output - // from different verifiers since several can be active at the same time. - // If not provided defaults to the simple class name. - private final String mLogTag; - // The most recently checked event and the nesting level at which it was checked. // This is only set when the verifier is called from a nesting level greater than 0 // so that the verifier can detect when it has been asked to verify the same event twice. @@ -107,19 +103,8 @@ public final class InputEventConsistencyVerifier { * @param flags Flags to the verifier, or 0 if none. */ public InputEventConsistencyVerifier(Object caller, int flags) { - this(caller, flags, InputEventConsistencyVerifier.class.getSimpleName()); - } - - /** - * Creates an input consistency verifier. - * @param caller The object to which the verifier is attached. - * @param flags Flags to the verifier, or 0 if none. - * @param logTag Tag for logging. If null defaults to the short class name. - */ - public InputEventConsistencyVerifier(Object caller, int flags, String logTag) { this.mCaller = caller; this.mFlags = flags; - this.mLogTag = (logTag != null) ? logTag : "InputEventConsistencyVerifier"; } /** @@ -611,7 +596,7 @@ public final class InputEventConsistencyVerifier { } } - Log.d(mLogTag, mViolationMessage.toString()); + Log.d(TAG, mViolationMessage.toString()); mViolationMessage.setLength(0); tainted = true; } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 4bc7f39a584c..4a6289285d41 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -3455,10 +3455,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility if (!isShown()) { return; } - - // Populate these here since they are related to the View that - // sends the event and should not be modified while dispatching - // to descendants. event.setClassName(getClass().getName()); event.setPackageName(getContext().getPackageName()); event.setEnabled(isEnabled()); @@ -3474,38 +3470,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility dispatchPopulateAccessibilityEvent(event); - // In the beginning we called #isShown(), so we know that getParent() is not null. - getParent().requestSendAccessibilityEvent(this, event); + AccessibilityManager.getInstance(mContext).sendAccessibilityEvent(event); } /** - * Dispatches an {@link AccessibilityEvent} to the {@link View} children to be populated. - * This method first calls {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} - * on this view allowing it to populate information about itself and also decide - * whether to intercept the population i.e. to prevent its children from populating - * the event. + * Dispatches an {@link AccessibilityEvent} to the {@link View} children + * to be populated. * * @param event The event. * * @return True if the event population was completed. */ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { - onPopulateAccessibilityEvent(event); return false; } /** - * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} - * giving a chance to this View to populate the accessibility evnet with - * information about itself. - * - * @param event The accessibility event which to populate. - */ - public void onPopulateAccessibilityEvent(AccessibilityEvent event) { - - } - - /** * Gets the {@link View} description. It briefly describes the view and is * primarily used for accessibility support. Set this property to enable * better accessibility support for your application. This is especially @@ -5410,6 +5390,20 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility * to receive the hover event. */ public boolean onHoverEvent(MotionEvent event) { + final int viewFlags = mViewFlags; + + if (((viewFlags & CLICKABLE) != CLICKABLE && + (viewFlags & LONG_CLICKABLE) != LONG_CLICKABLE)) { + // Nothing to do if the view is not clickable. + return false; + } + + if ((viewFlags & ENABLED_MASK) == DISABLED) { + // A disabled view that is clickable still consumes the hover events, it just doesn't + // respond to them. + return true; + } + switch (event.getAction()) { case MotionEvent.ACTION_HOVER_ENTER: setHovered(true); @@ -5420,7 +5414,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility break; } - return false; + return true; } /** @@ -5442,13 +5436,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility if ((mPrivateFlags & HOVERED) == 0) { mPrivateFlags |= HOVERED; refreshDrawableState(); - sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); } } else { if ((mPrivateFlags & HOVERED) != 0) { mPrivateFlags &= ~HOVERED; refreshDrawableState(); - sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); } } } diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index 94eb429dad64..739758c8c79f 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -19,6 +19,7 @@ package android.view; import android.app.AppGlobals; import android.content.Context; import android.content.res.Configuration; +import android.os.Bundle; import android.provider.Settings; import android.util.DisplayMetrics; import android.util.SparseArray; @@ -155,13 +156,6 @@ public class ViewConfiguration { private static final int MAXIMUM_FLING_VELOCITY = 8000; /** - * Distance between a touch up event denoting the end of a touch exploration - * gesture and the touch up event of a subsequent tap for the latter tap to be - * considered as a tap i.e. to perform a click. - */ - private static final int TOUCH_EXPLORATION_TAP_SLOP = 80; - - /** * The maximum size of View's drawing cache, expressed in bytes. This size * should be at least equal to the size of the screen in ARGB888 format. */ @@ -191,7 +185,6 @@ public class ViewConfiguration { private final int mTouchSlop; private final int mPagingTouchSlop; private final int mDoubleTapSlop; - private final int mScaledTouchExplorationTapSlop; private final int mWindowTouchSlop; private final int mMaximumDrawingCacheSize; private final int mOverscrollDistance; @@ -213,7 +206,6 @@ public class ViewConfiguration { mTouchSlop = TOUCH_SLOP; mPagingTouchSlop = PAGING_TOUCH_SLOP; mDoubleTapSlop = DOUBLE_TAP_SLOP; - mScaledTouchExplorationTapSlop = TOUCH_EXPLORATION_TAP_SLOP; mWindowTouchSlop = WINDOW_TOUCH_SLOP; //noinspection deprecation mMaximumDrawingCacheSize = MAXIMUM_DRAWING_CACHE_SIZE; @@ -250,7 +242,6 @@ public class ViewConfiguration { mTouchSlop = (int) (sizeAndDensity * TOUCH_SLOP + 0.5f); mPagingTouchSlop = (int) (sizeAndDensity * PAGING_TOUCH_SLOP + 0.5f); mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f); - mScaledTouchExplorationTapSlop = (int) (density * TOUCH_EXPLORATION_TAP_SLOP + 0.5f); mWindowTouchSlop = (int) (sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f); // Size of the screen in bytes, in ARGB_8888 format @@ -453,17 +444,6 @@ public class ViewConfiguration { } /** - * @return Distance between a touch up event denoting the end of a touch exploration - * gesture and the touch up event of a subsequent tap for the latter tap to be - * considered as a tap i.e. to perform a click. - * - * @hide - */ - public int getScaledTouchExplorationTapSlop() { - return mScaledTouchExplorationTapSlop; - } - - /** * @return Distance a touch must be outside the bounds of a window for it * to be counted as outside the window for purposes of dismissing that * window. diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index 7b404b45f729..08daa280b10a 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -586,35 +586,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager /** * {@inheritDoc} */ - public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { - ViewParent parent = getParent(); - if (parent == null) { - return false; - } - final boolean propagate = onRequestSendAccessibilityEvent(child, event); - if (!propagate) { - return false; - } - return parent.requestSendAccessibilityEvent(this, event); - } - - /** - * Called when a child has requested sending an {@link AccessibilityEvent} and - * gives an opportunity to its parent to augment the event. - * - * @param child The child which requests sending the event. - * @param event The event to be sent. - * @return True if the event should be sent. - * - * @see #requestSendAccessibilityEvent(View, AccessibilityEvent) - */ - public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { - return true; - } - - /** - * {@inheritDoc} - */ @Override public boolean dispatchUnhandledMove(View focused, int direction) { return mFocused != null && @@ -1245,8 +1216,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager eventNoHistory.setAction(MotionEvent.ACTION_HOVER_EXIT); handled |= dispatchTransformedGenericPointerEvent(eventNoHistory, mHoveredChild); eventNoHistory.setAction(action); + mHoveredChild = null; - } else { + } else if (action == MotionEvent.ACTION_HOVER_MOVE) { // Pointer is still within the child. handled |= dispatchTransformedGenericPointerEvent(event, mHoveredChild); } @@ -1306,17 +1278,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager return handled; } - @Override - public boolean onHoverEvent(MotionEvent event) { - // Handle the event only if leaf. This guarantees that - // the leafs (or any custom class that returns true from - // this method) will get a change to process the hover. - if (getChildCount() == 0) { - return super.onHoverEvent(event); - } - return false; - } - private static MotionEvent obtainMotionEventNoHistoryOrSelf(MotionEvent event) { if (event.getHistorySize() == 0) { return event; @@ -2130,16 +2091,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { - // We first get a chance to populate the event. - onPopulateAccessibilityEvent(event); - // Let our children have a shot in populating the event. + boolean populated = false; for (int i = 0, count = getChildCount(); i < count; i++) { - boolean handled = getChildAt(i).dispatchPopulateAccessibilityEvent(event); - if (handled) { - return handled; - } + populated |= getChildAt(i).dispatchPopulateAccessibilityEvent(event); } - return false; + return populated; } /** diff --git a/core/java/android/view/ViewParent.java b/core/java/android/view/ViewParent.java index 655df391ed4f..d7d4c3f02d0d 100644 --- a/core/java/android/view/ViewParent.java +++ b/core/java/android/view/ViewParent.java @@ -17,7 +17,6 @@ package android.view; import android.graphics.Rect; -import android.view.accessibility.AccessibilityEvent; /** * Defines the responsibilities for a class that will be a parent of a View. @@ -223,22 +222,4 @@ public interface ViewParent { */ public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate); - - /** - * Called by a child to request from its parent to send an {@link AccessibilityEvent}. - * The child has already populated a record for itself in the event and is delegating - * to its parent to send the event. The parent can optionally add a record for itself. - * <p> - * Note: An accessibility event is fired by an individual view which populates the - * event with a record for its state and requests from its parent to perform - * the sending. The parent can optionally add a record for itself before - * dispatching the request to its parent. A parent can also choose not to - * respect the request for sending the event. The accessibility event is sent - * by the topmost view in the view tree. - * - * @param child The child which requests sending the event. - * @param event The event to be sent. - * @return True if the event was sent. - */ - public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event); } diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java index f02dabac340d..4104b070f4a1 100644 --- a/core/java/android/view/ViewRoot.java +++ b/core/java/android/view/ViewRoot.java @@ -3530,14 +3530,6 @@ public final class ViewRoot extends Handler implements ViewParent, public void childDrawableStateChanged(View child) { } - public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { - if (mView == null) { - return false; - } - AccessibilityManager.getInstance(child.mContext).sendAccessibilityEvent(event); - return true; - } - void checkThread() { if (mThread != Thread.currentThread()) { throw new CalledFromWrongThreadException( diff --git a/core/java/android/view/accessibility/AccessibilityEvent.java b/core/java/android/view/accessibility/AccessibilityEvent.java index 11c93929b23e..9af19b8796a9 100644 --- a/core/java/android/view/accessibility/AccessibilityEvent.java +++ b/core/java/android/view/accessibility/AccessibilityEvent.java @@ -21,26 +21,13 @@ import android.os.Parcelable; import android.text.TextUtils; import java.util.ArrayList; +import java.util.List; /** * This class represents accessibility events that are sent by the system when * something notable happens in the user interface. For example, when a * {@link android.widget.Button} is clicked, a {@link android.view.View} is focused, etc. * <p> - * An accessibility event is fired by an individual view which populates the event with - * a record for its state and requests from its parent to send the event to interested - * parties. The parent can optionally add a record for itself before dispatching a similar - * request to its parent. A parent can also choose not to respect the request for sending - * an event. The accessibility event is sent by the topmost view in the view tree. - * Therefore, an {@link android.accessibilityservice.AccessibilityService} can explore - * all records in an accessibility event to obtain more information about the context - * in which the event was fired. - * <p> - * A client can add, remove, and modify records. The getters and setters for individual - * properties operate on the current record which can be explicitly set by the client. By - * default current is the first record. Thus, querying a record would require setting - * it as the current one and interacting with the property getters and setters. - * <p> * This class represents various semantically different accessibility event * types. Each event type has associated a set of related properties. In other * words, each event type is characterized via a subset of the properties exposed @@ -158,7 +145,7 @@ import java.util.ArrayList; * @see android.view.accessibility.AccessibilityManager * @see android.accessibilityservice.AccessibilityService */ -public final class AccessibilityEvent extends AccessibilityRecord implements Parcelable { +public final class AccessibilityEvent implements Parcelable { /** * Invalid selection/focus position. @@ -220,26 +207,6 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par public static final int TYPE_NOTIFICATION_STATE_CHANGED = 0x00000040; /** - * Represents the event of a hover enter over a {@link android.view.View}. - */ - public static final int TYPE_VIEW_HOVER_ENTER = 0x00000080; - - /** - * Represents the event of a hover exit over a {@link android.view.View}. - */ - public static final int TYPE_VIEW_HOVER_EXIT = 0x00000100; - - /** - * Represents the event of starting a touch exploration gesture. - */ - public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 0x00000200; - - /** - * Represents the event of ending a touch exploration gesture. - */ - public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 0x00000400; - - /** * Mask for {@link AccessibilityEvent} all types. * * @see #TYPE_VIEW_CLICKED @@ -252,53 +219,116 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par */ public static final int TYPES_ALL_MASK = 0xFFFFFFFF; - private static final int MAX_POOL_SIZE = 10; + private static final int MAX_POOL_SIZE = 2; private static final Object mPoolLock = new Object(); private static AccessibilityEvent sPool; private static int sPoolSize; + private static final int CHECKED = 0x00000001; + private static final int ENABLED = 0x00000002; + private static final int PASSWORD = 0x00000004; + private static final int FULL_SCREEN = 0x00000080; + private AccessibilityEvent mNext; - private boolean mIsInPool; private int mEventType; - private CharSequence mPackageName; + private int mBooleanProperties; + private int mCurrentItemIndex; + private int mItemCount; + private int mFromIndex; + private int mAddedCount; + private int mRemovedCount; + private long mEventTime; - private final ArrayList<AccessibilityRecord> mRecords = new ArrayList<AccessibilityRecord>(); + private CharSequence mClassName; + private CharSequence mPackageName; + private CharSequence mContentDescription; + private CharSequence mBeforeText; + + private Parcelable mParcelableData; + + private final List<CharSequence> mText = new ArrayList<CharSequence>(); + + private boolean mIsInPool; /* * Hide constructor from clients. */ private AccessibilityEvent() { + mCurrentItemIndex = INVALID_POSITION; + } + + /** + * Gets if the source is checked. + * + * @return True if the view is checked, false otherwise. + */ + public boolean isChecked() { + return getBooleanProperty(CHECKED); + } + + /** + * Sets if the source is checked. + * + * @param isChecked True if the view is checked, false otherwise. + */ + public void setChecked(boolean isChecked) { + setBooleanProperty(CHECKED, isChecked); + } + /** + * Gets if the source is enabled. + * + * @return True if the view is enabled, false otherwise. + */ + public boolean isEnabled() { + return getBooleanProperty(ENABLED); + } + + /** + * Sets if the source is enabled. + * + * @param isEnabled True if the view is enabled, false otherwise. + */ + public void setEnabled(boolean isEnabled) { + setBooleanProperty(ENABLED, isEnabled); + } + + /** + * Gets if the source is a password field. + * + * @return True if the view is a password field, false otherwise. + */ + public boolean isPassword() { + return getBooleanProperty(PASSWORD); } /** - * Gets the number of records contained in the event. + * Sets if the source is a password field. * - * @return The number of records. + * @param isPassword True if the view is a password field, false otherwise. */ - public int getRecordCount() { - return mRecords.size(); + public void setPassword(boolean isPassword) { + setBooleanProperty(PASSWORD, isPassword); } /** - * Appends an {@link AccessibilityRecord} to the end of event records. + * Sets if the source is taking the entire screen. * - * @param record The record to append. + * @param isFullScreen True if the source is full screen, false otherwise. */ - public void appendRecord(AccessibilityRecord record) { - mRecords.add(record); + public void setFullScreen(boolean isFullScreen) { + setBooleanProperty(FULL_SCREEN, isFullScreen); } /** - * Gets the records at a given index. + * Gets if the source is taking the entire screen. * - * @param index The index. - * @return The records at the specified index. + * @return True if the source is full screen, false otherwise. */ - public AccessibilityRecord getRecord(int index) { - return mRecords.get(index); + public boolean isFullScreen() { + return getBooleanProperty(FULL_SCREEN); } /** @@ -320,6 +350,96 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par } /** + * Gets the number of items that can be visited. + * + * @return The number of items. + */ + public int getItemCount() { + return mItemCount; + } + + /** + * Sets the number of items that can be visited. + * + * @param itemCount The number of items. + */ + public void setItemCount(int itemCount) { + mItemCount = itemCount; + } + + /** + * Gets the index of the source in the list of items the can be visited. + * + * @return The current item index. + */ + public int getCurrentItemIndex() { + return mCurrentItemIndex; + } + + /** + * Sets the index of the source in the list of items that can be visited. + * + * @param currentItemIndex The current item index. + */ + public void setCurrentItemIndex(int currentItemIndex) { + mCurrentItemIndex = currentItemIndex; + } + + /** + * Gets the index of the first character of the changed sequence. + * + * @return The index of the first character. + */ + public int getFromIndex() { + return mFromIndex; + } + + /** + * Sets the index of the first character of the changed sequence. + * + * @param fromIndex The index of the first character. + */ + public void setFromIndex(int fromIndex) { + mFromIndex = fromIndex; + } + + /** + * Gets the number of added characters. + * + * @return The number of added characters. + */ + public int getAddedCount() { + return mAddedCount; + } + + /** + * Sets the number of added characters. + * + * @param addedCount The number of added characters. + */ + public void setAddedCount(int addedCount) { + mAddedCount = addedCount; + } + + /** + * Gets the number of removed characters. + * + * @return The number of removed characters. + */ + public int getRemovedCount() { + return mRemovedCount; + } + + /** + * Sets the number of removed characters. + * + * @param removedCount The number of removed characters. + */ + public void setRemovedCount(int removedCount) { + mRemovedCount = removedCount; + } + + /** * Gets the time in which this event was sent. * * @return The event time. @@ -338,6 +458,24 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par } /** + * Gets the class name of the source. + * + * @return The class name. + */ + public CharSequence getClassName() { + return mClassName; + } + + /** + * Sets the class name of the source. + * + * @param className The lass name. + */ + public void setClassName(CharSequence className) { + mClassName = className; + } + + /** * Gets the package name of the source. * * @return The package name. @@ -356,6 +494,70 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par } /** + * Gets the text of the event. The index in the list represents the priority + * of the text. Specifically, the lower the index the higher the priority. + * + * @return The text. + */ + public List<CharSequence> getText() { + return mText; + } + + /** + * Sets the text before a change. + * + * @return The text before the change. + */ + public CharSequence getBeforeText() { + return mBeforeText; + } + + /** + * Sets the text before a change. + * + * @param beforeText The text before the change. + */ + public void setBeforeText(CharSequence beforeText) { + mBeforeText = beforeText; + } + + /** + * Gets the description of the source. + * + * @return The description. + */ + public CharSequence getContentDescription() { + return mContentDescription; + } + + /** + * Sets the description of the source. + * + * @param contentDescription The description. + */ + public void setContentDescription(CharSequence contentDescription) { + mContentDescription = contentDescription; + } + + /** + * Gets the {@link Parcelable} data. + * + * @return The parcelable data. + */ + public Parcelable getParcelableData() { + return mParcelableData; + } + + /** + * Sets the {@link Parcelable} data of the event. + * + * @param parcelableData The parcelable data. + */ + public void setParcelableData(Parcelable parcelableData) { + mParcelableData = parcelableData; + } + + /** * Returns a cached instance if such is available or a new one is * instantiated with type property set. * @@ -393,11 +595,11 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par * <p> * <b>Note: You must not touch the object after calling this function.</b> */ - @Override public void recycle() { if (mIsInPool) { return; } + clear(); synchronized (mPoolLock) { if (sPoolSize <= MAX_POOL_SIZE) { @@ -412,101 +614,86 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par /** * Clears the state of this instance. */ - @Override - protected void clear() { - super.clear(); + private void clear() { mEventType = 0; - mPackageName = null; + mBooleanProperties = 0; + mCurrentItemIndex = INVALID_POSITION; + mItemCount = 0; + mFromIndex = 0; + mAddedCount = 0; + mRemovedCount = 0; mEventTime = 0; - while (!mRecords.isEmpty()) { - AccessibilityRecord record = mRecords.remove(0); - record.recycle(); - } + mClassName = null; + mPackageName = null; + mContentDescription = null; + mBeforeText = null; + mParcelableData = null; + mText.clear(); } /** - * Creates a new instance from a {@link Parcel}. + * Gets the value of a boolean property. * - * @param parcel A parcel containing the state of a {@link AccessibilityEvent}. + * @param property The property. + * @return The value. */ - public void initFromParcel(Parcel parcel) { - mEventType = parcel.readInt(); - mPackageName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); - mEventTime = parcel.readLong(); - readAccessibilityRecordFromParcel(this, parcel); - - // Read the records. - final int recordCount = parcel.readInt(); - for (int i = 0; i < recordCount; i++) { - AccessibilityRecord record = AccessibilityRecord.obtain(); - readAccessibilityRecordFromParcel(record, parcel); - mRecords.add(record); - } + private boolean getBooleanProperty(int property) { + return (mBooleanProperties & property) == property; } /** - * Reads an {@link AccessibilityRecord} from a parcel. + * Sets a boolean property. * - * @param record The record to initialize. - * @param parcel The parcel to read from. - */ - private void readAccessibilityRecordFromParcel(AccessibilityRecord record, - Parcel parcel) { - record.mBooleanProperties = parcel.readInt(); - record.mCurrentItemIndex = parcel.readInt(); - record.mItemCount = parcel.readInt(); - record.mFromIndex = parcel.readInt(); - record.mAddedCount = parcel.readInt(); - record.mRemovedCount = parcel.readInt(); - record.mClassName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); - record.mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); - record.mBeforeText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); - record.mParcelableData = parcel.readParcelable(null); - parcel.readList(record.mText, null); + * @param property The property. + * @param value The value. + */ + private void setBooleanProperty(int property, boolean value) { + if (value) { + mBooleanProperties |= property; + } else { + mBooleanProperties &= ~property; + } } /** - * {@inheritDoc} + * Creates a new instance from a {@link Parcel}. + * + * @param parcel A parcel containing the state of a {@link AccessibilityEvent}. */ + public void initFromParcel(Parcel parcel) { + mEventType = parcel.readInt(); + mBooleanProperties = parcel.readInt(); + mCurrentItemIndex = parcel.readInt(); + mItemCount = parcel.readInt(); + mFromIndex = parcel.readInt(); + mAddedCount = parcel.readInt(); + mRemovedCount = parcel.readInt(); + mEventTime = parcel.readLong(); + mClassName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); + mPackageName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); + mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); + mBeforeText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); + mParcelableData = parcel.readParcelable(null); + parcel.readList(mText, null); + } + public void writeToParcel(Parcel parcel, int flags) { parcel.writeInt(mEventType); - TextUtils.writeToParcel(mPackageName, parcel, 0); + parcel.writeInt(mBooleanProperties); + parcel.writeInt(mCurrentItemIndex); + parcel.writeInt(mItemCount); + parcel.writeInt(mFromIndex); + parcel.writeInt(mAddedCount); + parcel.writeInt(mRemovedCount); parcel.writeLong(mEventTime); - writeAccessibilityRecordToParcel(this, parcel, flags); - - // Write the records. - final int recordCount = getRecordCount(); - parcel.writeInt(recordCount); - for (int i = 0; i < recordCount; i++) { - AccessibilityRecord record = mRecords.get(i); - writeAccessibilityRecordToParcel(record, parcel, flags); - } - } - - /** - * Writes an {@link AccessibilityRecord} to a parcel. - * - * @param record The record to write. - * @param parcel The parcel to which to write. - */ - private void writeAccessibilityRecordToParcel(AccessibilityRecord record, Parcel parcel, - int flags) { - parcel.writeInt(record.mBooleanProperties); - parcel.writeInt(record.mCurrentItemIndex); - parcel.writeInt(record.mItemCount); - parcel.writeInt(record.mFromIndex); - parcel.writeInt(record.mAddedCount); - parcel.writeInt(record.mRemovedCount); - TextUtils.writeToParcel(record.mClassName, parcel, flags); - TextUtils.writeToParcel(record.mContentDescription, parcel, flags); - TextUtils.writeToParcel(record.mBeforeText, parcel, flags); - parcel.writeParcelable(record.mParcelableData, flags); - parcel.writeList(record.mText); + TextUtils.writeToParcel(mClassName, parcel, 0); + TextUtils.writeToParcel(mPackageName, parcel, 0); + TextUtils.writeToParcel(mContentDescription, parcel, 0); + TextUtils.writeToParcel(mBeforeText, parcel, 0); + parcel.writeParcelable(mParcelableData, flags); + parcel.writeList(mText); } - /** - * {@inheritDoc} - */ public int describeContents() { return 0; } @@ -514,21 +701,24 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par @Override public String toString() { StringBuilder builder = new StringBuilder(); + builder.append(super.toString()); builder.append("; EventType: " + mEventType); builder.append("; EventTime: " + mEventTime); + builder.append("; ClassName: " + mClassName); builder.append("; PackageName: " + mPackageName); - builder.append(" \n{\n"); - builder.append(super.toString()); - builder.append("\n"); - for (int i = 0; i < mRecords.size(); i++) { - AccessibilityRecord record = mRecords.get(i); - builder.append(" Record "); - builder.append(i); - builder.append(":"); - builder.append(record.toString()); - builder.append("\n"); - } - builder.append("}\n"); + builder.append("; Text: " + mText); + builder.append("; ContentDescription: " + mContentDescription); + builder.append("; ItemCount: " + mItemCount); + builder.append("; CurrentItemIndex: " + mCurrentItemIndex); + builder.append("; IsEnabled: " + isEnabled()); + builder.append("; IsPassword: " + isPassword()); + builder.append("; IsChecked: " + isChecked()); + builder.append("; IsFullScreen: " + isFullScreen()); + builder.append("; BeforeText: " + mBeforeText); + builder.append("; FromIndex: " + mFromIndex); + builder.append("; AddedCount: " + mAddedCount); + builder.append("; RemovedCount: " + mRemovedCount); + builder.append("; ParcelableData: " + mParcelableData); return builder.toString(); } diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java index dd7719364a31..22cb0d482bf8 100644 --- a/core/java/android/view/accessibility/AccessibilityManager.java +++ b/core/java/android/view/accessibility/AccessibilityManager.java @@ -16,8 +16,6 @@ package android.view.accessibility; -import android.accessibilityservice.AccessibilityService; -import android.accessibilityservice.AccessibilityServiceInfo; import android.content.Context; import android.content.pm.ServiceInfo; import android.os.Binder; @@ -46,8 +44,6 @@ import java.util.List; * @see android.content.Context#getSystemService */ public final class AccessibilityManager { - private static final boolean DEBUG = false; - private static final String LOG_TAG = "AccessibilityManager"; static final Object sInstanceSync = new Object(); @@ -168,7 +164,7 @@ public final class AccessibilityManager { long identityToken = Binder.clearCallingIdentity(); doRecycle = mService.sendAccessibilityEvent(event); Binder.restoreCallingIdentity(identityToken); - if (DEBUG) { + if (false) { Log.i(LOG_TAG, event + " sent"); } } catch (RemoteException re) { @@ -189,7 +185,7 @@ public final class AccessibilityManager { } try { mService.interrupt(); - if (DEBUG) { + if (false) { Log.i(LOG_TAG, "Requested interrupt from all services"); } } catch (RemoteException re) { @@ -206,33 +202,7 @@ public final class AccessibilityManager { List<ServiceInfo> services = null; try { services = mService.getAccessibilityServiceList(); - if (DEBUG) { - Log.i(LOG_TAG, "Installed AccessibilityServices " + services); - } - } catch (RemoteException re) { - Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re); - } - return Collections.unmodifiableList(services); - } - - /** - * Returns the {@link ServiceInfo}s of the enabled accessibility services - * for a given feedback type. - * - * @param feedbackType The type of feedback. - * @return An unmodifiable list with {@link ServiceInfo}s. - * - * @see AccessibilityServiceInfo#FEEDBACK_AUDIBLE - * @see AccessibilityServiceInfo#FEEDBACK_HAPTIC - * @see AccessibilityServiceInfo#FEEDBACK_SPOKEN - * @see AccessibilityServiceInfo#FEEDBACK_VISUAL - * @see AccessibilityServiceInfo#FEEDBACK_GENERIC - */ - public List<ServiceInfo> getEnabledAccessibilityServiceList(int feedbackType) { - List<ServiceInfo> services = null; - try { - services = mService.getEnabledAccessibilityServiceList(feedbackType); - if (DEBUG) { + if (false) { Log.i(LOG_TAG, "Installed AccessibilityServices " + services); } } catch (RemoteException re) { diff --git a/core/java/android/view/accessibility/AccessibilityRecord.java b/core/java/android/view/accessibility/AccessibilityRecord.java deleted file mode 100644 index e095f435bfd6..000000000000 --- a/core/java/android/view/accessibility/AccessibilityRecord.java +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.view.accessibility; - -import android.os.Parcelable; - -import java.util.ArrayList; -import java.util.List; - -/** - * Represents a record in an accessibility event. This class encapsulates - * the information for a {@link android.view.View}. Note that not all properties - * are applicable to all view types. For detailed information please refer to - * {@link AccessibilityEvent}. - * - * @see AccessibilityEvent - */ -public class AccessibilityRecord { - - private static final int INVALID_POSITION = -1; - - private static final int PROPERTY_CHECKED = 0x00000001; - private static final int PROPERTY_ENABLED = 0x00000002; - private static final int PROPERTY_PASSWORD = 0x00000004; - private static final int PROPERTY_FULL_SCREEN = 0x00000080; - - private static final int MAX_POOL_SIZE = 10; - private static final Object mPoolLock = new Object(); - private static AccessibilityRecord sPool; - private static int sPoolSize; - - private AccessibilityRecord mNext; - private boolean mIsInPool; - - protected int mBooleanProperties; - protected int mCurrentItemIndex; - protected int mItemCount; - protected int mFromIndex; - protected int mAddedCount; - protected int mRemovedCount; - - protected CharSequence mClassName; - protected CharSequence mContentDescription; - protected CharSequence mBeforeText; - protected Parcelable mParcelableData; - - protected final List<CharSequence> mText = new ArrayList<CharSequence>(); - - /* - * Hide constructor. - */ - protected AccessibilityRecord() { - - } - - /** - * Gets if the source is checked. - * - * @return True if the view is checked, false otherwise. - */ - public boolean isChecked() { - return getBooleanProperty(PROPERTY_CHECKED); - } - - /** - * Sets if the source is checked. - * - * @param isChecked True if the view is checked, false otherwise. - */ - public void setChecked(boolean isChecked) { - setBooleanProperty(PROPERTY_CHECKED, isChecked); - } - - /** - * Gets if the source is enabled. - * - * @return True if the view is enabled, false otherwise. - */ - public boolean isEnabled() { - return getBooleanProperty(PROPERTY_ENABLED); - } - - /** - * Sets if the source is enabled. - * - * @param isEnabled True if the view is enabled, false otherwise. - */ - public void setEnabled(boolean isEnabled) { - setBooleanProperty(PROPERTY_ENABLED, isEnabled); - } - - /** - * Gets if the source is a password field. - * - * @return True if the view is a password field, false otherwise. - */ - public boolean isPassword() { - return getBooleanProperty(PROPERTY_PASSWORD); - } - - /** - * Sets if the source is a password field. - * - * @param isPassword True if the view is a password field, false otherwise. - */ - public void setPassword(boolean isPassword) { - setBooleanProperty(PROPERTY_PASSWORD, isPassword); - } - - /** - * Sets if the source is taking the entire screen. - * - * @param isFullScreen True if the source is full screen, false otherwise. - */ - public void setFullScreen(boolean isFullScreen) { - setBooleanProperty(PROPERTY_FULL_SCREEN, isFullScreen); - } - - /** - * Gets if the source is taking the entire screen. - * - * @return True if the source is full screen, false otherwise. - */ - public boolean isFullScreen() { - return getBooleanProperty(PROPERTY_FULL_SCREEN); - } - - /** - * Gets the number of items that can be visited. - * - * @return The number of items. - */ - public int getItemCount() { - return mItemCount; - } - - /** - * Sets the number of items that can be visited. - * - * @param itemCount The number of items. - */ - public void setItemCount(int itemCount) { - mItemCount = itemCount; - } - - /** - * Gets the index of the source in the list of items the can be visited. - * - * @return The current item index. - */ - public int getCurrentItemIndex() { - return mCurrentItemIndex; - } - - /** - * Sets the index of the source in the list of items that can be visited. - * - * @param currentItemIndex The current item index. - */ - public void setCurrentItemIndex(int currentItemIndex) { - mCurrentItemIndex = currentItemIndex; - } - - /** - * Gets the index of the first character of the changed sequence. - * - * @return The index of the first character. - */ - public int getFromIndex() { - return mFromIndex; - } - - /** - * Sets the index of the first character of the changed sequence. - * - * @param fromIndex The index of the first character. - */ - public void setFromIndex(int fromIndex) { - mFromIndex = fromIndex; - } - - /** - * Gets the number of added characters. - * - * @return The number of added characters. - */ - public int getAddedCount() { - return mAddedCount; - } - - /** - * Sets the number of added characters. - * - * @param addedCount The number of added characters. - */ - public void setAddedCount(int addedCount) { - mAddedCount = addedCount; - } - - /** - * Gets the number of removed characters. - * - * @return The number of removed characters. - */ - public int getRemovedCount() { - return mRemovedCount; - } - - /** - * Sets the number of removed characters. - * - * @param removedCount The number of removed characters. - */ - public void setRemovedCount(int removedCount) { - mRemovedCount = removedCount; - } - - /** - * Gets the class name of the source. - * - * @return The class name. - */ - public CharSequence getClassName() { - return mClassName; - } - - /** - * Sets the class name of the source. - * - * @param className The lass name. - */ - public void setClassName(CharSequence className) { - mClassName = className; - } - - /** - * Gets the text of the event. The index in the list represents the priority - * of the text. Specifically, the lower the index the higher the priority. - * - * @return The text. - */ - public List<CharSequence> getText() { - return mText; - } - - /** - * Sets the text before a change. - * - * @return The text before the change. - */ - public CharSequence getBeforeText() { - return mBeforeText; - } - - /** - * Sets the text before a change. - * - * @param beforeText The text before the change. - */ - public void setBeforeText(CharSequence beforeText) { - mBeforeText = beforeText; - } - - /** - * Gets the description of the source. - * - * @return The description. - */ - public CharSequence getContentDescription() { - return mContentDescription; - } - - /** - * Sets the description of the source. - * - * @param contentDescription The description. - */ - public void setContentDescription(CharSequence contentDescription) { - mContentDescription = contentDescription; - } - - /** - * Gets the {@link Parcelable} data. - * - * @return The parcelable data. - */ - public Parcelable getParcelableData() { - return mParcelableData; - } - - /** - * Sets the {@link Parcelable} data of the event. - * - * @param parcelableData The parcelable data. - */ - public void setParcelableData(Parcelable parcelableData) { - mParcelableData = parcelableData; - } - - /** - * Gets the value of a boolean property. - * - * @param property The property. - * @return The value. - */ - public boolean getBooleanProperty(int property) { - return (mBooleanProperties & property) == property; - } - - /** - * Sets a boolean property. - * - * @param property The property. - * @param value The value. - */ - private void setBooleanProperty(int property, boolean value) { - if (value) { - mBooleanProperties |= property; - } else { - mBooleanProperties &= ~property; - } - } - - /** - * Returns a cached instance if such is available or a new one is - * instantiated. - * - * @return An instance. - */ - protected static AccessibilityRecord obtain() { - synchronized (mPoolLock) { - if (sPool != null) { - AccessibilityRecord record = sPool; - sPool = sPool.mNext; - sPoolSize--; - record.mNext = null; - record.mIsInPool = false; - return record; - } - return new AccessibilityRecord(); - } - } - - /** - * Return an instance back to be reused. - * <p> - * <b>Note: You must not touch the object after calling this function.</b> - */ - public void recycle() { - if (mIsInPool) { - return; - } - clear(); - synchronized (mPoolLock) { - if (sPoolSize <= MAX_POOL_SIZE) { - mNext = sPool; - sPool = this; - mIsInPool = true; - sPoolSize++; - } - } - } - - /** - * Clears the state of this instance. - */ - protected void clear() { - mBooleanProperties = 0; - mCurrentItemIndex = INVALID_POSITION; - mItemCount = 0; - mFromIndex = 0; - mAddedCount = 0; - mRemovedCount = 0; - mClassName = null; - mContentDescription = null; - mBeforeText = null; - mParcelableData = null; - mText.clear(); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(" [ ClassName: " + mClassName); - builder.append("; Text: " + mText); - builder.append("; ContentDescription: " + mContentDescription); - builder.append("; ItemCount: " + mItemCount); - builder.append("; CurrentItemIndex: " + mCurrentItemIndex); - builder.append("; IsEnabled: " + getBooleanProperty(PROPERTY_ENABLED)); - builder.append("; IsPassword: " + getBooleanProperty(PROPERTY_PASSWORD)); - builder.append("; IsChecked: " + getBooleanProperty(PROPERTY_CHECKED)); - builder.append("; IsFullScreen: " + getBooleanProperty(PROPERTY_FULL_SCREEN)); - builder.append("; BeforeText: " + mBeforeText); - builder.append("; FromIndex: " + mFromIndex); - builder.append("; AddedCount: " + mAddedCount); - builder.append("; RemovedCount: " + mRemovedCount); - builder.append("; ParcelableData: " + mParcelableData); - builder.append(" ]"); - return builder.toString(); - } -} diff --git a/core/java/android/view/accessibility/IAccessibilityManager.aidl b/core/java/android/view/accessibility/IAccessibilityManager.aidl index aaaae327cb64..7633569d5312 100644 --- a/core/java/android/view/accessibility/IAccessibilityManager.aidl +++ b/core/java/android/view/accessibility/IAccessibilityManager.aidl @@ -35,7 +35,5 @@ interface IAccessibilityManager { List<ServiceInfo> getAccessibilityServiceList(); - List<ServiceInfo> getEnabledAccessibilityServiceList(int feedbackType); - void interrupt(); } |
