From dc0bfeb0cc8228f755da8c60c80241fce745b7e5 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Fri, 9 Sep 2016 10:01:04 -0700 Subject: [PATCH] CB-11828: Adding dirty userAgent checking to see if we're running Jellybean or not for bridge modes --- bin/templates/project/assets/www/cordova.js | 20 +++++++++++++++----- cordova-js-src/exec.js | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/bin/templates/project/assets/www/cordova.js b/bin/templates/project/assets/www/cordova.js index 700c667f..1f06fae4 100644 --- a/bin/templates/project/assets/www/cordova.js +++ b/bin/templates/project/assets/www/cordova.js @@ -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 @@ -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; @@ -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}; } @@ -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(); }; @@ -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]); } } @@ -2165,4 +2175,4 @@ window.cordova = require('cordova'); require('cordova/init'); -})(); +})(); \ No newline at end of file diff --git a/cordova-js-src/exec.js b/cordova-js-src/exec.js index 197fb5df..36298cec 100644 --- a/cordova-js-src/exec.js +++ b/cordova-js-src/exec.js @@ -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; @@ -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}; } @@ -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(); };