Refactoring due to removing some private APIs.
Change-Id: Id00d9fa974d8cb747cebb99c5a64ed5b438b56e9
This commit is contained in:
committed by
Android (Google) Code Review
parent
7531ada080
commit
00fc93c6fe
@@ -155,7 +155,8 @@ public class InstrumentationList extends ListActivity
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ActivityManagerNative.getDefault().
|
ActivityManagerNative.getDefault().
|
||||||
startInstrumentation(className, profilingFile, 0, null, mWatcher, UserHandle.myUserId());
|
startInstrumentation(className, profilingFile, 0, null, mWatcher, null,
|
||||||
|
UserHandle.myUserId());
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import android.app.IActivityManager;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.AndroidException;
|
|
||||||
import android.view.IWindowManager;
|
import android.view.IWindowManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +45,7 @@ public class MonkeyInstrumentationEvent extends MonkeyEvent {
|
|||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("class", mTestCaseName);
|
args.putString("class", mTestCaseName);
|
||||||
try {
|
try {
|
||||||
iam.startInstrumentation(cn, null, 0, args, null, 0);
|
iam.startInstrumentation(cn, null, 0, args, null, null, 0);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
System.err.println("** Failed talking with activity manager!");
|
System.err.println("** Failed talking with activity manager!");
|
||||||
return MonkeyEvent.INJECT_ERROR_REMOTE_EXCEPTION;
|
return MonkeyEvent.INJECT_ERROR_REMOTE_EXCEPTION;
|
||||||
|
|||||||
@@ -588,6 +588,7 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
|
|||||||
*/
|
*/
|
||||||
private void stopServer() throws IOException {
|
private void stopServer() throws IOException {
|
||||||
clientSocket.close();
|
clientSocket.close();
|
||||||
|
MonkeySourceNetworkViews.teardown();
|
||||||
input.close();
|
input.close();
|
||||||
output.close();
|
output.close();
|
||||||
started = false;
|
started = false;
|
||||||
|
|||||||
@@ -18,14 +18,16 @@ package com.android.commands.monkey;
|
|||||||
|
|
||||||
import static com.android.commands.monkey.MonkeySourceNetwork.EARG;
|
import static com.android.commands.monkey.MonkeySourceNetwork.EARG;
|
||||||
|
|
||||||
import android.accessibilityservice.UiTestAutomationBridge;
|
import android.app.UiAutomation;
|
||||||
|
import android.app.UiAutomationConnection;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.IPackageManager;
|
import android.content.pm.IPackageManager;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.os.HandlerThread;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityInteractionClient;
|
||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
|
|
||||||
import com.android.commands.monkey.MonkeySourceNetwork.CommandQueue;
|
import com.android.commands.monkey.MonkeySourceNetwork.CommandQueue;
|
||||||
@@ -45,11 +47,15 @@ import java.util.Map;
|
|||||||
* Script commands over the network.
|
* Script commands over the network.
|
||||||
*/
|
*/
|
||||||
public class MonkeySourceNetworkViews {
|
public class MonkeySourceNetworkViews {
|
||||||
protected static UiTestAutomationBridge sUiTestAutomationBridge;
|
|
||||||
|
protected static android.app.UiAutomation sUiTestAutomationBridge;
|
||||||
|
|
||||||
private static IPackageManager sPm =
|
private static IPackageManager sPm =
|
||||||
IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
|
IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
|
||||||
private static Map<String, Class<?>> sClassMap = new HashMap<String, Class<?>>();
|
private static Map<String, Class<?>> sClassMap = new HashMap<String, Class<?>>();
|
||||||
|
|
||||||
|
private static final String HANDLER_THREAD_NAME = "UiAutomationHandlerThread";
|
||||||
|
|
||||||
private static final String REMOTE_ERROR =
|
private static final String REMOTE_ERROR =
|
||||||
"Unable to retrieve application info from PackageManager";
|
"Unable to retrieve application info from PackageManager";
|
||||||
private static final String CLASS_NOT_FOUND = "Error retrieving class information";
|
private static final String CLASS_NOT_FOUND = "Error retrieving class information";
|
||||||
@@ -85,16 +91,25 @@ public class MonkeySourceNetworkViews {
|
|||||||
COMMAND_MAP.put("getaccessibilityids", new GetAccessibilityIds());
|
COMMAND_MAP.put("getaccessibilityids", new GetAccessibilityIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HandlerThread sHandlerThread = new HandlerThread(HANDLER_THREAD_NAME);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the event listener for AccessibilityEvents.
|
* Registers the event listener for AccessibilityEvents.
|
||||||
* Also sets up a communication connection so we can query the
|
* Also sets up a communication connection so we can query the
|
||||||
* accessibility service.
|
* accessibility service.
|
||||||
*/
|
*/
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
sUiTestAutomationBridge = new UiTestAutomationBridge();
|
sHandlerThread.setDaemon(true);
|
||||||
|
sHandlerThread.start();
|
||||||
|
sUiTestAutomationBridge = new UiAutomation(sHandlerThread.getLooper(),
|
||||||
|
new UiAutomationConnection());
|
||||||
sUiTestAutomationBridge.connect();
|
sUiTestAutomationBridge.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void teardown() {
|
||||||
|
sHandlerThread.quit();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ID class for the given package.
|
* Get the ID class for the given package.
|
||||||
* This will cause issues if people reload a package with different
|
* This will cause issues if people reload a package with different
|
||||||
@@ -118,60 +133,22 @@ public class MonkeySourceNetworkViews {
|
|||||||
return klass;
|
return klass;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPositionFromNode(AccessibilityNodeInfo node) {
|
|
||||||
Rect nodePosition = new Rect();
|
|
||||||
node.getBoundsInScreen(nodePosition);
|
|
||||||
StringBuilder positions = new StringBuilder();
|
|
||||||
positions.append(nodePosition.left).append(" ").append(nodePosition.top);
|
|
||||||
positions.append(" ").append(nodePosition.right-nodePosition.left).append(" ");
|
|
||||||
positions.append(nodePosition.bottom-nodePosition.top);
|
|
||||||
return positions.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a resource identifier into it's generated integer ID
|
|
||||||
*
|
|
||||||
* @param stringId the string identifier
|
|
||||||
* @return the generated integer identifier.
|
|
||||||
*/
|
|
||||||
private static int getId(String stringId, AccessibilityEvent event)
|
|
||||||
throws MonkeyViewException {
|
|
||||||
try {
|
|
||||||
AccessibilityNodeInfo node = event.getSource();
|
|
||||||
String packageName = node.getPackageName().toString();
|
|
||||||
ApplicationInfo appInfo = sPm.getApplicationInfo(packageName, 0, UserHandle.myUserId());
|
|
||||||
Class<?> klass;
|
|
||||||
klass = getIdClass(packageName, appInfo.sourceDir);
|
|
||||||
return klass.getField(stringId).getInt(null);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw new MonkeyViewException(REMOTE_ERROR);
|
|
||||||
} catch (ClassNotFoundException e){
|
|
||||||
throw new MonkeyViewException(e.getMessage());
|
|
||||||
} catch (NoSuchFieldException e){
|
|
||||||
throw new MonkeyViewException("No such node with given id");
|
|
||||||
} catch (IllegalAccessException e){
|
|
||||||
throw new MonkeyViewException("Private identifier");
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
// AccessibilityServiceConnection throws a NullPointerException if you hand it
|
|
||||||
// an ID that doesn't exist onscreen
|
|
||||||
throw new MonkeyViewException("No node with given id exists onscreen");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AccessibilityNodeInfo getNodeByAccessibilityIds(
|
private static AccessibilityNodeInfo getNodeByAccessibilityIds(
|
||||||
String windowString, String viewString) {
|
String windowString, String viewString) {
|
||||||
int windowId = Integer.parseInt(windowString);
|
int windowId = Integer.parseInt(windowString);
|
||||||
int viewId = Integer.parseInt(viewString);
|
int viewId = Integer.parseInt(viewString);
|
||||||
return sUiTestAutomationBridge.findAccessibilityNodeInfoByAccessibilityId(windowId,
|
int connectionId = sUiTestAutomationBridge.getConnectionId();
|
||||||
viewId);
|
AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance();
|
||||||
|
return client.findAccessibilityNodeInfoByAccessibilityId(connectionId, windowId, viewId, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AccessibilityNodeInfo getNodeByViewId(String viewId, AccessibilityEvent event)
|
private static AccessibilityNodeInfo getNodeByViewId(String viewId) throws MonkeyViewException {
|
||||||
throws MonkeyViewException {
|
int connectionId = sUiTestAutomationBridge.getConnectionId();
|
||||||
int id = getId(viewId, event);
|
AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance();
|
||||||
return sUiTestAutomationBridge.findAccessibilityNodeInfoByViewId(
|
List<AccessibilityNodeInfo> infos = client.findAccessibilityNodeInfosByViewId(
|
||||||
UiTestAutomationBridge.ACTIVE_WINDOW_ID, UiTestAutomationBridge.ROOT_NODE_ID, id);
|
connectionId, AccessibilityNodeInfo.ACTIVE_WINDOW_ID,
|
||||||
|
AccessibilityNodeInfo.ROOT_NODE_ID, viewId);
|
||||||
|
return (!infos.isEmpty()) ? infos.get(0) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,11 +159,7 @@ public class MonkeySourceNetworkViews {
|
|||||||
//listviews
|
//listviews
|
||||||
public MonkeyCommandReturn translateCommand(List<String> command,
|
public MonkeyCommandReturn translateCommand(List<String> command,
|
||||||
CommandQueue queue) {
|
CommandQueue queue) {
|
||||||
AccessibilityEvent lastEvent = sUiTestAutomationBridge.getLastAccessibilityEvent();
|
AccessibilityNodeInfo node = sUiTestAutomationBridge.getRootInActiveWindow();
|
||||||
if (lastEvent == null) {
|
|
||||||
return new MonkeyCommandReturn(false, NO_ACCESSIBILITY_EVENT);
|
|
||||||
}
|
|
||||||
AccessibilityNodeInfo node = lastEvent.getSource();
|
|
||||||
/* Occasionally the API will generate an event with no source, which is essentially the
|
/* Occasionally the API will generate an event with no source, which is essentially the
|
||||||
* same as it generating no event at all */
|
* same as it generating no event at all */
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
@@ -195,7 +168,8 @@ public class MonkeySourceNetworkViews {
|
|||||||
String packageName = node.getPackageName().toString();
|
String packageName = node.getPackageName().toString();
|
||||||
try{
|
try{
|
||||||
Class<?> klass;
|
Class<?> klass;
|
||||||
ApplicationInfo appInfo = sPm.getApplicationInfo(packageName, 0, UserHandle.myUserId());
|
ApplicationInfo appInfo = sPm.getApplicationInfo(packageName, 0,
|
||||||
|
UserHandle.myUserId());
|
||||||
klass = getIdClass(packageName, appInfo.sourceDir);
|
klass = getIdClass(packageName, appInfo.sourceDir);
|
||||||
StringBuilder fieldBuilder = new StringBuilder();
|
StringBuilder fieldBuilder = new StringBuilder();
|
||||||
Field[] fields = klass.getFields();
|
Field[] fields = klass.getFields();
|
||||||
@@ -222,20 +196,13 @@ public class MonkeySourceNetworkViews {
|
|||||||
public MonkeyCommandReturn translateCommand(List<String> command,
|
public MonkeyCommandReturn translateCommand(List<String> command,
|
||||||
CommandQueue queue) {
|
CommandQueue queue) {
|
||||||
if (command.size() > 2) {
|
if (command.size() > 2) {
|
||||||
if (!sUiTestAutomationBridge.isConnected()) {
|
|
||||||
return new MonkeyCommandReturn(false, NO_CONNECTION);
|
|
||||||
}
|
|
||||||
AccessibilityEvent lastEvent = sUiTestAutomationBridge.getLastAccessibilityEvent();
|
|
||||||
if (lastEvent == null) {
|
|
||||||
return new MonkeyCommandReturn(false, NO_ACCESSIBILITY_EVENT);
|
|
||||||
}
|
|
||||||
String idType = command.get(1);
|
String idType = command.get(1);
|
||||||
AccessibilityNodeInfo node;
|
AccessibilityNodeInfo node;
|
||||||
String viewQuery;
|
String viewQuery;
|
||||||
List<String> args;
|
List<String> args;
|
||||||
if ("viewid".equals(idType)) {
|
if ("viewid".equals(idType)) {
|
||||||
try {
|
try {
|
||||||
node = getNodeByViewId(command.get(2), lastEvent);
|
node = getNodeByViewId(command.get(2));
|
||||||
viewQuery = command.get(3);
|
viewQuery = command.get(3);
|
||||||
args = command.subList(4, command.size());
|
args = command.subList(4, command.size());
|
||||||
} catch (MonkeyViewException e) {
|
} catch (MonkeyViewException e) {
|
||||||
@@ -273,11 +240,7 @@ public class MonkeySourceNetworkViews {
|
|||||||
// getrootview
|
// getrootview
|
||||||
public MonkeyCommandReturn translateCommand(List<String> command,
|
public MonkeyCommandReturn translateCommand(List<String> command,
|
||||||
CommandQueue queue) {
|
CommandQueue queue) {
|
||||||
AccessibilityEvent lastEvent = sUiTestAutomationBridge.getLastAccessibilityEvent();
|
AccessibilityNodeInfo node = sUiTestAutomationBridge.getRootInActiveWindow();
|
||||||
if (lastEvent == null) {
|
|
||||||
return new MonkeyCommandReturn(false, NO_ACCESSIBILITY_EVENT);
|
|
||||||
}
|
|
||||||
AccessibilityNodeInfo node = lastEvent.getSource();
|
|
||||||
return (new GetAccessibilityIds()).query(node, new ArrayList<String>());
|
return (new GetAccessibilityIds()).query(node, new ArrayList<String>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,14 +255,13 @@ public class MonkeySourceNetworkViews {
|
|||||||
// getviewswithtext "some text here"
|
// getviewswithtext "some text here"
|
||||||
public MonkeyCommandReturn translateCommand(List<String> command,
|
public MonkeyCommandReturn translateCommand(List<String> command,
|
||||||
CommandQueue queue) {
|
CommandQueue queue) {
|
||||||
if (!sUiTestAutomationBridge.isConnected()) {
|
|
||||||
return new MonkeyCommandReturn(false, NO_CONNECTION);
|
|
||||||
}
|
|
||||||
if (command.size() == 2) {
|
if (command.size() == 2) {
|
||||||
String text = command.get(1);
|
String text = command.get(1);
|
||||||
List<AccessibilityNodeInfo> nodes = sUiTestAutomationBridge
|
int connectionId = sUiTestAutomationBridge.getConnectionId();
|
||||||
.findAccessibilityNodeInfosByText(UiTestAutomationBridge.ACTIVE_WINDOW_ID,
|
List<AccessibilityNodeInfo> nodes = AccessibilityInteractionClient.getInstance()
|
||||||
UiTestAutomationBridge.ROOT_NODE_ID, text);
|
.findAccessibilityNodeInfosByText(connectionId,
|
||||||
|
AccessibilityNodeInfo.ACTIVE_WINDOW_ID,
|
||||||
|
AccessibilityNodeInfo.ROOT_NODE_ID, text);
|
||||||
ViewIntrospectionCommand idGetter = new GetAccessibilityIds();
|
ViewIntrospectionCommand idGetter = new GetAccessibilityIds();
|
||||||
List<String> emptyArgs = new ArrayList<String>();
|
List<String> emptyArgs = new ArrayList<String>();
|
||||||
StringBuilder ids = new StringBuilder();
|
StringBuilder ids = new StringBuilder();
|
||||||
|
|||||||
Reference in New Issue
Block a user