Bug 1374572 - Don't access disconnected remote binder. r=esawin, a=jcristau
authorJohn Lin <jolin@mozilla.com>
Wed, 19 Jul 2017 12:53:04 +0800
changeset 414410 3d0ccc795265040da5765d88cc3505156047f8b4
parent 414409 285727e97c4c8488682e1deb95443bdc7f253e09
child 414411 e4222223d4ee4c96c9d586147e56b2843b16ed49
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin, jcristau
bugs1374572
milestone55.0
Bug 1374572 - Don't access disconnected remote binder. r=esawin, a=jcristau MozReview-Commit-ID: 6eYIbKgwRPd
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/RemoteManager.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/RemoteManager.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/RemoteManager.java
@@ -54,25 +54,17 @@ public final class RemoteManager impleme
                 mRemote = IMediaManager.Stub.asInterface(service);
                 notify();
             }
         }
 
         @Override
         public void onServiceDisconnected(ComponentName name) {
             if (DEBUG) Log.d(LOGTAG, "service disconnected");
-            try {
-                mRemote.asBinder().unlinkToDeath(RemoteManager.this, 0);
-            } catch (NoSuchElementException e) {
-                Log.w(LOGTAG, "death recipient already released");
-            }
-            synchronized (this) {
-                mRemote = null;
-                notify();
-            }
+            unlink();
         }
 
         private boolean connect() {
             Context appCtxt = GeckoAppShell.getApplicationContext();
             appCtxt.bindService(new Intent(appCtxt, MediaManager.class),
                     mConnection, Context.BIND_AUTO_CREATE);
             waitConnect();
             return mRemote != null;
@@ -98,16 +90,29 @@ public final class RemoteManager impleme
             while (mRemote != null) {
                 try {
                     wait(1000);
                 } catch (InterruptedException e) {
                     if (DEBUG) { e.printStackTrace(); }
                 }
             }
         }
+
+        private synchronized void unlink() {
+            if (mRemote == null) {
+                return;
+            }
+            try {
+                mRemote.asBinder().unlinkToDeath(RemoteManager.this, 0);
+            } catch (NoSuchElementException e) {
+                Log.w(LOGTAG, "death recipient already released");
+            }
+            mRemote = null;
+            notify();
+        }
     };
 
     RemoteConnection mConnection = new RemoteConnection();
 
     private synchronized boolean init() {
         if (mRemote != null) {
             return true;
         }
@@ -216,14 +221,13 @@ public final class RemoteManager impleme
             if (mProxies.remove(proxy) && mProxies.isEmpty()) {
                 release();
             }
         }
     }
 
     private void release() {
         if (DEBUG) Log.d(LOGTAG, "release remote manager " + this);
+        mConnection.unlink();
         Context appCtxt = GeckoAppShell.getApplicationContext();
-        mRemote.asBinder().unlinkToDeath(this, 0);
-        mRemote = null;
         appCtxt.unbindService(mConnection);
     }
 } // RemoteManager
\ No newline at end of file