mMainSdbConnection.close();
}
} catch (IOException e) {
- Log.e("sdb", "close main sdb connection failed:" + e);
+ Log.e("sdb", "close main sdb connection failed:" + e);
}
// wake up the secondary loop by closing the selector.
Log.e("DeviceMonitor",
"sdb restart attempts: " + mRestartAttemptCount);
}
+ waitABit();
} else {
Log.d("DeviceMonitor", "connected to sdb for device monitoring");
}
}
- waitABit();
-
- if (mMainSdbConnection != null) {
+ if (mMainSdbConnection != null && mMonitoring == false) {
mMonitoring = sendDeviceListMonitoringRequest();
}
mMainSdbConnection.close();
} catch (IOException ioe) {
// we can safely ignore that one.
- Log.e("sdb", "close main sdb connection failed:" + ioe);
+ Log.e("sdb", "close main sdb connection failed:" + ioe);
}
mMainSdbConnection = null;
}
// 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).
+ ArrayList<Device> devicesToQuery = new ArrayList<Device>();
synchronized (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
// * 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.size() ; ) {
+ for (int d = 0 ; d < mDevices.size() ;) {
Device device = mDevices.get(d);
// look for a similar device in the new list.
int count = newList.size();
{
device.checkArchitecture();
device.checkDeviceType();
- Log.d("DeviceMonitor", "updateDevices: " + device.getSerialNumber() + " changed state to onlined");
+ Log.d("DeviceMonitor", "updateDevices: " + device.getSerialNumber() + " onlined");
device.update(Device.CHANGE_STATE);
}
}
removeDevice(device);
mServer.deviceDisconnected(device);
Log.d("DeviceMonitor", "updateDevices: " + device.getSerialNumber() + " off-lined");
- }
- else
- {
+ } else {
+ // process the next one
d++;
}
}
// look for their build info.
if (newDevice.isOnline()) {
+ devicesToQuery.add(newDevice);
mServer.deviceConnected(newDevice);
- Log.d("DeviceMonitor", "[New Device]: " + newDevice.getSerialNumber() + " newly connected.");
+ Log.d("DeviceMonitor", "updateDevices: " + newDevice.getSerialNumber() + " newly connected.");
}
}
}
return Integer.parseInt(msg, 16);
} catch (NumberFormatException nfe) {
// we'll throw an exception below.
- Log.e("sdb", "parse integer failed:" + nfe);
+ Log.e("sdb", "parse integer failed:" + nfe);
}
}
try {
return new String(buffer, 0, buf.position(), SdbHelper.DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
- Log.e("sdb", "read buffer failed from socket:" + e);
+ Log.e("sdb", "read buffer failed from socket:" + e);
}
return null;