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)); }