Bug 875000 - Only attempt to tweak StrictMode on API 9+. r=trivial (bustage), a=lsblakk
authorRichard Newman <rnewman@mozilla.com>
Wed, 22 May 2013 11:26:46 -0700
changeset 142766 638cbe677011f67986467d5b30d60cc8d1beb1a0
parent 142765 624e976d35f090e80b0ee65f17e60858c0832eeb
child 142767 52db029185a4b143c52d652b559706efdda1e10b
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstrivial, lsblakk
bugs875000
milestone23.0a2
Bug 875000 - Only attempt to tweak StrictMode on API 9+. r=trivial (bustage), a=lsblakk
mobile/android/base/SysInfo.java.in
--- a/mobile/android/base/SysInfo.java.in
+++ b/mobile/android/base/SysInfo.java.in
@@ -45,32 +45,42 @@ public final class SysInfo {
        * @return the number of CPU cores, or 1 if the number could not be
        *         determined.
        */
     public static int getCPUCount() {
         if (cpuCount > 0) {
             return cpuCount;
         }
 
+        if (android.os.Build.VERSION.SDK_INT < 9) {
+            return readCPUCount();
+        }
+
+        // Avoid a strict mode warning... but only on devices that have StrictMode.
+        StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
+        try {
+            return readCPUCount();
+        } finally {
+            StrictMode.setThreadPolicy(savedPolicy);
+        }
+    }
+
+    private static int readCPUCount() {
         class CpuFilter implements FileFilter {
             @Override
             public boolean accept(File pathname) {
                 return Pattern.matches("cpu[0-9]+", pathname.getName());
             }
         }
-
-        StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
         try {
             final File dir = new File("/sys/devices/system/cpu/");
             return cpuCount = dir.listFiles(new CpuFilter()).length;
         } catch (Exception e) {
             Log.w(LOG_TAG, "Assuming 1 CPU; got exception.", e);
             return cpuCount = 1;
-        } finally {
-            StrictMode.setThreadPolicy(savedPolicy);
         }
     }
 
     /**
      * Fetch the total memory of the device in MB by parsing /proc/meminfo.
      * 
      * Of course, Android doesn't have a neat and tidy way to find total
      * RAM, so we do it by parsing /proc/meminfo.