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 android.os.Build; | 7 import android.os.Build; |
8 import android.os.StrictMode; | 8 import android.os.StrictMode; |
9 import android.util.Log; | 9 import android.util.Log; |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 private static final long ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB = 512; | 25 private static final long ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB = 512; |
26 | 26 |
27 private static final String TAG = "SysUtils"; | 27 private static final String TAG = "SysUtils"; |
28 | 28 |
29 private static Boolean sLowEndDevice; | 29 private static Boolean sLowEndDevice; |
30 | 30 |
31 private SysUtils() { } | 31 private SysUtils() { } |
32 | 32 |
33 /** | 33 /** |
34 * Return the amount of physical memory on this device in kilobytes. | 34 * Return the amount of physical memory on this device in kilobytes. |
35 * Note: the only reason this is public is for testability reason. | 35 * Note: the only reason this is public is for testability reason. |
Yaron
2014/06/23 18:48:00
I don't see that this is actually true. Please rem
c.shu
2014/06/23 18:56:40
This is kind of out of the scope of this CL but I
| |
36 * @return Amount of physical memory in kilobytes, or 0 if there was | 36 * @return Amount of physical memory in kilobytes, or 0 if there was |
37 * an error trying to access the information. | 37 * an error trying to access the information. |
38 * | 38 * |
39 * Note that this is CalledByNative for testing purpose only. | 39 * Note that this is CalledByNative for testing purpose only. |
40 */ | 40 */ |
41 @CalledByNative | |
42 public static int amountOfPhysicalMemoryKB() { | 41 public static int amountOfPhysicalMemoryKB() { |
43 // Extract total memory RAM size by parsing /proc/meminfo, note that | 42 // Extract total memory RAM size by parsing /proc/meminfo, note that |
44 // this is exactly what the implementation of sysconf(_SC_PHYS_PAGES) | 43 // this is exactly what the implementation of sysconf(_SC_PHYS_PAGES) |
45 // does. However, it can't be called because this method must be | 44 // does. However, it can't be called because this method must be |
46 // usable before any native code is loaded. | 45 // usable before any native code is loaded. |
47 | 46 |
48 // An alternative is to use ActivityManager.getMemoryInfo(), but this | 47 // An alternative is to use ActivityManager.getMemoryInfo(), but this |
49 // requires a valid ActivityManager handle, which can only come from | 48 // requires a valid ActivityManager handle, which can only come from |
50 // a valid Context object, which itself cannot be retrieved | 49 // a valid Context object, which itself cannot be retrieved |
51 // during early startup, where this method is called. And making it | 50 // during early startup, where this method is called. And making it |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 @CalledByNative | 100 @CalledByNative |
102 public static boolean isLowEndDevice() { | 101 public static boolean isLowEndDevice() { |
103 if (sLowEndDevice == null) { | 102 if (sLowEndDevice == null) { |
104 sLowEndDevice = detectLowEndDevice(); | 103 sLowEndDevice = detectLowEndDevice(); |
105 } | 104 } |
106 return sLowEndDevice.booleanValue(); | 105 return sLowEndDevice.booleanValue(); |
107 } | 106 } |
108 | 107 |
109 private static boolean detectLowEndDevice() { | 108 private static boolean detectLowEndDevice() { |
110 if (CommandLine.isInitialized()) { | 109 if (CommandLine.isInitialized()) { |
111 if (CommandLine.getInstance().hasSwitch(BaseSwitches.ENABLE_LOW_END_ DEVICE_MODE)) { | 110 if (CommandLine.getInstance().hasSwitch(BaseSwitches.LOW_END_DEVICE_ MODE)) { |
112 return true; | 111 int mode = Integer.parseInt(CommandLine.getInstance().getSwitchV alue( |
113 } | 112 BaseSwitches.LOW_END_DEVICE_MODE)); |
114 if (CommandLine.getInstance().hasSwitch(BaseSwitches.DISABLE_LOW_END _DEVICE_MODE)) { | 113 if (mode == 1) |
115 return false; | 114 return true; |
115 if (mode == 0) | |
116 return false; | |
116 } | 117 } |
117 } | 118 } |
118 | 119 |
119 if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) { | 120 if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) { |
120 return false; | 121 return false; |
121 } | 122 } |
122 | 123 |
123 int ramSizeKB = amountOfPhysicalMemoryKB(); | 124 int ramSizeKB = amountOfPhysicalMemoryKB(); |
124 return (ramSizeKB > 0 && ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_TH RESHOLD_MB); | 125 return (ramSizeKB > 0 && ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_TH RESHOLD_MB); |
125 } | 126 } |
126 } | 127 } |
OLD | NEW |