summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/view/accessibility/AccessibilityCache.java41
-rw-r--r--core/java/android/view/accessibility/AccessibilityInteractionClient.java6
2 files changed, 36 insertions, 11 deletions
diff --git a/core/java/android/view/accessibility/AccessibilityCache.java b/core/java/android/view/accessibility/AccessibilityCache.java
index d0dde00746bd..1da305f09f54 100644
--- a/core/java/android/view/accessibility/AccessibilityCache.java
+++ b/core/java/android/view/accessibility/AccessibilityCache.java
@@ -43,6 +43,8 @@ final class AccessibilityCache {
private long mAccessibilityFocus = AccessibilityNodeInfo.UNDEFINED_ITEM_ID;
private long mInputFocus = AccessibilityNodeInfo.UNDEFINED_ITEM_ID;
+ private boolean mIsAllWindowsCached;
+
private final SparseArray<AccessibilityWindowInfo> mWindowCache =
new SparseArray<>();
@@ -52,6 +54,24 @@ final class AccessibilityCache {
private final SparseArray<AccessibilityWindowInfo> mTempWindowArray =
new SparseArray<>();
+ public void setWindows(List<AccessibilityWindowInfo> windows) {
+ synchronized (mLock) {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "Set windows");
+ }
+ clearWindowCache();
+ if (windows == null) {
+ return;
+ }
+ final int windowCount = windows.size();
+ for (int i = 0; i < windowCount; i++) {
+ final AccessibilityWindowInfo window = windows.get(i);
+ addWindow(window);
+ }
+ mIsAllWindowsCached = true;
+ }
+ }
+
public void addWindow(AccessibilityWindowInfo window) {
synchronized (mLock) {
if (DEBUG) {
@@ -186,6 +206,10 @@ final class AccessibilityCache {
public List<AccessibilityWindowInfo> getWindows() {
synchronized (mLock) {
+ if (!mIsAllWindowsCached) {
+ return null;
+ }
+
final int windowCount = mWindowCache.size();
if (windowCount > 0) {
// Careful to return the windows in a decreasing layer order.
@@ -280,12 +304,7 @@ final class AccessibilityCache {
if (DEBUG) {
Log.i(LOG_TAG, "clear()");
}
- final int windowCount = mWindowCache.size();
- for (int i = windowCount - 1; i >= 0; i--) {
- AccessibilityWindowInfo window = mWindowCache.valueAt(i);
- window.recycle();
- mWindowCache.removeAt(i);
- }
+ clearWindowCache();
final int nodesForWindowCount = mNodeCache.size();
for (int i = 0; i < nodesForWindowCount; i++) {
final int windowId = mNodeCache.keyAt(i);
@@ -297,6 +316,16 @@ final class AccessibilityCache {
}
}
+ private void clearWindowCache() {
+ final int windowCount = mWindowCache.size();
+ for (int i = windowCount - 1; i >= 0; i--) {
+ AccessibilityWindowInfo window = mWindowCache.valueAt(i);
+ window.recycle();
+ mWindowCache.removeAt(i);
+ }
+ mIsAllWindowsCached = false;
+ }
+
private void clearNodesForWindowLocked(int windowId) {
if (DEBUG) {
Log.i(LOG_TAG, "clearNodesForWindowLocked(" + windowId + ")");
diff --git a/core/java/android/view/accessibility/AccessibilityInteractionClient.java b/core/java/android/view/accessibility/AccessibilityInteractionClient.java
index b49cbc6245ba..1406fbd9d074 100644
--- a/core/java/android/view/accessibility/AccessibilityInteractionClient.java
+++ b/core/java/android/view/accessibility/AccessibilityInteractionClient.java
@@ -228,11 +228,7 @@ public final class AccessibilityInteractionClient
windows = connection.getWindows();
Binder.restoreCallingIdentity(identityToken);
if (windows != null) {
- final int windowCount = windows.size();
- for (int i = 0; i < windowCount; i++) {
- AccessibilityWindowInfo window = windows.get(i);
- sAccessibilityCache.addWindow(window);
- }
+ sAccessibilityCache.setWindows(windows);
return windows;
}
} else {