OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.base; | 5 package org.chromium.base; |
6 | 6 |
7 import java.io.BufferedReader; | 7 import java.io.BufferedReader; |
8 import java.io.FileReader; | 8 import java.io.FileReader; |
9 import java.util.regex.Matcher; | 9 import java.util.regex.Matcher; |
10 import java.util.regex.Pattern; | 10 import java.util.regex.Pattern; |
11 | 11 |
12 import android.app.ActivityManager; | 12 import android.app.ActivityManager; |
13 import android.app.ActivityManager.MemoryInfo; | 13 import android.app.ActivityManager.MemoryInfo; |
14 import android.content.Context; | 14 import android.content.Context; |
15 import android.os.Build; | 15 import android.os.Build; |
16 import android.util.Log; | 16 import android.util.Log; |
17 | 17 |
18 import org.chromium.base.BaseSwitches; | |
19 import org.chromium.base.CommandLine; | |
20 | |
18 /** | 21 /** |
19 * Exposes system related information about the current device. | 22 * Exposes system related information about the current device. |
20 */ | 23 */ |
21 public class SysUtils { | 24 public class SysUtils { |
22 // Any device that runs this or an older version of the system cannot be con sidered 'low-end' | 25 // Any device that runs this or an older version of the system cannot be con sidered 'low-end' |
23 private static final int ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD = | 26 private static final int ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD = |
24 Build.VERSION_CODES.JELLY_BEAN_MR2; | 27 Build.VERSION_CODES.JELLY_BEAN_MR2; |
25 | 28 |
26 // A device reporting strictly more total memory in megabytes cannot be cons idered 'low-end'. | 29 // A device reporting strictly more total memory in megabytes cannot be cons idered 'low-end'. |
27 private static final long ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB = 512; | 30 private static final long ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB = 512; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 } | 94 } |
92 | 95 |
93 return 0; | 96 return 0; |
94 } | 97 } |
95 | 98 |
96 /** | 99 /** |
97 * @return Whether or not this device should be considered a low end device. | 100 * @return Whether or not this device should be considered a low end device. |
98 */ | 101 */ |
99 @CalledByNative | 102 @CalledByNative |
100 public static boolean isLowEndDevice() { | 103 public static boolean isLowEndDevice() { |
101 if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) { | 104 while (sLowEndDevice == null) { |
bulach
2013/11/20 16:31:12
not quite sure why use a loop here?
jdduke (slow)
2013/11/20 18:16:34
Only for ease of breaking upon |sLowEndDevice| ini
| |
102 return false; | 105 if (CommandLine.isInitialized()) { |
103 } | 106 if (CommandLine.getInstance().hasSwitch(BaseSwitches.ENABLE_LOW_ END_DEVICE_MODE)) { |
104 if (sLowEndDevice == null) { | 107 sLowEndDevice = true; |
108 break; | |
109 } | |
110 if (CommandLine.getInstance().hasSwitch(BaseSwitches.DISABLE_LOW _END_DEVICE_MODE)) { | |
111 sLowEndDevice = false; | |
112 break; | |
113 } | |
114 } | |
115 | |
116 if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOL D) { | |
117 sLowEndDevice = false; | |
118 break; | |
119 } | |
120 | |
105 int ramSizeKB = amountOfPhysicalMemoryKB(); | 121 int ramSizeKB = amountOfPhysicalMemoryKB(); |
106 sLowEndDevice = (ramSizeKB > 0 && | 122 sLowEndDevice = (ramSizeKB > 0 && |
107 ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB); | 123 ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB); |
108 } | 124 } |
109 | 125 |
110 return sLowEndDevice.booleanValue(); | 126 return sLowEndDevice.booleanValue(); |
111 } | 127 } |
112 } | 128 } |
OLD | NEW |