From 59e85c25a65b9d89855de9366fef499003a65e29 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Thu, 5 Dec 2019 16:22:57 +0800 Subject: [PATCH] Add warning message when entering loop twice The messages in queue could be executed before current message completed. Bug: 140599188 Test: calling Looper.loop() twice Change-Id: I1a4628606ed974e7a6a76b2832044959a9261bb9 --- core/java/android/os/Looper.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/java/android/os/Looper.java b/core/java/android/os/Looper.java index b478dbe2555d5..a7e326378228d 100644 --- a/core/java/android/os/Looper.java +++ b/core/java/android/os/Looper.java @@ -77,6 +77,7 @@ public final class Looper { @UnsupportedAppUsage final MessageQueue mQueue; final Thread mThread; + private boolean mInLoop; @UnsupportedAppUsage private Printer mLogging; @@ -155,6 +156,12 @@ public final class Looper { if (me == null) { throw new RuntimeException("No Looper; Looper.prepare() wasn't called on this thread."); } + if (me.mInLoop) { + Slog.w(TAG, "Loop again would have the queued messages be executed" + + " before this one completed."); + } + + me.mInLoop = true; final MessageQueue queue = me.mQueue; // Make sure the identity of this thread is that of the local process,