Skip to content

Commit

Permalink
android-recover-both-usb-disconnect-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
remibettan committed Mar 8, 2020
1 parent 213596b commit d090b58
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/uvc/uvc-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ namespace librealsense
_messenger = _usb_device->open(_info.mi);
if (_messenger)
{
listen_to_interrupts();
try{
listen_to_interrupts();
} catch(std::exception exception) {
// this exception catching avoids crash when disconnecting 2 devices at once - bug seen in android os
LOG_WARNING("rs_uvc_device exception in listen_to_interrupts method: " << exception.what());
}
_power_state = D0;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private synchronized void start() {
Log.d(TAG, "streaming started successfully");
} catch (Exception e) {
Log.d(TAG, "failed to start streaming");
mGLSurfaceView.clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,22 @@ private synchronized void invalidateDevices() {
}
}

private void removeDevice(UsbDesc desc) {
Log.d(TAG, "Removing device: " + desc.name);

nRemoveUsbDevice(desc.descriptor);
desc.connection.close();
private void updateListeners(){
for(DeviceListener listener : mAppDeviceListener) {
try {
listener.onDeviceDetach();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
}

private void removeDevice(UsbDesc desc) {
Log.d(TAG, "Removing device: " + desc.name);

nRemoveUsbDevice(desc.descriptor);
desc.connection.close();
updateListeners();
Log.d(TAG, "Device: " + desc.name + " removed successfully");
}

Expand All @@ -108,13 +112,7 @@ private void addDevice(UsbDevice device) {
mDescriptors.put(device.getDeviceName(), desc);
nAddUsbDevice(desc.name, desc.descriptor);

for (DeviceListener listener : mAppDeviceListener){
try {
listener.onDeviceAttach();
} catch (Exception e){
Log.e(TAG, e.getMessage());
}
}
updateListeners();
Log.d(TAG, "Device: " + desc.name + " added successfully");
}

Expand Down

0 comments on commit d090b58

Please sign in to comment.