Bug 1336734 - Part 3 - Don't stop the GeckoNetworkManager unless we're really backgrounded. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 05 Feb 2017 15:47:51 +0100
changeset 479465 c426e659c0478e450beb33dcbdd711bfa08d5a7b
parent 479464 1838c30e259032f193138f866330f9570151b417
child 544695 e4dfdbf9f56ae9cae93cc78df1c8017af89e6880
push id44266
push usermozilla@buttercookie.de
push dateMon, 06 Feb 2017 19:35:12 +0000
reviewerssebastian
bugs1336734
milestone54.0a1
Bug 1336734 - Part 3 - Don't stop the GeckoNetworkManager unless we're really backgrounded. r?sebastian Launching a new activity within our app triggers both onActivityPause() (the current activity) and onActivityResume() (the new activity) in GeckoApplication. The most prominent example at the moment are probably our preferences - entering/exiting/navigating within them always triggers a pause/resume combo. This means that currently, each time this happens the network manager is stopped only to be immediately restarted. To avoid this, we stop the network manager only when Gecko is actually being paused. MozReview-Commit-ID: 6NdScT5cLYL
mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -36,16 +36,17 @@ import java.io.File;
 import java.lang.reflect.Method;
 
 public class GeckoApplication extends Application
     implements ContextGetter {
     private static final String LOG_TAG = "GeckoApplication";
 
     private boolean mInBackground;
     private boolean mPausedGecko;
+    private boolean mIsInitialResume;
 
     private LightweightTheme mLightweightTheme;
 
     private RefWatcher mRefWatcher;
 
     public GeckoApplication() {
         super();
     }
@@ -116,35 +117,39 @@ public class GeckoApplication extends Ap
 
             final BrowserDB db = BrowserDB.from(this);
             ThreadUtils.postToBackgroundThread(new Runnable() {
                 @Override
                 public void run() {
                     db.expireHistory(getContentResolver(), BrowserContract.ExpirePriority.NORMAL);
                 }
             });
+
+            GeckoNetworkManager.getInstance().stop();
         }
-        GeckoNetworkManager.getInstance().stop();
     }
 
     public void onActivityResume(GeckoActivityStatus activity) {
-        if (mPausedGecko) {
+        if (mIsInitialResume) {
+            GeckoBatteryManager.getInstance().start(this);
+            GeckoNetworkManager.getInstance().start(this);
+            mIsInitialResume = false;
+        } else if (mPausedGecko) {
             GeckoThread.onResume();
             mPausedGecko = false;
+            GeckoNetworkManager.getInstance().start(this);
         }
 
-        GeckoBatteryManager.getInstance().start(this);
-        GeckoNetworkManager.getInstance().start(this);
-
         mInBackground = false;
     }
 
     @Override
     public void onCreate() {
         Log.i(LOG_TAG, "zerdatime " + SystemClock.uptimeMillis() + " - Fennec application start");
+        mIsInitialResume = true;
 
         mRefWatcher = LeakCanary.install(this);
 
         final Context context = getApplicationContext();
         GeckoAppShell.setApplicationContext(context);
         HardwareUtils.init(context);
         FilePicker.init(context);
         DownloadsIntegration.init();