public static FakeDevice inDisconnectedState(String deviceId, DeviceState deviceState) { checkArgument(!deviceState.equals(DeviceState.ONLINE)); // In this state, querying device doesn't work. return new FakeDevice( deviceId, deviceState, Integer.MAX_VALUE, ImmutableList.of(), /* density= */ -1, ImmutableList.of(), ImmutableMap.of()); }
/** * Processes an incoming device message from the socket * @param socket * @param length * @throws IOException */ private void processIncomingDeviceData(int length) throws IOException { ArrayList<Device> list = new ArrayList<Device>(); if (length > 0) { byte[] buffer = new byte[length]; String result = read(mMainAdbConnection, buffer); String[] devices = result.split("\n"); //$NON-NLS-1$ for (String d : devices) { String[] param = d.split("\t"); //$NON-NLS-1$ if (param.length == 2) { // new adb uses only serial numbers to identify devices Device device = new Device(this, param[0] /*serialnumber*/, DeviceState.getState(param[1])); //add the device to the list list.add(device); } } } // now merge the new devices with the old ones. updateDevices(list); }
/** * Returns a {@link DeviceState} from the string returned by <code>adb devices</code>. * * @param state the device state. * @return a {@link DeviceState} object or <code>null</code> if the state is unknown. */ @Nullable public static DeviceState getState(String state) { for (DeviceState deviceState : values()) { if (deviceState.mState.equals(state)) { return deviceState; } } return null; }
/** * Returns a {@link DeviceState} from the string returned by <code>adb devices</code>. * * @param state the device state. * @return a {@link DeviceState} object or <code>null</code> if the state is unknown. */ public static DeviceState getState(String state) { for (DeviceState deviceState : values()) { if (deviceState.mState.equals(state)) { return deviceState; } } return null; } }
@VisibleForTesting static Map<String, DeviceState> parseDeviceListResponse(@Nullable String result) { Map<String, DeviceState> deviceStateMap = Maps.newHashMap(); String[] devices = result == null ? new String[0] : result.split("\n"); //$NON-NLS-1$ for (String d : devices) { String[] param = d.split("\t"); //$NON-NLS-1$ if (param.length == 2) { // new adb uses only serial numbers to identify devices deviceStateMap.put(param[0], DeviceState.getState(param[1])); } } return deviceStateMap; }
private Device getAndValidateDevice(Optional<String> deviceId) throws TimeoutException { Device device = getTargetDevice(deviceId) .orElseThrow( () -> CommandExecutionException.builder() .withMessage("Unable to find the requested device.") .build()); if (device.getState().equals(DeviceState.UNAUTHORIZED)) { throw CommandExecutionException.builder() .withMessage( "Device found but not authorized for connecting. " + "Please allow USB debugging on the device.") .build(); } else if (!device.getState().equals(DeviceState.ONLINE)) { throw CommandExecutionException.builder() .withMessage( "Unable to connect to the device (device state: '%s').", device.getState().name()) .build(); } return device; }