From 12bff7b5fdb8c5a7ab06560234fd9f5b71b8f7c2 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Wed, 22 May 2013 11:26:46 -0700 Subject: [PATCH] Bug 875000 - Only attempt to tweak StrictMode on API 9+. r=trivial (bustage) --- mobile/android/base/SysInfo.java.in | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mobile/android/base/SysInfo.java.in b/mobile/android/base/SysInfo.java.in index bacd7779c6d1..36762e2844ef 100644 --- a/mobile/android/base/SysInfo.java.in +++ b/mobile/android/base/SysInfo.java.in @@ -50,22 +50,32 @@ public final class SysInfo { 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); } }