cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject [1/3] git commit: CB-6047 Fix online sometimes getting in a bad state on page transitions.
Date Thu, 06 Mar 2014 18:50:56 GMT
Repository: cordova-amazon-fireos
Updated Branches:
  refs/heads/master aa66c9b31 -> f69e724c6


CB-6047 Fix online sometimes getting in a bad state on page transitions.

The online bridge toggles between on & off. Turns out that starting with
Android 4.3, navigation resets the online state, so the code had a 50/50
chance of being caught in the wrong state.

We now forcefully reset the online state on page transitions.


Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/f69e724c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/f69e724c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/f69e724c

Branch: refs/heads/master
Commit: f69e724c6e0281907cadb41647898825cb40e849
Parents: 0e88d66
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Feb 26 20:23:07 2014 -0500
Committer: Archana Naik <naika@lab126.com>
Committed: Thu Mar 6 10:50:29 2014 -0800

----------------------------------------------------------------------
 .../org/apache/cordova/NativeToJsMessageQueue.java    | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/f69e724c/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
index babb871..9b61f98 100755
--- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
+++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
@@ -102,7 +102,8 @@ public class NativeToJsMessageQueue {
                 synchronized (this) {
                     activeListenerIndex = value;
                     BridgeMode activeListener = registeredListeners[value];
-                    if (!paused && !queue.isEmpty() && activeListener !=
null) {
+                    activeListener.reset();
+                    if (!paused && !queue.isEmpty()) {
                         activeListener.onNativeToJsMessageAvailable();
                     }
                 }
@@ -117,6 +118,7 @@ public class NativeToJsMessageQueue {
         synchronized (this) {
             queue.clear();
             setBridgeMode(DEFAULT_BRIDGE_MODE);
+            registeredListeners[activeListenerIndex].reset();
         }
     }
 
@@ -249,7 +251,7 @@ public class NativeToJsMessageQueue {
     private void enqueueMessage(JsMessage message) {
         synchronized (this) {
             queue.add(message);
-            if (!paused && registeredListeners[activeListenerIndex] != null) {
+            if (!paused) {
                 registeredListeners[activeListenerIndex].onNativeToJsMessageAvailable();
             }
         }        
@@ -264,7 +266,7 @@ public class NativeToJsMessageQueue {
         paused = value;
         if (!value) {
             synchronized (this) {
-                if (!queue.isEmpty() && registeredListeners[activeListenerIndex]
!= null) {
+                if (!queue.isEmpty()) {
                     registeredListeners[activeListenerIndex].onNativeToJsMessageAvailable();
                 }
             }   
@@ -278,6 +280,7 @@ public class NativeToJsMessageQueue {
     private abstract class BridgeMode {
         abstract void onNativeToJsMessageAvailable();
         void notifyOfFlush(boolean fromOnlineEvent) {}
+        void reset() {}
     }
 
     /** Uses JS polls for messages on a timer.. */
@@ -304,7 +307,7 @@ public class NativeToJsMessageQueue {
 
     /** Uses online/offline events to tell the JS when to poll for messages. */
     private class OnlineEventsBridgeMode extends BridgeMode {
-        boolean online = false;
+        private boolean online;
         final Runnable runnable = new Runnable() {
             public void run() {
                 if (!queue.isEmpty()) {
@@ -312,7 +315,8 @@ public class NativeToJsMessageQueue {
                 }
             }                
         };
-        OnlineEventsBridgeMode() {
+        @Override void reset() {
+            online = false;
             webView.setNetworkAvailable(true);
         }
         @Override void onNativeToJsMessageAvailable() {


Mime
View raw message