From a698c25d7e2859cdec09278cd49462ff887ee278 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Fri, 8 Feb 2013 18:17:42 -0500 Subject: [PATCH] Bug 826053 - Avoid reporting duplicate ANRs; r=blassey --- mobile/android/base/ANRReporter.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mobile/android/base/ANRReporter.java b/mobile/android/base/ANRReporter.java index 81861a5f9adc..ce5955a31fa5 100644 --- a/mobile/android/base/ANRReporter.java +++ b/mobile/android/base/ANRReporter.java @@ -58,6 +58,7 @@ public final class ANRReporter extends BroadcastReceiver private static final ANRReporter sInstance = new ANRReporter(); private static int sRegisteredCount; private Handler mHandler; + private volatile boolean mPendingANR; public static void register(Context context) { if (sRegisteredCount++ != 0) { @@ -444,6 +445,27 @@ public final class ANRReporter extends BroadcastReceiver @Override public void onReceive(Context context, Intent intent) { + if (mPendingANR) { + // we already processed an ANR without getting unstuck; skip this one + if (DEBUG) { + Log.d(LOGTAG, "skipping duplicate ANR"); + } + return; + } + if (GeckoApp.mAppContext != null && GeckoApp.mAppContext.mMainHandler != null) { + mPendingANR = true; + // detect when the main thread gets unstuck + GeckoApp.mAppContext.mMainHandler.post(new Runnable() { + @Override + public void run() { + // okay to reset mPendingANR on main thread + mPendingANR = false; + if (DEBUG) { + Log.d(LOGTAG, "yay we got unstuck!"); + } + } + }); + } if (DEBUG) { Log.d(LOGTAG, "receiving " + String.valueOf(intent)); }