Bug 1055562 - crash in java.lang.IllegalStateException: Callback has already been executed. r=wesj
authorRandall Barker <rbarker@mozilla.com>
Mon, 13 Oct 2014 13:48:00 +0200
changeset 210332 441c734a3643e0a25c4ac2a1f85df8d2f617b9eb
parent 210331 073e83cef2381484ade504b58df6f845b796ed84
child 210333 14db61bb86658c3184ed5940fd7eb9111b9c0cae
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerswesj
bugs1055562
milestone36.0a1
Bug 1055562 - crash in java.lang.IllegalStateException: Callback has already been executed. r=wesj
mobile/android/base/ChromeCast.java
--- a/mobile/android/base/ChromeCast.java
+++ b/mobile/android/base/ChromeCast.java
@@ -371,25 +371,30 @@ class ChromeCast implements GeckoMediaPl
                                            });
                 } catch (Exception e) {
                     Log.e(LOGTAG, "Exception while sending message", e);
                 }
             }
         }
     }
     private class MirrorCallback implements ResultCallback<ApplicationConnectionResult> {
-
-        final EventCallback callback;
+        // See Bug 1055562, callback is set to null after it has been
+        // invoked so that it will not be called a second time.
+        EventCallback callback;
         MirrorCallback(final EventCallback callback) {
             this.callback = callback;
         }
 
 
         @Override
         public void onResult(ApplicationConnectionResult result) {
+            if (callback == null) {
+                Log.e(LOGTAG, "Attempting to invoke MirrorChannel callback more than once.");
+                return;
+            }
             Status status = result.getStatus();
             if (status.isSuccess()) {
                 ApplicationMetadata applicationMetadata = result.getApplicationMetadata();
                 mSessionId = result.getSessionId();
                 String applicationStatus = result.getApplicationStatus();
                 boolean wasLaunched = result.getWasLaunched();
                 mApplicationStarted = true;
 
@@ -397,23 +402,25 @@ class ChromeCast implements GeckoMediaPl
                 // channel
                 mMirrorChannel = new MirrorChannel();
                 try {
                     Cast.CastApi.setMessageReceivedCallbacks(apiClient,
                                                              mMirrorChannel
                                                              .getNamespace(),
                                                              mMirrorChannel);
                     callback.sendSuccess(null);
+                    callback = null;
                 } catch (IOException e) {
                     Log.e(LOGTAG, "Exception while creating channel", e);
                 }
 
                 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Casting:Mirror", route.getId()));
             } else {
                 callback.sendError(status.toString());
+                callback = null;
             }
         }
     }
 
     @Override
     public void message(String msg, final EventCallback callback) {
         if (mMirrorChannel != null) {
             mMirrorChannel.sendMessage(msg);