device.executeShellCommand(GetPropReceiver.GETPROP_COMMAND, new GetPropReceiver(device)); if (device.isEmulator()) { EmulatorConsole console = EmulatorConsole.getConsole(device); if (console != null) { device.setAvdName(console.getAvdName()); device.getSerialNumber())); device.getSerialNumber(), e.getMessage())); device.getSerialNumber())); device.getSerialNumber()));
@Override public void deviceListUpdate(@NonNull Map<String, DeviceState> devices) { List<Device> l = Lists.newArrayListWithExpectedSize(devices.size()); for (Map.Entry<String, DeviceState> entry : devices.entrySet()) { l.add(new Device(DeviceMonitor.this, entry.getKey(), entry.getValue())); } // now merge the new devices with the old ones. updateDevices(l); } }
public String getName() { if (mName != null) { return mName; } if (isOnline()) { // cache name only if device is online mName = constructName(); return mName; } else { return constructName(); } }
private void removeDevice(@NonNull Device device) { device.setState(DeviceState.DISCONNECTED); device.clearClientList(); mDevices.remove(device); SocketChannel channel = device.getClientMonitoringSocket(); if (channel != null) { try { channel.close(); } catch (IOException e) { // doesn't really matter if the close fails. } } }
private String constructName() { if (isEmulator()) { String avdName = getAvdName(); if (avdName != null) { return String.format("%s [%s]", avdName, getSerialNumber()); } else { return getSerialNumber(); manufacturer = cleanupStringForDisplay(getProperty(PROP_DEVICE_MANUFACTURER)); model = cleanupStringForDisplay(getProperty(PROP_DEVICE_MODEL)); } catch (Exception e) { sb.append(getSerialNumber()); return sb.toString();
public String syncPackageToDevice(String localFilePath) throws IOException, AdbCommandRejectedException, TimeoutException, SyncException { try { String packageFileName = getFileName(localFilePath); String remoteFilePath = String.format("/data/local/tmp/%1$s", packageFileName); //$NON-NLS-1$ Log.d(packageFileName, String.format("Uploading %1$s onto device '%2$s'", packageFileName, getSerialNumber())); SyncService sync = getSyncService(); if (sync != null) { String message = String.format("Uploading file onto device '%1$s'", getSerialNumber()); Log.d(LOG_TAG, message); sync.pushFile(localFilePath, remoteFilePath, SyncService.getNullProgressMonitor()); } else { throw new IOException("Unable to open sync connection!"); } return remoteFilePath; } catch (TimeoutException e) { Log.e(LOG_TAG, "Error during Sync: timeout."); throw e; } catch (SyncException e) { Log.e(LOG_TAG, String.format("Error during Sync: %1$s", e.getMessage())); throw e; } catch (IOException e) { Log.e(LOG_TAG, String.format("Error during Sync: %1$s", e.getMessage())); throw e; } }
Device newDevice = newList.get(dd); if (newDevice.getSerialNumber().equals(device.getSerialNumber())) { foundMatch = true; if (device.getState() != newDevice.getState()) { device.setState(newDevice.getState()); device.update(Device.CHANGE_STATE); if (device.isOnline()) { if (AndroidDebugBridge.getClientSupport() == true) { if (startMonitoringDevice(device) == false) { Log.e("DeviceMonitor", "Failed to start monitoring " + device.getSerialNumber()); if (device.getPropertyCount() == 0) { devicesToQuery.add(device); if (newDevice.isOnline()) { startMonitoringDevice(newDevice); if (newDevice.isOnline()) { devicesToQuery.add(newDevice);
device.setState(entry.getValue()); device.update(Device.CHANGE_STATE); if (device.isOnline()) { newlyOnline.add(device); if (!startMonitoringDevice(device)) { Log.e("DeviceMonitor", "Failed to start monitoring " + device.getSerialNumber()); device.getSystemProperty(IDevice.PROP_BUILD_API_LEVEL);
private void queryNewDeviceForMountingPoint(final Device device, final String name) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { device.executeShellCommand("echo $" + name, new MultiLineReceiver() { //$NON-NLS-1$ public boolean isCancelled() { return false; } @Override public void processNewLines(String[] lines) { for (String line : lines) { if (line.length() > 0) { // this should be the only one. device.setMountingPoint(name, line); } } } }); }
private void initiatePropertiesQuery() { String threadName = String.format("query-prop-%s", mDevice.getSerialNumber()); Thread propThread = new Thread(threadName) { @Override public void run() { try { GetPropReceiver propReceiver = new GetPropReceiver(); mDevice.executeShellCommand(GETPROP_COMMAND, propReceiver, GETPROP_TIMEOUT_SEC, TimeUnit.SECONDS); populateCache(propReceiver.getCollectedProperties()); } catch (Exception e) { handleException(e); } } }; propThread.setDaemon(true); propThread.start(); }
private String constructName() { String manufacturer = null; String model = null; try { manufacturer = cleanupStringForDisplay( getSystemProperty(PROP_DEVICE_MANUFACTURER).get()); model = cleanupStringForDisplay( getSystemProperty(PROP_DEVICE_MODEL).get()); } catch (Exception e) { // If there are exceptions thrown while attempting to get these properties, // we can just use the serial number, so ignore these exceptions. } StringBuilder sb = new StringBuilder(20); if (manufacturer != null) { sb.append(manufacturer); sb.append(SEPARATOR); } if (model != null) { sb.append(model); sb.append(SEPARATOR); } sb.append(getSerialNumber()); return sb.toString(); }
/** * Updates the device list with the new items received from the monitoring service. */ private void updateDevices(@NonNull List<Device> newList) { DeviceListComparisonResult result = DeviceListComparisonResult.compare(mDevices, newList); for (Device device : result.removed) { removeDevice(device); AndroidDebugBridge.deviceDisconnected(device); } List<Device> newlyOnline = new ArrayList<>(mDevices.size()); for (Map.Entry<Device, DeviceState> entry : result.updated.entrySet()) { Device device = entry.getKey(); device.setState(entry.getValue()); if (device.isOnline()) { newlyOnline.add(device); } } for (Device device : result.added) { mDevices.add(device); AndroidDebugBridge.deviceConnected(device); if (device.isOnline()) { newlyOnline.add(device); } } for (Device device : newlyOnline) { // Initiate a property fetch so that future requests can be served out of this cache. // This is necessary for backwards compatibility device.getSystemProperty(Device.PROP_BUILD_API_LEVEL); } }
private static void queryAvdName(@NonNull Device device) { if (!device.isEmulator()) { return; } EmulatorConsole console = EmulatorConsole.getConsole(device); if (console != null) { device.setAvdName(console.getAvdName()); console.close(); } }
@Override public void startScreenRecorder( @NonNull String remoteFilePath, @NonNull ScreenRecorderOptions options, @NonNull IShellOutputReceiver receiver) throws TimeoutException, AdbCommandRejectedException, IOException, ShellCommandUnresponsiveException { executeShellCommand(getScreenRecorderCommand(remoteFilePath, options), receiver, 0, null); }
/** * Sets the name of the AVD */ void setAvdName(String avdName) { if (isEmulator() == false) { throw new IllegalArgumentException( "Cannot set the AVD name of the device is not an emulator"); } mAvdName = avdName; }
private void removeDevice(@NonNull Device device) { device.setState(DeviceState.DISCONNECTED); mDevices.remove(device); }
device.addClient(client); monitorThread.addClient(client);
SyncService sync = null; try { String targetFileName = getFileName(local); targetFileName, getSerialNumber())); sync = getSyncService(); if (sync != null) { String message = String.format("Uploading file onto device '%1$s'", getSerialNumber()); Log.d(LOG_TAG, message); sync.pushFile(local, remote, SyncService.getNullProgressMonitor());
public static void shell(Device device, String cmd, IShellOutputReceiver outputReceiver) { try { device.executeShellCommand(cmd, outputReceiver, 60, TimeUnit.SECONDS); } catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException ex) { if (device.logError) LLog.ex(ex); } }
public static void createForward(InetSocketAddress adbSockAddr, Device device, int localPort, int remotePort) throws TimeoutException, AdbCommandRejectedException, IOException { SocketChannel adbChan = null; try { adbChan = SocketChannel.open(adbSockAddr); adbChan.configureBlocking(false); byte[] request = formAdbRequest(String.format( "host-serial:%1$s:forward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$ device.getSerialNumber(), localPort, remotePort)); write(adbChan, request);