private void removeDevice(@NonNull Device device) { device.setState(DeviceState.DISCONNECTED); mDevices.remove(device); }
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. } } }
/** * 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); } }
device.setState(entry.getValue()); device.update(Device.CHANGE_STATE);
device.setState(newDevice.getState()); device.update(Device.CHANGE_STATE);