Commit 373df295 authored by bashi's avatar bashi Committed by Commit bot

Handle RuntimeException in MemoryMonitorAndroid.getMemoryInfo

A RuntimeException can be thrown when we call
ActivityManager.getMemoryInfo() when the system is going to restart.
To avoid immediate crash, handle these exceptions gracefully.


Cr-Commit-Position: refs/heads/master@{#435568}
parent e0c686cc
......@@ -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;
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(
try {
} catch (RuntimeException e) {
// RuntimeException can be thrown when the system is going to
// restart. Pass arbitrary values to the callback.
"Failed to get memory info due to a runtime exception: %s",
sMemoryInfo.availMem = 1;
sMemoryInfo.lowMemory = true;
sMemoryInfo.threshold = 1;
sMemoryInfo.totalMem = 1;
sMemoryInfo.availMem, sMemoryInfo.lowMemory,
sMemoryInfo.threshold, sMemoryInfo.totalMem, outPtr);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment