diff options
Diffstat (limited to 'chimpchat/src')
15 files changed, 98 insertions, 21 deletions
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"), |