diff options
author | Scott Jackson <daneren2005@gmail.com> | 2018-07-29 14:31:32 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2018-07-29 14:55:01 -0700 |
commit | ec8eda88305cad19f2fe16cf5516f27cd9fb2e50 (patch) | |
tree | 0708798fcb61df62d9e3d64d82a5603a60cd43aa | |
parent | 86bb65d838bb37f27e8de00b5f7ff3fe30c30782 (diff) | |
download | dsub-ec8eda88305cad19f2fe16cf5516f27cd9fb2e50.tar.gz dsub-ec8eda88305cad19f2fe16cf5516f27cd9fb2e50.tar.bz2 dsub-ec8eda88305cad19f2fe16cf5516f27cd9fb2e50.zip |
Probably fix crashes in DLNARouterProvider from concurrent add/remove events
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java b/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java index 0ee16723..f4238c99 100644 --- a/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java +++ b/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java @@ -228,7 +228,9 @@ public class DLNARouteProvider extends MediaRouteProvider { removing.remove(id); return; } - adding.add(id); + synchronized (adding) { + adding.add(id); + } if(device.getType().getType().equals("MediaRenderer") && device instanceof RemoteDevice) { try { @@ -255,21 +257,35 @@ public class DLNARouteProvider extends MediaRouteProvider { 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) { |