Skip to content

Commit

Permalink
Fix NPE caused by NetworkManager sending update before JS is ready.
Browse files Browse the repository at this point in the history
This was happening for me when the device has been sleeping long
enough to turn its networking off, and I start an app via adb.
  • Loading branch information
agrieve committed Oct 2, 2012
1 parent 6f873ff commit 5289d56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions framework/src/org/apache/cordova/NativeToJsMessageQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ public void addJavaScript(String statement) {
* Add a JavaScript statement to the list.
*/
public void addPluginResult(PluginResult result, String callbackId) {
if (callbackId == null) {
Log.e(LOG_TAG, "Got plugin result with no callbackId", new Throwable());
return;
}
// Don't send anything if there is no result and there is no need to
// clear the callbacks.
boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal();
Expand Down
8 changes: 5 additions & 3 deletions framework/src/org/apache/cordova/NetworkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ private String getConnectionInfo(NetworkInfo info) {
* @param connection the network info to set as navigator.connection
*/
private void sendUpdate(String type) {
PluginResult result = new PluginResult(PluginResult.Status.OK, type);
result.setKeepCallback(true);
this.success(result, this.connectionCallbackId);
if (connectionCallbackId != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, type);
result.setKeepCallback(true);
this.success(result, this.connectionCallbackId);
}

webView.postMessage("networkconnection", type);
}
Expand Down

0 comments on commit 5289d56

Please sign in to comment.