summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/launcher3/Utilities.java9
-rw-r--r--src/com/android/launcher3/WidgetPreviewLoader.java3
-rw-r--r--src/com/android/launcher3/model/WidgetsModel.java4
-rw-r--r--src/com/android/launcher3/util/Preconditions.java50
4 files changed, 54 insertions, 12 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 3969d308b..dd9b5fc40 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -47,7 +47,6 @@ import android.graphics.drawable.PaintDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
-import android.os.Process;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
@@ -62,7 +61,6 @@ import android.widget.Toast;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.config.FeatureFlags;
-import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.util.IconNormalizer;
import java.io.ByteArrayOutputStream;
@@ -728,13 +726,6 @@ public final class Utilities {
(res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
}
- public static void assertWorkerThread() {
- if (ProviderConfig.IS_DOGFOOD_BUILD &&
- (LauncherModel.sWorkerThread.getThreadId() != Process.myTid())) {
- throw new IllegalStateException();
- }
- }
-
/**
* Returns true if the intent is a valid launch intent for a launcher activity of an app.
* This is used to identify shortcuts which are different from the ones exposed by the
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java
index cb3126c48..d9bd78251 100644
--- a/src/com/android/launcher3/WidgetPreviewLoader.java
+++ b/src/com/android/launcher3/WidgetPreviewLoader.java
@@ -33,6 +33,7 @@ import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.SQLiteCacheHelper;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.widget.WidgetCell;
@@ -169,7 +170,7 @@ public class WidgetPreviewLoader {
* This ensures that we remove entries for packages which changed while the launcher was dead.
*/
public void removeObsoletePreviews(ArrayList<? extends ComponentKey> list) {
- Utilities.assertWorkerThread();
+ Preconditions.assertWorkerThread();
LongSparseArray<HashSet<String>> validPackages = new LongSparseArray<>();
diff --git a/src/com/android/launcher3/model/WidgetsModel.java b/src/com/android/launcher3/model/WidgetsModel.java
index 1107b441d..b2a94bb34 100644
--- a/src/com/android/launcher3/model/WidgetsModel.java
+++ b/src/com/android/launcher3/model/WidgetsModel.java
@@ -16,10 +16,10 @@ import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
-import com.android.launcher3.Utilities;
import com.android.launcher3.compat.AlphabeticIndexCompat;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.config.ProviderConfig;
+import com.android.launcher3.util.Preconditions;
import java.util.ArrayList;
import java.util.Collections;
@@ -101,7 +101,7 @@ public class WidgetsModel {
}
public WidgetsModel updateAndClone(Context context) {
- Utilities.assertWorkerThread();
+ Preconditions.assertWorkerThread();
try {
final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
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;
+ }
+}