summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/util
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-04-15 18:03:27 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-04-15 18:03:50 -0700
commit6388b2c61b17bd6988f4243ad206c193a1e567c1 (patch)
treee4c431f875fdd4a2d4c6fb3630f1226f6b22ec90 /src/com/android/launcher3/util
parent534058492ff7d9a8a75b0fe709bddb6c3f6dcd79 (diff)
downloadandroid_packages_apps_Trebuchet-6388b2c61b17bd6988f4243ad206c193a1e567c1.tar.gz
android_packages_apps_Trebuchet-6388b2c61b17bd6988f4243ad206c193a1e567c1.tar.bz2
android_packages_apps_Trebuchet-6388b2c61b17bd6988f4243ad206c193a1e567c1.zip
Adding some utility methods for thread verification
Change-Id: I3fb6a1b860bba8a6efe413dd2698f972dc3e2506
Diffstat (limited to 'src/com/android/launcher3/util')
-rw-r--r--src/com/android/launcher3/util/Preconditions.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/com/android/launcher3/util/Preconditions.java b/src/com/android/launcher3/util/Preconditions.java
new file mode 100644
index 000000000..3760c6372
--- /dev/null
+++ b/src/com/android/launcher3/util/Preconditions.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.util;
+
+import android.os.Looper;
+
+import com.android.launcher3.LauncherModel;
+import com.android.launcher3.config.ProviderConfig;
+
+/**
+ * A set of utility methods for thread verification.
+ */
+public class Preconditions {
+
+ public static void assertWorkerThread() {
+ if (ProviderConfig.IS_DOGFOOD_BUILD && !isSameLooper(LauncherModel.getWorkerLooper())) {
+ throw new IllegalStateException();
+ }
+ }
+
+ public static void assertUIThread() {
+ if (ProviderConfig.IS_DOGFOOD_BUILD && !isSameLooper(Looper.getMainLooper())) {
+ throw new IllegalStateException();
+ }
+ }
+
+ public static void assertNonUiThread() {
+ if (ProviderConfig.IS_DOGFOOD_BUILD && isSameLooper(Looper.getMainLooper())) {
+ throw new IllegalStateException();
+ }
+ }
+
+ private static boolean isSameLooper(Looper looper) {
+ return Looper.myLooper() == looper;
+ }
+}