Improve the window query API performamce.

We are caching the window data in the accessibility service process.
When windows change we were sending the dalta of the windows the
service knows about. To make this work when the app asked for all
windows we had to call into the system as new windows may have
appeared. This was slow.

Now we are telling the service some windows change and if it gets
the windows we cache them. We call into the system only on a cache
miss and evict all windows from the cache on window change event.
We do not evict the nodes of the window as the former may have
just moved. If views in a window change they fire accessibility
events that trigger the correct eviction.

Change-Id: I586a72a2497b0d44a75288fa758e7e88817f3300
This commit is contained in:
Svetoslav
2014-07-24 14:17:05 -07:00
committed by Svetoslav Ganov
parent 0dcebb9246
commit a4725efd0b
5 changed files with 71 additions and 204 deletions

View File

@@ -23,7 +23,6 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.accessibility.AccessibilityEvent;
@@ -659,16 +658,12 @@ public abstract class AccessibilityService extends Service {
*/
public static class IAccessibilityServiceClientWrapper extends IAccessibilityServiceClient.Stub
implements HandlerCaller.Callback {
static final int NO_ID = -1;
private static final int DO_SET_SET_CONNECTION = 1;
private static final int DO_ON_INTERRUPT = 2;
private static final int DO_ON_ACCESSIBILITY_EVENT = 3;
private static final int DO_ON_GESTURE = 4;
private static final int DO_CLEAR_ACCESSIBILITY_CACHE = 5;
private static final int DO_ON_KEY_EVENT = 6;
private static final int DO_ON_WINDOWS_CHANGED = 7;
private final HandlerCaller mCaller;
@@ -714,12 +709,6 @@ public abstract class AccessibilityService extends Service {
mCaller.sendMessage(message);
}
@Override
public void onWindowsChanged(int[] windowIds) {
Message message = mCaller.obtainMessageO(DO_ON_WINDOWS_CHANGED, windowIds);
mCaller.sendMessage(message);
}
@Override
public void executeMessage(Message message) {
switch (message.what) {
@@ -791,31 +780,6 @@ public abstract class AccessibilityService extends Service {
}
} return;
case DO_ON_WINDOWS_CHANGED: {
final int[] windowIds = (int[]) message.obj;
// Update the cached windows first.
// NOTE: The cache will hold on to the windows so do not recycle.
if (windowIds != null) {
AccessibilityInteractionClient.getInstance().removeWindows(windowIds);
}
// Let the client know the windows changed.
AccessibilityEvent event = AccessibilityEvent.obtain(
AccessibilityEvent.TYPE_WINDOWS_CHANGED);
event.setEventTime(SystemClock.uptimeMillis());
event.setSealed(true);
mCallback.onAccessibilityEvent(event);
// Make sure the event is recycled.
try {
event.recycle();
} catch (IllegalStateException ise) {
/* ignore - best effort */
}
} break;
default :
Log.w(LOG_TAG, "Unknown message type " + message.what);
}

View File

@@ -39,6 +39,4 @@ import android.view.KeyEvent;
void clearAccessibilityCache();
void onKeyEvent(in KeyEvent event, int sequence);
void onWindowsChanged(in int[] changedWindowIds);
}