use of com.android.ddmlib.IDevice in project buck by facebook.
the class AdbHelperTest method testDeviceFilterNoMatchingDevices.
/**
* Verify that if no devices match filters null is returned.
*/
@Test
public void testDeviceFilterNoMatchingDevices() throws CmdLineException {
IDevice[] devices = new IDevice[] { createRealDevice("1", IDevice.DeviceState.ONLINE), createEmulator("2", IDevice.DeviceState.ONLINE), createRealDevice("3", IDevice.DeviceState.ONLINE), createEmulator("4", IDevice.DeviceState.ONLINE) };
AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, false, Optional.of("invalid-serial")));
List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
assertNull(filteredDevices);
}
use of com.android.ddmlib.IDevice in project buck by facebook.
the class AndroidDebugger method attachDebugger.
public static void attachDebugger(final String packageName, final Project project) throws InterruptedException {
IDevice[] devices = AndroidDebugBridge.getBridge().getDevices();
if (devices.length == 0) {
return;
}
IDevice device = devices[0];
Client client;
int currentRetryNumber = 0;
int currentRetryTime = RETRY_TIME;
// It takes some time to get the updated client process list, so wait for it
do {
client = device.getClient(packageName);
currentRetryTime *= 2;
Thread.sleep(currentRetryTime);
currentRetryNumber++;
} while (client == null && currentRetryNumber < MAX_RETRIES);
if (client == null) {
throw new RuntimeException("Connecting to the adb debug server timed out." + "Can't find package with name " + packageName + ".");
}
String debugPort = String.valueOf(client.getDebuggerListenPort());
final RunnerAndConfigurationSettings settings = createRunConfiguration(project, debugPort);
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
// Needs read access which is available on the read thread.
ProgramRunnerUtil.executeConfiguration(project, settings, DefaultDebugExecutor.getDebugExecutorInstance());
}
});
}
use of com.android.ddmlib.IDevice in project buck by facebook.
the class InstrumentationTestRunner method run.
public void run() throws Throwable {
IDevice device = getDevice(this.deviceSerial);
if (device == null) {
System.err.printf("Unable to get device/emulator with serial %s", this.deviceSerial);
System.exit(1);
}
if (this.instrumentationApkPath != null) {
DdmPreferences.setTimeOut(60000);
device.installPackage(this.instrumentationApkPath, true);
if (this.apkUnderTestPath != null) {
device.installPackage(this.apkUnderTestPath, true);
}
}
try {
final RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner(this.packageName, this.testRunner, getDevice(deviceSerial));
for (Map.Entry<String, String> entry : this.extraInstrumentationArguments.entrySet()) {
runner.addInstrumentationArg(entry.getKey(), entry.getValue());
}
BuckXmlTestRunListener listener = new BuckXmlTestRunListener();
ITestRunListener trimLineListener = new ITestRunListener() {
/**
* Before the actual run starts (and after the
* InstrumentationResultsParser is created), we need to do
* some reflection magic to make RemoteAndroidTestRunner not
* trim indentation from lines.
*/
@Override
public void testRunStarted(String runName, int testCount) {
setTrimLine(runner, false);
}
@Override
public void testRunEnded(long elapsedTime, Map<String, String> runMetrics) {
}
@Override
public void testRunFailed(String errorMessage) {
}
@Override
public void testStarted(TestIdentifier test) {
}
@Override
public void testFailed(TestIdentifier test, String trace) {
}
@Override
public void testAssumptionFailure(TestIdentifier test, String trace) {
}
@Override
public void testIgnored(TestIdentifier test) {
}
@Override
public void testEnded(TestIdentifier test, Map<String, String> testMetrics) {
}
@Override
public void testRunStopped(long elapsedTime) {
}
};
listener.setReportDir(this.outputDirectory);
runner.run(trimLineListener, listener);
} finally {
if (this.attemptUninstall) {
// Best effort uninstall from the emulator/device.
device.uninstallPackage(this.packageName);
}
}
}
use of com.android.ddmlib.IDevice in project adb-idea by pbreault.
the class MyDeviceChooser method getSelectedDevices.
@NotNull
public IDevice[] getSelectedDevices() {
int[] rows = mySelectedRows != null ? mySelectedRows : myDeviceTable.getSelectedRows();
List<IDevice> result = new ArrayList<IDevice>();
for (int row : rows) {
if (row >= 0) {
Object serial = myDeviceTable.getValueAt(row, SERIAL_COLUMN_INDEX);
final AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(myFacet.getModule().getProject());
if (bridge == null) {
return EMPTY_DEVICE_ARRAY;
}
IDevice[] devices = getFilteredDevices(bridge);
for (IDevice device : devices) {
if (device.getSerialNumber().equals(serial.toString())) {
result.add(device);
break;
}
}
}
}
return result.toArray(new IDevice[result.size()]);
}
use of com.android.ddmlib.IDevice in project otertool by wuntee.
the class Test method main.
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
AndroidDebugBridge.init(true);
AndroidDebugBridge adb = AndroidDebugBridge.createBridge("/Applications/android-sdk-macosx/platform-tools/adb", true);
while (!adb.hasInitialDeviceList()) {
System.out.println("Waiting...");
Thread.sleep(1000);
}
for (IDevice dev : adb.getDevices()) {
System.out.println(dev);
for (Client client : dev.getClients()) {
System.out.println(" -" + client);
}
}
IDevice dev = adb.getDevices()[0];
Client cli = dev.getClients()[0];
AndroidDebugBridge.disconnectBridge();
}
Aggregations