Skip to content

Commit

Permalink
CB-11828: Adding dirty userAgent checking to see if we're running Jel…
Browse files Browse the repository at this point in the history
…lybean or not for bridge modes
  • Loading branch information
infil00p committed Sep 9, 2016
1 parent deea0f7 commit dc0bfeb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
20 changes: 15 additions & 5 deletions bin/templates/project/assets/www/cordova.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Platform: android
// d403ce434788ffe1937711d6ebcbcc837fcbcb14
// 2fd4bcb84048415922d13d80d35b8d1668e8e150
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -901,7 +901,7 @@ var cordova = require('cordova'),
EVAL_BRIDGE: 3
},
jsToNativeBridgeMode, // Set lazily.
nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT,
nativeToJsBridgeMode = nativeToJsModes.EVAL_BRIDGE,
pollEnabled = false,
bridgeSecret = -1;

Expand Down Expand Up @@ -933,7 +933,6 @@ function androidExec(success, fail, service, action, args) {

var callbackId = service + cordova.callbackId++,
argsJson = JSON.stringify(args);

if (success || fail) {
cordova.callbacks[callbackId] = {success:success, fail:fail};
}
Expand All @@ -953,6 +952,17 @@ function androidExec(success, fail, service, action, args) {
}

androidExec.init = function() {
//CB-11828
//This failsafe checks the version of Android and if it's Jellybean, it switches it to
//using the Online Event bridge for communicating from Native to JS
//
//It's ugly, but it's necessary.
var check = navigator.userAgent.toLowerCase().match(/android\s[0-9].[0-9]/);
var version_code = check[0].match(/4.[0-3].*/);
if (version_code != null && nativeToJsBridgeMode == nativeToJsModes.EVAL_BRIDGE) {
nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT;
}

bridgeSecret = +prompt('', 'gap_init:' + nativeToJsBridgeMode);
channel.onNativeReady.fire();
};
Expand Down Expand Up @@ -2084,7 +2094,7 @@ utils.clone = function(obj) {

retVal = {};
for(i in obj){
if((!(i in retVal) || retVal[i] != obj[i]) && typeof obj[i] != 'undefined') {
if(!(i in retVal) || retVal[i] != obj[i]) {
retVal[i] = utils.clone(obj[i]);
}
}
Expand Down Expand Up @@ -2165,4 +2175,4 @@ window.cordova = require('cordova');

require('cordova/init');

})();
})();
14 changes: 12 additions & 2 deletions cordova-js-src/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var cordova = require('cordova'),
EVAL_BRIDGE: 3
},
jsToNativeBridgeMode, // Set lazily.
nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT,
nativeToJsBridgeMode = nativeToJsModes.EVAL_BRIDGE,
pollEnabled = false,
bridgeSecret = -1;

Expand Down Expand Up @@ -87,7 +87,6 @@ function androidExec(success, fail, service, action, args) {

var callbackId = service + cordova.callbackId++,
argsJson = JSON.stringify(args);

if (success || fail) {
cordova.callbacks[callbackId] = {success:success, fail:fail};
}
Expand All @@ -107,6 +106,17 @@ function androidExec(success, fail, service, action, args) {
}

androidExec.init = function() {
//CB-11828
//This failsafe checks the version of Android and if it's Jellybean, it switches it to
//using the Online Event bridge for communicating from Native to JS
//
//It's ugly, but it's necessary.
var check = navigator.userAgent.toLowerCase().match(/android\s[0-9].[0-9]/);
var version_code = check[0].match(/4.[0-3].*/);
if (version_code != null && nativeToJsBridgeMode == nativeToJsModes.EVAL_BRIDGE) {
nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT;
}

bridgeSecret = +prompt('', 'gap_init:' + nativeToJsBridgeMode);
channel.onNativeReady.fire();
};
Expand Down

0 comments on commit dc0bfeb

Please sign in to comment.