Bug 1239376 - Fix StrictMode thread read access in SysInfo.getMemSize. r=mfinkle
This caused a StrictMode violation on startup.
--- a/mobile/android/base/java/org/mozilla/gecko/SysInfo.java
+++ b/mobile/android/base/java/org/mozilla/gecko/SysInfo.java
@@ -138,16 +138,19 @@ public final class SysInfo {
*/
public static int getMemSize() {
if (totalRAM >= 0) {
return totalRAM;
}
// This is the string "MemTotal" that we're searching for in the buffer.
final byte[] MEMTOTAL = {'M', 'e', 'm', 'T', 'o', 't', 'a', 'l'};
+
+ // `/proc/meminfo` is not a real file and thus safe to read on the main thread.
+ final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
try {
final byte[] buffer = new byte[MEMINFO_BUFFER_SIZE_BYTES];
final FileInputStream is = new FileInputStream("/proc/meminfo");
try {
final int length = is.read(buffer);
for (int i = 0; i < length; i++) {
if (matchMemText(buffer, i, length, MEMTOTAL)) {
@@ -162,16 +165,18 @@ public final class SysInfo {
}
Log.w(LOG_TAG, "Did not find MemTotal line in /proc/meminfo.");
return totalRAM = 0;
} catch (FileNotFoundException f) {
return totalRAM = 0;
} catch (IOException e) {
return totalRAM = 0;
+ } finally {
+ StrictMode.setThreadPolicy(savedPolicy);
}
}
/**
* @return the SDK version supported by this device, such as '16'.
*/
public static int getVersion() {
return android.os.Build.VERSION.SDK_INT;