Bug 742216: Disable sensors on application pause. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Wed, 04 Apr 2012 17:29:30 -0700
changeset 94359 ee64f3c826df1044056408f6e5f5bdb03759d2a4
parent 94358 563c26d0a991506dee0e3089fc56520fca5a6a99
child 94360 fccc5ee8c51b262e0f990043dfc7fdc33a3fe6d6
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs742216
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 742216: Disable sensors on application pause. [r=mfinkle]
mobile/android/base/GeckoApp.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1584,18 +1584,16 @@ abstract public class GeckoApp
 
         mBrowserToolbar = new BrowserToolbar(mAppContext);
         mBrowserToolbar.from(actionBar);
 
         // setup gecko layout
         mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout);
         mMainLayout = (LinearLayout) findViewById(R.id.main_layout);
 
-        mConnectivityReceiver = new GeckoConnectivityReceiver();
-
         ((GeckoApplication) getApplication()).addApplicationLifecycleCallbacks(this);
     }
 
     private void initialize() {
         mInitialized = true;
 
         Intent intent = getIntent();
         String action = intent.getAction();
@@ -1737,17 +1735,23 @@ abstract public class GeckoApp
         batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
         mBatteryReceiver = new GeckoBatteryManager();
         registerReceiver(mBatteryReceiver, batteryFilter);
 
         if (SmsManager.getInstance() != null) {
           SmsManager.getInstance().start();
         }
 
+        mConnectivityReceiver = new GeckoConnectivityReceiver();
+        mConnectivityReceiver.registerFor(mAppContext);
+
         GeckoNetworkManager.getInstance().init();
+        GeckoNetworkManager.getInstance().start();
+
+        GeckoScreenOrientationListener.getInstance().start();
 
         final GeckoApp self = this;
 
         GeckoAppShell.getHandler().postDelayed(new Runnable() {
             public void run() {
                 Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - pre checkLaunchState");
 
                 /*
@@ -1983,20 +1987,16 @@ abstract public class GeckoApp
         // has come to the foreground yet; for Gecko, we may want to
         // stop repainting, for example.
 
         // Whatever we do here should be fast, because we're blocking
         // the next activity from showing up until we finish.
 
         // onPause will be followed by either onResume or onStop.
         super.onPause();
-
-        mConnectivityReceiver.unregisterFor(mAppContext);
-        GeckoNetworkManager.getInstance().stop();
-        GeckoScreenOrientationListener.getInstance().stop();
     }
 
     @Override
     public void onResume()
     {
         Log.i(LOGTAG, "resume");
 
         // After an onPause, the activity is back in the foreground.
@@ -2015,24 +2015,16 @@ abstract public class GeckoApp
         }
 
         int newOrientation = getResources().getConfiguration().orientation;
 
         if (mOrientation != newOrientation) {
             mOrientation = newOrientation;
             refreshActionBar();
         }
-
-        mMainHandler.post(new Runnable() {
-            public void run() {
-                mConnectivityReceiver.registerFor(mAppContext);
-                GeckoNetworkManager.getInstance().start();
-                GeckoScreenOrientationListener.getInstance().start();
-            }
-        });
     }
 
     @Override
     public void onStop()
     {
         Log.i(LOGTAG, "stop");
         // We're about to be stopped, potentially in preparation for
         // being destroyed.  We're killable after this point -- as I
@@ -2151,23 +2143,31 @@ abstract public class GeckoApp
             GeckoAppShell.onLowMemory();
         super.onLowMemory();
     }
 
     @Override
     public void onApplicationPause() {
         Log.i(LOGTAG, "application paused");
         GeckoAppShell.sendEventToGecko(GeckoEvent.createPauseEvent(true));
+
+        mConnectivityReceiver.unregisterFor(mAppContext);
+        GeckoNetworkManager.getInstance().stop();
+        GeckoScreenOrientationListener.getInstance().stop();
     }
 
     @Override
     public void onApplicationResume() {
         Log.i(LOGTAG, "application resumed");
         if (checkLaunchState(LaunchState.GeckoRunning))
             GeckoAppShell.sendEventToGecko(GeckoEvent.createResumeEvent(true));
+
+        mConnectivityReceiver.registerFor(mAppContext);
+        GeckoNetworkManager.getInstance().start();
+        GeckoScreenOrientationListener.getInstance().start();
     }
 
     abstract public String getPackageName();
     abstract public String getContentProcessName();
 
     public void addEnvToIntent(Intent intent) {
         Map<String,String> envMap = System.getenv();
         Set<Map.Entry<String,String>> envSet = envMap.entrySet();