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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java

Issue 2545673002: Handle RuntimeException in MemoryMonitorAndroid.getMemoryInfo (Closed)
Patch Set: Log exception Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java b/content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java
index 501b69c257970490fd8bb9b3689d7df8ef9d2364..55718943a71bf6e88f41e867ef8d2308e4809919 100644
--- a/content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java
+++ b/content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java
@@ -9,6 +9,7 @@ import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.res.Configuration;
+import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
@@ -17,6 +18,7 @@ import org.chromium.base.annotations.JNINamespace;
*/
@JNINamespace("content")
class MemoryMonitorAndroid {
+ private static final String TAG = "MemoryMonitorAndroid";
private static final ActivityManager.MemoryInfo sMemoryInfo =
new ActivityManager.MemoryInfo();
private static ComponentCallbacks2 sCallbacks = null;
@@ -36,7 +38,19 @@ class MemoryMonitorAndroid {
private static void getMemoryInfo(Context context, long outPtr) {
ActivityManager am = (ActivityManager) context.getSystemService(
Context.ACTIVITY_SERVICE);
- am.getMemoryInfo(sMemoryInfo);
+ try {
+ am.getMemoryInfo(sMemoryInfo);
+ } catch (RuntimeException e) {
+ // RuntimeException can be thrown when the system is going to
+ // restart. Pass arbitrary values to the callback.
+ Log.e(TAG,
+ "Failed to get memory info due to a runtime exception: %s",
+ e);
+ sMemoryInfo.availMem = 1;
+ sMemoryInfo.lowMemory = true;
+ sMemoryInfo.threshold = 1;
+ sMemoryInfo.totalMem = 1;
+ }
nativeGetMemoryInfoCallback(
sMemoryInfo.availMem, sMemoryInfo.lowMemory,
sMemoryInfo.threshold, sMemoryInfo.totalMem, outPtr);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698