Skip to content

Commit

Permalink
Probably fix crashes in DLNARouterProvider from concurrent add/remove…
Browse files Browse the repository at this point in the history
… events
  • Loading branch information
daneren2005 committed Jul 29, 2018
1 parent eebdb97 commit 2f2a031
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ private void deviceAdded(final Device device) {
removing.remove(id);
return;
}
adding.add(id);
synchronized (adding) {
adding.add(id);
}

if(device.getType().getType().equals("MediaRenderer") && device instanceof RemoteDevice) {
try {
Expand All @@ -255,21 +257,35 @@ public void run() {
broadcastDescriptors();
}
});
adding.remove(id);

synchronized (adding) {
if (adding.contains(id)) {
adding.remove(id);
}
}
}

@Override
public void failure(ActionInvocation actionInvocation, UpnpResponse upnpResponse, String s) {
Log.w(TAG, "Failed to get default volume for DLNA route");
Log.w(TAG, "Reason: " + s);
adding.remove(id);

synchronized (adding) {
if (adding.contains(id)) {
adding.remove(id);
}
}
}
});
} catch(Exception e) {
Log.e(TAG, "Failed to add device", e);
}
} else {
adding.remove(id);
synchronized (adding) {
if(adding.contains(id)) {
adding.remove(id);
}
}
}
}
private void deviceRemoved(Device device) {
Expand Down

0 comments on commit 2f2a031

Please sign in to comment.