aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2011-06-13 09:17:03 -0700
committerMichael Wright <michaelwr@google.com>2011-06-20 14:24:05 -0700
commit8c09f35fe02c38c18f8f7b9e0a531d6ac158476e (patch)
tree3528a0073582805b438e88b8d0014e844d914c41
parent7af6646391705a276b814bf8b45f8874554831fb (diff)
downloadsdk-8c09f35fe02c38c18f8f7b9e0a531d6ac158476e.zip
sdk-8c09f35fe02c38c18f8f7b9e0a531d6ac158476e.tar.gz
sdk-8c09f35fe02c38c18f8f7b9e0a531d6ac158476e.tar.bz2
Refactored MonkeyRunner to use ChimpChat
Change-Id: Icbe5bcb066021d578faae43aa49b58ab1595870b
-rw-r--r--chimpchat/Android.mk1
-rw-r--r--chimpchat/src/com/android/chimpchat/ChimpChat.java58
-rw-r--r--chimpchat/src/com/android/chimpchat/ChimpManager.java4
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/AdbBackend.java8
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java14
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/AdbChimpImage.java2
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/CommandOutputCapture.java2
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/LinearInterpolator.java2
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/LoggingOutputReceiver.java2
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/image/CaptureRawAndConvertedImage.java8
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/image/ImageUtils.java2
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/image/SixteenBitColorModel.java2
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/image/ThirtyTwoBitColorModel.java2
-rw-r--r--chimpchat/src/com/android/chimpchat/core/IChimpBackend.java2
-rw-r--r--chimpchat/src/com/android/chimpchat/core/IChimpDevice.java7
-rw-r--r--chimpchat/src/com/android/chimpchat/core/PhysicalButton.java (renamed from chimpchat/src/com/android/chimpchat/PhysicalButton.java)4
-rw-r--r--chimpchat/test/Android.mk25
-rw-r--r--chimpchat/test/com/android/chimpchat/AllTests.java49
-rw-r--r--chimpchat/test/com/android/chimpchat/ImageUtilsTest.java (renamed from monkeyrunner/test/com/android/monkeyrunner/ImageUtilsTest.java)12
-rw-r--r--chimpchat/test/com/android/chimpchat/adb/AdbChimpDeviceTest.java (renamed from monkeyrunner/test/com/android/monkeyrunner/adb/AdbMonkeyDeviceTest.java)14
-rw-r--r--chimpchat/test/com/android/chimpchat/adb/LinearInterpolatorTest.java (renamed from monkeyrunner/test/com/android/monkeyrunner/adb/LinearInterpolatorTest.java)6
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/adb/instrument_result.txt10
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/adb/multiline_instrument_result.txt15
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/image1.pngbin0 -> 184289 bytes
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/image1.rawbin0 -> 307545 bytes
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/image2.pngbin0 -> 82036 bytes
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/image2.rawbin0 -> 1536345 bytes
-rw-r--r--monkeyrunner/src/Android.mk1
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java27
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/MonkeyImage.java16
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/MonkeyManager.java351
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java31
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java38
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/PhysicalButton.java39
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/AdbBackend.java124
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/AdbMonkeyDevice.java552
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/AdbMonkeyImage.java47
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/CommandOutputCapture.java42
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/LinearInterpolator.java128
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/LoggingOutputReceiver.java47
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/image/CaptureRawAndConvertedImage.java108
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/image/ImageUtils.java100
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/image/SixteenBitColorModel.java95
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/adb/image/ThirtyTwoBitColorModel.java126
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyController.java13
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyControllerFrame.java50
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/controller/VariableFrame.java24
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyBackend.java45
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyDevice.java196
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyImage.java36
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/core/MonkeyImageBase.java219
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/core/TouchPressType.java49
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/easy/By.java19
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/easy/EasyMonkeyDevice.java17
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/easy/HierarchyViewer.java158
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/exceptions/MonkeyRunnerException.java33
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorder.java11
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorderFrame.java10
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/recorder/actions/Action.java4
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/recorder/actions/DragAction.java4
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/recorder/actions/PressAction.java6
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TouchAction.java6
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TypeAction.java4
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/recorder/actions/WaitAction.java4
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/stub/StubBackend.java41
-rw-r--r--monkeyrunner/test/com/android/monkeyrunner/AllTests.java8
66 files changed, 342 insertions, 2738 deletions
diff --git a/chimpchat/Android.mk b/chimpchat/Android.mk
index e284d5d..281b1ea 100644
--- a/chimpchat/Android.mk
+++ b/chimpchat/Android.mk
@@ -15,3 +15,4 @@
#
CHIMPCHAT_LOCAL_DIR := $(call my-dir)
include $(CHIMPCHAT_LOCAL_DIR)/src/Android.mk
+include $(CHIMPCHAT_LOCAL_DIR)/test/Android.mk
diff --git a/chimpchat/src/com/android/chimpchat/ChimpChat.java b/chimpchat/src/com/android/chimpchat/ChimpChat.java
index 1927535..ad9ef0d 100644
--- a/chimpchat/src/com/android/chimpchat/ChimpChat.java
+++ b/chimpchat/src/com/android/chimpchat/ChimpChat.java
@@ -19,8 +19,10 @@ package com.android.chimpchat;
import com.android.chimpchat.adb.AdbBackend;
import com.android.chimpchat.core.IChimpBackend;
+import com.android.chimpchat.core.IChimpDevice;
import java.util.Map;
+import java.util.TreeMap;
/**
* ChimpChat is a host-side library that provides an API for communication with
@@ -30,6 +32,7 @@ import java.util.Map;
*/
public class ChimpChat {
private final IChimpBackend mBackend;
+ private static String sAdbLocation;
private ChimpChat(IChimpBackend backend) {
this.mBackend = backend;
@@ -38,10 +41,11 @@ public class ChimpChat {
/**
* Generates a new instance of ChimpChat based on the options passed.
* @param options a map of settings for the new ChimpChat instance
- * @return a new instance of ChimpChat or null if there was an issue setting up the backend
+ * @return a new instance of ChimpChat or null if errors occur during creation
*/
public static ChimpChat getInstance(Map<String, String> options) {
- IChimpBackend backend = ChimpChat.createBackendByName(options.get("backend"));
+ sAdbLocation = options.get("adbLocation");
+ IChimpBackend backend = createBackendByName(options.get("backend"));
if (backend == null) {
return null;
}
@@ -49,12 +53,58 @@ public class ChimpChat {
return chimpchat;
}
+ /** Generates a new instance of ChimpChat using default settings
+ * @return a new instance of ChimpChat or null if errors occur during creation
+ */
+ public static ChimpChat getInstance() {
+ Map<String, String> options = new TreeMap<String, String>();
+ options.put("backend", "adb");
+ return ChimpChat.getInstance(options);
+ }
+
- public static IChimpBackend createBackendByName(String backendName) {
+ /**
+ * Creates a specific backend by name.
+ *
+ * @param backendName the name of the backend to create
+ * @return the new backend, or null if none were found.
+ */
+
+ private static IChimpBackend createBackendByName(String backendName) {
if ("adb".equals(backendName)) {
- return new AdbBackend();
+ if (sAdbLocation == null) {
+ return new AdbBackend();
+ } else {
+ return new AdbBackend(sAdbLocation);
+ }
} else {
return null;
}
}
+
+ /**
+ * Retrieves an instance of the device from the backend
+ * @param timeoutMs length of time to wait before timing out
+ * @param deviceId the id of the device you want to connect to
+ * @return an instance of the device
+ */
+ public IChimpDevice waitForConnection(long timeoutMs, String deviceId){
+ return mBackend.waitForConnection(timeoutMs, deviceId);
+ }
+
+ /**
+ * Retrieves an instance of the device from the backend.
+ * Defaults to the longest possible wait time and any available device.
+ * @return an instance of the device
+ */
+ public IChimpDevice waitForConnection(){
+ return mBackend.waitForConnection(Integer.MAX_VALUE, ".*");
+ }
+
+ /**
+ * Shutdown and clean up chimpchat.
+ */
+ public void shutdown(){
+ mBackend.shutdown();
+ }
}
diff --git a/chimpchat/src/com/android/chimpchat/ChimpManager.java b/chimpchat/src/com/android/chimpchat/ChimpManager.java
index a858e6a..c68b7df 100644
--- a/chimpchat/src/com/android/chimpchat/ChimpManager.java
+++ b/chimpchat/src/com/android/chimpchat/ChimpManager.java
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
@@ -18,6 +18,8 @@ package com.android.chimpchat;
import com.google.common.collect.Lists;
+import com.android.chimpchat.core.PhysicalButton;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
diff --git a/chimpchat/src/com/android/chimpchat/adb/AdbBackend.java b/chimpchat/src/com/android/chimpchat/adb/AdbBackend.java
index e2f9ca0..9354737 100644
--- a/chimpchat/src/com/android/chimpchat/adb/AdbBackend.java
+++ b/chimpchat/src/com/android/chimpchat/adb/AdbBackend.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
@@ -49,6 +49,12 @@ public class AdbBackend implements IChimpBackend {
adbLocation, true /* forceNewBridge */);
}
+ public AdbBackend(String location) {
+ AndroidDebugBridge.init(false /* debugger support */);
+ bridge = AndroidDebugBridge.createBridge(location,
+ true /* force new bridge */);
+ }
+
private String findAdb() {
File location =
new File(AdbBackend.class.getProtectionDomain().getCodeSource().getLocation().getPath());
diff --git a/chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java b/chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java
index 5b70148..cfc0755 100644
--- a/chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java
+++ b/chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
@@ -80,6 +80,8 @@ public class AdbChimpDevice implements IChimpDevice {
} catch (IOException e) {
LOG.log(Level.SEVERE, "Error getting the manager to quit", e);
}
+ manager.close();
+ executor.shutdown();
manager = null;
}
@@ -228,6 +230,16 @@ public class AdbChimpDevice implements IChimpDevice {
}
@Override
+ public Collection<String> getPropertyList() {
+ try {
+ return manager.listVariable();
+ } catch (IOException e) {
+ LOG.log(Level.SEVERE, "Unable to get variable list", e);
+ return null;
+ }
+ }
+
+ @Override
public void wake() {
try {
manager.wake();
diff --git a/chimpchat/src/com/android/chimpchat/adb/AdbChimpImage.java b/chimpchat/src/com/android/chimpchat/adb/AdbChimpImage.java
index 2d41600..f37896f 100644
--- a/chimpchat/src/com/android/chimpchat/adb/AdbChimpImage.java
+++ b/chimpchat/src/com/android/chimpchat/adb/AdbChimpImage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
diff --git a/chimpchat/src/com/android/chimpchat/adb/CommandOutputCapture.java b/chimpchat/src/com/android/chimpchat/adb/CommandOutputCapture.java
index eadd697..736e82f 100644
--- a/chimpchat/src/com/android/chimpchat/adb/CommandOutputCapture.java
+++ b/chimpchat/src/com/android/chimpchat/adb/CommandOutputCapture.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
diff --git a/chimpchat/src/com/android/chimpchat/adb/LinearInterpolator.java b/chimpchat/src/com/android/chimpchat/adb/LinearInterpolator.java
index 708007d..934749a 100644
--- a/chimpchat/src/com/android/chimpchat/adb/LinearInterpolator.java
+++ b/chimpchat/src/com/android/chimpchat/adb/LinearInterpolator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
diff --git a/chimpchat/src/com/android/chimpchat/adb/LoggingOutputReceiver.java b/chimpchat/src/com/android/chimpchat/adb/LoggingOutputReceiver.java
index e318a01..e1002d1 100644
--- a/chimpchat/src/com/android/chimpchat/adb/LoggingOutputReceiver.java
+++ b/chimpchat/src/com/android/chimpchat/adb/LoggingOutputReceiver.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
diff --git a/chimpchat/src/com/android/chimpchat/adb/image/CaptureRawAndConvertedImage.java b/chimpchat/src/com/android/chimpchat/adb/image/CaptureRawAndConvertedImage.java
index 2b700ea..6327a77 100644
--- a/chimpchat/src/com/android/chimpchat/adb/image/CaptureRawAndConvertedImage.java
+++ b/chimpchat/src/com/android/chimpchat/adb/image/CaptureRawAndConvertedImage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
@@ -32,7 +32,7 @@ import java.io.Serializable;
* This is used to generate the test data for ImageUtilsTest.
*/
public class CaptureRawAndConvertedImage {
- public static class ChimpRunnerRawImage implements Serializable {
+ public static class ChimpRawImage implements Serializable {
public int version;
public int bpp;
public int size;
@@ -49,7 +49,7 @@ public class CaptureRawAndConvertedImage {
public byte[] data;
- public ChimpRunnerRawImage(RawImage rawImage) {
+ public ChimpRawImage(RawImage rawImage) {
version = rawImage.version;
bpp = rawImage.bpp;
size = rawImage.size;
@@ -91,7 +91,7 @@ public class CaptureRawAndConvertedImage {
private static void writeOutImage(RawImage screenshot, String name) throws IOException {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(name));
- out.writeObject(new ChimpRunnerRawImage(screenshot));
+ out.writeObject(new ChimpRawImage(screenshot));
out.close();
}
diff --git a/chimpchat/src/com/android/chimpchat/adb/image/ImageUtils.java b/chimpchat/src/com/android/chimpchat/adb/image/ImageUtils.java
index 39ec533..131c9ef 100644
--- a/chimpchat/src/com/android/chimpchat/adb/image/ImageUtils.java
+++ b/chimpchat/src/com/android/chimpchat/adb/image/ImageUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
diff --git a/chimpchat/src/com/android/chimpchat/adb/image/SixteenBitColorModel.java b/chimpchat/src/com/android/chimpchat/adb/image/SixteenBitColorModel.java
index 1a1fbd9..ad1392f 100644
--- a/chimpchat/src/com/android/chimpchat/adb/image/SixteenBitColorModel.java
+++ b/chimpchat/src/com/android/chimpchat/adb/image/SixteenBitColorModel.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
diff --git a/chimpchat/src/com/android/chimpchat/adb/image/ThirtyTwoBitColorModel.java b/chimpchat/src/com/android/chimpchat/adb/image/ThirtyTwoBitColorModel.java
index dda43dc..d4e8c9e 100644
--- a/chimpchat/src/com/android/chimpchat/adb/image/ThirtyTwoBitColorModel.java
+++ b/chimpchat/src/com/android/chimpchat/adb/image/ThirtyTwoBitColorModel.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
diff --git a/chimpchat/src/com/android/chimpchat/core/IChimpBackend.java b/chimpchat/src/com/android/chimpchat/core/IChimpBackend.java
index 092b849..ac9353d 100644
--- a/chimpchat/src/com/android/chimpchat/core/IChimpBackend.java
+++ b/chimpchat/src/com/android/chimpchat/core/IChimpBackend.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
diff --git a/chimpchat/src/com/android/chimpchat/core/IChimpDevice.java b/chimpchat/src/com/android/chimpchat/core/IChimpDevice.java
index 7ba09c8..03dc09d 100644
--- a/chimpchat/src/com/android/chimpchat/core/IChimpDevice.java
+++ b/chimpchat/src/com/android/chimpchat/core/IChimpDevice.java
@@ -60,6 +60,13 @@ public interface IChimpDevice {
void reboot(@Nullable String into);
/**
+ * List properties of the device that we can inspect
+ *
+ * @return the list of property keys
+ */
+ Collection<String> getPropertyList();
+
+ /**
* Get device's property.
*
* @param key the property name
diff --git a/chimpchat/src/com/android/chimpchat/PhysicalButton.java b/chimpchat/src/com/android/chimpchat/core/PhysicalButton.java
index 9363c08..1da571e 100644
--- a/chimpchat/src/com/android/chimpchat/PhysicalButton.java
+++ b/chimpchat/src/com/android/chimpchat/core/PhysicalButton.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.chimpchat;
+package com.android.chimpchat.core;
public enum PhysicalButton {
HOME("home"),
diff --git a/chimpchat/test/Android.mk b/chimpchat/test/Android.mk
new file mode 100644
index 0000000..7b6698d
--- /dev/null
+++ b/chimpchat/test/Android.mk
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+LOCAL_MODULE := chimpchattest
+LOCAL_JAVA_LIBRARIES := junit chimpchat ddmlib guavalib
+
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/chimpchat/test/com/android/chimpchat/AllTests.java b/chimpchat/test/com/android/chimpchat/AllTests.java
new file mode 100644
index 0000000..9f647e3
--- /dev/null
+++ b/chimpchat/test/com/android/chimpchat/AllTests.java
@@ -0,0 +1,49 @@
+/*
+ * 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 com.android.chimpchat;
+
+import com.android.chimpchat.adb.AdbChimpDeviceTest;
+import com.android.chimpchat.adb.LinearInterpolatorTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Test suite to run all the tests for MonkeyRunner.
+ */
+public class AllTests {
+ public static Test suite(Class<? extends TestCase>... classes) {
+ TestSuite suite = new TestSuite();
+ for (Class<? extends TestCase> clz : classes) {
+ suite.addTestSuite(clz);
+ }
+ return suite;
+ }
+
+ public static void main(String args[]) {
+ TestRunner tr = new TestRunner();
+ TestResult result = tr.doRun(AllTests.suite(ImageUtilsTest.class,
+ LinearInterpolatorTest.class, AdbChimpDeviceTest.class));
+ if (result.wasSuccessful()) {
+ System.exit(0);
+ } else {
+ System.exit(1);
+ }
+ }
+}
diff --git a/monkeyrunner/test/com/android/monkeyrunner/ImageUtilsTest.java b/chimpchat/test/com/android/chimpchat/ImageUtilsTest.java
index f07c2f3..19dc4ed 100644
--- a/monkeyrunner/test/com/android/monkeyrunner/ImageUtilsTest.java
+++ b/chimpchat/test/com/android/chimpchat/ImageUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.monkeyrunner;
+package com.android.chimpchat;
import com.android.ddmlib.RawImage;
-import com.android.monkeyrunner.adb.image.CaptureRawAndConvertedImage;
-import com.android.monkeyrunner.adb.image.ImageUtils;
-import com.android.monkeyrunner.adb.image.CaptureRawAndConvertedImage.MonkeyRunnerRawImage;
+import com.android.chimpchat.adb.image.CaptureRawAndConvertedImage;
+import com.android.chimpchat.adb.image.ImageUtils;
+import com.android.chimpchat.adb.image.CaptureRawAndConvertedImage.ChimpRawImage;
import junit.framework.TestCase;
@@ -41,7 +41,7 @@ public class ImageUtilsTest extends TestCase {
private static RawImage createRawImage(String name) throws IOException, ClassNotFoundException {
ObjectInputStream is =
new ObjectInputStream(ImageUtilsTest.class.getResourceAsStream(name));
- CaptureRawAndConvertedImage.MonkeyRunnerRawImage wrapper = (MonkeyRunnerRawImage) is.readObject();
+ CaptureRawAndConvertedImage.ChimpRawImage wrapper = (ChimpRawImage) is.readObject();
is.close();
return wrapper.toRawImage();
}
diff --git a/monkeyrunner/test/com/android/monkeyrunner/adb/AdbMonkeyDeviceTest.java b/chimpchat/test/com/android/chimpchat/adb/AdbChimpDeviceTest.java
index 258e184..482941a 100644
--- a/monkeyrunner/test/com/android/monkeyrunner/adb/AdbMonkeyDeviceTest.java
+++ b/chimpchat/test/com/android/chimpchat/adb/AdbChimpDeviceTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.monkeyrunner.adb;
+package com.android.chimpchat.adb;
import com.google.common.base.Joiner;
import com.google.common.io.Resources;
@@ -27,9 +27,9 @@ import java.util.List;
import java.util.Map;
/**
- * Unit Tests for AdbMonkeyDevice.
+ * Unit Tests for AdbChimpDevice.
*/
-public class AdbMonkeyDeviceTest extends TestCase {
+public class AdbChimpDeviceTest extends TestCase {
private static String MULTILINE_RESULT = "\r\n" +
"Test results for InstrumentationTestRunner=.\r\n" +
"Time: 2.242\r\n" +
@@ -37,14 +37,14 @@ public class AdbMonkeyDeviceTest extends TestCase {
"OK (1 test)";
private static String getResource(String resName) throws IOException {
- URL resource = Resources.getResource(AdbMonkeyDeviceTest.class, resName);
+ URL resource = Resources.getResource(AdbChimpDeviceTest.class, resName);
List<String> lines = Resources.readLines(resource, Charset.defaultCharset());
return Joiner.on("\r\n").join(lines);
}
public void testSimpleResultParse() throws IOException {
String result = getResource("instrument_result.txt");
- Map<String, Object> convertedResult = AdbMonkeyDevice.convertInstrumentResult(result);
+ Map<String, Object> convertedResult = AdbChimpDevice.convertInstrumentResult(result);
assertEquals("one", convertedResult.get("result1"));
assertEquals("two", convertedResult.get("result2"));
@@ -52,7 +52,7 @@ public class AdbMonkeyDeviceTest extends TestCase {
public void testMultilineResultParse() throws IOException {
String result = getResource("multiline_instrument_result.txt");
- Map<String, Object> convertedResult = AdbMonkeyDevice.convertInstrumentResult(result);
+ Map<String, Object> convertedResult = AdbChimpDevice.convertInstrumentResult(result);
assertEquals(MULTILINE_RESULT, convertedResult.get("stream"));
}
diff --git a/monkeyrunner/test/com/android/monkeyrunner/adb/LinearInterpolatorTest.java b/chimpchat/test/com/android/chimpchat/adb/LinearInterpolatorTest.java
index 00670ce..f9bc72f 100644
--- a/monkeyrunner/test/com/android/monkeyrunner/adb/LinearInterpolatorTest.java
+++ b/chimpchat/test/com/android/chimpchat/adb/LinearInterpolatorTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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.
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.monkeyrunner.adb;
+package com.android.chimpchat.adb;
import com.google.common.collect.Lists;
-import com.android.monkeyrunner.adb.LinearInterpolator.Point;
+import com.android.chimpchat.adb.LinearInterpolator.Point;
import junit.framework.TestCase;
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/adb/instrument_result.txt b/chimpchat/test/resources/com/android/monkeyrunner/adb/instrument_result.txt
new file mode 100644
index 0000000..c127c0f
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/adb/instrument_result.txt
@@ -0,0 +1,10 @@
+INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
+INSTRUMENTATION_STATUS: current=1
+INSTRUMENTATION_STATUS: class=com.example.android.notepad.NotePadTest
+INSTRUMENTATION_STATUS: stream=.
+INSTRUMENTATION_STATUS: numtests=1
+INSTRUMENTATION_STATUS: test=testActivityTestCaseSetUpProperly
+INSTRUMENTATION_STATUS_CODE: 0
+INSTRUMENTATION_RESULT: result1=one
+INSTRUMENTATION_RESULT: result2=two
+INSTRUMENTATION_CODE: -1
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/adb/multiline_instrument_result.txt b/chimpchat/test/resources/com/android/monkeyrunner/adb/multiline_instrument_result.txt
new file mode 100644
index 0000000..32fd901
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/adb/multiline_instrument_result.txt
@@ -0,0 +1,15 @@
+INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
+INSTRUMENTATION_STATUS: current=1
+INSTRUMENTATION_STATUS: class=com.example.android.notepad.NotePadTest
+INSTRUMENTATION_STATUS: stream=.
+INSTRUMENTATION_STATUS: numtests=1
+INSTRUMENTATION_STATUS: test=testActivityTestCaseSetUpProperly
+INSTRUMENTATION_STATUS_CODE: 0
+INSTRUMENTATION_RESULT: stream=
+Test results for InstrumentationTestRunner=.
+Time: 2.242
+
+OK (1 test)
+
+
+INSTRUMENTATION_CODE: -1
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/image1.png b/chimpchat/test/resources/com/android/monkeyrunner/image1.png
new file mode 100644
index 0000000..9ef1800
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/image1.png
Binary files differ
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/image1.raw b/chimpchat/test/resources/com/android/monkeyrunner/image1.raw
new file mode 100644
index 0000000..99ec013
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/image1.raw
Binary files differ
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/image2.png b/chimpchat/test/resources/com/android/monkeyrunner/image2.png
new file mode 100644
index 0000000..03ff0c1
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/image2.png
Binary files differ
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/image2.raw b/chimpchat/test/resources/com/android/monkeyrunner/image2.raw
new file mode 100644
index 0000000..06e5b47
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/image2.raw
Binary files differ
diff --git a/monkeyrunner/src/Android.mk b/monkeyrunner/src/Android.mk
index 8cca0bc..b151bfc 100644
--- a/monkeyrunner/src/Android.mk
+++ b/monkeyrunner/src/Android.mk
@@ -20,6 +20,7 @@ LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_JAR_MANIFEST := ../etc/manifest.txt
LOCAL_JAVA_LIBRARIES := \
+ chimpchat \
ddmlib \
jython \
guavalib \
diff --git a/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java b/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java
index 100da68..61e92a0 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java
@@ -19,11 +19,13 @@ import com.google.common.base.Functions;
import com.google.common.base.Preconditions;
import com.google.common.collect.Collections2;
-import com.android.monkeyrunner.core.IMonkeyDevice;
-import com.android.monkeyrunner.core.IMonkeyImage;
-import com.android.monkeyrunner.core.TouchPressType;
+import com.android.chimpchat.ChimpChat;
+import com.android.chimpchat.core.IChimpDevice;
+import com.android.chimpchat.core.IChimpImage;
+import com.android.chimpchat.core.TouchPressType;
+import com.android.chimpchat.hierarchyviewer.HierarchyViewer;
+
import com.android.monkeyrunner.doc.MonkeyRunnerExported;
-import com.android.monkeyrunner.easy.HierarchyViewer;
import org.python.core.ArgParser;
import org.python.core.ClassDictInit;
@@ -60,13 +62,13 @@ public class MonkeyDevice extends PyObject implements ClassDictInit {
@MonkeyRunnerExported(doc = "Sends a DOWN event, immediately followed by an UP event when used with touch() or press()")
public static final String DOWN_AND_UP = TouchPressType.DOWN_AND_UP.getIdentifier();
- private IMonkeyDevice impl;
+ private IChimpDevice impl;
- public MonkeyDevice(IMonkeyDevice impl) {
+ public MonkeyDevice(IChimpDevice impl) {
this.impl = impl;
}
- public IMonkeyDevice getImpl() {
+ public IChimpDevice getImpl() {
return impl;
}
@@ -80,7 +82,7 @@ public class MonkeyDevice extends PyObject implements ClassDictInit {
"Gets the device's screen buffer, yielding a screen capture of the entire display.",
returns = "A MonkeyImage object (a bitmap wrapper)")
public MonkeyImage takeSnapshot() {
- IMonkeyImage image = impl.takeSnapshot();
+ IChimpImage image = impl.takeSnapshot();
return new MonkeyImage(image);
}
@@ -175,10 +177,17 @@ public class MonkeyDevice extends PyObject implements ClassDictInit {
Preconditions.checkNotNull(ap);
String name = ap.getString(0);
+ String touchType = ap.getString(1);
+
+ // The old docs had this string, and so in favor of maintaining
+ // backwards compatibility, let's special case it to the new one.
+ if (touchType.equals("DOWN_AND_UP")){
+ touchType = "downAndUp";
+ }
TouchPressType type = TouchPressType.fromIdentifier(ap.getString(1));
if (type == null) {
LOG.warning(String.format("Invalid TouchPressType specified (%s) default used instead",
- ap.getString(2)));
+ ap.getString(1)));
type = TouchPressType.DOWN_AND_UP;
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/MonkeyImage.java b/monkeyrunner/src/com/android/monkeyrunner/MonkeyImage.java
index b55b4f3..4480c22 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/MonkeyImage.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/MonkeyImage.java
@@ -17,7 +17,7 @@ package com.android.monkeyrunner;
import com.google.common.base.Preconditions;
-import com.android.monkeyrunner.core.IMonkeyImage;
+import com.android.chimpchat.core.IChimpImage;
import com.android.monkeyrunner.doc.MonkeyRunnerExported;
import org.python.core.ArgParser;
@@ -40,13 +40,13 @@ public class MonkeyImage extends PyObject implements ClassDictInit {
JythonUtils.convertDocAnnotationsForClass(MonkeyImage.class, dict);
}
- private IMonkeyImage impl;
+ private IChimpImage impl;
- public MonkeyImage(IMonkeyImage impl) {
+ public MonkeyImage(IChimpImage impl) {
this.impl = impl;
}
- public IMonkeyImage getImpl() {
+ public IChimpImage getImpl() {
return impl;
}
@@ -135,8 +135,8 @@ public class MonkeyImage extends PyObject implements ClassDictInit {
PyObject otherObject = ap.getPyObject(0);
// TODO: check if this conversion wortks
- IMonkeyImage other = (IMonkeyImage) otherObject.__tojava__(
- IMonkeyImage.class);
+ IChimpImage other = (IChimpImage) otherObject.__tojava__(
+ IChimpImage.class);
double percent = JythonUtils.getFloat(ap, 1, 1.0);
@@ -159,7 +159,7 @@ public class MonkeyImage extends PyObject implements ClassDictInit {
int w = rect.__getitem__(2).asInt();
int h = rect.__getitem__(3).asInt();
- IMonkeyImage image = impl.getSubImage(x, y, w, h);
+ IChimpImage image = impl.getSubImage(x, y, w, h);
return new MonkeyImage(image);
}
-} \ No newline at end of file
+}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/MonkeyManager.java b/monkeyrunner/src/com/android/monkeyrunner/MonkeyManager.java
deleted file mode 100644
index 11a2dd4..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/MonkeyManager.java
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner;
-
-import com.google.common.collect.Lists;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.net.Socket;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.StringTokenizer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Provides a nicer interface to interacting with the low-level network access protocol for talking
- * to the monkey.
- *
- * This class is thread-safe and can handle being called from multiple threads.
- */
-public class MonkeyManager {
- private static Logger LOG = Logger.getLogger(MonkeyManager.class.getName());
-
- private Socket monkeySocket;
- private BufferedWriter monkeyWriter;
- private BufferedReader monkeyReader;
-
- /**
- * Create a new MonkeyMananger to talk to the specified device.
- *
- * @param monkeySocket the already connected socket on which to send protocol messages.
- */
- public MonkeyManager(Socket monkeySocket) {
- try {
- this.monkeySocket = monkeySocket;
- monkeyWriter = new BufferedWriter(new OutputStreamWriter(monkeySocket.getOutputStream()));
- monkeyReader = new BufferedReader(new InputStreamReader(monkeySocket.getInputStream()));
- } catch(IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Send a touch down event at the specified location.
- *
- * @param x the x coordinate of where to click
- * @param y the y coordinate of where to click
- * @return success or not
- * @throws IOException on error communicating with the device
- */
- public boolean touchDown(int x, int y) throws IOException {
- return sendMonkeyEvent("touch down " + x + " " + y);
- }
-
- /**
- * Send a touch down event at the specified location.
- *
- * @param x the x coordinate of where to click
- * @param y the y coordinate of where to click
- * @return success or not
- * @throws IOException on error communicating with the device
- */
- public boolean touchUp(int x, int y) throws IOException {
- return sendMonkeyEvent("touch up " + x + " " + y);
- }
-
- /**
- * Send a touch move event at the specified location.
- *
- * @param x the x coordinate of where to click
- * @param y the y coordinate of where to click
- * @return success or not
- * @throws IOException on error communicating with the device
- */
- public boolean touchMove(int x, int y) throws IOException {
- return sendMonkeyEvent("touch move " + x + " " + y);
- }
-
- /**
- * Send a touch (down and then up) event at the specified location.
- *
- * @param x the x coordinate of where to click
- * @param y the y coordinate of where to click
- * @return success or not
- * @throws IOException on error communicating with the device
- */
- public boolean touch(int x, int y) throws IOException {
- return sendMonkeyEvent("tap " + x + " " + y);
- }
-
- /**
- * Press a physical button on the device.
- *
- * @param name the name of the button (As specified in the protocol)
- * @return success or not
- * @throws IOException on error communicating with the device
- */
- public boolean press(String name) throws IOException {
- return sendMonkeyEvent("press " + name);
- }
-
- /**
- * Send a Key Down event for the specified button.
- *
- * @param name the name of the button (As specified in the protocol)
- * @return success or not
- * @throws IOException on error communicating with the device
- */
- public boolean keyDown(String name) throws IOException {
- return sendMonkeyEvent("key down " + name);
- }
-
- /**
- * Send a Key Up event for the specified button.
- *
- * @param name the name of the button (As specified in the protocol)
- * @return success or not
- * @throws IOException on error communicating with the device
- */
- public boolean keyUp(String name) throws IOException {
- return sendMonkeyEvent("key up " + name);
- }
-
- /**
- * Press a physical button on the device.
- *
- * @param button the button to press
- * @return success or not
- * @throws IOException on error communicating with the device
- */
- public boolean press(PhysicalButton button) throws IOException {
- return press(button.getKeyName());
- }
-
- /**
- * This function allows the communication bridge between the host and the device
- * to be invisible to the script for internal needs.
- * It splits a command into monkey events and waits for responses for each over an adb tcp socket.
- * Returns on an error, else continues and sets up last response.
- *
- * @param command the monkey command to send to the device
- * @return the (unparsed) response returned from the monkey.
- */
- private String sendMonkeyEventAndGetResponse(String command) throws IOException {
- command = command.trim();
- LOG.info("Monkey Command: " + command + ".");
-
- // send a single command and get the response
- monkeyWriter.write(command + "\n");
- monkeyWriter.flush();
- return monkeyReader.readLine();
- }
-
- /**
- * Parse a monkey response string to see if the command succeeded or not.
- *
- * @param monkeyResponse the response
- * @return true if response code indicated success.
- */
- private boolean parseResponseForSuccess(String monkeyResponse) {
- if (monkeyResponse == null) {
- return false;
- }
- // return on ok
- if(monkeyResponse.startsWith("OK")) {
- return true;
- }
-
- return false;
- }
-
- /**
- * Parse a monkey response string to get the extra data returned.
- *
- * @param monkeyResponse the response
- * @return any extra data that was returned, or empty string if there was nothing.
- */
- private String parseResponseForExtra(String monkeyResponse) {
- int offset = monkeyResponse.indexOf(':');
- if (offset < 0) {
- return "";
- }
- return monkeyResponse.substring(offset + 1);
- }
-
- /**
- * This function allows the communication bridge between the host and the device
- * to be invisible to the script for internal needs.
- * It splits a command into monkey events and waits for responses for each over an
- * adb tcp socket.
- *
- * @param command the monkey command to send to the device
- * @return true on success.
- */
- private boolean sendMonkeyEvent(String command) throws IOException {
- synchronized (this) {
- String monkeyResponse = sendMonkeyEventAndGetResponse(command);
- return parseResponseForSuccess(monkeyResponse);
- }
- }
-
- /**
- * Close all open resources related to this device.
- */
- public void close() {
- try {
- monkeySocket.close();
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Unable to close monkeySocket", e);
- }
- try {
- monkeyReader.close();
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Unable to close monkeyReader", e);
- }
- try {
- monkeyWriter.close();
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Unable to close monkeyWriter", e);
- }
- }
-
- /**
- * Function to get a static variable from the device.
- *
- * @param name name of static variable to get
- * @return the value of the variable, or null if there was an error
- */
- public String getVariable(String name) throws IOException {
- synchronized (this) {
- String response = sendMonkeyEventAndGetResponse("getvar " + name);
- if (!parseResponseForSuccess(response)) {
- return null;
- }
- return parseResponseForExtra(response);
- }
- }
-
- /**
- * Function to get the list of static variables from the device.
- */
- public Collection<String> listVariable() throws IOException {
- synchronized (this) {
- String response = sendMonkeyEventAndGetResponse("listvar");
- if (!parseResponseForSuccess(response)) {
- Collections.emptyList();
- }
- String extras = parseResponseForExtra(response);
- return Lists.newArrayList(extras.split(" "));
- }
- }
-
- /**
- * Tells the monkey that we are done for this session.
- * @throws IOException
- */
- public void done() throws IOException {
- // this command just drops the connection, so handle it here
- synchronized (this) {
- sendMonkeyEventAndGetResponse("done");
- }
- }
-
- /**
- * Tells the monkey that we are done forever.
- * @throws IOException
- */
- public void quit() throws IOException {
- // this command drops the connection, so handle it here
- synchronized (this) {
- sendMonkeyEventAndGetResponse("quit");
- }
- }
-
- /**
- * Send a tap event at the specified location.
- *
- * @param x the x coordinate of where to click
- * @param y the y coordinate of where to click
- * @return success or not
- * @throws IOException
- * @throws IOException on error communicating with the device
- */
- public boolean tap(int x, int y) throws IOException {
- return sendMonkeyEvent("tap " + x + " " + y);
- }
-
- /**
- * Type the following string to the monkey.
- *
- * @param text the string to type
- * @return success
- * @throws IOException
- */
- public boolean type(String text) throws IOException {
- // The network protocol can't handle embedded line breaks, so we have to handle it
- // here instead
- StringTokenizer tok = new StringTokenizer(text, "\n", true);
- while (tok.hasMoreTokens()) {
- String line = tok.nextToken();
- if ("\n".equals(line)) {
- boolean success = press(PhysicalButton.ENTER);
- if (!success) {
- return false;
- }
- } else {
- boolean success = sendMonkeyEvent("type " + line);
- if (!success) {
- return false;
- }
- }
- }
- return true;
- }
-
- /**
- * Type the character to the monkey.
- *
- * @param keyChar the character to type.
- * @return success
- * @throws IOException
- */
- public boolean type(char keyChar) throws IOException {
- return type(Character.toString(keyChar));
- }
-
- /**
- * Wake the device up from sleep.
- * @throws IOException
- */
- public void wake() throws IOException {
- sendMonkeyEvent("wake");
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java b/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java
index 5529802..d047052 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java
@@ -19,10 +19,11 @@ import com.google.common.base.Functions;
import com.google.common.base.Preconditions;
import com.google.common.collect.Collections2;
-import com.android.monkeyrunner.core.IMonkeyBackend;
-import com.android.monkeyrunner.core.IMonkeyDevice;
-import com.android.monkeyrunner.core.IMonkeyImage;
-import com.android.monkeyrunner.core.MonkeyImageBase;
+import com.android.chimpchat.ChimpChat;
+import com.android.chimpchat.core.IChimpBackend;
+import com.android.chimpchat.core.IChimpDevice;
+import com.android.chimpchat.core.IChimpImage;
+import com.android.chimpchat.core.ChimpImageBase;
import com.android.monkeyrunner.doc.MonkeyRunnerExported;
import org.python.core.ArgParser;
@@ -42,27 +43,23 @@ import javax.swing.JOptionPane;
@MonkeyRunnerExported(doc = "Main entry point for MonkeyRunner")
public class MonkeyRunner extends PyObject implements ClassDictInit {
private static final Logger LOG = Logger.getLogger(MonkeyRunner.class.getCanonicalName());
- private static IMonkeyBackend backend;
+ private static ChimpChat chimpchat;
public static void classDictInit(PyObject dict) {
JythonUtils.convertDocAnnotationsForClass(MonkeyRunner.class, dict);
}
- /**
- * Set the backend MonkeyRunner is using.
- *
- * @param backend the backend to use.
- */
- /* package */ static void setBackend(IMonkeyBackend backend) {
- MonkeyRunner.backend = backend;
+ static void setChimpChat(ChimpChat chimp){
+ chimpchat = chimp;
}
+
@MonkeyRunnerExported(doc = "Waits for the workstation to connect to the device.",
args = {"timeout", "deviceId"},
argDocs = {"The timeout in seconds to wait. The default is to wait indefinitely.",
"A regular expression that specifies the device name. See the documentation " +
"for 'adb' in the Developer Guide to learn more about device names."},
- returns = "A MonkeyDevice object representing the connected device.")
+ returns = "A ChimpDevice object representing the connected device.")
public static MonkeyDevice waitForConnection(PyObject[] args, String[] kws) {
ArgParser ap = JythonUtils.createArgParser(args, kws);
Preconditions.checkNotNull(ap);
@@ -75,10 +72,10 @@ public class MonkeyRunner extends PyObject implements ClassDictInit {
timeoutMs = Long.MAX_VALUE;
}
- IMonkeyDevice device = backend.waitForConnection(timeoutMs,
+ IChimpDevice device = chimpchat.waitForConnection(timeoutMs,
ap.getString(1, ".*"));
- MonkeyDevice monkeyDevice = new MonkeyDevice(device);
- return monkeyDevice;
+ MonkeyDevice chimpDevice = new MonkeyDevice(device);
+ return chimpDevice;
}
@MonkeyRunnerExported(doc = "Pause the currently running program for the specified " +
@@ -191,7 +188,7 @@ public class MonkeyRunner extends PyObject implements ClassDictInit {
Preconditions.checkNotNull(ap);
String path = ap.getString(0);
- IMonkeyImage image = MonkeyImageBase.loadImageFromFile(path);
+ IChimpImage image = ChimpImageBase.loadImageFromFile(path);
return new MonkeyImage(image);
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java b/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java
index 8c9942c..dd7aec9 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java
@@ -19,9 +19,7 @@ import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
-import com.android.monkeyrunner.adb.AdbBackend;
-import com.android.monkeyrunner.core.IMonkeyBackend;
-import com.android.monkeyrunner.stub.StubBackend;
+import com.android.chimpchat.ChimpChat;
import org.python.util.PythonInterpreter;
@@ -32,6 +30,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.Map;
+import java.util.TreeMap;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
@@ -51,49 +50,33 @@ public class MonkeyRunnerStarter {
private static final Logger LOG = Logger.getLogger(MonkeyRunnerStarter.class.getName());
private static final String MONKEY_RUNNER_MAIN_MANIFEST_NAME = "MonkeyRunnerStartupRunner";
- private final IMonkeyBackend backend;
+ private final ChimpChat chimp;
private final MonkeyRunnerOptions options;
public MonkeyRunnerStarter(MonkeyRunnerOptions options) {
+ Map<String, String> chimp_options = new TreeMap<String, String>();
+ chimp_options.put("backend", options.getBackendName());
this.options = options;
- this.backend = MonkeyRunnerStarter.createBackendByName(options.getBackendName());
- if (this.backend == null) {
- throw new RuntimeException("Unknown backend");
- }
+ this.chimp = ChimpChat.getInstance(chimp_options);
+ MonkeyRunner.setChimpChat(chimp);
}
- /**
- * Creates a specific backend by name.
- *
- * @param backendName the name of the backend to create
- * @return the new backend, or null if none were found.
- */
- public static IMonkeyBackend createBackendByName(String backendName) {
- if ("adb".equals(backendName)) {
- return new AdbBackend();
- } else if ("stub".equals(backendName)) {
- return new StubBackend();
- } else {
- return null;
- }
- }
private int run() {
// This system property gets set by the included starter script
String monkeyRunnerPath = System.getProperty("com.android.monkeyrunner.bindir") +
File.separator + "monkeyrunner";
- MonkeyRunner.setBackend(backend);
Map<String, Predicate<PythonInterpreter>> plugins = handlePlugins();
if (options.getScriptFile() == null) {
ScriptRunner.console(monkeyRunnerPath);
+ chimp.shutdown();
return 0;
} else {
int error = ScriptRunner.run(monkeyRunnerPath, options.getScriptFile().getAbsolutePath(),
options.getArguments(), plugins);
- backend.shutdown();
- MonkeyRunner.setBackend(null);
+ chimp.shutdown();
return error;
}
}
@@ -174,6 +157,9 @@ public class MonkeyRunnerStarter {
return builder.build();
}
+ /* Similar to above, when this fails, it no longer throws a
+ * runtime exception, but merely will log the failure.
+ */
private static final void replaceAllLogFormatters(Formatter form, Level level) {
diff --git a/monkeyrunner/src/com/android/monkeyrunner/PhysicalButton.java b/monkeyrunner/src/com/android/monkeyrunner/PhysicalButton.java
deleted file mode 100644
index f0525a0..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/PhysicalButton.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner;
-
-public enum PhysicalButton {
- HOME("home"),
- SEARCH("search"),
- MENU("menu"),
- BACK("back"),
- DPAD_UP("DPAD_UP"),
- DPAD_DOWN("DPAD_DOWN"),
- DPAD_LEFT("DPAD_LEFT"),
- DPAD_RIGHT("DPAD_RIGHT"),
- DPAD_CENTER("DPAD_CENTER"),
- ENTER("enter");
-
- private String keyName;
-
- private PhysicalButton(String keyName) {
- this.keyName = keyName;
- }
-
- public String getKeyName() {
- return keyName;
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/AdbBackend.java b/monkeyrunner/src/com/android/monkeyrunner/adb/AdbBackend.java
deleted file mode 100644
index 49cac08..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/AdbBackend.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb;
-
-import com.google.common.collect.Lists;
-
-import com.android.ddmlib.AndroidDebugBridge;
-import com.android.ddmlib.IDevice;
-import com.android.monkeyrunner.core.IMonkeyBackend;
-import com.android.monkeyrunner.core.IMonkeyDevice;
-import com.android.sdklib.SdkConstants;
-
-import java.io.File;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.regex.Pattern;
-
-/**
- * Backend implementation that works over ADB to talk to the device.
- */
-public class AdbBackend implements IMonkeyBackend {
- private static Logger LOG = Logger.getLogger(AdbBackend.class.getCanonicalName());
- // How long to wait each time we check for the device to be connected.
- private static final int CONNECTION_ITERATION_TIMEOUT_MS = 200;
- private final List<IMonkeyDevice> devices = Lists.newArrayList();
- private final AndroidDebugBridge bridge;
-
- public AdbBackend() {
- // [try to] ensure ADB is running
- String adbLocation = findAdb();
-
- AndroidDebugBridge.init(false /* debugger support */);
-
- bridge = AndroidDebugBridge.createBridge(
- adbLocation, true /* forceNewBridge */);
- }
-
- private String findAdb() {
- String mrParentLocation =
- System.getProperty("com.android.monkeyrunner.bindir"); //$NON-NLS-1$
-
- // in the new SDK, adb is in the platform-tools, but when run from the command line
- // in the Android source tree, then adb is next to monkeyrunner.
- if (mrParentLocation != null && mrParentLocation.length() != 0) {
- // check if there's a platform-tools folder
- File platformTools = new File(new File(mrParentLocation).getParent(),
- SdkConstants.FD_PLATFORM_TOOLS);
- if (platformTools.isDirectory()) {
- return platformTools.getAbsolutePath() + File.separator + SdkConstants.FN_ADB;
- }
-
- return mrParentLocation + File.separator + SdkConstants.FN_ADB;
- }
-
- return SdkConstants.FN_ADB;
- }
-
- /**
- * Checks the attached devices looking for one whose device id matches the specified regex.
- *
- * @param deviceIdRegex the regular expression to match against
- * @return the Device (if found), or null (if not found).
- */
- private IDevice findAttacedDevice(String deviceIdRegex) {
- Pattern pattern = Pattern.compile(deviceIdRegex);
- for (IDevice device : bridge.getDevices()) {
- String serialNumber = device.getSerialNumber();
- if (pattern.matcher(serialNumber).matches()) {
- return device;
- }
- }
- return null;
- }
-
- @Override
- public IMonkeyDevice waitForConnection() {
- return waitForConnection(Integer.MAX_VALUE, ".*");
- }
-
- @Override
- public IMonkeyDevice waitForConnection(long timeoutMs, String deviceIdRegex) {
- do {
- IDevice device = findAttacedDevice(deviceIdRegex);
- // Only return the device when it is online
- if (device != null && device.getState() == IDevice.DeviceState.ONLINE) {
- IMonkeyDevice monkeyDevice = new AdbMonkeyDevice(device);
- devices.add(monkeyDevice);
- return monkeyDevice;
- }
-
- try {
- Thread.sleep(CONNECTION_ITERATION_TIMEOUT_MS);
- } catch (InterruptedException e) {
- LOG.log(Level.SEVERE, "Error sleeping", e);
- }
- timeoutMs -= CONNECTION_ITERATION_TIMEOUT_MS;
- } while (timeoutMs > 0);
-
- // Timeout. Give up.
- return null;
- }
-
- @Override
- public void shutdown() {
- for (IMonkeyDevice device : devices) {
- device.dispose();
- }
- AndroidDebugBridge.terminate();
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/AdbMonkeyDevice.java b/monkeyrunner/src/com/android/monkeyrunner/adb/AdbMonkeyDevice.java
deleted file mode 100644
index 050292a..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/AdbMonkeyDevice.java
+++ /dev/null
@@ -1,552 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-import com.android.ddmlib.AdbCommandRejectedException;
-import com.android.ddmlib.IDevice;
-import com.android.ddmlib.InstallException;
-import com.android.ddmlib.ShellCommandUnresponsiveException;
-import com.android.ddmlib.TimeoutException;
-import com.android.monkeyrunner.MonkeyManager;
-import com.android.monkeyrunner.adb.LinearInterpolator.Point;
-import com.android.monkeyrunner.core.IMonkeyImage;
-import com.android.monkeyrunner.core.IMonkeyDevice;
-import com.android.monkeyrunner.core.TouchPressType;
-import com.android.monkeyrunner.easy.HierarchyViewer;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.annotation.Nullable;
-
-public class AdbMonkeyDevice implements IMonkeyDevice {
- private static final Logger LOG = Logger.getLogger(AdbMonkeyDevice.class.getName());
-
- private static final String[] ZERO_LENGTH_STRING_ARRAY = new String[0];
- private static final long MANAGER_CREATE_TIMEOUT_MS = 30 * 1000; // 30 seconds
- private static final long MANAGER_CREATE_WAIT_TIME_MS = 1000; // wait 1 second
-
- private final ExecutorService executor = Executors.newCachedThreadPool();
-
- private final IDevice device;
- private MonkeyManager manager;
-
- public AdbMonkeyDevice(IDevice device) {
- this.device = device;
- this.manager = createManager("127.0.0.1", 12345);
-
- Preconditions.checkNotNull(this.manager);
- }
-
- @Override
- public MonkeyManager getManager() {
- return manager;
- }
-
- @Override
- public void dispose() {
- try {
- manager.quit();
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error getting the manager to quit", e);
- }
- manager = null;
- }
-
- @Override
- public HierarchyViewer getHierarchyViewer() {
- return new HierarchyViewer(device);
- }
-
- private void executeAsyncCommand(final String command,
- final LoggingOutputReceiver logger) {
- executor.submit(new Runnable() {
- @Override
- public void run() {
- try {
- device.executeShellCommand(command, logger);
- } catch (TimeoutException e) {
- LOG.log(Level.SEVERE, "Error starting command: " + command, e);
- throw new RuntimeException(e);
- } catch (AdbCommandRejectedException e) {
- LOG.log(Level.SEVERE, "Error starting command: " + command, e);
- throw new RuntimeException(e);
- } catch (ShellCommandUnresponsiveException e) {
- // This happens a lot
- LOG.log(Level.INFO, "Error starting command: " + command, e);
- throw new RuntimeException(e);
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error starting command: " + command, e);
- throw new RuntimeException(e);
- }
- }
- });
- }
-
- private MonkeyManager createManager(String address, int port) {
- try {
- device.createForward(port, port);
- } catch (TimeoutException e) {
- LOG.log(Level.SEVERE, "Timeout creating adb port forwarding", e);
- return null;
- } catch (AdbCommandRejectedException e) {
- LOG.log(Level.SEVERE, "Adb rejected adb port forwarding command: " + e.getMessage(), e);
- return null;
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Unable to create adb port forwarding: " + e.getMessage(), e);
- return null;
- }
-
- String command = "monkey --port " + port;
- executeAsyncCommand(command, new LoggingOutputReceiver(LOG, Level.FINE));
-
- // Sleep for a second to give the command time to execute.
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- LOG.log(Level.SEVERE, "Unable to sleep", e);
- }
-
- InetAddress addr;
- try {
- addr = InetAddress.getByName(address);
- } catch (UnknownHostException e) {
- LOG.log(Level.SEVERE, "Unable to convert address into InetAddress: " + address, e);
- return null;
- }
-
- // We have a tough problem to solve here. "monkey" on the device gives us no indication
- // when it has started up and is ready to serve traffic. If you try too soon, commands
- // will fail. To remedy this, we will keep trying until a single command (in this case,
- // wake) succeeds.
- boolean success = false;
- MonkeyManager mm = null;
- long start = System.currentTimeMillis();
-
- while (!success) {
- long now = System.currentTimeMillis();
- long diff = now - start;
- if (diff > MANAGER_CREATE_TIMEOUT_MS) {
- LOG.severe("Timeout while trying to create monkey mananger");
- return null;
- }
-
- try {
- Thread.sleep(MANAGER_CREATE_WAIT_TIME_MS);
- } catch (InterruptedException e) {
- LOG.log(Level.SEVERE, "Unable to sleep", e);
- }
-
- Socket monkeySocket;
- try {
- monkeySocket = new Socket(addr, port);
- } catch (IOException e) {
- LOG.log(Level.FINE, "Unable to connect socket", e);
- success = false;
- continue;
- }
-
- mm = new MonkeyManager(monkeySocket);
-
- try {
- mm.wake();
- } catch (IOException e) {
- LOG.log(Level.FINE, "Unable to wake up device", e);
- success = false;
- continue;
- }
- success = true;
- }
-
- return mm;
- }
-
- @Override
- public IMonkeyImage takeSnapshot() {
- try {
- return new AdbMonkeyImage(device.getScreenshot());
- } catch (TimeoutException e) {
- LOG.log(Level.SEVERE, "Unable to take snapshot", e);
- return null;
- } catch (AdbCommandRejectedException e) {
- LOG.log(Level.SEVERE, "Unable to take snapshot", e);
- return null;
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Unable to take snapshot", e);
- return null;
- }
- }
-
- @Override
- public String getSystemProperty(String key) {
- return device.getProperty(key);
- }
-
- @Override
- public String getProperty(String key) {
- try {
- return manager.getVariable(key);
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Unable to get variable: " + key, e);
- return null;
- }
- }
-
- @Override
- public void wake() {
- try {
- manager.wake();
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Unable to wake device (too sleepy?)", e);
- }
- }
-
- private String shell(String... args) {
- StringBuilder cmd = new StringBuilder();
- for (String arg : args) {
- cmd.append(arg).append(" ");
- }
- return shell(cmd.toString());
- }
-
- @Override
- public String shell(String cmd) {
- CommandOutputCapture capture = new CommandOutputCapture();
- try {
- device.executeShellCommand(cmd, capture);
- } catch (TimeoutException e) {
- LOG.log(Level.SEVERE, "Error executing command: " + cmd, e);
- return null;
- } catch (ShellCommandUnresponsiveException e) {
- LOG.log(Level.SEVERE, "Error executing command: " + cmd, e);
- return null;
- } catch (AdbCommandRejectedException e) {
- LOG.log(Level.SEVERE, "Error executing command: " + cmd, e);
- return null;
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error executing command: " + cmd, e);
- return null;
- }
- return capture.toString();
- }
-
- @Override
- public boolean installPackage(String path) {
- try {
- String result = device.installPackage(path, true);
- if (result != null) {
- LOG.log(Level.SEVERE, "Got error installing package: "+ result);
- return false;
- }
- return true;
- } catch (InstallException e) {
- LOG.log(Level.SEVERE, "Error installing package: " + path, e);
- return false;
- }
- }
-
- @Override
- public boolean removePackage(String packageName) {
- try {
- String result = device.uninstallPackage(packageName);
- if (result != null) {
- LOG.log(Level.SEVERE, "Got error uninstalling package "+ packageName + ": " +
- result);
- return false;
- }
- return true;
- } catch (InstallException e) {
- LOG.log(Level.SEVERE, "Error installing package: " + packageName, e);
- return false;
- }
- }
-
- @Override
- public void press(String keyName, TouchPressType type) {
- try {
- switch (type) {
- case DOWN_AND_UP:
- manager.press(keyName);
- break;
- case DOWN:
- manager.keyDown(keyName);
- break;
- case UP:
- manager.keyUp(keyName);
- break;
- }
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error sending press event: " + keyName + " " + type, e);
- }
- }
-
- @Override
- public void type(String string) {
- try {
- manager.type(string);
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error Typing: " + string, e);
- }
- }
-
- @Override
- public void touch(int x, int y, TouchPressType type) {
- try {
- switch (type) {
- case DOWN:
- manager.touchDown(x, y);
- break;
- case UP:
- manager.touchUp(x, y);
- break;
- case DOWN_AND_UP:
- manager.tap(x, y);
- break;
- }
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error sending touch event: " + x + " " + y + " " + type, e);
- }
- }
-
- @Override
- public void reboot(String into) {
- try {
- device.reboot(into);
- } catch (TimeoutException e) {
- LOG.log(Level.SEVERE, "Unable to reboot device", e);
- } catch (AdbCommandRejectedException e) {
- LOG.log(Level.SEVERE, "Unable to reboot device", e);
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Unable to reboot device", e);
- }
- }
-
- @Override
- public void startActivity(String uri, String action, String data, String mimetype,
- Collection<String> categories, Map<String, Object> extras, String component,
- int flags) {
- List<String> intentArgs = buildIntentArgString(uri, action, data, mimetype, categories,
- extras, component, flags);
- shell(Lists.asList("am", "start",
- intentArgs.toArray(ZERO_LENGTH_STRING_ARRAY)).toArray(ZERO_LENGTH_STRING_ARRAY));
- }
-
- @Override
- public void broadcastIntent(String uri, String action, String data, String mimetype,
- Collection<String> categories, Map<String, Object> extras, String component,
- int flags) {
- List<String> intentArgs = buildIntentArgString(uri, action, data, mimetype, categories,
- extras, component, flags);
- shell(Lists.asList("am", "broadcast",
- intentArgs.toArray(ZERO_LENGTH_STRING_ARRAY)).toArray(ZERO_LENGTH_STRING_ARRAY));
- }
-
- private static boolean isNullOrEmpty(@Nullable String string) {
- return string == null || string.length() == 0;
- }
-
- private List<String> buildIntentArgString(String uri, String action, String data, String mimetype,
- Collection<String> categories, Map<String, Object> extras, String component,
- int flags) {
- List<String> parts = Lists.newArrayList();
-
- // from adb docs:
- //<INTENT> specifications include these flags:
- // [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
- // [-c <CATEGORY> [-c <CATEGORY>] ...]
- // [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
- // [--esn <EXTRA_KEY> ...]
- // [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
- // [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
- // [-n <COMPONENT>] [-f <FLAGS>]
- // [<URI>]
-
- if (!isNullOrEmpty(action)) {
- parts.add("-a");
- parts.add(action);
- }
-
- if (!isNullOrEmpty(data)) {
- parts.add("-d");
- parts.add(data);
- }
-
- if (!isNullOrEmpty(mimetype)) {
- parts.add("-t");
- parts.add(mimetype);
- }
-
- // Handle categories
- for (String category : categories) {
- parts.add("-c");
- parts.add(category);
- }
-
- // Handle extras
- for (Entry<String, Object> entry : extras.entrySet()) {
- // Extras are either boolean, string, or int. See which we have
- Object value = entry.getValue();
- String valueString;
- String arg;
- if (value instanceof Integer) {
- valueString = Integer.toString((Integer) value);
- arg = "--ei";
- } else if (value instanceof Boolean) {
- valueString = Boolean.toString((Boolean) value);
- arg = "--ez";
- } else {
- // treat is as a string.
- valueString = value.toString();
- arg = "--es";
- }
- parts.add(arg);
- parts.add(entry.getKey());
- parts.add(valueString);
- }
-
- if (!isNullOrEmpty(component)) {
- parts.add("-n");
- parts.add(component);
- }
-
- if (flags != 0) {
- parts.add("-f");
- parts.add(Integer.toString(flags));
- }
-
- if (!isNullOrEmpty(uri)) {
- parts.add(uri);
- }
-
- return parts;
- }
-
- @Override
- public Map<String, Object> instrument(String packageName, Map<String, Object> args) {
- List<String> shellCmd = Lists.newArrayList("am", "instrument", "-w", "-r", packageName);
- String result = shell(shellCmd.toArray(ZERO_LENGTH_STRING_ARRAY));
- return convertInstrumentResult(result);
- }
-
- /**
- * Convert the instrumentation result into it's Map representation.
- *
- * @param result the result string
- * @return the new map
- */
- @VisibleForTesting
- /* package */ static Map<String, Object> convertInstrumentResult(String result) {
- Map<String, Object> map = Maps.newHashMap();
- Pattern pattern = Pattern.compile("^INSTRUMENTATION_(\\w+): ", Pattern.MULTILINE);
- Matcher matcher = pattern.matcher(result);
-
- int previousEnd = 0;
- String previousWhich = null;
-
- while (matcher.find()) {
- if ("RESULT".equals(previousWhich)) {
- String resultLine = result.substring(previousEnd, matcher.start()).trim();
- // Look for the = in the value, and split there
- int splitIndex = resultLine.indexOf("=");
- String key = resultLine.substring(0, splitIndex);
- String value = resultLine.substring(splitIndex + 1);
-
- map.put(key, value);
- }
-
- previousEnd = matcher.end();
- previousWhich = matcher.group(1);
- }
- if ("RESULT".equals(previousWhich)) {
- String resultLine = result.substring(previousEnd, matcher.start()).trim();
- // Look for the = in the value, and split there
- int splitIndex = resultLine.indexOf("=");
- String key = resultLine.substring(0, splitIndex);
- String value = resultLine.substring(splitIndex + 1);
-
- map.put(key, value);
- }
- return map;
- }
-
- @Override
- public void drag(int startx, int starty, int endx, int endy, int steps, long ms) {
- final long iterationTime = ms / steps;
-
- LinearInterpolator lerp = new LinearInterpolator(steps);
- LinearInterpolator.Point start = new LinearInterpolator.Point(startx, starty);
- LinearInterpolator.Point end = new LinearInterpolator.Point(endx, endy);
- lerp.interpolate(start, end, new LinearInterpolator.Callback() {
- @Override
- public void step(Point point) {
- try {
- manager.touchMove(point.getX(), point.getY());
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error sending drag start event", e);
- }
-
- try {
- Thread.sleep(iterationTime);
- } catch (InterruptedException e) {
- LOG.log(Level.SEVERE, "Error sleeping", e);
- }
- }
-
- @Override
- public void start(Point point) {
- try {
- manager.touchDown(point.getX(), point.getY());
- manager.touchMove(point.getX(), point.getY());
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error sending drag start event", e);
- }
-
- try {
- Thread.sleep(iterationTime);
- } catch (InterruptedException e) {
- LOG.log(Level.SEVERE, "Error sleeping", e);
- }
- }
-
- @Override
- public void end(Point point) {
- try {
- manager.touchMove(point.getX(), point.getY());
- manager.touchUp(point.getX(), point.getY());
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error sending drag end event", e);
- }
- }
- });
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/AdbMonkeyImage.java b/monkeyrunner/src/com/android/monkeyrunner/adb/AdbMonkeyImage.java
deleted file mode 100644
index e2bd86e..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/AdbMonkeyImage.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb;
-
-import com.android.ddmlib.RawImage;
-import com.android.monkeyrunner.adb.image.ImageUtils;
-import com.android.monkeyrunner.core.MonkeyImageBase;
-
-import java.awt.image.BufferedImage;
-
-/**
- * ADB implementation of the MonkeyImage class.
- */
-public class AdbMonkeyImage extends MonkeyImageBase {
- private final RawImage image;
-
- /**
- * Create a new AdbMonkeyImage.
- *
- * @param image the image from adb.
- */
- AdbMonkeyImage(RawImage image) {
- this.image = image;
- }
-
- @Override
- public BufferedImage createBufferedImage() {
- return ImageUtils.convertImage(image);
- }
-
- public RawImage getRawImage() {
- return image;
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/CommandOutputCapture.java b/monkeyrunner/src/com/android/monkeyrunner/adb/CommandOutputCapture.java
deleted file mode 100644
index 9f99a7a..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/CommandOutputCapture.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb;
-
-import com.android.ddmlib.IShellOutputReceiver;
-
-/**
- * Shell Output Receiver that captures shell output into a String for
- * later retrieval.
- */
-public class CommandOutputCapture implements IShellOutputReceiver {
- private final StringBuilder builder = new StringBuilder();
-
- public void flush() { }
-
- public boolean isCancelled() {
- return false;
- }
-
- public void addOutput(byte[] data, int offset, int length) {
- String message = new String(data, offset, length);
- builder.append(message);
- }
-
- @Override
- public String toString() {
- return builder.toString();
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/LinearInterpolator.java b/monkeyrunner/src/com/android/monkeyrunner/adb/LinearInterpolator.java
deleted file mode 100644
index e39fefd..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/LinearInterpolator.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb;
-
-
-
-/**
- * Linear Interpolation class.
- */
-public class LinearInterpolator {
- private final int steps;
-
- /**
- * Use our own Point class so we don't pull in java.awt.* just for this simple class.
- */
- public static class Point {
- private final int x;
- private final int y;
-
- public Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- @Override
- public String toString() {
- return new StringBuilder().
- append("(").
- append(x).
- append(",").
- append(y).
- append(")").toString();
- }
-
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof Point) {
- Point that = (Point) obj;
- return this.x == that.x && this.y == that.y;
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return 0x43125315 + x + y;
- }
-
- public int getX() {
- return x;
- }
-
- public int getY() {
- return y;
- }
- }
-
- /**
- * Callback interface to recieve interpolated points.
- */
- public interface Callback {
- /**
- * Called once to inform of the start point.
- */
- void start(Point point);
- /**
- * Called once to inform of the end point.
- */
- void end(Point point);
- /**
- * Called at every step in-between start and end.
- */
- void step(Point point);
- }
-
- /**
- * Create a new linear Interpolator.
- *
- * @param steps How many steps should be in a single run. This counts the intervals
- * in-between points, so the actual number of points generated will be steps + 1.
- */
- public LinearInterpolator(int steps) {
- this.steps = steps;
- }
-
- // Copied from android.util.MathUtils since we couldn't link it in on the host.
- private static float lerp(float start, float stop, float amount) {
- return start + (stop - start) * amount;
- }
-
- /**
- * Calculate the interpolated points.
- *
- * @param start The starting point
- * @param end The ending point
- * @param callback the callback to call with each calculated points.
- */
- public void interpolate(Point start, Point end, Callback callback) {
- int xDistance = Math.abs(end.getX() - start.getX());
- int yDistance = Math.abs(end.getY() - start.getY());
- float amount = (float) (1.0 / steps);
-
-
- callback.start(start);
- for (int i = 1; i < steps; i++) {
- float newX = lerp(start.getX(), end.getX(), amount * i);
- float newY = lerp(start.getY(), end.getY(), amount * i);
-
- callback.step(new Point(Math.round(newX), Math.round(newY)));
- }
- // Generate final point
- callback.end(end);
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/LoggingOutputReceiver.java b/monkeyrunner/src/com/android/monkeyrunner/adb/LoggingOutputReceiver.java
deleted file mode 100644
index b78aff3..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/LoggingOutputReceiver.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb;
-
-import com.android.ddmlib.IShellOutputReceiver;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Shell Output Receiver that sends shell output to a Logger.
- */
-public class LoggingOutputReceiver implements IShellOutputReceiver {
- private final Logger log;
- private final Level level;
-
- public LoggingOutputReceiver(Logger log, Level level) {
- this.log = log;
- this.level = level;
- }
-
- public void addOutput(byte[] data, int offset, int length) {
- String message = new String(data, offset, length);
- for (String line : message.split("\n")) {
- log.log(level, line);
- }
- }
-
- public void flush() { }
-
- public boolean isCancelled() {
- return false;
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/image/CaptureRawAndConvertedImage.java b/monkeyrunner/src/com/android/monkeyrunner/adb/image/CaptureRawAndConvertedImage.java
deleted file mode 100644
index 5a317f1..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/image/CaptureRawAndConvertedImage.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb.image;
-
-import com.android.ddmlib.RawImage;
-import com.android.monkeyrunner.adb.AdbBackend;
-import com.android.monkeyrunner.adb.AdbMonkeyImage;
-import com.android.monkeyrunner.core.IMonkeyBackend;
-import com.android.monkeyrunner.core.IMonkeyImage;
-import com.android.monkeyrunner.core.IMonkeyDevice;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-
-/**
- * Utility program to capture raw and converted images from a device and write them to a file.
- * This is used to generate the test data for ImageUtilsTest.
- */
-public class CaptureRawAndConvertedImage {
- public static class MonkeyRunnerRawImage implements Serializable {
- public int version;
- public int bpp;
- public int size;
- public int width;
- public int height;
- public int red_offset;
- public int red_length;
- public int blue_offset;
- public int blue_length;
- public int green_offset;
- public int green_length;
- public int alpha_offset;
- public int alpha_length;
-
- public byte[] data;
-
- public MonkeyRunnerRawImage(RawImage rawImage) {
- version = rawImage.version;
- bpp = rawImage.bpp;
- size = rawImage.size;
- width = rawImage.width;
- height = rawImage.height;
- red_offset = rawImage.red_offset;
- red_length = rawImage.red_length;
- blue_offset = rawImage.blue_offset;
- blue_length = rawImage.blue_length;
- green_offset = rawImage.green_offset;
- green_length = rawImage.green_length;
- alpha_offset = rawImage.alpha_offset;
- alpha_length = rawImage.alpha_length;
-
- data = rawImage.data;
- }
-
- public RawImage toRawImage() {
- RawImage rawImage = new RawImage();
-
- rawImage.version = version;
- rawImage.bpp = bpp;
- rawImage.size = size;
- rawImage.width = width;
- rawImage.height = height;
- rawImage.red_offset = red_offset;
- rawImage.red_length = red_length;
- rawImage.blue_offset = blue_offset;
- rawImage.blue_length = blue_length;
- rawImage.green_offset = green_offset;
- rawImage.green_length = green_length;
- rawImage.alpha_offset = alpha_offset;
- rawImage.alpha_length = alpha_length;
-
- rawImage.data = data;
- return rawImage;
- }
- }
-
- private static void writeOutImage(RawImage screenshot, String name) throws IOException {
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(name));
- out.writeObject(new MonkeyRunnerRawImage(screenshot));
- out.close();
- }
-
- public static void main(String[] args) throws IOException {
- IMonkeyBackend backend = new AdbBackend();
- IMonkeyDevice device = backend.waitForConnection();
- IMonkeyImage snapshot = (IMonkeyImage) device.takeSnapshot();
-
- // write out to a file
- snapshot.writeToFile("output.png", "png");
- writeOutImage(((AdbMonkeyImage)snapshot).getRawImage(), "output.raw");
- System.exit(0);
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/image/ImageUtils.java b/monkeyrunner/src/com/android/monkeyrunner/adb/image/ImageUtils.java
deleted file mode 100644
index c3eaf01..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/image/ImageUtils.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb.image;
-
-import com.android.ddmlib.RawImage;
-
-import java.awt.Point;
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferByte;
-import java.awt.image.PixelInterleavedSampleModel;
-import java.awt.image.Raster;
-import java.awt.image.WritableRaster;
-import java.util.Hashtable;
-/**
- * Useful image related functions.
- */
-public class ImageUtils {
- // Utility class
- private ImageUtils() { }
-
- private static Hashtable<?,?> EMPTY_HASH = new Hashtable();
- private static int[] BAND_OFFSETS_32 = { 0, 1, 2, 3 };
- private static int[] BAND_OFFSETS_16 = { 0, 1 };
-
- /**
- * Convert a raw image into a buffered image.
- *
- * @param rawImage the raw image to convert
- * @param image the old image to (possibly) recycle
- * @return the converted image
- */
- public static BufferedImage convertImage(RawImage rawImage, BufferedImage image) {
- switch (rawImage.bpp) {
- case 16:
- return rawImage16toARGB(image, rawImage);
- case 32:
- return rawImage32toARGB(rawImage);
- }
- return null;
- }
-
- /**
- * Convert a raw image into a buffered image.
- *
- * @param rawImage the image to convert.
- * @return the converted image.
- */
- public static BufferedImage convertImage(RawImage rawImage) {
- return convertImage(rawImage, null);
- }
-
- static int getMask(int length) {
- int res = 0;
- for (int i = 0 ; i < length ; i++) {
- res = (res << 1) + 1;
- }
-
- return res;
- }
-
- private static BufferedImage rawImage32toARGB(RawImage rawImage) {
- // Do as much as we can to not make an extra copy of the data. This is just a bunch of
- // classes that wrap's the raw byte array of the image data.
- DataBufferByte dataBuffer = new DataBufferByte(rawImage.data, rawImage.size);
-
- PixelInterleavedSampleModel sampleModel =
- new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, rawImage.width, rawImage.height,
- 4, rawImage.width * 4, BAND_OFFSETS_32);
- WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer,
- new Point(0, 0));
- return new BufferedImage(new ThirtyTwoBitColorModel(rawImage), raster, false, EMPTY_HASH);
- }
-
- private static BufferedImage rawImage16toARGB(BufferedImage image, RawImage rawImage) {
- // Do as much as we can to not make an extra copy of the data. This is just a bunch of
- // classes that wrap's the raw byte array of the image data.
- DataBufferByte dataBuffer = new DataBufferByte(rawImage.data, rawImage.size);
-
- PixelInterleavedSampleModel sampleModel =
- new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, rawImage.width, rawImage.height,
- 2, rawImage.width * 2, BAND_OFFSETS_16);
- WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer,
- new Point(0, 0));
- return new BufferedImage(new SixteenBitColorModel(rawImage), raster, false, EMPTY_HASH);
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/image/SixteenBitColorModel.java b/monkeyrunner/src/com/android/monkeyrunner/adb/image/SixteenBitColorModel.java
deleted file mode 100644
index 06ab939..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/image/SixteenBitColorModel.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb.image;
-
-import com.android.ddmlib.RawImage;
-
-import java.awt.Transparency;
-import java.awt.color.ColorSpace;
-import java.awt.image.ColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.Raster;
-
-/**
- * Internal color model used to do conversion of 16bpp RawImages.
- */
-class SixteenBitColorModel extends ColorModel {
- private static final int[] BITS = {
- 8, 8, 8, 8
- };
- public SixteenBitColorModel(RawImage rawImage) {
- super(32
- , BITS, ColorSpace.getInstance(ColorSpace.CS_sRGB),
- true, false, Transparency.TRANSLUCENT,
- DataBuffer.TYPE_BYTE);
- }
-
- @Override
- public boolean isCompatibleRaster(Raster raster) {
- return true;
- }
-
- private int getPixel(Object inData) {
- byte[] data = (byte[]) inData;
- int value = data[0] & 0x00FF;
- value |= (data[1] << 8) & 0x0FF00;
-
- return value;
- }
-
- @Override
- public int getAlpha(Object inData) {
- return 0xff;
- }
-
- @Override
- public int getBlue(Object inData) {
- int pixel = getPixel(inData);
- return ((pixel >> 0) & 0x01F) << 3;
- }
-
- @Override
- public int getGreen(Object inData) {
- int pixel = getPixel(inData);
- return ((pixel >> 5) & 0x03F) << 2;
- }
-
- @Override
- public int getRed(Object inData) {
- int pixel = getPixel(inData);
- return ((pixel >> 11) & 0x01F) << 3;
- }
-
- @Override
- public int getAlpha(int pixel) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getBlue(int pixel) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getGreen(int pixel) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getRed(int pixel) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/image/ThirtyTwoBitColorModel.java b/monkeyrunner/src/com/android/monkeyrunner/adb/image/ThirtyTwoBitColorModel.java
deleted file mode 100644
index d4e47ea..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/adb/image/ThirtyTwoBitColorModel.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.adb.image;
-
-import com.android.ddmlib.RawImage;
-
-import java.awt.Transparency;
-import java.awt.color.ColorSpace;
-import java.awt.image.ColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.Raster;
-
-/**
- * Internal color model used to do conversion of 32bpp RawImages.
- */
-class ThirtyTwoBitColorModel extends ColorModel {
- private static final int[] BITS = {
- 8, 8, 8, 8,
- };
- private final int alphaLength;
- private final int alphaMask;
- private final int alphaOffset;
- private final int blueMask;
- private final int blueLength;
- private final int blueOffset;
- private final int greenMask;
- private final int greenLength;
- private final int greenOffset;
- private final int redMask;
- private final int redLength;
- private final int redOffset;
-
- public ThirtyTwoBitColorModel(RawImage rawImage) {
- super(32, BITS, ColorSpace.getInstance(ColorSpace.CS_sRGB),
- true, false, Transparency.TRANSLUCENT,
- DataBuffer.TYPE_BYTE);
-
- redOffset = rawImage.red_offset;
- redLength = rawImage.red_length;
- redMask = ImageUtils.getMask(redLength);
- greenOffset = rawImage.green_offset;
- greenLength = rawImage.green_length;
- greenMask = ImageUtils.getMask(greenLength);
- blueOffset = rawImage.blue_offset;
- blueLength = rawImage.blue_length;
- blueMask = ImageUtils.getMask(blueLength);
- alphaLength = rawImage.alpha_length;
- alphaOffset = rawImage.alpha_offset;
- alphaMask = ImageUtils.getMask(alphaLength);
- }
-
- @Override
- public boolean isCompatibleRaster(Raster raster) {
- return true;
- }
-
- private int getPixel(Object inData) {
- byte[] data = (byte[]) inData;
- int value = data[0] & 0x00FF;
- value |= (data[1] & 0x00FF) << 8;
- value |= (data[2] & 0x00FF) << 16;
- value |= (data[3] & 0x00FF) << 24;
-
- return value;
- }
-
- @Override
- public int getAlpha(Object inData) {
- int pixel = getPixel(inData);
- if(alphaLength == 0) {
- return 0xff;
- }
- return ((pixel >>> alphaOffset) & alphaMask) << (8 - alphaLength);
- }
-
- @Override
- public int getBlue(Object inData) {
- int pixel = getPixel(inData);
- return ((pixel >>> blueOffset) & blueMask) << (8 - blueLength);
- }
-
- @Override
- public int getGreen(Object inData) {
- int pixel = getPixel(inData);
- return ((pixel >>> greenOffset) & greenMask) << (8 - greenLength);
- }
-
- @Override
- public int getRed(Object inData) {
- int pixel = getPixel(inData);
- return ((pixel >>> redOffset) & redMask) << (8 - redLength);
- }
-
- @Override
- public int getAlpha(int pixel) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getBlue(int pixel) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getGreen(int pixel) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getRed(int pixel) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyController.java b/monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyController.java
index ca3195c..6fc4ea6 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyController.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyController.java
@@ -15,13 +15,14 @@
*/
package com.android.monkeyrunner.controller;
-import com.android.monkeyrunner.adb.AdbBackend;
-import com.android.monkeyrunner.core.IMonkeyBackend;
-import com.android.monkeyrunner.core.IMonkeyDevice;
+import com.android.chimpchat.ChimpChat;
+import com.android.chimpchat.core.IChimpDevice;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.logging.Logger;
+import java.util.Map;
+import java.util.TreeMap;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
@@ -39,8 +40,10 @@ public class MonkeyController extends JFrame {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
- IMonkeyBackend adb = new AdbBackend();
- final IMonkeyDevice device = adb.waitForConnection();
+ Map<String, String> options = new TreeMap<String, String>();
+ options.put("backend", "adb");
+ ChimpChat chimpchat = ChimpChat.getInstance(options);
+ final IChimpDevice device = chimpchat.waitForConnection();
MonkeyControllerFrame mf = new MonkeyControllerFrame(device);
mf.setVisible(true);
mf.addWindowListener(new WindowAdapter() {
diff --git a/monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyControllerFrame.java b/monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyControllerFrame.java
index 7750936..8bb2513 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyControllerFrame.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/controller/MonkeyControllerFrame.java
@@ -15,10 +15,10 @@
*/
package com.android.monkeyrunner.controller;
-import com.android.monkeyrunner.MonkeyManager;
-import com.android.monkeyrunner.PhysicalButton;
-import com.android.monkeyrunner.core.IMonkeyImage;
-import com.android.monkeyrunner.core.IMonkeyDevice;
+import com.android.chimpchat.core.PhysicalButton;
+import com.android.chimpchat.core.TouchPressType;
+import com.android.chimpchat.core.IChimpImage;
+import com.android.chimpchat.core.IChimpDevice;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
@@ -52,29 +52,28 @@ public class MonkeyControllerFrame extends JFrame {
private final JLabel imageLabel = new JLabel();
private final VariableFrame variableFrame;
- private MonkeyManager monkeyManager;
+ private final IChimpDevice device;
private BufferedImage currentImage;
+ private final TouchPressType DOWN_AND_UP = TouchPressType.DOWN_AND_UP;
+
private final Timer timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateScreen();
}
});
- private final IMonkeyDevice device;
-
private class PressAction extends AbstractAction {
private final PhysicalButton button;
public PressAction(PhysicalButton button) {
this.button = button;
}
+ /* When this fails, it no longer throws a runtime exception,
+ * but merely will log the failure.
+ */
public void actionPerformed(ActionEvent event) {
- try {
- monkeyManager.press(button);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ device.press(button.getKeyName(), DOWN_AND_UP);
updateScreen();
}
}
@@ -85,9 +84,9 @@ public class MonkeyControllerFrame extends JFrame {
return button;
}
- public MonkeyControllerFrame(IMonkeyDevice device) {
+ public MonkeyControllerFrame(IChimpDevice chimpDevice) {
super("MonkeyController");
- this.device = device;
+ this.device = chimpDevice;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -117,14 +116,13 @@ public class MonkeyControllerFrame extends JFrame {
}
});
+ /* Similar to above, when the following two methods fail, they
+ * no longer throw a runtime exception, but merely will log the failure.
+ */
imageLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
- try {
- monkeyManager.touch(event.getX(), event.getY());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ device.touch(event.getX(), event.getY(), DOWN_AND_UP);
updateScreen();
}
@@ -134,11 +132,7 @@ public class MonkeyControllerFrame extends JFrame {
focusManager.addKeyEventDispatcher(new KeyEventDispatcher() {
public boolean dispatchKeyEvent(KeyEvent event) {
if (KeyEvent.KEY_TYPED == event.getID()) {
- try {
- monkeyManager.type(event.getKeyChar());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ device.type(Character.toString(event.getKeyChar()));
}
return false;
}
@@ -147,7 +141,7 @@ public class MonkeyControllerFrame extends JFrame {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
init();
- variableFrame.init(monkeyManager);
+ variableFrame.init(device);
}
});
@@ -155,7 +149,7 @@ public class MonkeyControllerFrame extends JFrame {
}
private void updateScreen() {
- IMonkeyImage snapshot = device.takeSnapshot();
+ IChimpImage snapshot = device.takeSnapshot();
currentImage = snapshot.createBufferedImage();
imageLabel.setIcon(new ImageIcon(currentImage));
@@ -163,10 +157,6 @@ public class MonkeyControllerFrame extends JFrame {
}
private void init() {
- monkeyManager = device.getManager();
- if (monkeyManager == null) {
- throw new RuntimeException("Unable to create monkey manager");
- }
updateScreen();
timer.start();
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/controller/VariableFrame.java b/monkeyrunner/src/com/android/monkeyrunner/controller/VariableFrame.java
index 9015b5d..f9c6ef3 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/controller/VariableFrame.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/controller/VariableFrame.java
@@ -17,13 +17,12 @@ package com.android.monkeyrunner.controller;
import com.google.common.collect.Sets;
-import com.android.monkeyrunner.MonkeyManager;
+import com.android.chimpchat.core.IChimpDevice;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
-import java.io.IOException;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
@@ -48,7 +47,7 @@ import javax.swing.table.AbstractTableModel;
public class VariableFrame extends JFrame {
private static final Logger LOG = Logger.getLogger(VariableFrame.class.getName());
private static final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
- private MonkeyManager monkeyManager;
+ private IChimpDevice device;
private static class VariableHolder implements Comparable<VariableHolder> {
private final String key;
@@ -88,23 +87,12 @@ public class VariableFrame extends JFrame {
public void refresh() {
Collection<String> variables;
- try {
- variables = monkeyManager.listVariable();
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error getting list of variables", e);
- return;
- }
+ variables = device.getPropertyList();
for (final String variable : variables) {
EXECUTOR.execute(new Runnable() {
public void run() {
String value;
- try {
- value = monkeyManager.getVariable(variable);
- } catch (IOException e) {
- LOG.log(Level.SEVERE,
- "Error getting variable value for " + variable, e);
- return;
- }
+ value = device.getProperty(variable);
if (value == null) {
value = "";
}
@@ -179,7 +167,7 @@ public class VariableFrame extends JFrame {
pack();
}
- public void init(MonkeyManager monkeyManager) {
- this.monkeyManager = monkeyManager;
+ public void init(IChimpDevice device) {
+ this.device = device;
}
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyBackend.java b/monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyBackend.java
deleted file mode 100644
index 3c1b943..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyBackend.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.core;
-
-import com.android.monkeyrunner.MonkeyDevice;
-
-/**
- * Interface between MonkeyRunner common code and the MonkeyRunner backend. The backend is
- * responsible for communicating between the host and the device.
- */
-public interface IMonkeyBackend {
- /**
- * Wait for a default device to connect to the backend.
- *
- * @return the connected device (or null if timeout);
- */
- IMonkeyDevice waitForConnection();
-
- /**
- * Wait for a device to connect to the backend.
- *
- * @param timeoutMs how long (in ms) to wait
- * @param deviceIdRegex the regular expression to specify which device to wait for.
- * @return the connected device (or null if timeout);
- */
- IMonkeyDevice waitForConnection(long timeoutMs, String deviceIdRegex);
-
- /**
- * Shutdown the backend and cleanup any resources it was using.
- */
- void shutdown();
-} \ No newline at end of file
diff --git a/monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyDevice.java b/monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyDevice.java
deleted file mode 100644
index 9c06ec4..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyDevice.java
+++ /dev/null
@@ -1,196 +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 com.android.monkeyrunner.core;
-
-import com.android.monkeyrunner.MonkeyManager;
-import com.android.monkeyrunner.easy.HierarchyViewer;
-
-import java.util.Collection;
-import java.util.Map;
-
-import javax.annotation.Nullable;
-
-/**
- * MonkeyDevice interface.
- */
-public interface IMonkeyDevice {
- /**
- * Create a MonkeyMananger for talking to this device.
- *
- * @return the MonkeyManager
- */
- MonkeyManager getManager();
-
- /**
- * Dispose of any native resources this device may have taken hold of.
- */
- void dispose();
-
- /**
- * @return hierarchy viewer implementation for querying state of the view
- * hierarchy.
- */
- HierarchyViewer getHierarchyViewer();
-
- /**
- * Take the current screen's snapshot.
- * @return the snapshot image
- */
- IMonkeyImage takeSnapshot();
-
- /**
- * Reboot the device.
- *
- * @param into which bootloader to boot into. Null means default reboot.
- */
- void reboot(@Nullable String into);
-
- /**
- * Get device's property.
- *
- * @param key the property name
- * @return the property value
- */
- String getProperty(String key);
-
- /**
- * Get system property.
- *
- * @param key the name of the system property
- * @return the property value
- */
- String getSystemProperty(String key);
-
- /**
- * Perform a touch of the given type at (x,y).
- *
- * @param x the x coordinate
- * @param y the y coordinate
- * @param type the touch type
- */
- void touch(int x, int y, TouchPressType type);
-
- /**
- * Perform a press of a given type using a given key.
- *
- * TODO: define standard key names in a separate class or enum
- *
- * @param keyName the name of the key to use
- * @param type the type of press to perform
- */
- void press(String keyName, TouchPressType type);
-
- /**
- * Perform a drag from one one location to another
- *
- * @param startx the x coordinate of the drag's starting point
- * @param starty the y coordinate of the drag's starting point
- * @param endx the x coordinate of the drag's end point
- * @param endy the y coordinate of the drag's end point
- * @param steps the number of steps to take when interpolating points
- * @param ms the duration of the drag
- */
- void drag(int startx, int starty, int endx, int endy, int steps, long ms);
-
- /**
- * Type a given string.
- *
- * @param string the string to type
- */
- void type(String string);
-
- /**
- * Execute a shell command.
- *
- * @param cmd the command to execute
- * @return the output of the command
- */
- String shell(String cmd);
-
- /**
- * Install a given package.
- *
- * @param path the path to the installation package
- * @return true if success
- */
- boolean installPackage(String path);
-
- /**
- * Uninstall a given package.
- *
- * @param packageName the name of the package
- * @return true if success
- */
- boolean removePackage(String packageName);
-
- /**
- * Start an activity.
- *
- * @param uri the URI for the Intent
- * @param action the action for the Intent
- * @param data the data URI for the Intent
- * @param mimeType the mime type for the Intent
- * @param categories the category names for the Intent
- * @param extras the extras to add to the Intent
- * @param component the component of the Intent
- * @param flags the flags for the Intent
- */
- void startActivity(@Nullable String uri, @Nullable String action,
- @Nullable String data, @Nullable String mimeType,
- Collection<String> categories, Map<String, Object> extras, @Nullable String component,
- int flags);
-
- /**
- * Send a broadcast intent to the device.
- *
- * @param uri the URI for the Intent
- * @param action the action for the Intent
- * @param data the data URI for the Intent
- * @param mimeType the mime type for the Intent
- * @param categories the category names for the Intent
- * @param extras the extras to add to the Intent
- * @param component the component of the Intent
- * @param flags the flags for the Intent
- */
- void broadcastIntent(@Nullable String uri, @Nullable String action,
- @Nullable String data, @Nullable String mimeType,
- Collection<String> categories, Map<String, Object> extras, @Nullable String component,
- int flags);
-
- /**
- * Run the specified package with instrumentation and return the output it
- * generates.
- *
- * Use this to run a test package using InstrumentationTestRunner.
- *
- * @param packageName The class to run with instrumentation. The format is
- * packageName/className. Use packageName to specify the Android package to
- * run, and className to specify the class to run within that package. For
- * test packages, this is usually testPackageName/InstrumentationTestRunner
- * @param args a map of strings to objects containing the arguments to pass
- * to this instrumentation.
- * @return A map of strings to objects for the output from the package.
- * For a test package, contains a single key-value pair: the key is 'stream'
- * and the value is a string containing the test output.
- */
- Map<String, Object> instrument(String packageName,
- Map<String, Object> args);
-
- /**
- * Wake up the screen on the device.
- */
- void wake();
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyImage.java b/monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyImage.java
deleted file mode 100644
index 5a24fa7..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/core/IMonkeyImage.java
+++ /dev/null
@@ -1,36 +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 com.android.monkeyrunner.core;
-
-import java.awt.image.BufferedImage;
-
-/**
- * MonkeyImage interface.
- *
- * This interface defines an image representing a screen snapshot.
- */
-public interface IMonkeyImage {
- // TODO: add java docs
- BufferedImage createBufferedImage();
- BufferedImage getBufferedImage();
-
- IMonkeyImage getSubImage(int x, int y, int w, int h);
-
- byte[] convertToBytes(String format);
- boolean writeToFile(String path, String format);
- int getPixel(int x, int y);
- boolean sameAs(IMonkeyImage other, double percent);
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/core/MonkeyImageBase.java b/monkeyrunner/src/com/android/monkeyrunner/core/MonkeyImageBase.java
deleted file mode 100644
index 04ccb93..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/core/MonkeyImageBase.java
+++ /dev/null
@@ -1,219 +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 com.android.monkeyrunner.core;
-
-import java.awt.Graphics;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-import java.util.Iterator;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.imageio.ImageIO;
-import javax.imageio.ImageWriter;
-import javax.imageio.stream.ImageOutputStream;
-
-/**
- * Base class with basic functionality for MonkeyImage implementations.
- */
-public abstract class MonkeyImageBase implements IMonkeyImage {
- private static Logger LOG = Logger.getLogger(MonkeyImageBase.class.getCanonicalName());
-
- /**
- * Convert the MonkeyImage to a BufferedImage.
- *
- * @return a BufferedImage for this MonkeyImage.
- */
- @Override
- public abstract BufferedImage createBufferedImage();
-
- // Cache the BufferedImage so we don't have to generate it every time.
- private WeakReference<BufferedImage> cachedBufferedImage = null;
-
- /**
- * Utility method to handle getting the BufferedImage and managing the cache.
- *
- * @return the BufferedImage for this image.
- */
- @Override
- public BufferedImage getBufferedImage() {
- // Check the cache first
- if (cachedBufferedImage != null) {
- BufferedImage img = cachedBufferedImage.get();
- if (img != null) {
- return img;
- }
- }
-
- // Not in the cache, so create it and cache it.
- BufferedImage img = createBufferedImage();
- cachedBufferedImage = new WeakReference<BufferedImage>(img);
- return img;
- }
-
- @Override
- public byte[] convertToBytes(String format) {
- BufferedImage argb = convertSnapshot();
-
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- try {
- ImageIO.write(argb, format, os);
- } catch (IOException e) {
- return new byte[0];
- }
- return os.toByteArray();
- }
-
- @Override
- public boolean writeToFile(String path, String format) {
- if (format != null) {
- return writeToFileHelper(path, format);
- }
- int offset = path.lastIndexOf('.');
- if (offset < 0) {
- return writeToFileHelper(path, "png");
- }
- String ext = path.substring(offset + 1);
- Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix(ext);
- if (!writers.hasNext()) {
- return writeToFileHelper(path, "png");
- }
- ImageWriter writer = writers.next();
- BufferedImage image = convertSnapshot();
- try {
- File f = new File(path);
- f.delete();
-
- ImageOutputStream outputStream = ImageIO.createImageOutputStream(f);
- writer.setOutput(outputStream);
-
- try {
- writer.write(image);
- } finally {
- writer.dispose();
- outputStream.flush();
- }
- } catch (IOException e) {
- return false;
- }
- return true;
- }
-
- @Override
- public int getPixel(int x, int y) {
- BufferedImage image = getBufferedImage();
- return image.getRGB(x, y);
- }
-
- private BufferedImage convertSnapshot() {
- BufferedImage image = getBufferedImage();
-
- // Convert the image to ARGB so ImageIO writes it out nicely
- BufferedImage argb = new BufferedImage(image.getWidth(), image.getHeight(),
- BufferedImage.TYPE_INT_ARGB);
- Graphics g = argb.createGraphics();
- g.drawImage(image, 0, 0, null);
- g.dispose();
- return argb;
- }
-
- private boolean writeToFileHelper(String path, String format) {
- BufferedImage argb = convertSnapshot();
-
- try {
- ImageIO.write(argb, format, new File(path));
- } catch (IOException e) {
- return false;
- }
- return true;
- }
-
- @Override
- public boolean sameAs(IMonkeyImage other, double percent) {
- BufferedImage otherImage = other.getBufferedImage();
- BufferedImage myImage = getBufferedImage();
-
- // Easy size check
- if (otherImage.getWidth() != myImage.getWidth()) {
- return false;
- }
- if (otherImage.getHeight() != myImage.getHeight()) {
- return false;
- }
-
- int[] otherPixel = new int[1];
- int[] myPixel = new int[1];
-
- int width = myImage.getWidth();
- int height = myImage.getHeight();
-
- int numDiffPixels = 0;
- // Now, go through pixel-by-pixel and check that the images are the same;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- if (myImage.getRGB(x, y) != otherImage.getRGB(x, y)) {
- numDiffPixels++;
- }
- }
- }
- double numberPixels = (height * width);
- double diffPercent = numDiffPixels / numberPixels;
- return percent <= 1.0 - diffPercent;
- }
-
- // TODO: figure out the location of this class and is superclasses
- private static class BufferedImageMonkeyImage extends MonkeyImageBase {
- private final BufferedImage image;
-
- public BufferedImageMonkeyImage(BufferedImage image) {
- this.image = image;
- }
-
- @Override
- public BufferedImage createBufferedImage() {
- return image;
- }
- }
-
- public static IMonkeyImage loadImageFromFile(String path) {
- File f = new File(path);
- if (f.exists() && f.canRead()) {
- try {
- BufferedImage bufferedImage = ImageIO.read(new File(path));
- if (bufferedImage == null) {
- LOG.log(Level.WARNING, "Cannot decode file %s", path);
- return null;
- }
- return new BufferedImageMonkeyImage(bufferedImage);
- } catch (IOException e) {
- LOG.log(Level.WARNING, "Exception trying to decode image", e);
- return null;
- }
- } else {
- LOG.log(Level.WARNING, "Cannot read file %s", path);
- return null;
- }
- }
-
- @Override
- public IMonkeyImage getSubImage(int x, int y, int w, int h) {
- BufferedImage image = getBufferedImage();
- return new BufferedImageMonkeyImage(image.getSubimage(x, y, w, h));
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/core/TouchPressType.java b/monkeyrunner/src/com/android/monkeyrunner/core/TouchPressType.java
deleted file mode 100644
index cfa878a..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/core/TouchPressType.java
+++ /dev/null
@@ -1,49 +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 com.android.monkeyrunner.core;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * TouchPressType enum contains valid input for the "touch" Monkey command.
- * When passed as a string, the "identifier" value is used.
- */
-public enum TouchPressType {
- DOWN("down"), UP("up"), DOWN_AND_UP("downAndUp");
-
- private static final Map<String,TouchPressType> identifierToEnum =
- new HashMap<String,TouchPressType>();
- static {
- for (TouchPressType type : values()) {
- identifierToEnum.put(type.identifier, type);
- }
- }
-
- private String identifier;
-
- TouchPressType(String identifier) {
- this.identifier = identifier;
- }
-
- public String getIdentifier() {
- return identifier;
- }
-
- public static TouchPressType fromIdentifier(String name) {
- return identifierToEnum.get(name);
- }
-} \ No newline at end of file
diff --git a/monkeyrunner/src/com/android/monkeyrunner/easy/By.java b/monkeyrunner/src/com/android/monkeyrunner/easy/By.java
index 1ed1c6f..082586d 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/easy/By.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/easy/By.java
@@ -18,6 +18,7 @@ package com.android.monkeyrunner.easy;
import com.google.common.base.Preconditions;
+import com.android.chimpchat.hierarchyviewer.HierarchyViewer;
import com.android.hierarchyviewerlib.device.ViewNode;
import com.android.monkeyrunner.JythonUtils;
import com.android.monkeyrunner.doc.MonkeyRunnerExported;
@@ -67,19 +68,9 @@ public class By extends PyObject implements ClassDictInit {
return new By(id);
}
- /**
- * Find the selected view from the root view node.
- */
- ViewNode find(ViewNode rootNode) {
- if (rootNode.id.equals(id)) {
- return rootNode;
- }
- for (ViewNode child : rootNode.children) {
- ViewNode found = find(child);
- if (found != null) {
- return found;
- }
- }
- return null;
+ public ViewNode findView(HierarchyViewer viewer) {
+ return viewer.findViewById(id);
}
+
+
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/easy/EasyMonkeyDevice.java b/monkeyrunner/src/com/android/monkeyrunner/easy/EasyMonkeyDevice.java
index 1c6c71b..fb778b7 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/easy/EasyMonkeyDevice.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/easy/EasyMonkeyDevice.java
@@ -18,10 +18,11 @@ package com.android.monkeyrunner.easy;
import com.google.common.base.Preconditions;
+import com.android.chimpchat.core.TouchPressType;
+import com.android.chimpchat.hierarchyviewer.HierarchyViewer;
import com.android.hierarchyviewerlib.device.ViewNode;
import com.android.monkeyrunner.JythonUtils;
import com.android.monkeyrunner.MonkeyDevice;
-import com.android.monkeyrunner.core.TouchPressType;
import com.android.monkeyrunner.doc.MonkeyRunnerExported;
import org.eclipse.swt.graphics.Point;
@@ -115,7 +116,7 @@ public class EasyMonkeyDevice extends PyObject implements ClassDictInit {
By selector = getSelector(ap, 0);
- ViewNode node = mHierarchyViewer.findView(selector);
+ ViewNode node = selector.findView(mHierarchyViewer);
Point p = HierarchyViewer.getAbsolutePositionOfView(node);
PyTuple tuple = new PyTuple(
new PyInteger(p.x),
@@ -138,7 +139,7 @@ public class EasyMonkeyDevice extends PyObject implements ClassDictInit {
}
public boolean exists(By selector) {
- ViewNode node = mHierarchyViewer.findView(selector);
+ ViewNode node = selector.findView(mHierarchyViewer);
return node != null;
}
@@ -155,7 +156,8 @@ public class EasyMonkeyDevice extends PyObject implements ClassDictInit {
}
public boolean visible(By selector) {
- return mHierarchyViewer.visible(selector);
+ ViewNode node = selector.findView(mHierarchyViewer);
+ return mHierarchyViewer.visible(node);
}
@MonkeyRunnerExported(doc = "Obtain the text in the selected input box.",
@@ -171,7 +173,8 @@ public class EasyMonkeyDevice extends PyObject implements ClassDictInit {
}
public String getText(By selector) {
- return mHierarchyViewer.getText(selector);
+ ViewNode node = selector.findView(mHierarchyViewer);
+ return mHierarchyViewer.getText(node);
}
@MonkeyRunnerExported(doc = "Gets the id of the focused window.",
@@ -213,7 +216,7 @@ public class EasyMonkeyDevice extends PyObject implements ClassDictInit {
* @return the (x,y) coordinates of the center
*/
private Point getElementCenter(By selector) {
- ViewNode node = mHierarchyViewer.findView(selector);
+ ViewNode node = selector.findView(mHierarchyViewer);
if (node == null) {
throw new PyException(Py.ValueError,
String.format("View not found: %s", selector));
@@ -223,4 +226,4 @@ public class EasyMonkeyDevice extends PyObject implements ClassDictInit {
return p;
}
-} \ No newline at end of file
+}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/easy/HierarchyViewer.java b/monkeyrunner/src/com/android/monkeyrunner/easy/HierarchyViewer.java
deleted file mode 100644
index 450571c..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/easy/HierarchyViewer.java
+++ /dev/null
@@ -1,158 +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 com.android.monkeyrunner.easy;
-
-import com.android.ddmlib.IDevice;
-import com.android.ddmlib.Log;
-import com.android.hierarchyviewerlib.device.DeviceBridge;
-import com.android.hierarchyviewerlib.device.ViewNode;
-import com.android.hierarchyviewerlib.device.Window;
-
-import org.eclipse.swt.graphics.Point;
-
-/**
- * Class for querying the view hierarchy of the device.
- */
-public class HierarchyViewer {
- public static final String TAG = "hierarchyviewer";
-
- private IDevice mDevice;
-
- /**
- * Constructs the hierarchy viewer for the specified device.
- *
- * @param device The Android device to connect to.
- */
- public HierarchyViewer(IDevice device) {
- this.mDevice = device;
- setupViewServer();
- }
-
- private void setupViewServer() {
- DeviceBridge.setupDeviceForward(mDevice);
- if (!DeviceBridge.isViewServerRunning(mDevice)) {
- if (!DeviceBridge.startViewServer(mDevice)) {
- // TODO: Get rid of this delay.
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- }
- if (!DeviceBridge.startViewServer(mDevice)) {
- Log.e(TAG, "Unable to debug device " + mDevice);
- throw new RuntimeException("Could not connect to the view server");
- }
- return;
- }
- }
- DeviceBridge.loadViewServerInfo(mDevice);
- }
-
- /**
- * Finds a view using a selector. Currently only supports selectors which
- * specify an id.
- *
- * @param selector selector for the view.
- * @return view with the specified ID, or {@code null} if no view found.
- */
- public ViewNode findView(By selector) {
- ViewNode rootNode = DeviceBridge.loadWindowData(
- new Window(mDevice, "", 0xffffffff));
- if (rootNode == null) {
- throw new RuntimeException("Could not dump view");
- }
- return selector.find(rootNode);
- }
-
- /**
- * Gets the window that currently receives the focus.
- *
- * @return name of the window that currently receives the focus.
- */
- public String getFocusedWindowName() {
- int id = DeviceBridge.getFocusedWindow(mDevice);
- Window[] windows = DeviceBridge.loadWindows(mDevice);
- for (Window w : windows) {
- if (w.getHashCode() == id)
- return w.getTitle();
- }
- return null;
- }
-
- /**
- * Gets the absolute x/y position of the view node.
- *
- * @param node view node to find position of.
- * @return point specifying the x/y position of the node.
- */
- public static Point getAbsolutePositionOfView(ViewNode node) {
- int x = node.left;
- int y = node.top;
- ViewNode p = node.parent;
- while (p != null) {
- x += p.left - p.scrollX;
- y += p.top - p.scrollY;
- p = p.parent;
- }
- return new Point(x, y);
- }
-
- /**
- * Gets the absolute x/y center of the specified view node.
- *
- * @param node view node to find position of.
- * @return absolute x/y center of the specified view node.
- */
- public static Point getAbsoluteCenterOfView(ViewNode node) {
- Point point = getAbsolutePositionOfView(node);
- return new Point(
- point.x + (node.width / 2), point.y + (node.height / 2));
- }
-
- /**
- * Gets the visibility of a given element.
- *
- * @param selector selector for the view.
- * @return True if the element is visible.
- */
- public boolean visible(By selector) {
- ViewNode node = findView(selector);
- boolean ret = (node != null)
- && node.namedProperties.containsKey("getVisibility()")
- && "VISIBLE".equalsIgnoreCase(
- node.namedProperties.get("getVisibility()").value);
- return ret;
-
- }
-
- /**
- * Gets the text of a given element.
- *
- * @param selector selector for the view.
- * @return the text of the given element.
- */
- public String getText(By selector) {
- ViewNode node = findView(selector);
- if (node == null) {
- throw new RuntimeException("Node not found");
- }
- ViewNode.Property textProperty = node.namedProperties.get("text:mText");
- if (textProperty == null) {
- throw new RuntimeException("No text property on node");
- }
- return textProperty.value;
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/exceptions/MonkeyRunnerException.java b/monkeyrunner/src/com/android/monkeyrunner/exceptions/MonkeyRunnerException.java
deleted file mode 100644
index 8fe4143..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/exceptions/MonkeyRunnerException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.exceptions;
-
-/**
- * Base exception class for all MonkeyRunner Exceptions.
- */
-public class MonkeyRunnerException extends Exception {
- public MonkeyRunnerException(String message) {
- super(message);
- }
-
- public MonkeyRunnerException(Throwable e) {
- super(e);
- }
-
- public MonkeyRunnerException(String message, Throwable e) {
- super(message, e);
- }
-}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorder.java b/monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorder.java
index bde882e..c8b4553 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorder.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorder.java
@@ -15,10 +15,9 @@
*/
package com.android.monkeyrunner.recorder;
+import com.android.chimpchat.ChimpChat;
+import com.android.chimpchat.core.IChimpDevice;
import com.android.monkeyrunner.MonkeyDevice;
-import com.android.monkeyrunner.adb.AdbBackend;
-import com.android.monkeyrunner.core.IMonkeyBackend;
-import com.android.monkeyrunner.core.IMonkeyDevice;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@@ -50,7 +49,7 @@ public class MonkeyRecorder {
start(device.getImpl());
}
- /* package */static void start(final IMonkeyDevice device) {
+ /* package */static void start(final IChimpDevice device) {
MonkeyRecorderFrame frame = new MonkeyRecorderFrame(device);
// TODO: this is a hack until the window listener works.
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
@@ -75,7 +74,7 @@ public class MonkeyRecorder {
}
public static void main(String[] args) {
- IMonkeyBackend adb = new AdbBackend();
- MonkeyRecorder.start(adb.waitForConnection());
+ ChimpChat chimp = ChimpChat.getInstance();
+ MonkeyRecorder.start(chimp.waitForConnection());
}
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorderFrame.java b/monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorderFrame.java
index 88c1e16..394b895 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorderFrame.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/recorder/MonkeyRecorderFrame.java
@@ -16,8 +16,8 @@
package com.android.monkeyrunner.recorder;
import com.android.monkeyrunner.MonkeyDevice;
-import com.android.monkeyrunner.core.IMonkeyImage;
-import com.android.monkeyrunner.core.IMonkeyDevice;
+import com.android.chimpchat.core.IChimpImage;
+import com.android.chimpchat.core.IChimpDevice;
import com.android.monkeyrunner.recorder.actions.Action;
import com.android.monkeyrunner.recorder.actions.DragAction;
import com.android.monkeyrunner.recorder.actions.DragAction.Direction;
@@ -61,7 +61,7 @@ public class MonkeyRecorderFrame extends JFrame {
private static final Logger LOG =
Logger.getLogger(MonkeyRecorderFrame.class.getName());
- private final IMonkeyDevice device;
+ private final IChimpDevice device;
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
@@ -93,7 +93,7 @@ public class MonkeyRecorderFrame extends JFrame {
/**
* This is the default constructor
*/
- public MonkeyRecorderFrame(IMonkeyDevice device) {
+ public MonkeyRecorderFrame(IChimpDevice device) {
this.device = device;
initialize();
}
@@ -112,7 +112,7 @@ public class MonkeyRecorderFrame extends JFrame {
}
private void refreshDisplay() {
- IMonkeyImage snapshot = device.takeSnapshot();
+ IChimpImage snapshot = device.takeSnapshot();
currentImage = snapshot.createBufferedImage();
Graphics2D g = scaledImage.createGraphics();
diff --git a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/Action.java b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/Action.java
index 6fa91ab..905f1f1 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/Action.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/Action.java
@@ -15,7 +15,7 @@
*/
package com.android.monkeyrunner.recorder.actions;
-import com.android.monkeyrunner.core.IMonkeyDevice;
+import com.android.chimpchat.core.IChimpDevice;
/**
* All actions that can be recorded must implement this interface.
@@ -41,5 +41,5 @@ public interface Action {
*
* @param device the device to execute the action on.
*/
- void execute(IMonkeyDevice device) throws Exception;
+ void execute(IChimpDevice device) throws Exception;
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/DragAction.java b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/DragAction.java
index 2461c0d..498bc6b 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/DragAction.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/DragAction.java
@@ -15,7 +15,7 @@
*/
package com.android.monkeyrunner.recorder.actions;
-import com.android.monkeyrunner.core.IMonkeyDevice;
+import com.android.chimpchat.core.IChimpDevice;
/**
* Action to drag the "finger" across the device.
@@ -77,7 +77,7 @@ public class DragAction implements Action {
}
@Override
- public void execute(IMonkeyDevice device) {
+ public void execute(IChimpDevice device) {
device.drag(startx, starty, endx, endy, steps, timeMs);
}
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/PressAction.java b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/PressAction.java
index 88c3fa7..4245736 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/PressAction.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/PressAction.java
@@ -19,8 +19,8 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.android.monkeyrunner.MonkeyDevice;
-import com.android.monkeyrunner.core.IMonkeyDevice;
-import com.android.monkeyrunner.core.TouchPressType;
+import com.android.chimpchat.core.IChimpDevice;
+import com.android.chimpchat.core.TouchPressType;
/**
* Action to press a certain button.
@@ -62,7 +62,7 @@ public class PressAction implements Action {
}
@Override
- public void execute(IMonkeyDevice device) {
+ public void execute(IChimpDevice device) {
device.press(key, TouchPressType.fromIdentifier(downUpFlag));
}
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TouchAction.java b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TouchAction.java
index 1001bef..146bb55 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TouchAction.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TouchAction.java
@@ -19,8 +19,8 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.android.monkeyrunner.MonkeyDevice;
-import com.android.monkeyrunner.core.IMonkeyDevice;
-import com.android.monkeyrunner.core.TouchPressType;
+import com.android.chimpchat.core.IChimpDevice;
+import com.android.chimpchat.core.TouchPressType;
/**
* Action to touch the touchscreen at a certain location.
@@ -48,7 +48,7 @@ public class TouchAction implements Action {
}
@Override
- public void execute(IMonkeyDevice device) throws Exception {
+ public void execute(IChimpDevice device) throws Exception {
device.touch(x, y, TouchPressType.fromIdentifier(direction));
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TypeAction.java b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TypeAction.java
index 78e90b0..fd5f786 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TypeAction.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/TypeAction.java
@@ -15,7 +15,7 @@
*/
package com.android.monkeyrunner.recorder.actions;
-import com.android.monkeyrunner.core.IMonkeyDevice;
+import com.android.chimpchat.core.IChimpDevice;
/**
* Action to type in a string on the device.
@@ -40,7 +40,7 @@ public class TypeAction implements Action {
}
@Override
- public void execute(IMonkeyDevice device) {
+ public void execute(IChimpDevice device) {
device.type(whatToType);
}
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/WaitAction.java b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/WaitAction.java
index bd2d421..d61570b 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/WaitAction.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/recorder/actions/WaitAction.java
@@ -15,7 +15,7 @@
*/
package com.android.monkeyrunner.recorder.actions;
-import com.android.monkeyrunner.core.IMonkeyDevice;
+import com.android.chimpchat.core.IChimpDevice;
/**
* Action that specifies to wait for a certain amount of time.
@@ -36,7 +36,7 @@ public class WaitAction implements Action {
return "WAIT|" + pydict;
}
- public void execute(IMonkeyDevice device) throws Exception {
+ public void execute(IChimpDevice device) throws Exception {
long ms = (long) (1000.0f * howLongSeconds);
Thread.sleep(ms);
}
diff --git a/monkeyrunner/src/com/android/monkeyrunner/stub/StubBackend.java b/monkeyrunner/src/com/android/monkeyrunner/stub/StubBackend.java
deleted file mode 100644
index b868bf1..0000000
--- a/monkeyrunner/src/com/android/monkeyrunner/stub/StubBackend.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.monkeyrunner.stub;
-
-import com.android.monkeyrunner.MonkeyManager;
-import com.android.monkeyrunner.core.IMonkeyBackend;
-import com.android.monkeyrunner.core.IMonkeyDevice;
-
-public class StubBackend implements IMonkeyBackend {
- public MonkeyManager createManager(String address, int port) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public IMonkeyDevice waitForConnection() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public IMonkeyDevice waitForConnection(long timeout, String deviceId) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void shutdown() {
- // We're stub - we've got nothing to do.
- }
-}
diff --git a/monkeyrunner/test/com/android/monkeyrunner/AllTests.java b/monkeyrunner/test/com/android/monkeyrunner/AllTests.java
index 9616759..2e0bffd 100644
--- a/monkeyrunner/test/com/android/monkeyrunner/AllTests.java
+++ b/monkeyrunner/test/com/android/monkeyrunner/AllTests.java
@@ -15,9 +15,6 @@
*/
package com.android.monkeyrunner;
-import com.android.monkeyrunner.adb.AdbMonkeyDeviceTest;
-import com.android.monkeyrunner.adb.LinearInterpolatorTest;
-
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
@@ -38,9 +35,8 @@ public class AllTests {
public static void main(String args[]) {
TestRunner tr = new TestRunner();
- TestResult result = tr.doRun(AllTests.suite(ImageUtilsTest.class, JythonUtilsTest.class,
- MonkeyRunnerOptionsTest.class, LinearInterpolatorTest.class,
- AdbMonkeyDeviceTest.class));
+ TestResult result = tr.doRun(AllTests.suite(JythonUtilsTest.class,
+ MonkeyRunnerOptionsTest.class));
if (result.wasSuccessful()) {
System.exit(0);
} else {