Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2012)

Side by Side Diff: base/android/java/src/org/chromium/base/SysUtils.java

Issue 258663002: Expose a low-end device mode override flags for non-android OSs as well (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/android/java/src/org/chromium/base/BaseSwitches.java ('k') | base/android/sys_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
36 * @return Amount of physical memory in kilobytes, or 0 if there was 35 * @return Amount of physical memory in kilobytes, or 0 if there was
37 * an error trying to access the information. 36 * an error trying to access the information.
38 *
39 * Note that this is CalledByNative for testing purpose only.
40 */ 37 */
41 @CalledByNative 38 private static int amountOfPhysicalMemoryKB() {
42 public static int amountOfPhysicalMemoryKB() {
43 // Extract total memory RAM size by parsing /proc/meminfo, note that 39 // Extract total memory RAM size by parsing /proc/meminfo, note that
44 // this is exactly what the implementation of sysconf(_SC_PHYS_PAGES) 40 // this is exactly what the implementation of sysconf(_SC_PHYS_PAGES)
45 // does. However, it can't be called because this method must be 41 // does. However, it can't be called because this method must be
46 // usable before any native code is loaded. 42 // usable before any native code is loaded.
47 43
48 // An alternative is to use ActivityManager.getMemoryInfo(), but this 44 // An alternative is to use ActivityManager.getMemoryInfo(), but this
49 // requires a valid ActivityManager handle, which can only come from 45 // requires a valid ActivityManager handle, which can only come from
50 // a valid Context object, which itself cannot be retrieved 46 // a valid Context object, which itself cannot be retrieved
51 // during early startup, where this method is called. And making it 47 // during early startup, where this method is called. And making it
52 // an explicit parameter here makes all call paths _much_ more 48 // an explicit parameter here makes all call paths _much_ more
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 @CalledByNative 97 @CalledByNative
102 public static boolean isLowEndDevice() { 98 public static boolean isLowEndDevice() {
103 if (sLowEndDevice == null) { 99 if (sLowEndDevice == null) {
104 sLowEndDevice = detectLowEndDevice(); 100 sLowEndDevice = detectLowEndDevice();
105 } 101 }
106 return sLowEndDevice.booleanValue(); 102 return sLowEndDevice.booleanValue();
107 } 103 }
108 104
109 private static boolean detectLowEndDevice() { 105 private static boolean detectLowEndDevice() {
110 if (CommandLine.isInitialized()) { 106 if (CommandLine.isInitialized()) {
111 if (CommandLine.getInstance().hasSwitch(BaseSwitches.ENABLE_LOW_END_ DEVICE_MODE)) { 107 if (CommandLine.getInstance().hasSwitch(BaseSwitches.LOW_END_DEVICE_ MODE)) {
112 return true; 108 int mode = Integer.parseInt(CommandLine.getInstance().getSwitchV alue(
113 } 109 BaseSwitches.LOW_END_DEVICE_MODE));
114 if (CommandLine.getInstance().hasSwitch(BaseSwitches.DISABLE_LOW_END _DEVICE_MODE)) { 110 if (mode == 1)
115 return false; 111 return true;
112 if (mode == 0)
113 return false;
116 } 114 }
117 } 115 }
118 116
119 if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) { 117 if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) {
120 return false; 118 return false;
121 } 119 }
122 120
123 int ramSizeKB = amountOfPhysicalMemoryKB(); 121 int ramSizeKB = amountOfPhysicalMemoryKB();
124 return (ramSizeKB > 0 && ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_TH RESHOLD_MB); 122 return (ramSizeKB > 0 && ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_TH RESHOLD_MB);
125 } 123 }
126 } 124 }
OLDNEW
« no previous file with comments | « base/android/java/src/org/chromium/base/BaseSwitches.java ('k') | base/android/sys_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698