Log friendlier messages when bridge calls are recieved from previous page

This commit is contained in:
Andrew Grieve 2014-07-10 10:14:47 -04:00
parent 4b4b71ff32
commit fc2a202afa
2 changed files with 22 additions and 0 deletions

View File

@ -41,7 +41,22 @@ public class CordovaBridge {
this.jsMessageQueue = jsMessageQueue;
}
private final boolean checkBridgeEnabled(String action) {
if (!jsMessageQueue.isBridgeEnabled()) {
if (bridgeSecret == -1) {
Log.d(LOG_TAG, action + " call made before bridge was enabled.");
} else {
Log.d(LOG_TAG, "Ignoring " + action + " from previous page load.");
}
return false;
}
return true;
}
public String jsExec(int bridgeSecret, String service, String action, String callbackId, String arguments) throws JSONException, IllegalAccessException {
if (!checkBridgeEnabled("exec()")) {
return "";
}
verifySecret(bridgeSecret);
// If the arguments weren't received, send a message back to JS. It will switch bridge modes and try again. See CB-2666.
// We send a message meant specifically for this case. It starts with "@" so no other message can be encoded into the same string.
@ -74,6 +89,9 @@ public class CordovaBridge {
}
public String jsRetrieveJsMessages(int bridgeSecret, boolean fromOnlineEvent) throws IllegalAccessException {
if (!checkBridgeEnabled("retrieveJsMessages()")) {
return "";
}
verifySecret(bridgeSecret);
return jsMessageQueue.popAndEncode(fromOnlineEvent);
}

View File

@ -85,6 +85,10 @@ public class NativeToJsMessageQueue {
reset();
}
public boolean isBridgeEnabled() {
return activeBridgeMode != null;
}
/**
* Changes the bridge mode.
*/