From 4a57534a4bc24099e6b66819a89860e77b63b1e8 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Thu, 22 May 2014 17:34:04 -0700 Subject: [PATCH] Bug 1014338 - Pre: add ThreadUtils.assertNotOnUiThread. r=margaret --- mobile/android/base/util/ThreadUtils.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mobile/android/base/util/ThreadUtils.java b/mobile/android/base/util/ThreadUtils.java index 3d591a82b5a..55a3c9e6156 100644 --- a/mobile/android/base/util/ThreadUtils.java +++ b/mobile/android/base/util/ThreadUtils.java @@ -120,6 +120,10 @@ public final class ThreadUtils { assertOnThread(getUiThread(), AssertBehavior.THROW); } + public static void assertNotOnUiThread() { + assertNotOnThread(getUiThread(), AssertBehavior.THROW); + } + @RobocopTarget public static void assertOnGeckoThread() { assertOnThread(sGeckoThread, AssertBehavior.THROW); @@ -134,11 +138,19 @@ public final class ThreadUtils { } public static void assertOnThread(final Thread expectedThread, AssertBehavior behavior) { + assertOnThreadComparison(expectedThread, behavior, true); + } + + public static void assertNotOnThread(final Thread expectedThread, AssertBehavior behavior) { + assertOnThreadComparison(expectedThread, behavior, false); + } + + private static void assertOnThreadComparison(final Thread expectedThread, AssertBehavior behavior, boolean expected) { final Thread currentThread = Thread.currentThread(); final long currentThreadId = currentThread.getId(); final long expectedThreadId = expectedThread.getId(); - if (currentThreadId == expectedThreadId) { + if ((currentThreadId == expectedThreadId) == expected) { return; }