Bug 1055562 - crash in java.lang.IllegalStateException: Callback has already been executed. r=wesj
--- 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);