summaryrefslogtreecommitdiffstats
path: root/base/android
diff options
context:
space:
mode:
authordtrainor@chromium.org <dtrainor@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-20 18:36:08 +0000
committerdtrainor@chromium.org <dtrainor@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-20 18:36:08 +0000
commitb9ff40c9a746f3a5ef7914d706ed5e843065cec4 (patch)
tree9fea93f8eea6f6be54340c9e4d3398794c3db563 /base/android
parent3fc84827e9b332b799b09e40650a5af041d0c663 (diff)
downloadchromium_src-b9ff40c9a746f3a5ef7914d706ed5e843065cec4.zip
chromium_src-b9ff40c9a746f3a5ef7914d706ed5e843065cec4.tar.gz
chromium_src-b9ff40c9a746f3a5ef7914d706ed5e843065cec4.tar.bz2
Add a method for catching low end devices
Add a Java and native method for detecting if a device should be considered low end. BUG=246134 Review URL: https://chromiumcodereview.appspot.com/17151011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207498 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/android')
-rw-r--r--base/android/base_jni_registrar.cc2
-rw-r--r--base/android/java/src/org/chromium/base/SysUtils.java30
-rw-r--r--base/android/sys_utils.cc31
-rw-r--r--base/android/sys_utils.h26
4 files changed, 89 insertions, 0 deletions
diff --git a/base/android/base_jni_registrar.cc b/base/android/base_jni_registrar.cc
index 36d638b..706290b 100644
--- a/base/android/base_jni_registrar.cc
+++ b/base/android/base_jni_registrar.cc
@@ -13,6 +13,7 @@
#include "base/android/memory_pressure_listener_android.h"
#include "base/android/path_service_android.h"
#include "base/android/path_utils.h"
+#include "base/android/sys_utils.h"
#include "base/android/thread_utils.h"
#include "base/basictypes.h"
#include "base/debug/trace_event.h"
@@ -40,6 +41,7 @@ static RegistrationMethod kBaseRegisteredMethods[] = {
{ "PathService", base::android::RegisterPathService },
{ "PathUtils", base::android::RegisterPathUtils },
{ "SystemMessageHandler", base::MessagePumpForUI::RegisterBindings },
+ { "SysUtils", base::android::SysUtils::Register },
{ "PowerMonitor", base::RegisterPowerMonitor },
{ "ThreadUtils", base::RegisterThreadUtils },
};
diff --git a/base/android/java/src/org/chromium/base/SysUtils.java b/base/android/java/src/org/chromium/base/SysUtils.java
new file mode 100644
index 0000000..7af5a40
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/SysUtils.java
@@ -0,0 +1,30 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.base;
+
+import android.app.ActivityManager;
+import android.app.ActivityManager.MemoryInfo;
+import android.content.Context;
+import android.os.Build;
+
+/**
+ * Exposes system related information about the current device.
+ */
+public class SysUtils {
+ private static Boolean sLowEndDevice;
+
+ private SysUtils() { }
+
+ /**
+ * @return Whether or not this device should be considered a low end device.
+ */
+ public static boolean isLowEndDevice() {
+ if (sLowEndDevice == null) sLowEndDevice = nativeIsLowEndDevice();
+
+ return sLowEndDevice.booleanValue();
+ }
+
+ private static native boolean nativeIsLowEndDevice();
+}
diff --git a/base/android/sys_utils.cc b/base/android/sys_utils.cc
new file mode 100644
index 0000000..c231253
--- /dev/null
+++ b/base/android/sys_utils.cc
@@ -0,0 +1,31 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/android/sys_utils.h"
+
+#include "base/sys_info.h"
+#include "jni/SysUtils_jni.h"
+
+const int64 kLowEndMemoryThreshold = 1024 * 1024 * 512; // 512 mb.
+
+// Defined and called by JNI
+static jboolean IsLowEndDevice(JNIEnv* env, jclass clazz) {
+ return base::android::SysUtils::IsLowEndDevice();
+}
+
+namespace base {
+namespace android {
+
+bool SysUtils::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+bool SysUtils::IsLowEndDevice() {
+ return SysInfo::AmountOfPhysicalMemory() <= kLowEndMemoryThreshold;
+}
+
+SysUtils::SysUtils() { }
+
+} // namespace android
+} // namespace base
diff --git a/base/android/sys_utils.h b/base/android/sys_utils.h
new file mode 100644
index 0000000..78122ff
--- /dev/null
+++ b/base/android/sys_utils.h
@@ -0,0 +1,26 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_ANDROID_SYS_UTILS_H_
+#define BASE_ANDROID_SYS_UTILS_H_
+
+#include "base/android/jni_android.h"
+
+namespace base {
+namespace android {
+
+class BASE_EXPORT SysUtils {
+ public:
+ static bool Register(JNIEnv* env);
+
+ static bool IsLowEndDevice();
+
+ private:
+ SysUtils();
+};
+
+} // namespace android
+} // namespace base
+
+#endif // BASE_ANDROID_SYS_UTILS_H_