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

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

Issue 62833002: [Android] Add a low-end device mode override flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years 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/base_switches.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 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
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) {
102 return false;
103 }
104 if (sLowEndDevice == null) { 104 if (sLowEndDevice == null) {
105 int ramSizeKB = amountOfPhysicalMemoryKB(); 105 sLowEndDevice = detectLowEndDevice();
106 sLowEndDevice = (ramSizeKB > 0 &&
107 ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB);
108 } 106 }
109 107
110 return sLowEndDevice.booleanValue(); 108 return sLowEndDevice.booleanValue();
111 } 109 }
110
111 private static boolean detectLowEndDevice() {
112 if (CommandLine.isInitialized()) {
113 if (CommandLine.getInstance().hasSwitch(BaseSwitches.ENABLE_LOW_END_ DEVICE_MODE)) {
114 return true;
115 }
116 if (CommandLine.getInstance().hasSwitch(BaseSwitches.DISABLE_LOW_END _DEVICE_MODE)) {
117 return false;
118 }
119 }
120
121 if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) {
122 return false;
123 }
124
125 int ramSizeKB = amountOfPhysicalMemoryKB();
126 return (ramSizeKB > 0 && ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_TH RESHOLD_MB);
127 }
112 } 128 }
OLDNEW
« no previous file with comments | « base/android/java/src/org/chromium/base/BaseSwitches.java ('k') | base/base_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698