private void deviceClientMonitorLoop() { do { try { // This synchronized block stops us from doing the select() if a new // Device is being added. // @see startMonitoringDevice() lock (mDevices) { } int count = mSelector.select(); if (mQuit) { return; } lock (mClientsToReopen) { if (mClientsToReopen.Count > 0) { var clients = mClientsToReopen.Keys; MonitorThread monitorThread = MonitorThread.instance; foreach (Client client in clients) { Device device = client.deviceImpl; int pid = client.clientData.pid; monitorThread.dropClient(client, false); // notify // This is kinda bad, but if we don't wait a bit, the client // will never answer the second handshake! waitABit(); int port = mClientsToReopen[client]; if (port == DebugPortManager.DebugPortProvider.NO_STATIC_PORT) { port = nextDebuggerPort; } Log.d("DeviceMonitor", "Reopening " + client); openClient(device, pid, port, monitorThread); device.update(DeviceConstants.CHANGE_CLIENT_LIST); } mClientsToReopen.Clear(); } } if (count == 0) { continue; } var keys = mSelector.selectedKeys(); foreach (var key in keys) { //SelectionKey key = iter.Current; //iter.remove(); if (key.valid && key.readable) { object attachment = key.attachment(); if (attachment is Device) { Device device = (Device)attachment; SocketChannel socket = device.clientMonitoringSocket; if (socket != null) { try { int length = readLength(socket, mLengthBuffer2); processIncomingJdwpData(device, socket, length); } catch (IOException ioe) { Log.d("DeviceMonitor", "Error reading jdwp list: " + ioe.Message); socket.close(); // restart the monitoring of that device lock (mDevices) { if (mDevices.Contains(device)) { Log.d("DeviceMonitor", "Restarting monitoring service for " + device); startMonitoringDevice(device); } } } } } } } } catch (IOException) { if (mQuit == false) { } } } while (mQuit == false); }
public override void done() { mDevice.update(DeviceConstants.CHANGE_BUILD_INFO); }
/// <summary> /// Updates the device list with the new items received from the monitoring service. /// </summary> private void updateDevices(List <Device> newList) { // because we are going to call mServer.deviceDisconnected which will acquire this lock // we lock it first, so that the AndroidDebugBridge lock is always locked first. lock (AndroidDebugBridge.@lock) { // array to store the devices that must be queried for information. // it's important to not do it inside the synchronized loop as this could block // the whole workspace (this lock is acquired during build too). List <Device> devicesToQuery = new List <Device>(); lock (mDevices) { // For each device in the current list, we look for a matching the new list. // * if we find it, we update the current object with whatever new information // there is // (mostly state change, if the device becomes ready, we query for build info). // We also remove the device from the new list to mark it as "processed" // * if we do not find it, we remove it from the current list. // Once this is done, the new list contains device we aren't monitoring yet, so we // add them to the list, and start monitoring them. for (int d = 0; d < mDevices.Count;) { Device device = mDevices[d]; // look for a similar device in the new list. int count = newList.Count; bool foundMatch = false; for (int dd = 0; dd < count; dd++) { Device newDevice = newList[dd]; // see if it matches in id and serial number. if (newDevice.serialNumber.Equals(device.serialNumber)) { foundMatch = true; // update the state if needed. if (device.state != newDevice.state) { device.state = newDevice.state; device.update(DeviceConstants.CHANGE_STATE); // if the device just got ready/online, we need to start // monitoring it. if (device.online) { if (AndroidDebugBridge.clientSupport == true) { if (startMonitoringDevice(device) == false) { Log.e("DeviceMonitor", "Failed to start monitoring " + device.serialNumber); } } if (device.propertyCount == 0) { devicesToQuery.Add(device); } } } // remove the new device from the list since it's been used newList.RemoveAt(dd); break; } } if (foundMatch == false) { // the device is gone, we need to remove it, and keep current index // to process the next one. removeDevice(device); mServer.deviceDisconnected(device); } else { // process the next one d++; } } // at this point we should still have some new devices in newList, so we // process them. foreach (Device newDevice in newList) { // add them to the list mDevices.Add(newDevice); mServer.deviceConnected(newDevice); // start monitoring them. if (AndroidDebugBridge.clientSupport == true) { if (newDevice.online) { startMonitoringDevice(newDevice); } } // look for their build info. if (newDevice.online) { devicesToQuery.Add(newDevice); } } } // query the new devices for info. foreach (Device d in devicesToQuery) { queryNewDeviceForInfo(d); } } newList.Clear(); }
internal virtual void update(int changeMask) { mDevice.update(this, changeMask); }