Bug 761706 - Fix indenting in a few classes. r=mfinkle
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 14 Sep 2012 11:19:39 -0400
changeset 107202 cf2e7dc4182f98bf03834ef342c03d0dac181f76
parent 107201 97769a28d9e1f9f94735c4023ff7f1ceabc64f9c
child 107203 338823aa94a63d28394001d7a36293d85365a238
push id74
push usershu@rfrn.org
push dateTue, 18 Sep 2012 19:23:47 +0000
reviewersmfinkle
bugs761706
milestone18.0a1
Bug 761706 - Fix indenting in a few classes. r=mfinkle
mobile/android/base/GeckoBatteryManager.java
mobile/android/base/GeckoNetworkManager.java
mobile/android/base/GeckoScreenOrientationListener.java
--- a/mobile/android/base/GeckoBatteryManager.java
+++ b/mobile/android/base/GeckoBatteryManager.java
@@ -10,175 +10,174 @@ import android.content.BroadcastReceiver
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.os.BatteryManager;
 import android.os.Build;
 import android.os.SystemClock;
 import android.util.Log;
 
-public class GeckoBatteryManager
-  extends BroadcastReceiver
-{
-  private static final String LOGTAG = "GeckoBatteryManager";
+public class GeckoBatteryManager extends BroadcastReceiver {
+    private static final String LOGTAG = "GeckoBatteryManager";
 
-  // Those constants should be keep in sync with the ones in:
-  // dom/battery/Constants.h
-  private final static double  kDefaultLevel         = 1.0;
-  private final static boolean kDefaultCharging      = true;
-  private final static double  kDefaultRemainingTime = -1.0;
-  private final static double  kUnknownRemainingTime = -1.0;
+    // Those constants should be keep in sync with the ones in:
+    // dom/battery/Constants.h
+    private final static double  kDefaultLevel         = 1.0;
+    private final static boolean kDefaultCharging      = true;
+    private final static double  kDefaultRemainingTime = -1.0;
+    private final static double  kUnknownRemainingTime = -1.0;
 
-  private static long    sLastLevelChange            = 0;
-  private static boolean sNotificationsEnabled       = false;
-  private static double  sLevel                      = kDefaultLevel;
-  private static boolean sCharging                   = kDefaultCharging;
-  private static double  sRemainingTime              = kDefaultRemainingTime;;
+    private static long    sLastLevelChange            = 0;
+    private static boolean sNotificationsEnabled       = false;
+    private static double  sLevel                      = kDefaultLevel;
+    private static boolean sCharging                   = kDefaultCharging;
+    private static double  sRemainingTime              = kDefaultRemainingTime;;
 
-  private static boolean isRegistered = false;
+    private static boolean isRegistered = false;
 
-  public void registerFor(Activity activity) {
-      if (!isRegistered) {
-          IntentFilter filter = new IntentFilter();
-          filter.addAction(Intent.ACTION_BATTERY_CHANGED);
-
-          // registerReceiver can return null if registering fails
-          isRegistered = activity.registerReceiver(this, filter) != null;
-          if (!isRegistered)
-              Log.e(LOGTAG, "Registering receiver failed");
-      }
-  }
+    public void registerFor(Activity activity) {
+        if (!isRegistered) {
+            IntentFilter filter = new IntentFilter();
+            filter.addAction(Intent.ACTION_BATTERY_CHANGED);
 
-  public void unregisterFor(Activity activity) {
-      if (isRegistered) {
-          try {
-              activity.unregisterReceiver(this);
-          } catch (IllegalArgumentException iae) {
-              Log.e(LOGTAG, "Unregistering receiver failed", iae);
-          }
-          isRegistered = false;
-      }
-  }
+            // registerReceiver can return null if registering fails
+            isRegistered = activity.registerReceiver(this, filter) != null;
+            if (!isRegistered) {
+                Log.e(LOGTAG, "Registering receiver failed");
+            }
+        }
+    }
 
-  @Override
-  public void onReceive(Context context, Intent intent) {
-    if (!intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
-      Log.e(LOGTAG, "Got an unexpected intent!");
-      return;
+    public void unregisterFor(Activity activity) {
+        if (isRegistered) {
+            try {
+                activity.unregisterReceiver(this);
+            } catch (IllegalArgumentException iae) {
+                Log.e(LOGTAG, "Unregistering receiver failed", iae);
+            }
+            isRegistered = false;
+        }
     }
 
-    boolean previousCharging = isCharging();
-    double previousLevel = getLevel();
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (!intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
+            Log.e(LOGTAG, "Got an unexpected intent!");
+            return;
+        }
+
+        boolean previousCharging = isCharging();
+        double previousLevel = getLevel();
 
-    // NOTE: it might not be common (in 2012) but technically, Android can run
-    // on a device that has no battery so we want to make sure it's not the case
-    // before bothering checking for battery state.
-    // However, the Galaxy Nexus phone advertizes itself as battery-less which
-    // force us to special-case the logic.
-    // See the Google bug: https://code.google.com/p/android/issues/detail?id=22035
-    if (intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false) ||
-        Build.MODEL.equals("Galaxy Nexus")) {
-      int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
-      if (plugged == -1) {
-        sCharging = kDefaultCharging;
-        Log.e(LOGTAG, "Failed to get the plugged status!");
-      } else {
-        // Likely, if plugged > 0, it's likely plugged and charging but the doc
-        // isn't clear about that.
-        sCharging = plugged != 0;
-      }
+        // NOTE: it might not be common (in 2012) but technically, Android can run
+        // on a device that has no battery so we want to make sure it's not the case
+        // before bothering checking for battery state.
+        // However, the Galaxy Nexus phone advertizes itself as battery-less which
+        // force us to special-case the logic.
+        // See the Google bug: https://code.google.com/p/android/issues/detail?id=22035
+        if (intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false) ||
+                Build.MODEL.equals("Galaxy Nexus")) {
+            int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
+            if (plugged == -1) {
+                sCharging = kDefaultCharging;
+                Log.e(LOGTAG, "Failed to get the plugged status!");
+            } else {
+                // Likely, if plugged > 0, it's likely plugged and charging but the doc
+                // isn't clear about that.
+                sCharging = plugged != 0;
+            }
 
-      if (sCharging != previousCharging) {
-        sRemainingTime = kUnknownRemainingTime;
-        // The new remaining time is going to take some time to show up but
-        // it's the best way to show a not too wrong value.
-        sLastLevelChange = 0;
-      }
+            if (sCharging != previousCharging) {
+                sRemainingTime = kUnknownRemainingTime;
+                // The new remaining time is going to take some time to show up but
+                // it's the best way to show a not too wrong value.
+                sLastLevelChange = 0;
+            }
+
+            // We need two doubles because sLevel is a double.
+            double current =  (double)intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
+            double max = (double)intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
+            if (current == -1 || max == -1) {
+                Log.e(LOGTAG, "Failed to get battery level!");
+                sLevel = kDefaultLevel;
+            } else {
+                sLevel = current / max;
+            }
 
-      // We need two doubles because sLevel is a double.
-      double current =  (double)intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
-      double max = (double)intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
-      if (current == -1 || max == -1) {
-        Log.e(LOGTAG, "Failed to get battery level!");
-        sLevel = kDefaultLevel;
-      } else {
-        sLevel = current / max;
-      }
+            if (sLevel == 1.0 && sCharging) {
+                sRemainingTime = 0.0;
+            } else if (sLevel != previousLevel) {
+                // Estimate remaining time.
+                if (sLastLevelChange != 0) {
+                    // Use elapsedRealtime() because we want to track time across device sleeps.
+                    long currentTime = SystemClock.elapsedRealtime();
+                    long dt = (currentTime - sLastLevelChange) / 1000;
+                    double dLevel = sLevel - previousLevel;
 
-      if (sLevel == 1.0 && sCharging) {
-        sRemainingTime = 0.0;
-      } else if (sLevel != previousLevel) {
-        // Estimate remaining time.
-        if (sLastLevelChange != 0) {
-          // Use elapsedRealtime() because we want to track time across device sleeps.
-          long currentTime = SystemClock.elapsedRealtime();
-          long dt = (currentTime - sLastLevelChange) / 1000;
-          double dLevel = sLevel - previousLevel;
+                    if (sCharging) {
+                        if (dLevel < 0) {
+                            Log.w(LOGTAG, "When charging, level should increase!");
+                            sRemainingTime = kUnknownRemainingTime;
+                        } else {
+                            sRemainingTime = Math.round(dt / dLevel * (1.0 - sLevel));
+                        }
+                    } else {
+                        if (dLevel > 0) {
+                            Log.w(LOGTAG, "When discharging, level should decrease!");
+                            sRemainingTime = kUnknownRemainingTime;
+                        } else {
+                            sRemainingTime = Math.round(dt / -dLevel * sLevel);
+                        }
+                    }
 
-          if (sCharging) {
-            if (dLevel < 0) {
-              Log.w(LOGTAG, "When charging, level should increase!");
-              sRemainingTime = kUnknownRemainingTime;
-            } else {
-              sRemainingTime = Math.round(dt / dLevel * (1.0 - sLevel));
+                    sLastLevelChange = currentTime;
+                } else {
+                    // That's the first time we got an update, we can't do anything.
+                    sLastLevelChange = SystemClock.elapsedRealtime();
+                }
             }
-          } else {
-            if (dLevel > 0) {
-              Log.w(LOGTAG, "When discharging, level should decrease!");
-              sRemainingTime = kUnknownRemainingTime;
-            } else {
-              sRemainingTime = Math.round(dt / -dLevel * sLevel);
-            }
-          }
+        } else {
+            sLevel = kDefaultLevel;
+            sCharging = kDefaultCharging;
+            sRemainingTime = 0;
+        }
 
-          sLastLevelChange = currentTime;
-        } else {
-          // That's the first time we got an update, we can't do anything.
-          sLastLevelChange = SystemClock.elapsedRealtime();
+        /*
+         * We want to inform listeners if the following conditions are fulfilled:
+         *  - we have at least one observer;
+         *  - the charging state or the level has changed.
+         *
+         * Note: no need to check for a remaining time change given that it's only
+         * updated if there is a level change or a charging change.
+         *
+         * The idea is to prevent doing all the way to the DOM code in the child
+         * process to finally not send an event.
+         */
+        if (sNotificationsEnabled &&
+                (previousCharging != isCharging() || previousLevel != getLevel())) {
+            GeckoAppShell.notifyBatteryChange(getLevel(), isCharging(), getRemainingTime());
         }
-      }
-    } else {
-      sLevel = kDefaultLevel;
-      sCharging = kDefaultCharging;
-      sRemainingTime = 0;
     }
 
-    /*
-     * We want to inform listeners if the following conditions are fulfilled:
-     *  - we have at least one observer;
-     *  - the charging state or the level has changed.
-     *
-     * Note: no need to check for a remaining time change given that it's only
-     * updated if there is a level change or a charging change.
-     *
-     * The idea is to prevent doing all the way to the DOM code in the child
-     * process to finally not send an event.
-     */
-    if (sNotificationsEnabled &&
-        (previousCharging != isCharging() || previousLevel != getLevel())) {
-      GeckoAppShell.notifyBatteryChange(getLevel(), isCharging(), getRemainingTime());
+    public static boolean isCharging() {
+        return sCharging;
     }
-  }
 
-  public static boolean isCharging() {
-    return sCharging;
-  }
+    public static double getLevel() {
+        return sLevel;
+    }
+
+    public static double getRemainingTime() {
+        return sRemainingTime;
+    }
 
-  public static double getLevel() {
-    return sLevel;
-  }
-
-  public static double getRemainingTime() {
-    return sRemainingTime;
-  }
+    public static void enableNotifications() {
+        sNotificationsEnabled = true;
+    }
 
-  public static void enableNotifications() {
-    sNotificationsEnabled = true;
-  }
+    public static void disableNotifications() {
+        sNotificationsEnabled = false;
+    }
 
-  public static void disableNotifications() {
-    sNotificationsEnabled = false;
-  }
-
-  public static double[] getCurrentInformation() {
-    return new double[] { getLevel(), isCharging() ? 1.0 : 0.0, getRemainingTime() };
-  }
+    public static double[] getCurrentInformation() {
+        return new double[] { getLevel(), isCharging() ? 1.0 : 0.0, getRemainingTime() };
+    }
 }
--- a/mobile/android/base/GeckoNetworkManager.java
+++ b/mobile/android/base/GeckoNetworkManager.java
@@ -52,245 +52,244 @@ import android.util.Log;
  *
  * 3.75G (20 Mb/s)
  * int NETWORK_TYPE_HSPAP    Current network is HSPA+
  *
  * 3.9G (50 Mb/s)
  * int NETWORK_TYPE_LTE      Current network is LTE
  */
 
-public class GeckoNetworkManager
-  extends BroadcastReceiver
-{
-  static private final GeckoNetworkManager sInstance = new GeckoNetworkManager();
-
-  static private final double  kDefaultBandwidth    = -1.0;
-  static private final boolean kDefaultCanBeMetered = false;
-
-  static private final double  kMaxBandwidth = 20.0;
+public class GeckoNetworkManager extends BroadcastReceiver {
+    private static final String LOGTAG = "GeckoNetworkManager";
 
-  static private final double  kNetworkSpeedEthernet = 20.0;           // 20 Mb/s
-  static private final double  kNetworkSpeedWifi     = 20.0;           // 20 Mb/s
-  static private final double  kNetworkSpeedWiMax    = 40.0;           // 40 Mb/s
-  static private final double  kNetworkSpeed_2_G     = 15.0 / 1024.0;  // 15 kb/s
-  static private final double  kNetworkSpeed_2_5_G   = 60.0 / 1024.0;  // 60 kb/s
-  static private final double  kNetworkSpeed_2_75_G  = 200.0 / 1024.0; // 200 kb/s
-  static private final double  kNetworkSpeed_3_G     = 300.0 / 1024.0; // 300 kb/s
-  static private final double  kNetworkSpeed_3_5_G   = 7.0;            // 7 Mb/s
-  static private final double  kNetworkSpeed_3_75_G  = 20.0;           // 20 Mb/s
-  static private final double  kNetworkSpeed_3_9_G   = 50.0;           // 50 Mb/s
+    static private final GeckoNetworkManager sInstance = new GeckoNetworkManager();
 
-  private enum NetworkType {
-    NETWORK_NONE,
-    NETWORK_ETHERNET,
-    NETWORK_WIFI,
-    NETWORK_WIMAX,
-    NETWORK_2_G,    // 2G
-    NETWORK_2_5_G,  // 2.5G
-    NETWORK_2_75_G, // 2.75G
-    NETWORK_3_G,    // 3G
-    NETWORK_3_5_G,  // 3.5G
-    NETWORK_3_75_G, // 3.75G
-    NETWORK_3_9_G,  // 3.9G
-    NETWORK_UNKNOWN
-  }
+    static private final double  kDefaultBandwidth    = -1.0;
+    static private final boolean kDefaultCanBeMetered = false;
 
-  private NetworkType  mNetworkType = NetworkType.NETWORK_NONE;
-  private IntentFilter mNetworkFilter = new IntentFilter();
-  // Whether the manager should be listening to Network Information changes.
-  private boolean mShouldBeListening = false;
-  // Whether the manager should notify Gecko that a change in Network
-  // Information happened.
-  private boolean mShouldNotify      = false;
+    static private final double  kMaxBandwidth = 20.0;
 
-  public static GeckoNetworkManager getInstance() {
-    return sInstance;
-  }
-
-  @Override
-  public void onReceive(Context aContext, Intent aIntent) {
-    updateNetworkType();
-  }
-
-  public void init() {
-    mNetworkFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
-
-    mNetworkType = getNetworkType();
-  }
-
-  public void start() {
-    mShouldBeListening = true;
-    updateNetworkType();
+    static private final double  kNetworkSpeedEthernet = 20.0;           // 20 Mb/s
+    static private final double  kNetworkSpeedWifi     = 20.0;           // 20 Mb/s
+    static private final double  kNetworkSpeedWiMax    = 40.0;           // 40 Mb/s
+    static private final double  kNetworkSpeed_2_G     = 15.0 / 1024.0;  // 15 kb/s
+    static private final double  kNetworkSpeed_2_5_G   = 60.0 / 1024.0;  // 60 kb/s
+    static private final double  kNetworkSpeed_2_75_G  = 200.0 / 1024.0; // 200 kb/s
+    static private final double  kNetworkSpeed_3_G     = 300.0 / 1024.0; // 300 kb/s
+    static private final double  kNetworkSpeed_3_5_G   = 7.0;            // 7 Mb/s
+    static private final double  kNetworkSpeed_3_75_G  = 20.0;           // 20 Mb/s
+    static private final double  kNetworkSpeed_3_9_G   = 50.0;           // 50 Mb/s
 
-    if (mShouldNotify) {
-      startListening();
-    }
-  }
-
-  private void startListening() {
-    GeckoApp.mAppContext.registerReceiver(sInstance, mNetworkFilter);
-  }
-
-  public void stop() {
-    mShouldBeListening = false;
-
-    if (mShouldNotify) {
-      stopListening();
-    }
-  }
-
-  private void stopListening() {
-    GeckoApp.mAppContext.unregisterReceiver(sInstance);
-  }
-
-  private void updateNetworkType() {
-    NetworkType previousNetworkType = mNetworkType;
-    mNetworkType = getNetworkType();
-
-    if (mNetworkType == previousNetworkType || !mShouldNotify) {
-      return;
+    private enum NetworkType {
+        NETWORK_NONE,
+        NETWORK_ETHERNET,
+        NETWORK_WIFI,
+        NETWORK_WIMAX,
+        NETWORK_2_G,    // 2G
+        NETWORK_2_5_G,  // 2.5G
+        NETWORK_2_75_G, // 2.75G
+        NETWORK_3_G,    // 3G
+        NETWORK_3_5_G,  // 3.5G
+        NETWORK_3_75_G, // 3.75G
+        NETWORK_3_9_G,  // 3.9G
+        NETWORK_UNKNOWN
     }
 
-    GeckoAppShell.sendEventToGecko(GeckoEvent.createNetworkEvent(
+    private NetworkType  mNetworkType = NetworkType.NETWORK_NONE;
+    private IntentFilter mNetworkFilter = new IntentFilter();
+    // Whether the manager should be listening to Network Information changes.
+    private boolean mShouldBeListening = false;
+    // Whether the manager should notify Gecko that a change in Network
+    // Information happened.
+    private boolean mShouldNotify      = false;
+
+    public static GeckoNetworkManager getInstance() {
+        return sInstance;
+    }
+
+    @Override
+    public void onReceive(Context aContext, Intent aIntent) {
+        updateNetworkType();
+    }
+
+    public void init() {
+        mNetworkFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+        mNetworkType = getNetworkType();
+    }
+
+    public void start() {
+        mShouldBeListening = true;
+        updateNetworkType();
+
+        if (mShouldNotify) {
+            startListening();
+        }
+    }
+
+    private void startListening() {
+        GeckoApp.mAppContext.registerReceiver(sInstance, mNetworkFilter);
+    }
+
+    public void stop() {
+        mShouldBeListening = false;
+
+        if (mShouldNotify) {
+        stopListening();
+        }
+    }
+
+    private void stopListening() {
+        GeckoApp.mAppContext.unregisterReceiver(sInstance);
+    }
+
+    private void updateNetworkType() {
+        NetworkType previousNetworkType = mNetworkType;
+        mNetworkType = getNetworkType();
+
+        if (mNetworkType == previousNetworkType || !mShouldNotify) {
+            return;
+        }
+
+        GeckoAppShell.sendEventToGecko(GeckoEvent.createNetworkEvent(
                                        getNetworkSpeed(mNetworkType),
                                        isNetworkUsuallyMetered(mNetworkType)));
-  }
-
-  public double[] getCurrentInformation() {
-    return new double[] { getNetworkSpeed(mNetworkType),
-                          isNetworkUsuallyMetered(mNetworkType) ? 1.0 : 0.0 };
-  }
-
-  public void enableNotifications() {
-    // We set mShouldNotify *after* calling updateNetworkType() to make sure we
-    // don't notify an eventual change in mNetworkType.
-    updateNetworkType();
-    mShouldNotify = true;
+    }
 
-    if (mShouldBeListening) {
-      startListening();
-    }
-  }
-
-  public void disableNotifications() {
-    mShouldNotify = false;
-
-    if (mShouldBeListening) {
-      stopListening();
-    }
-  }
-
-  private static NetworkType getNetworkType() {
-    ConnectivityManager cm =
-      (ConnectivityManager)GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
-    if (cm == null) {
-      Log.e("GeckoNetworkManager", "Connectivity service does not exist");
-      return NetworkType.NETWORK_NONE;
+    public double[] getCurrentInformation() {
+        return new double[] { getNetworkSpeed(mNetworkType),
+                              isNetworkUsuallyMetered(mNetworkType) ? 1.0 : 0.0 };
     }
 
-    NetworkInfo ni = cm.getActiveNetworkInfo();
-    if (ni == null) {
-      return NetworkType.NETWORK_NONE;
+    public void enableNotifications() {
+        // We set mShouldNotify *after* calling updateNetworkType() to make sure we
+        // don't notify an eventual change in mNetworkType.
+        updateNetworkType();
+        mShouldNotify = true;
+
+        if (mShouldBeListening) {
+            startListening();
+        }
     }
 
-    switch (ni.getType()) {
-      case ConnectivityManager.TYPE_ETHERNET:
-        return NetworkType.NETWORK_ETHERNET;
-      case ConnectivityManager.TYPE_WIFI:
-        return NetworkType.NETWORK_WIFI;
-      case ConnectivityManager.TYPE_WIMAX:
-        return NetworkType.NETWORK_WIMAX;
-      case ConnectivityManager.TYPE_MOBILE:
-        break; // We will handle sub-types after the switch.
-      default:
-        Log.w("GeckoNetworkManager", "Ignoring the current network type.");
-        return NetworkType.NETWORK_UNKNOWN;
-    }
+    public void disableNotifications() {
+        mShouldNotify = false;
 
-    TelephonyManager tm =
-      (TelephonyManager)GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
-    if (tm == null) {
-      Log.e("GeckoNetworkManager", "Telephony service does not exist");
-      return NetworkType.NETWORK_UNKNOWN;
+        if (mShouldBeListening) {
+            stopListening();
+        }
     }
 
-    switch (tm.getNetworkType()) {
-      case TelephonyManager.NETWORK_TYPE_IDEN:
-      case TelephonyManager.NETWORK_TYPE_CDMA:
-        return NetworkType.NETWORK_2_G;
-      case TelephonyManager.NETWORK_TYPE_GPRS:
-      case TelephonyManager.NETWORK_TYPE_1xRTT:
-        return NetworkType.NETWORK_2_5_G;
-      case TelephonyManager.NETWORK_TYPE_EDGE:
-        return NetworkType.NETWORK_2_75_G;
-      case TelephonyManager.NETWORK_TYPE_UMTS:
-      case TelephonyManager.NETWORK_TYPE_EVDO_0:
-        return NetworkType.NETWORK_3_G;
-      case TelephonyManager.NETWORK_TYPE_HSPA:
-      case TelephonyManager.NETWORK_TYPE_HSDPA:
-      case TelephonyManager.NETWORK_TYPE_HSUPA:
-      case TelephonyManager.NETWORK_TYPE_EVDO_A:
-      case TelephonyManager.NETWORK_TYPE_EVDO_B:
-      case TelephonyManager.NETWORK_TYPE_EHRPD:
-        return NetworkType.NETWORK_3_5_G;
-      case TelephonyManager.NETWORK_TYPE_HSPAP:
-        return NetworkType.NETWORK_3_75_G;
-      case TelephonyManager.NETWORK_TYPE_LTE:
-        return NetworkType.NETWORK_3_9_G;
-      case TelephonyManager.NETWORK_TYPE_UNKNOWN:
-      default:
-        Log.w("GeckoNetworkManager", "Connected to an unknown mobile network!");
-        return NetworkType.NETWORK_UNKNOWN;
-    }
-  }
+    private static NetworkType getNetworkType() {
+        ConnectivityManager cm =
+            (ConnectivityManager)GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+        if (cm == null) {
+            Log.e(LOGTAG, "Connectivity service does not exist");
+            return NetworkType.NETWORK_NONE;
+        }
+
+        NetworkInfo ni = cm.getActiveNetworkInfo();
+        if (ni == null) {
+            return NetworkType.NETWORK_NONE;
+        }
+
+        switch (ni.getType()) {
+        case ConnectivityManager.TYPE_ETHERNET:
+            return NetworkType.NETWORK_ETHERNET;
+        case ConnectivityManager.TYPE_WIFI:
+            return NetworkType.NETWORK_WIFI;
+        case ConnectivityManager.TYPE_WIMAX:
+            return NetworkType.NETWORK_WIMAX;
+        case ConnectivityManager.TYPE_MOBILE:
+            break; // We will handle sub-types after the switch.
+        default:
+            Log.w(LOGTAG, "Ignoring the current network type.");
+            return NetworkType.NETWORK_UNKNOWN;
+        }
+
+        TelephonyManager tm =
+            (TelephonyManager)GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
+        if (tm == null) {
+            Log.e(LOGTAG, "Telephony service does not exist");
+            return NetworkType.NETWORK_UNKNOWN;
+        }
 
-  private static double getNetworkSpeed(NetworkType aType) {
-    switch (aType) {
-      case NETWORK_NONE:
-        return 0.0;
-      case NETWORK_ETHERNET:
-        return kNetworkSpeedEthernet;
-      case NETWORK_WIFI:
-        return kNetworkSpeedWifi;
-      case NETWORK_WIMAX:
-        return kNetworkSpeedWiMax;
-      case NETWORK_2_G:
-        return kNetworkSpeed_2_G;
-      case NETWORK_2_5_G:
-        return kNetworkSpeed_2_5_G;
-      case NETWORK_2_75_G:
-        return kNetworkSpeed_2_75_G;
-      case NETWORK_3_G:
-        return kNetworkSpeed_3_G;
-      case NETWORK_3_5_G:
-        return kNetworkSpeed_3_5_G;
-      case NETWORK_3_75_G:
-        return kNetworkSpeed_3_75_G;
-      case NETWORK_3_9_G:
-        return kNetworkSpeed_3_9_G;
-      case NETWORK_UNKNOWN:
-      default:
-        return kDefaultBandwidth;
+        switch (tm.getNetworkType()) {
+        case TelephonyManager.NETWORK_TYPE_IDEN:
+        case TelephonyManager.NETWORK_TYPE_CDMA:
+            return NetworkType.NETWORK_2_G;
+        case TelephonyManager.NETWORK_TYPE_GPRS:
+        case TelephonyManager.NETWORK_TYPE_1xRTT:
+            return NetworkType.NETWORK_2_5_G;
+        case TelephonyManager.NETWORK_TYPE_EDGE:
+            return NetworkType.NETWORK_2_75_G;
+        case TelephonyManager.NETWORK_TYPE_UMTS:
+        case TelephonyManager.NETWORK_TYPE_EVDO_0:
+            return NetworkType.NETWORK_3_G;
+        case TelephonyManager.NETWORK_TYPE_HSPA:
+        case TelephonyManager.NETWORK_TYPE_HSDPA:
+        case TelephonyManager.NETWORK_TYPE_HSUPA:
+        case TelephonyManager.NETWORK_TYPE_EVDO_A:
+        case TelephonyManager.NETWORK_TYPE_EVDO_B:
+        case TelephonyManager.NETWORK_TYPE_EHRPD:
+            return NetworkType.NETWORK_3_5_G;
+        case TelephonyManager.NETWORK_TYPE_HSPAP:
+            return NetworkType.NETWORK_3_75_G;
+        case TelephonyManager.NETWORK_TYPE_LTE:
+            return NetworkType.NETWORK_3_9_G;
+        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
+        default:
+            Log.w(LOGTAG, "Connected to an unknown mobile network!");
+            return NetworkType.NETWORK_UNKNOWN;
+        }
     }
-  }
 
-  private static boolean isNetworkUsuallyMetered(NetworkType aType) {
-    switch (aType) {
-      case NETWORK_NONE:
-      case NETWORK_UNKNOWN:
-      case NETWORK_ETHERNET:
-      case NETWORK_WIFI:
-      case NETWORK_WIMAX:
-        return false;
-      case NETWORK_2_G:
-      case NETWORK_2_5_G:
-      case NETWORK_2_75_G:
-      case NETWORK_3_G:
-      case NETWORK_3_5_G:
-      case NETWORK_3_75_G:
-      case NETWORK_3_9_G:
-        return true;
-      default:
-        Log.e("GeckoNetworkManager", "Got an unexpected network type!");
-        return false;
+    private static double getNetworkSpeed(NetworkType aType) {
+        switch (aType) {
+        case NETWORK_NONE:
+            return 0.0;
+        case NETWORK_ETHERNET:
+            return kNetworkSpeedEthernet;
+        case NETWORK_WIFI:
+            return kNetworkSpeedWifi;
+        case NETWORK_WIMAX:
+            return kNetworkSpeedWiMax;
+        case NETWORK_2_G:
+            return kNetworkSpeed_2_G;
+        case NETWORK_2_5_G:
+            return kNetworkSpeed_2_5_G;
+        case NETWORK_2_75_G:
+            return kNetworkSpeed_2_75_G;
+        case NETWORK_3_G:
+            return kNetworkSpeed_3_G;
+        case NETWORK_3_5_G:
+            return kNetworkSpeed_3_5_G;
+        case NETWORK_3_75_G:
+            return kNetworkSpeed_3_75_G;
+        case NETWORK_3_9_G:
+            return kNetworkSpeed_3_9_G;
+        case NETWORK_UNKNOWN:
+        default:
+            return kDefaultBandwidth;
+        }
     }
-  }
+
+    private static boolean isNetworkUsuallyMetered(NetworkType aType) {
+        switch (aType) {
+        case NETWORK_NONE:
+        case NETWORK_UNKNOWN:
+        case NETWORK_ETHERNET:
+        case NETWORK_WIFI:
+        case NETWORK_WIMAX:
+            return false;
+        case NETWORK_2_G:
+        case NETWORK_2_5_G:
+        case NETWORK_2_75_G:
+        case NETWORK_3_G:
+        case NETWORK_3_5_G:
+        case NETWORK_3_75_G:
+        case NETWORK_3_9_G:
+            return true;
+        default:
+            Log.e(LOGTAG, "Got an unexpected network type!");
+            return false;
+        }
+    }
 }
--- a/mobile/android/base/GeckoScreenOrientationListener.java
+++ b/mobile/android/base/GeckoScreenOrientationListener.java
@@ -14,229 +14,228 @@ import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.json.JSONArray;
 import org.json.JSONObject;
 
 import org.mozilla.gecko.util.GeckoEventListener;
 
-public class GeckoScreenOrientationListener implements GeckoEventListener
-{
-  private static final String LOGTAG = "GeckoScreenOrientationListener";
+public class GeckoScreenOrientationListener implements GeckoEventListener {
+    private static final String LOGTAG = "GeckoScreenOrientationListener";
 
-  static class OrientationEventListenerImpl extends OrientationEventListener {
-    public OrientationEventListenerImpl(Context c) {
-      super(c);
+    static class OrientationEventListenerImpl extends OrientationEventListener {
+        public OrientationEventListenerImpl(Context c) {
+            super(c);
+        }
+
+        @Override
+        public void onOrientationChanged(int aOrientation) {
+            GeckoScreenOrientationListener.getInstance().updateScreenOrientation();
+        }
     }
 
-    @Override
-    public void onOrientationChanged(int aOrientation) {
-      GeckoScreenOrientationListener.getInstance().updateScreenOrientation();
-    }
-  }
+    static private GeckoScreenOrientationListener sInstance = null;
 
-  static private GeckoScreenOrientationListener sInstance = null;
+    // Make sure that any change in dom/base/ScreenOrientation.h happens here too.
+    static public final short eScreenOrientation_None               = 0;
+    static public final short eScreenOrientation_PortraitPrimary    = 1;
+    static public final short eScreenOrientation_PortraitSecondary  = 2;
+    static public final short eScreenOrientation_Portrait           = 3;
+    static public final short eScreenOrientation_LandscapePrimary   = 4;
+    static public final short eScreenOrientation_LandscapeSecondary = 8;
+    static public final short eScreenOrientation_Landscape          = 12;
+
+    static private final short DEFAULT_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+
+    private short mOrientation;
+    private OrientationEventListenerImpl mListener = null;
 
-  // Make sure that any change in dom/base/ScreenOrientation.h happens here too.
-  static public final short eScreenOrientation_None               = 0;
-  static public final short eScreenOrientation_PortraitPrimary    = 1;
-  static public final short eScreenOrientation_PortraitSecondary  = 2;
-  static public final short eScreenOrientation_Portrait           = 3;
-  static public final short eScreenOrientation_LandscapePrimary   = 4;
-  static public final short eScreenOrientation_LandscapeSecondary = 8;
-  static public final short eScreenOrientation_Landscape          = 12;
+    // Whether the listener should be listening to changes.
+    private boolean mShouldBeListening = false;
+    // Whether the listener should notify Gecko that a change happened.
+    private boolean mShouldNotify      = false;
+    // The default orientation to use if nothing is specified
+    private short mDefaultOrientation;
+
+    private static final String DEFAULT_ORIENTATION_PREF = "app.orientation.default";
+
+    private GeckoScreenOrientationListener() {
+        mListener = new OrientationEventListenerImpl(GeckoApp.mAppContext);
 
-  static private final short DEFAULT_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+        ArrayList<String> prefs = new ArrayList<String>();
+        prefs.add(DEFAULT_ORIENTATION_PREF);
+        JSONArray jsonPrefs = new JSONArray(prefs);
+        GeckoAppShell.registerEventListener("Preferences:Data", this);
+        GeckoEvent event = GeckoEvent.createBroadcastEvent("Preferences:Get", jsonPrefs.toString());
+        GeckoAppShell.sendEventToGecko(event);
 
-  private short mOrientation;
-  private OrientationEventListenerImpl mListener = null;
+        mDefaultOrientation = DEFAULT_ORIENTATION;
+    }
+
+    public static GeckoScreenOrientationListener getInstance() {
+        if (sInstance == null) {
+            sInstance = new GeckoScreenOrientationListener();
+        }
 
-  // Whether the listener should be listening to changes.
-  private boolean mShouldBeListening = false;
-  // Whether the listener should notify Gecko that a change happened.
-  private boolean mShouldNotify      = false;
-  // The default orientation to use if nothing is specified
-  private short mDefaultOrientation;
+        return sInstance;
+    }
+
+    public void start() {
+        mShouldBeListening = true;
+        updateScreenOrientation();
 
-  private static final String DEFAULT_ORIENTATION_PREF = "app.orientation.default";
+        if (mShouldNotify) {
+            startListening();
+        }
+    }
 
-  private GeckoScreenOrientationListener() {
-      mListener = new OrientationEventListenerImpl(GeckoApp.mAppContext);
+    public void stop() {
+        mShouldBeListening = false;
+
+        if (mShouldNotify) {
+            stopListening();
+        }
+    }
 
-      ArrayList<String> prefs = new ArrayList<String>();
-      prefs.add(DEFAULT_ORIENTATION_PREF);
-      JSONArray jsonPrefs = new JSONArray(prefs);
-      GeckoAppShell.registerEventListener("Preferences:Data", this);
-      GeckoEvent event = GeckoEvent.createBroadcastEvent("Preferences:Get", jsonPrefs.toString());
-      GeckoAppShell.sendEventToGecko(event);
-  
-      mDefaultOrientation = DEFAULT_ORIENTATION;
-  }
+    public void enableNotifications() {
+        updateScreenOrientation();
+        mShouldNotify = true;
+
+        if (mShouldBeListening) {
+            startListening();
+        }
+    }
+
+    public void disableNotifications() {
+        mShouldNotify = false;
 
-  public static GeckoScreenOrientationListener getInstance() {
-    if (sInstance == null) {
-      sInstance = new GeckoScreenOrientationListener();
+        if (mShouldBeListening) {
+            stopListening();
+        }
+    }
+
+    private void startListening() {
+        mListener.enable();
+    }
+
+    private void stopListening() {
+        mListener.disable();
     }
 
-    return sInstance;
-  }
-
-  public void start() {
-    mShouldBeListening = true;
-    updateScreenOrientation();
-
-    if (mShouldNotify) {
-      startListening();
-    }
-  }
+    public void handleMessage(String event, JSONObject message) {
+        try {
+            if ("Preferences:Data".equals(event)) {
+                JSONArray jsonPrefs = message.getJSONArray("preferences");
+                final int length = jsonPrefs.length();
+                for (int i = 0; i < length; i++) {
+                    JSONObject jPref = jsonPrefs.getJSONObject(i);
+                    final String prefName = jPref.getString("name");
 
-  public void stop() {
-    mShouldBeListening = false;
+                    if (DEFAULT_ORIENTATION_PREF.equals(prefName)) {
+                        final String value = jPref.getString("value");
+                        mDefaultOrientation = orientationFromStringArray(value);
+                        unlockScreenOrientation();
 
-    if (mShouldNotify) {
-      stopListening();
-    }
-  }
-
-  public void enableNotifications() {
-    updateScreenOrientation();
-    mShouldNotify = true;
-
-    if (mShouldBeListening) {
-      startListening();
+                        // this is the only pref we care about. unregister after we receive it
+                        GeckoAppShell.unregisterEventListener("Preferences:Data", this);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
+        }
     }
-  }
-
-  public void disableNotifications() {
-    mShouldNotify = false;
-
-    if (mShouldBeListening) {
-      stopListening();
-    }
-  }
-
-  private void startListening() {
-    mListener.enable();
-  }
-
-  private void stopListening() {
-    mListener.disable();
-  }
-
-  public void handleMessage(String event, JSONObject message) {
-      try {
-          if ("Preferences:Data".equals(event)) {
-              JSONArray jsonPrefs = message.getJSONArray("preferences");
-              final int length = jsonPrefs.length();
-              for (int i = 0; i < length; i++) {
-                  JSONObject jPref = jsonPrefs.getJSONObject(i);
-                  final String prefName = jPref.getString("name");
 
-                  if (DEFAULT_ORIENTATION_PREF.equals(prefName)) {
-                      final String value = jPref.getString("value");
-                      mDefaultOrientation = orientationFromStringArray(value);
-                      unlockScreenOrientation();
+    private short orientationFromStringArray(String val) {
+        List<String> orientations = Arrays.asList(val.split(","));
+        // if nothing is listed, return unspecified
+        if (orientations.size() == 0)
+            return DEFAULT_ORIENTATION;
 
-                      // this is the only pref we care about. unregister after we receive it
-                      GeckoAppShell.unregisterEventListener("Preferences:Data", this);
-                  }
-              }
-          }
-      } catch (Exception e) {
-          Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
-      }
-  }
-
-  private short orientationFromStringArray(String val) {
-      List<String> orientations = Arrays.asList(val.split(","));
-      // if nothing is listed, return unspecified
-      if (orientations.size() == 0)
-          return DEFAULT_ORIENTATION;
-
-      // we dont' support multiple orientations yet. To avoid developer confusion,
-      // just take the first one listed
-      return orientationFromString(orientations.get(0));
-  }
+        // we dont' support multiple orientations yet. To avoid developer confusion,
+        // just take the first one listed
+        return orientationFromString(orientations.get(0));
+    }
 
-  private short orientationFromString(String val) {
-    if ("portrait".equals(val))
-      return (short)ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
-    else if ("landscape".equals(val))
-      return (short)ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
-    else if ("portrait-primary".equals(val))
-      return (short)ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
-    else if ("portrait-secondary".equals(val))
-      return (short)ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
-    else if ("landscape-primary".equals(val))
-      return (short)ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
-    else if ("landscape-secondary".equals(val))
-      return (short)ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
-    return DEFAULT_ORIENTATION;
-  }
-
-  // NOTE: this is public so OrientationEventListenerImpl can access it.
-  // Unfortunately, Java doesn't know about friendship.
-  public void updateScreenOrientation() {
-    int rotation = GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getRotation();
-    short previousOrientation = mOrientation;
-
-    if (rotation == Surface.ROTATION_0) {
-      mOrientation = eScreenOrientation_PortraitPrimary;
-    } else if (rotation == Surface.ROTATION_180) {
-      mOrientation = eScreenOrientation_PortraitSecondary;
-    } else if (rotation == Surface.ROTATION_270) {
-      mOrientation = eScreenOrientation_LandscapeSecondary;
-    } else if (rotation == Surface.ROTATION_90) {
-      mOrientation = eScreenOrientation_LandscapePrimary;
-    } else {
-      Log.e(LOGTAG, "Unexpected value received! (" + rotation + ")");
-      return;
+    private short orientationFromString(String val) {
+        if ("portrait".equals(val))
+            return (short)ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
+        else if ("landscape".equals(val))
+            return (short)ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
+        else if ("portrait-primary".equals(val))
+            return (short)ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+        else if ("portrait-secondary".equals(val))
+            return (short)ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
+        else if ("landscape-primary".equals(val))
+            return (short)ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+        else if ("landscape-secondary".equals(val))
+            return (short)ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
+        return DEFAULT_ORIENTATION;
     }
 
-    if (mShouldNotify && mOrientation != previousOrientation) {
-      GeckoAppShell.sendEventToGecko(GeckoEvent.createScreenOrientationEvent(mOrientation));
-    }
-  }
-
-  public short getScreenOrientation() {
-    return mOrientation;
-  }
-
-  public void lockScreenOrientation(int aOrientation) {
-    int orientation = 0;
+    // NOTE: this is public so OrientationEventListenerImpl can access it.
+    // Unfortunately, Java doesn't know about friendship.
+    public void updateScreenOrientation() {
+        int rotation = GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getRotation();
+        short previousOrientation = mOrientation;
 
-    switch (aOrientation) {
-      case eScreenOrientation_PortraitPrimary:
-        orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
-        break;
-      case eScreenOrientation_PortraitSecondary:
-        orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
-        break;
-      case eScreenOrientation_Portrait:
-        orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
-        break;
-      case eScreenOrientation_LandscapePrimary:
-        orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
-        break;
-      case eScreenOrientation_LandscapeSecondary:
-        orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
-        break;
-      case eScreenOrientation_Landscape:
-        orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
-        break;
-      default:
-        Log.e(LOGTAG, "Unexpected value received! (" + aOrientation + ")");
-        return;
+        if (rotation == Surface.ROTATION_0) {
+            mOrientation = eScreenOrientation_PortraitPrimary;
+        } else if (rotation == Surface.ROTATION_180) {
+            mOrientation = eScreenOrientation_PortraitSecondary;
+        } else if (rotation == Surface.ROTATION_270) {
+            mOrientation = eScreenOrientation_LandscapeSecondary;
+        } else if (rotation == Surface.ROTATION_90) {
+            mOrientation = eScreenOrientation_LandscapePrimary;
+        } else {
+            Log.e(LOGTAG, "Unexpected value received! (" + rotation + ")");
+            return;
+        }
+
+        if (mShouldNotify && mOrientation != previousOrientation) {
+            GeckoAppShell.sendEventToGecko(GeckoEvent.createScreenOrientationEvent(mOrientation));
+        }
+    }
+
+    public short getScreenOrientation() {
+        return mOrientation;
     }
 
-    GeckoApp.mAppContext.setRequestedOrientation(orientation);
-    updateScreenOrientation();
-  }
+    public void lockScreenOrientation(int aOrientation) {
+        int orientation = 0;
 
-  public void unlockScreenOrientation() {
-    if (GeckoApp.mAppContext.getRequestedOrientation() == mDefaultOrientation)
-      return;
+        switch (aOrientation) {
+        case eScreenOrientation_PortraitPrimary:
+            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+            break;
+        case eScreenOrientation_PortraitSecondary:
+            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
+            break;
+        case eScreenOrientation_Portrait:
+            orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
+            break;
+        case eScreenOrientation_LandscapePrimary:
+            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+            break;
+        case eScreenOrientation_LandscapeSecondary:
+            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
+            break;
+        case eScreenOrientation_Landscape:
+            orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
+            break;
+        default:
+            Log.e(LOGTAG, "Unexpected value received! (" + aOrientation + ")");
+            return;
+        }
 
-    GeckoApp.mAppContext.setRequestedOrientation(mDefaultOrientation);
-    updateScreenOrientation();
-  }
+        GeckoApp.mAppContext.setRequestedOrientation(orientation);
+        updateScreenOrientation();
+    }
+
+    public void unlockScreenOrientation() {
+        if (GeckoApp.mAppContext.getRequestedOrientation() == mDefaultOrientation)
+            return;
+
+        GeckoApp.mAppContext.setRequestedOrientation(mDefaultOrientation);
+        updateScreenOrientation();
+    }
 }