summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2019-08-15 14:53:41 -0700
committerSunny Goyal <sunnygoyal@google.com>2019-08-20 14:36:17 -0700
commit6fe3eec95cfb153ed7c16c6381623b7e762452c3 (patch)
treee530f240d9ce0b08d06c17e6ffe49d6c1ceab962 /src/com
parent4fa6f63ffd7a5ab230d17e8401d29cae3e5440b8 (diff)
downloadandroid_packages_apps_Trebuchet-6fe3eec95cfb153ed7c16c6381623b7e762452c3.tar.gz
android_packages_apps_Trebuchet-6fe3eec95cfb153ed7c16c6381623b7e762452c3.tar.bz2
android_packages_apps_Trebuchet-6fe3eec95cfb153ed7c16c6381623b7e762452c3.zip
Moving various common executors to a single location
Change-Id: I44bca49b8adb6fa22c3b48d10f674e42c28d792c
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/launcher3/InstallShortcutReceiver.java118
-rw-r--r--src/com/android/launcher3/InvariantDeviceProfile.java9
-rw-r--r--src/com/android/launcher3/LauncherModel.java46
-rw-r--r--src/com/android/launcher3/MainThreadExecutor.java33
-rw-r--r--src/com/android/launcher3/SessionCommitReceiver.java4
-rw-r--r--src/com/android/launcher3/Utilities.java18
-rw-r--r--src/com/android/launcher3/WidgetPreviewLoader.java34
-rw-r--r--src/com/android/launcher3/Workspace.java3
-rw-r--r--src/com/android/launcher3/compat/LauncherAppsCompatVO.java10
-rw-r--r--src/com/android/launcher3/compat/PackageInstallerCompatVL.java12
-rw-r--r--src/com/android/launcher3/dragndrop/AddItemActivity.java5
-rw-r--r--src/com/android/launcher3/dragndrop/DragView.java14
-rw-r--r--src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java5
-rw-r--r--src/com/android/launcher3/graphics/DragPreviewProvider.java6
-rw-r--r--src/com/android/launcher3/graphics/GridOptionsProvider.java8
-rw-r--r--src/com/android/launcher3/icons/IconCache.java15
-rw-r--r--src/com/android/launcher3/logging/FileLog.java7
-rw-r--r--src/com/android/launcher3/model/BaseLoaderResults.java7
-rw-r--r--src/com/android/launcher3/model/LoaderTask.java4
-rw-r--r--src/com/android/launcher3/model/ModelWriter.java19
-rw-r--r--src/com/android/launcher3/notification/NotificationListener.java8
-rw-r--r--src/com/android/launcher3/popup/PopupContainerWithArrow.java9
-rw-r--r--src/com/android/launcher3/states/InternalStateHandler.java9
-rw-r--r--src/com/android/launcher3/testing/TestInformationHandler.java9
-rw-r--r--src/com/android/launcher3/util/ConfigMonitor.java10
-rw-r--r--src/com/android/launcher3/util/DefaultDisplay.java4
-rw-r--r--src/com/android/launcher3/util/Executors.java87
-rw-r--r--src/com/android/launcher3/util/LooperExecutor.java35
-rw-r--r--src/com/android/launcher3/util/MainThreadInitializedObject.java5
-rw-r--r--src/com/android/launcher3/util/Preconditions.java5
-rw-r--r--src/com/android/launcher3/util/UiThreadHelper.java17
-rw-r--r--src/com/android/launcher3/util/ViewOnDrawExecutor.java7
-rw-r--r--src/com/android/launcher3/util/WallpaperOffsetInterpolator.java4
-rw-r--r--src/com/android/launcher3/views/FloatingIconView.java20
-rw-r--r--src/com/android/launcher3/widget/LauncherAppWidgetHostView.java10
35 files changed, 312 insertions, 304 deletions
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java
index a6b53b92d..351635c25 100644
--- a/src/com/android/launcher3/InstallShortcutReceiver.java
+++ b/src/com/android/launcher3/InstallShortcutReceiver.java
@@ -16,6 +16,8 @@
package com.android.launcher3;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.BroadcastReceiver;
@@ -28,9 +30,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.os.Handler;
import android.os.Looper;
-import android.os.Message;
import android.os.Parcelable;
import android.os.Process;
import android.os.UserHandle;
@@ -39,6 +39,8 @@ import android.util.Base64;
import android.util.Log;
import android.util.Pair;
+import androidx.annotation.WorkerThread;
+
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.icons.BitmapInfo;
@@ -65,9 +67,6 @@ import java.util.Set;
public class InstallShortcutReceiver extends BroadcastReceiver {
- private static final int MSG_ADD_TO_QUEUE = 1;
- private static final int MSG_FLUSH_QUEUE = 2;
-
public static final int FLAG_ACTIVITY_PAUSED = 1;
public static final int FLAG_LOADER_RUNNING = 2;
public static final int FLAG_DRAG_AND_DROP = 4;
@@ -100,65 +99,56 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
public static final int NEW_SHORTCUT_BOUNCE_DURATION = 450;
public static final int NEW_SHORTCUT_STAGGER_DELAY = 85;
- private static final Handler sHandler = new Handler(LauncherModel.getWorkerLooper()) {
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_ADD_TO_QUEUE: {
- Pair<Context, PendingInstallShortcutInfo> pair =
- (Pair<Context, PendingInstallShortcutInfo>) msg.obj;
- String encoded = pair.second.encodeToString();
- SharedPreferences prefs = Utilities.getPrefs(pair.first);
- Set<String> strings = prefs.getStringSet(APPS_PENDING_INSTALL, null);
- strings = (strings != null) ? new HashSet<>(strings) : new HashSet<String>(1);
- strings.add(encoded);
- prefs.edit().putStringSet(APPS_PENDING_INSTALL, strings).apply();
- return;
- }
- case MSG_FLUSH_QUEUE: {
- Context context = (Context) msg.obj;
- LauncherModel model = LauncherAppState.getInstance(context).getModel();
- if (model.getCallback() == null) {
- // Launcher not loaded
- return;
- }
-
- ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
- SharedPreferences prefs = Utilities.getPrefs(context);
- Set<String> strings = prefs.getStringSet(APPS_PENDING_INSTALL, null);
- if (DBG) Log.d(TAG, "Getting and clearing APPS_PENDING_INSTALL: " + strings);
- if (strings == null) {
- return;
- }
-
- LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
- for (String encoded : strings) {
- PendingInstallShortcutInfo info = decode(encoded, context);
- if (info == null) {
- continue;
- }
-
- String pkg = getIntentPackage(info.launchIntent);
- if (!TextUtils.isEmpty(pkg)
- && !launcherApps.isPackageEnabledForProfile(pkg, info.user)) {
- if (DBG) Log.d(TAG, "Ignoring shortcut for absent package: "
- + info.launchIntent);
- continue;
- }
-
- // Generate a shortcut info to add into the model
- installQueue.add(info.getItemInfo());
- }
- prefs.edit().remove(APPS_PENDING_INSTALL).apply();
- if (!installQueue.isEmpty()) {
- model.addAndBindAddedWorkspaceItems(installQueue);
- }
- return;
+ @WorkerThread
+ private static void addToQueue(Context context, PendingInstallShortcutInfo info) {
+ String encoded = info.encodeToString();
+ SharedPreferences prefs = Utilities.getPrefs(context);
+ Set<String> strings = prefs.getStringSet(APPS_PENDING_INSTALL, null);
+ strings = (strings != null) ? new HashSet<>(strings) : new HashSet<>(1);
+ strings.add(encoded);
+ prefs.edit().putStringSet(APPS_PENDING_INSTALL, strings).apply();
+ }
+
+ @WorkerThread
+ private static void flushQueueInBackground(Context context) {
+ LauncherModel model = LauncherAppState.getInstance(context).getModel();
+ if (model.getCallback() == null) {
+ // Launcher not loaded
+ return;
+ }
+
+ ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
+ SharedPreferences prefs = Utilities.getPrefs(context);
+ Set<String> strings = prefs.getStringSet(APPS_PENDING_INSTALL, null);
+ if (DBG) Log.d(TAG, "Getting and clearing APPS_PENDING_INSTALL: " + strings);
+ if (strings == null) {
+ return;
+ }
+
+ LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
+ for (String encoded : strings) {
+ PendingInstallShortcutInfo info = decode(encoded, context);
+ if (info == null) {
+ continue;
+ }
+
+ String pkg = getIntentPackage(info.launchIntent);
+ if (!TextUtils.isEmpty(pkg)
+ && !launcherApps.isPackageEnabledForProfile(pkg, info.user)) {
+ if (DBG) {
+ Log.d(TAG, "Ignoring shortcut for absent package: " + info.launchIntent);
}
+ continue;
}
+
+ // Generate a shortcut info to add into the model
+ installQueue.add(info.getItemInfo());
}
- };
+ prefs.edit().remove(APPS_PENDING_INSTALL).apply();
+ if (!installQueue.isEmpty()) {
+ model.addAndBindAddedWorkspaceItems(installQueue);
+ }
+ }
public static void removeFromInstallQueue(Context context, HashSet<String> packageNames,
UserHandle user) {
@@ -288,7 +278,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
private static void queuePendingShortcutInfo(PendingInstallShortcutInfo info, Context context) {
// Queue the item up for adding if launcher has not loaded properly yet
- Message.obtain(sHandler, MSG_ADD_TO_QUEUE, Pair.create(context, info)).sendToTarget();
+ MODEL_EXECUTOR.post(() -> addToQueue(context, info));
flushInstallQueue(context);
}
@@ -304,7 +294,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
if (sInstallQueueDisabledFlags != 0) {
return;
}
- Message.obtain(sHandler, MSG_FLUSH_QUEUE, context.getApplicationContext()).sendToTarget();
+ MODEL_EXECUTOR.post(() -> flushQueueInBackground(context));
}
/**
@@ -484,7 +474,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
appInfo.title = "";
appInfo.applyFrom(app.getIconCache().getDefaultIcon(user));
final WorkspaceItemInfo si = appInfo.makeWorkspaceItem();
- if (Looper.myLooper() == LauncherModel.getWorkerLooper()) {
+ if (Looper.myLooper() == MODEL_EXECUTOR.getLooper()) {
app.getIconCache().getTitleAndIcon(si, activityInfo, false /* useLowResIcon */);
} else {
app.getModel().updateAndBindWorkspaceItem(() -> {
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index bde87cb50..8ee530f0f 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -18,6 +18,7 @@ package com.android.launcher3;
import static com.android.launcher3.Utilities.getDevicePrefs;
import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter;
import android.annotation.TargetApi;
@@ -42,6 +43,9 @@ import android.util.Xml;
import android.view.Display;
import android.view.WindowManager;
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+
import com.android.launcher3.graphics.IconShape;
import com.android.launcher3.util.ConfigMonitor;
import com.android.launcher3.util.IntArray;
@@ -55,9 +59,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
-import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
-
public class InvariantDeviceProfile {
public static final String TAG = "IDP";
@@ -280,7 +281,7 @@ public class InvariantDeviceProfile {
public void setCurrentGrid(Context context, String gridName) {
Context appContext = context.getApplicationContext();
Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
- new MainThreadExecutor().execute(() -> onConfigChanged(appContext));
+ MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
}
private void onConfigChanged(Context context) {
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index eed23770e..da9617af7 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -18,20 +18,21 @@ package com.android.launcher3;
import static com.android.launcher3.LauncherAppState.ACTION_FORCE_ROLOAD;
import static com.android.launcher3.config.FeatureFlags.IS_DOGFOOD_BUILD;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
import android.os.Process;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
+import androidx.annotation.Nullable;
+
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
import com.android.launcher3.compat.UserManagerCompat;
@@ -65,8 +66,6 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.Executor;
import java.util.function.Supplier;
-import androidx.annotation.Nullable;
-
/**
* Maintains in-memory state of the Launcher. It is expected that there should be only one
* LauncherModel object held in a static. Also provide APIs for updating the database state
@@ -78,21 +77,12 @@ public class LauncherModel extends BroadcastReceiver
static final String TAG = "Launcher.Model";
- private final MainThreadExecutor mUiExecutor = new MainThreadExecutor();
@Thunk final LauncherAppState mApp;
@Thunk final Object mLock = new Object();
@Thunk
LoaderTask mLoaderTask;
@Thunk boolean mIsLoaderTaskRunning;
- @Thunk static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
- private static final Looper mWorkerLooper;
- static {
- sWorkerThread.start();
- mWorkerLooper = sWorkerThread.getLooper();
- }
- @Thunk static final Handler sWorker = new Handler(mWorkerLooper);
-
// Indicates whether the current model data is valid or not.
// We start off with everything not loaded. After that, we assume that
// our monitoring of the package manager provides all updates and we never
@@ -318,7 +308,7 @@ public class LauncherModel extends BroadcastReceiver
if (mCallbacks != null && mCallbacks.get() != null) {
final Callbacks oldCallbacks = mCallbacks.get();
// Clear any pending bind-runnables from the synchronized load process.
- mUiExecutor.execute(oldCallbacks::clearPendingBinds);
+ MAIN_EXECUTOR.execute(oldCallbacks::clearPendingBinds);
// If there is already one running, tell it to stop.
stopLoader();
@@ -362,7 +352,7 @@ public class LauncherModel extends BroadcastReceiver
// Always post the loader task, instead of running directly (even on same thread) so
// that we exit any nested synchronized blocks
- sWorker.post(mLoaderTask);
+ MODEL_EXECUTOR.post(mLoaderTask);
}
}
@@ -429,8 +419,8 @@ public class LauncherModel extends BroadcastReceiver
* use partial updates similar to {@link UserManagerCompat}
*/
public void refreshShortcutsIfRequired() {
- sWorker.removeCallbacks(mShortcutPermissionCheckRunnable);
- sWorker.post(mShortcutPermissionCheckRunnable);
+ MODEL_EXECUTOR.getHandler().removeCallbacks(mShortcutPermissionCheckRunnable);
+ MODEL_EXECUTOR.post(mShortcutPermissionCheckRunnable);
}
/**
@@ -457,14 +447,8 @@ public class LauncherModel extends BroadcastReceiver
}
public void enqueueModelUpdateTask(ModelUpdateTask task) {
- task.init(mApp, this, sBgDataModel, mBgAllAppsList, mUiExecutor);
-
- if (sWorkerThread.getThreadId() == Process.myTid()) {
- task.run();
- } else {
- // If we are not on the worker thread, then post to the worker handler
- sWorker.post(task);
- }
+ task.init(mApp, this, sBgDataModel, mBgAllAppsList, MAIN_EXECUTOR);
+ MODEL_EXECUTOR.execute(task);
}
/**
@@ -540,14 +524,4 @@ public class LauncherModel extends BroadcastReceiver
return mCallbacks != null ? mCallbacks.get() : null;
}
- /**
- * @return the looper for the worker thread which can be used to start background tasks.
- */
- public static Looper getWorkerLooper() {
- return mWorkerLooper;
- }
-
- public static void setWorkerPriority(final int priority) {
- Process.setThreadPriority(sWorkerThread.getThreadId(), priority);
- }
}
diff --git a/src/com/android/launcher3/MainThreadExecutor.java b/src/com/android/launcher3/MainThreadExecutor.java
deleted file mode 100644
index 509468233..000000000
--- a/src/com/android/launcher3/MainThreadExecutor.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2014 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;
-
-import android.os.Looper;
-
-import com.android.launcher3.util.LooperExecutor;
-
-/**
- * An executor service that executes its tasks on the main thread.
- *
- * Shutting down this executor is not supported.
- */
-public class MainThreadExecutor extends LooperExecutor {
-
- public MainThreadExecutor() {
- super(Looper.getMainLooper());
- }
-}
diff --git a/src/com/android/launcher3/SessionCommitReceiver.java b/src/com/android/launcher3/SessionCommitReceiver.java
index b0da6b9cd..a1c77ef1d 100644
--- a/src/com/android/launcher3/SessionCommitReceiver.java
+++ b/src/com/android/launcher3/SessionCommitReceiver.java
@@ -30,13 +30,13 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
-import android.os.Process;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.android.launcher3.compat.LauncherAppsCompat;
+import com.android.launcher3.util.Executors;
import java.util.List;
@@ -103,7 +103,7 @@ public class SessionCommitReceiver extends BroadcastReceiver {
// grid.
prefs.edit().putBoolean(ADD_ICON_PREFERENCE_KEY, true).apply();
} else if (!prefs.contains(ADD_ICON_PREFERENCE_INITIALIZED_KEY)) {
- new PrefInitTask(context).executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
+ new PrefInitTask(context).executeOnExecutor(Executors.THREAD_POOL_EXECUTOR);
}
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 05336f2e7..6ddebe75d 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -76,10 +76,6 @@ import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
-import java.util.concurrent.Executor;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -112,8 +108,6 @@ public final class Utilities {
public static final boolean ATLEAST_OREO =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
- public static final int SINGLE_FRAME_MS = 16;
-
/**
* Set on a motion event dispatched from the nav bar. See {@link MotionEvent#setEdgeFlags(int)}.
*/
@@ -136,18 +130,6 @@ public final class Utilities {
public static final String EXTRA_WALLPAPER_OFFSET = "com.android.launcher3.WALLPAPER_OFFSET";
public static final String EXTRA_WALLPAPER_FLAVOR = "com.android.launcher3.WALLPAPER_FLAVOR";
- // These values are same as that in {@link AsyncTask}.
- private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
- private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
- private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
- private static final int KEEP_ALIVE = 1;
- /**
- * An {@link Executor} to be used with async task with no limit on the queue size.
- */
- public static final Executor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
- CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
- TimeUnit.SECONDS, new LinkedBlockingQueue<>());
-
public static boolean IS_RUNNING_IN_TEST_HARNESS =
ActivityManager.isRunningInTestHarness();
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java
index 6d1bc1a9c..003bcc1ce 100644
--- a/src/com/android/launcher3/WidgetPreviewLoader.java
+++ b/src/com/android/launcher3/WidgetPreviewLoader.java
@@ -1,5 +1,8 @@
package com.android.launcher3;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
@@ -23,21 +26,23 @@ import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.CancellationSignal;
-import android.os.Handler;
import android.os.Process;
import android.os.UserHandle;
import android.util.Log;
import android.util.LongSparseArray;
+import androidx.annotation.Nullable;
+
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.ShortcutConfigActivityInfo;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.icons.GraphicsUtils;
+import com.android.launcher3.icons.IconCache;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.icons.ShadowGenerator;
-import com.android.launcher3.icons.IconCache;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.Executors;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.SQLiteCacheHelper;
@@ -50,11 +55,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.WeakHashMap;
-import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
-import androidx.annotation.Nullable;
-
public class WidgetPreviewLoader {
private static final String TAG = "WidgetPreviewLoader";
@@ -68,23 +70,18 @@ public class WidgetPreviewLoader {
* Note: synchronized block used for this variable is expensive and the block should always
* be posted to a background thread.
*/
- @Thunk final Set<Bitmap> mUnusedBitmaps =
- Collections.newSetFromMap(new WeakHashMap<Bitmap, Boolean>());
+ @Thunk final Set<Bitmap> mUnusedBitmaps = Collections.newSetFromMap(new WeakHashMap<>());
private final Context mContext;
private final IconCache mIconCache;
private final UserManagerCompat mUserManager;
private final CacheDb mDb;
- private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
- @Thunk final Handler mWorkerHandler;
-
public WidgetPreviewLoader(Context context, IconCache iconCache) {
mContext = context;
mIconCache = iconCache;
mUserManager = UserManagerCompat.getInstance(context);
mDb = new CacheDb(context);
- mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());
}
/**
@@ -99,7 +96,7 @@ public class WidgetPreviewLoader {
WidgetCacheKey key = new WidgetCacheKey(item.componentName, item.user, size);
PreviewLoadTask task = new PreviewLoadTask(key, item, previewWidth, previewHeight, caller);
- task.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
+ task.executeOnExecutor(Executors.THREAD_POOL_EXECUTOR);
CancellationSignal signal = new CancellationSignal();
signal.setOnCancelListener(task);
@@ -494,12 +491,7 @@ public class WidgetPreviewLoader {
private Drawable mutateOnMainThread(final Drawable drawable) {
try {
- return mMainThreadExecutor.submit(new Callable<Drawable>() {
- @Override
- public Drawable call() throws Exception {
- return drawable.mutate();
- }
- }).get();
+ return MAIN_EXECUTOR.submit(drawable::mutate).get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
@@ -607,7 +599,7 @@ public class WidgetPreviewLoader {
// Write the generated preview to the DB in the worker thread
if (mVersions != null) {
- mWorkerHandler.post(new Runnable() {
+ MODEL_EXECUTOR.post(new Runnable() {
@Override
public void run() {
if (!isCancelled()) {
@@ -637,7 +629,7 @@ public class WidgetPreviewLoader {
// recycled set immediately. Otherwise, it will be recycled after the preview is written
// to disk.
if (preview != null) {
- mWorkerHandler.post(new Runnable() {
+ MODEL_EXECUTOR.post(new Runnable() {
@Override
public void run() {
synchronized (mUnusedBitmaps) {
@@ -658,7 +650,7 @@ public class WidgetPreviewLoader {
// in the tasks's onCancelled() call, and if cancelled while the task is writing to
// disk, it will be cancelled in the task's onPostExecute() call.
if (mBitmapToRecycle != null) {
- mWorkerHandler.post(new Runnable() {
+ MODEL_EXECUTOR.post(new Runnable() {
@Override
public void run() {
synchronized (mUnusedBitmaps) {
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 812f44458..d9eb311bd 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -90,6 +90,7 @@ import com.android.launcher3.touch.WorkspaceTouchListener;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
+import com.android.launcher3.util.Executors;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.IntSparseArrayMap;
@@ -1159,7 +1160,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
protected void setWallpaperDimension() {
- Utilities.THREAD_POOL_EXECUTOR.execute(new Runnable() {
+ Executors.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
final Point size = LauncherAppState.getIDP(getContext()).defaultWallpaperSize;
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java
index 6e7a1bdcf..5e13d00b7 100644
--- a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java
+++ b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java
@@ -16,6 +16,8 @@
package com.android.launcher3.compat;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
@@ -30,19 +32,17 @@ import android.os.Parcelable;
import android.os.Process;
import android.os.UserHandle;
+import androidx.annotation.Nullable;
+
import com.android.launcher3.LauncherAppState;
-import com.android.launcher3.LauncherModel;
import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.compat.ShortcutConfigActivityInfo.ShortcutConfigActivityInfoVO;
import com.android.launcher3.icons.LauncherIcons;
-import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.util.PackageUserKey;
import java.util.ArrayList;
import java.util.List;
-import androidx.annotation.Nullable;
-
@TargetApi(26)
public class LauncherAppsCompatVO extends LauncherAppsCompatVL {
@@ -120,7 +120,7 @@ public class LauncherAppsCompatVO extends LauncherAppsCompatVL {
}
} else {
// Block the worker thread until the accept() is called.
- new LooperExecutor(LauncherModel.getWorkerLooper()).execute(new Runnable() {
+ MODEL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
try {
diff --git a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
index 8a5eabca9..052b0c373 100644
--- a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
+++ b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
@@ -16,22 +16,22 @@
package com.android.launcher3.compat;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionCallback;
import android.content.pm.PackageInstaller.SessionInfo;
-import android.os.Handler;
import android.os.Process;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.SparseArray;
-import com.android.launcher3.Utilities;
-import com.android.launcher3.icons.IconCache;
import com.android.launcher3.LauncherAppState;
-import com.android.launcher3.LauncherModel;
+import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.icons.IconCache;
import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
@@ -47,7 +47,6 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
@Thunk final PackageInstaller mInstaller;
private final IconCache mCache;
- private final Handler mWorker;
private final Context mAppContext;
private final HashMap<String,Boolean> mSessionVerifiedMap = new HashMap<>();
private final LauncherAppsCompat mLauncherApps;
@@ -56,8 +55,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
mAppContext = context.getApplicationContext();
mInstaller = context.getPackageManager().getPackageInstaller();
mCache = LauncherAppState.getInstance(context).getIconCache();
- mWorker = new Handler(LauncherModel.getWorkerLooper());
- mInstaller.registerSessionCallback(mCallback, mWorker);
+ mInstaller.registerSessionCallback(mCallback, MODEL_EXECUTOR.getHandler());
mLauncherApps = LauncherAppsCompat.getInstance(context);
}
diff --git a/src/com/android/launcher3/dragndrop/AddItemActivity.java b/src/com/android/launcher3/dragndrop/AddItemActivity.java
index a2dcbf87d..9fb10905f 100644
--- a/src/com/android/launcher3/dragndrop/AddItemActivity.java
+++ b/src/com/android/launcher3/dragndrop/AddItemActivity.java
@@ -20,6 +20,7 @@ import static com.android.launcher3.logging.LoggerUtils.newCommandAction;
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
import static com.android.launcher3.logging.LoggerUtils.newItemTarget;
import static com.android.launcher3.logging.LoggerUtils.newLauncherEvent;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import android.annotation.TargetApi;
import android.app.ActivityOptions;
@@ -47,7 +48,6 @@ import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetHost;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
-import com.android.launcher3.LauncherModel;
import com.android.launcher3.R;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.LauncherAppsCompatVO;
@@ -55,7 +55,6 @@ import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.util.InstantAppResolver;
-import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.views.BaseDragLayer;
import com.android.launcher3.widget.PendingAddShortcutInfo;
import com.android.launcher3.widget.PendingAddWidgetInfo;
@@ -234,7 +233,7 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener
mWidgetCell.applyFromCellItem(item, mApp.getWidgetCache());
mWidgetCell.ensurePreview();
}
- }.executeOnExecutor(new LooperExecutor(LauncherModel.getWorkerLooper()));
+ }.executeOnExecutor(MODEL_EXECUTOR);
// TODO: Create a worker looper executor and reuse that everywhere.
}
diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java
index 09c5e5b2b..f66d07e3d 100644
--- a/src/com/android/launcher3/dragndrop/DragView.java
+++ b/src/com/android/launcher3/dragndrop/DragView.java
@@ -17,6 +17,7 @@
package com.android.launcher3.dragndrop;
import static com.android.launcher3.Utilities.getBadge;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -41,16 +42,19 @@ import android.os.Handler;
import android.os.Looper;
import android.view.View;
+import androidx.dynamicanimation.animation.FloatPropertyCompat;
+import androidx.dynamicanimation.animation.SpringAnimation;
+import androidx.dynamicanimation.animation.SpringForce;
+
import com.android.launcher3.FastBitmapDrawable;
+import com.android.launcher3.FirstFrameAnimatorHelper;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
-import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
-import com.android.launcher3.FirstFrameAnimatorHelper;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.util.Themes;
@@ -58,10 +62,6 @@ import com.android.launcher3.util.Thunk;
import java.util.Arrays;
-import androidx.dynamicanimation.animation.FloatPropertyCompat;
-import androidx.dynamicanimation.animation.SpringAnimation;
-import androidx.dynamicanimation.animation.SpringForce;
-
public class DragView extends View implements LauncherStateManager.StateListener {
private static final ColorMatrix sTempMatrix1 = new ColorMatrix();
private static final ColorMatrix sTempMatrix2 = new ColorMatrix();
@@ -210,7 +210,7 @@ public class DragView extends View implements LauncherStateManager.StateListener
return;
}
// Load the adaptive icon on a background thread and add the view in ui thread.
- new Handler(LauncherModel.getWorkerLooper()).postAtFrontOfQueue(new Runnable() {
+ MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(new Runnable() {
@Override
public void run() {
Object[] outObj = new Object[1];
diff --git a/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java b/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java
index d8a1f9951..0bb3fbac5 100644
--- a/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java
+++ b/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java
@@ -16,6 +16,8 @@
package com.android.launcher3.dragndrop;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -31,7 +33,6 @@ import android.util.Log;
import androidx.annotation.Nullable;
import com.android.launcher3.Launcher;
-import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.PreviewBackground;
@@ -85,7 +86,7 @@ public class FolderAdaptiveIcon extends AdaptiveIconDrawable {
// Create the actual drawable on the UI thread to avoid race conditions with
// FolderIcon draw pass
try {
- return new MainThreadExecutor().submit(() -> {
+ return MAIN_EXECUTOR.submit(() -> {
FolderIcon icon = launcher.findFolderIcon(folderId);
return icon == null ? null : createDrawableOnUiThread(icon, badge, dragViewSize);
}).get();
diff --git a/src/com/android/launcher3/graphics/DragPreviewProvider.java b/src/com/android/launcher3/graphics/DragPreviewProvider.java
index 9263a2ac9..747efe307 100644
--- a/src/com/android/launcher3/graphics/DragPreviewProvider.java
+++ b/src/com/android/launcher3/graphics/DragPreviewProvider.java
@@ -16,6 +16,8 @@
package com.android.launcher3.graphics;
+import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
+
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
@@ -25,7 +27,6 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
-import android.os.Handler;
import android.view.View;
import com.android.launcher3.BubbleTextView;
@@ -35,7 +36,6 @@ import com.android.launcher3.R;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.icons.BitmapRenderer;
-import com.android.launcher3.util.UiThreadHelper;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.widget.PendingAppWidgetHostView;
@@ -157,7 +157,7 @@ public class DragPreviewProvider {
}
mOutlineGeneratorCallback = new OutlineGeneratorCallback(preview);
- new Handler(UiThreadHelper.getBackgroundLooper()).post(mOutlineGeneratorCallback);
+ UI_HELPER_EXECUTOR.post(mOutlineGeneratorCallback);
}
protected static Rect getDrawableBounds(Drawable d) {
diff --git a/src/com/android/launcher3/graphics/GridOptionsProvider.java b/src/com/android/launcher3/graphics/GridOptionsProvider.java
index efd39ee8e..71b436600 100644
--- a/src/com/android/launcher3/graphics/GridOptionsProvider.java
+++ b/src/com/android/launcher3/graphics/GridOptionsProvider.java
@@ -1,5 +1,7 @@
package com.android.launcher3.graphics;
+import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
+
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.res.XmlResourceParser;
@@ -17,8 +19,6 @@ import android.util.Xml;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.InvariantDeviceProfile.GridOption;
import com.android.launcher3.R;
-import com.android.launcher3.util.LooperExecutor;
-import com.android.launcher3.util.UiThreadHelper;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -180,10 +180,10 @@ public class GridOptionsProvider extends ContentProvider {
throw new FileNotFoundException(e.getMessage());
}
- LooperExecutor executor = new LooperExecutor(UiThreadHelper.getBackgroundLooper());
try {
return openPipeHelper(uri, MIME_TYPE_PNG, null,
- executor.submit(new LauncherPreviewRenderer(getContext(), idp)), BITMAP_WRITER);
+ UI_HELPER_EXECUTOR.submit(new LauncherPreviewRenderer(getContext(), idp)),
+ BITMAP_WRITER);
} catch (Exception e) {
throw new FileNotFoundException(e.getMessage());
}
diff --git a/src/com/android/launcher3/icons/IconCache.java b/src/com/android/launcher3/icons/IconCache.java
index 55d58b9c0..5fb833ced 100644
--- a/src/com/android/launcher3/icons/IconCache.java
+++ b/src/com/android/launcher3/icons/IconCache.java
@@ -16,6 +16,9 @@
package com.android.launcher3.icons;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
@@ -36,8 +39,6 @@ import com.android.launcher3.IconProvider;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.LauncherFiles;
-import com.android.launcher3.LauncherModel;
-import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.Utilities;
import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.compat.LauncherAppsCompat;
@@ -59,8 +60,6 @@ public class IconCache extends BaseIconCache {
private static final String TAG = "Launcher.IconCache";
- private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
-
private final CachingLogic<ComponentWithLabel> mComponentWithLabelCachingLogic;
private final CachingLogic<LauncherActivityInfo> mLauncherActivityInfoCachingLogic;
@@ -72,7 +71,7 @@ public class IconCache extends BaseIconCache {
private int mPendingIconRequestCount = 0;
public IconCache(Context context, InvariantDeviceProfile inv) {
- super(context, LauncherFiles.APP_ICONS_DB, LauncherModel.getWorkerLooper(),
+ super(context, LauncherFiles.APP_ICONS_DB, MODEL_EXECUTOR.getLooper(),
inv.fillResIconDpi, inv.iconBitmapSize, true /* inMemoryCache */);
mComponentWithLabelCachingLogic = new ComponentCachingLogic(context);
mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context);
@@ -123,7 +122,7 @@ public class IconCache extends BaseIconCache {
final ItemInfoWithIcon info) {
Preconditions.assertUIThread();
if (mPendingIconRequestCount <= 0) {
- LauncherModel.setWorkerPriority(Process.THREAD_PRIORITY_FOREGROUND);
+ MODEL_EXECUTOR.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
}
mPendingIconRequestCount ++;
@@ -135,7 +134,7 @@ public class IconCache extends BaseIconCache {
} else if (info instanceof PackageItemInfo) {
getTitleAndIconForApp((PackageItemInfo) info, false);
}
- mMainThreadExecutor.execute(() -> {
+ MAIN_EXECUTOR.execute(() -> {
caller.reapplyItemInfo(info);
onEnd();
});
@@ -148,7 +147,7 @@ public class IconCache extends BaseIconCache {
private void onIconRequestEnd() {
mPendingIconRequestCount --;
if (mPendingIconRequestCount <= 0) {
- LauncherModel.setWorkerPriority(Process.THREAD_PRIORITY_BACKGROUND);
+ MODEL_EXECUTOR.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
}
}
diff --git a/src/com/android/launcher3/logging/FileLog.java b/src/com/android/launcher3/logging/FileLog.java
index cc920767f..47a0f537c 100644
--- a/src/com/android/launcher3/logging/FileLog.java
+++ b/src/com/android/launcher3/logging/FileLog.java
@@ -1,5 +1,7 @@
package com.android.launcher3.logging;
+import static com.android.launcher3.util.Executors.createAndStartNewLooper;
+
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
@@ -92,9 +94,8 @@ public final class FileLog {
private static Handler getHandler() {
synchronized (DATE_FORMAT) {
if (sHandler == null) {
- HandlerThread thread = new HandlerThread("file-logger");
- thread.start();
- sHandler = new Handler(thread.getLooper(), new LogWriterCallback());
+ sHandler = new Handler(createAndStartNewLooper("file-logger"),
+ new LogWriterCallback());
}
}
return sHandler;
diff --git a/src/com/android/launcher3/model/BaseLoaderResults.java b/src/com/android/launcher3/model/BaseLoaderResults.java
index 018f93a5c..0a4f00582 100644
--- a/src/com/android/launcher3/model/BaseLoaderResults.java
+++ b/src/com/android/launcher3/model/BaseLoaderResults.java
@@ -16,6 +16,8 @@
package com.android.launcher3.model;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+
import android.os.Looper;
import android.util.Log;
@@ -25,11 +27,10 @@ import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetInfo;
import com.android.launcher3.LauncherModel.CallbackTask;
-import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.LauncherSettings;
-import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.PagedView;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.LooperIdleLock;
@@ -64,7 +65,7 @@ public abstract class BaseLoaderResults {
public BaseLoaderResults(LauncherAppState app, BgDataModel dataModel,
AllAppsList allAppsList, int pageToBindFirst, WeakReference<Callbacks> callbacks) {
- mUiExecutor = new MainThreadExecutor();
+ mUiExecutor = MAIN_EXECUTOR;
mApp = app;
mBgDataModel = dataModel;
mBgAllAppsList = allAppsList;
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index 54249dc61..8845ab392 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -20,6 +20,7 @@ import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER;
import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_SAFEMODE;
import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_SUSPENDED;
import static com.android.launcher3.model.LoaderResults.filterCurrentWorkspaceItems;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import static com.android.launcher3.util.PackageManagerHelper.isSystemApp;
import android.appwidget.AppWidgetProviderInfo;
@@ -32,7 +33,6 @@ import android.content.pm.LauncherActivityInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.ShortcutInfo;
-import android.os.Handler;
import android.os.Process;
import android.os.UserHandle;
import android.text.TextUtils;
@@ -772,7 +772,7 @@ public class LoaderTask implements Runnable {
new SdCardAvailableReceiver(mApp, pendingPackages),
new IntentFilter(Intent.ACTION_BOOT_COMPLETED),
null,
- new Handler(LauncherModel.getWorkerLooper()));
+ MODEL_EXECUTOR.getHandler());
}
}
}
diff --git a/src/com/android/launcher3/model/ModelWriter.java b/src/com/android/launcher3/model/ModelWriter.java
index d7ab0ddae..b7a19d39e 100644
--- a/src/com/android/launcher3/model/ModelWriter.java
+++ b/src/com/android/launcher3/model/ModelWriter.java
@@ -16,6 +16,8 @@
package com.android.launcher3.model;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -31,17 +33,16 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetHost;
import com.android.launcher3.LauncherAppWidgetInfo;
import com.android.launcher3.LauncherModel;
-import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.LauncherProvider;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherSettings.Settings;
-import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.Utilities;
+import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.util.ContentWriter;
import com.android.launcher3.util.ItemInfoMatcher;
-import com.android.launcher3.util.LooperExecutor;
import java.util.ArrayList;
import java.util.Arrays;
@@ -61,7 +62,6 @@ public class ModelWriter {
private final BgDataModel mBgDataModel;
private final Handler mUiHandler;
- private final Executor mWorkerExecutor;
private final boolean mHasVerticalHotseat;
private final boolean mVerifyChanges;
@@ -74,7 +74,6 @@ public class ModelWriter {
mContext = context;
mModel = model;
mBgDataModel = dataModel;
- mWorkerExecutor = new LooperExecutor(LauncherModel.getWorkerLooper());
mHasVerticalHotseat = hasVerticalHotseat;
mVerifyChanges = verifyChanges;
mUiHandler = new Handler(Looper.getMainLooper());
@@ -194,7 +193,7 @@ public class ModelWriter {
item.spanX = spanX;
item.spanY = spanY;
- mWorkerExecutor.execute(new UpdateItemRunnable(item, () ->
+ ((Executor) MODEL_EXECUTOR).execute(new UpdateItemRunnable(item, () ->
new ContentWriter(mContext)
.put(Favorites.CONTAINER, item.container)
.put(Favorites.CELLX, item.cellX)
@@ -209,7 +208,7 @@ public class ModelWriter {
* Update an item to the database in a specified container.
*/
public void updateItemInDatabase(ItemInfo item) {
- mWorkerExecutor.execute(new UpdateItemRunnable(item, () -> {
+ ((Executor) MODEL_EXECUTOR).execute(new UpdateItemRunnable(item, () -> {
ContentWriter writer = new ContentWriter(mContext);
item.onAddToDatabase(writer);
return writer;
@@ -229,7 +228,7 @@ public class ModelWriter {
ModelVerifier verifier = new ModelVerifier();
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
- mWorkerExecutor.execute(() -> {
+ ((Executor) MODEL_EXECUTOR).execute(() -> {
// Write the item on background thread, as some properties might have been updated in
// the background.
final ContentWriter writer = new ContentWriter(mContext);
@@ -333,14 +332,14 @@ public class ModelWriter {
if (mPreparingToUndo) {
mDeleteRunnables.add(r);
} else {
- mWorkerExecutor.execute(r);
+ ((Executor) MODEL_EXECUTOR).execute(r);
}
}
public void commitDelete() {
mPreparingToUndo = false;
for (Runnable runnable : mDeleteRunnables) {
- mWorkerExecutor.execute(runnable);
+ ((Executor) MODEL_EXECUTOR).execute(runnable);
}
mDeleteRunnables.clear();
}
diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java
index e57a051f8..10378ee43 100644
--- a/src/com/android/launcher3/notification/NotificationListener.java
+++ b/src/com/android/launcher3/notification/NotificationListener.java
@@ -16,6 +16,7 @@
package com.android.launcher3.notification;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import static com.android.launcher3.util.SecureSettingsObserver.newNotificationSettingsObserver;
import android.annotation.TargetApi;
@@ -31,7 +32,8 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
-import com.android.launcher3.LauncherModel;
+import androidx.annotation.Nullable;
+
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.SecureSettingsObserver;
@@ -43,8 +45,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import androidx.annotation.Nullable;
-
/**
* A {@link NotificationListenerService} that sends updates to its
* {@link NotificationsChangedListener} when notifications are posted or canceled,
@@ -141,7 +141,7 @@ public class NotificationListener extends NotificationListenerService {
public NotificationListener() {
super();
- mWorkerHandler = new Handler(LauncherModel.getWorkerLooper(), mWorkerCallback);
+ mWorkerHandler = new Handler(MODEL_EXECUTOR.getLooper(), mWorkerCallback);
mUiHandler = new Handler(Looper.getMainLooper(), mUiCallback);
sNotificationListenerInstance = this;
}
diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
index baaad6573..1296a969d 100644
--- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java
+++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
@@ -24,6 +24,7 @@ import static com.android.launcher3.popup.PopupPopulator.MAX_SHORTCUTS_IF_NOTIFI
import static com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import static com.android.launcher3.userevent.nano.LauncherLogProto.ItemType;
import static com.android.launcher3.userevent.nano.LauncherLogProto.Target;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import android.animation.AnimatorSet;
import android.animation.LayoutTransition;
@@ -36,7 +37,6 @@ import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
-import android.util.Log;
import android.util.Pair;
import android.view.MotionEvent;
import android.view.View;
@@ -51,9 +51,7 @@ import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.Launcher;
-import com.android.launcher3.LauncherModel;
import com.android.launcher3.R;
-import com.android.launcher3.Utilities;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
import com.android.launcher3.accessibility.ShortcutMenuAccessibilityDelegate;
import com.android.launcher3.dot.DotInfo;
@@ -65,10 +63,8 @@ import com.android.launcher3.notification.NotificationInfo;
import com.android.launcher3.notification.NotificationItemView;
import com.android.launcher3.notification.NotificationKeyData;
import com.android.launcher3.popup.PopupDataProvider.PopupDataChangeListener;
-import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider;
-import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.util.PackageUserKey;
@@ -307,8 +303,7 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource,
setLayoutTransition(new LayoutTransition());
// Load the shortcuts on a background thread and update the container as it animates.
- final Looper workerLooper = LauncherModel.getWorkerLooper();
- new Handler(workerLooper).postAtFrontOfQueue(PopupPopulator.createUpdateRunnable(
+ MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(PopupPopulator.createUpdateRunnable(
mLauncher, originalItemInfo, new Handler(Looper.getMainLooper()),
this, mShortcuts, notificationKeys));
}
diff --git a/src/com/android/launcher3/states/InternalStateHandler.java b/src/com/android/launcher3/states/InternalStateHandler.java
index 446d4f8ed..a23cd6d2e 100644
--- a/src/com/android/launcher3/states/InternalStateHandler.java
+++ b/src/com/android/launcher3/states/InternalStateHandler.java
@@ -15,6 +15,8 @@
*/
package com.android.launcher3.states;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+
import android.content.Intent;
import android.os.Binder;
import android.os.Bundle;
@@ -23,7 +25,6 @@ import android.os.IBinder;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.model.BgDataModel.Callbacks;
-import com.android.launcher3.MainThreadExecutor;
import java.lang.ref.WeakReference;
@@ -94,16 +95,12 @@ public abstract class InternalStateHandler extends Binder {
private static class Scheduler implements Runnable {
private WeakReference<InternalStateHandler> mPendingHandler = new WeakReference<>(null);
- private MainThreadExecutor mMainThreadExecutor;
public void schedule(InternalStateHandler handler) {
synchronized (this) {
mPendingHandler = new WeakReference<>(handler);
- if (mMainThreadExecutor == null) {
- mMainThreadExecutor = new MainThreadExecutor();
- }
}
- mMainThreadExecutor.execute(this);
+ MAIN_EXECUTOR.execute(this);
}
@Override
diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java
index 4fd0f884d..516c251bf 100644
--- a/src/com/android/launcher3/testing/TestInformationHandler.java
+++ b/src/com/android/launcher3/testing/TestInformationHandler.java
@@ -15,6 +15,8 @@
*/
package com.android.launcher3.testing;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+
import android.content.Context;
import android.os.Bundle;
@@ -23,7 +25,6 @@ import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherState;
-import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.launcher3.allapps.AllAppsStore;
import com.android.launcher3.util.ResourceBasedOverride;
@@ -88,20 +89,20 @@ public class TestInformationHandler implements ResourceBasedOverride {
break;
case TestProtocol.REQUEST_FREEZE_APP_LIST:
- new MainThreadExecutor().execute(() ->
+ MAIN_EXECUTOR.execute(() ->
mLauncher.getAppsView().getAppsStore().enableDeferUpdates(
AllAppsStore.DEFER_UPDATES_TEST));
break;
case TestProtocol.REQUEST_UNFREEZE_APP_LIST:
- new MainThreadExecutor().execute(() ->
+ MAIN_EXECUTOR.execute(() ->
mLauncher.getAppsView().getAppsStore().disableDeferUpdates(
AllAppsStore.DEFER_UPDATES_TEST));
break;
case TestProtocol.REQUEST_APP_LIST_FREEZE_FLAGS: {
try {
- final int deferUpdatesFlags = new MainThreadExecutor().submit(() ->
+ final int deferUpdatesFlags = MAIN_EXECUTOR.submit(() ->
mLauncher.getAppsView().getAppsStore().getDeferUpdatesFlags()).get();
response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD,
deferUpdatesFlags);
diff --git a/src/com/android/launcher3/util/ConfigMonitor.java b/src/com/android/launcher3/util/ConfigMonitor.java
index 12d35e962..4ae84d808 100644
--- a/src/com/android/launcher3/util/ConfigMonitor.java
+++ b/src/com/android/launcher3/util/ConfigMonitor.java
@@ -16,6 +16,9 @@ package com.android.launcher3.util;
* limitations under the License.
*/
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
+
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -24,13 +27,10 @@ import android.content.res.Configuration;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
-import android.os.Handler;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
-import com.android.launcher3.MainThreadExecutor;
-
import java.util.function.Consumer;
/**
@@ -78,7 +78,7 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener
// Listen for display manager change
mContext.getSystemService(DisplayManager.class)
- .registerDisplayListener(this, new Handler(UiThreadHelper.getBackgroundLooper()));
+ .registerDisplayListener(this, UI_HELPER_EXECUTOR.getHandler());
}
@Override
@@ -122,7 +122,7 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener
if (mCallback != null) {
Consumer<Context> callback = mCallback;
mCallback = null;
- new MainThreadExecutor().execute(() -> callback.accept(mContext));
+ MAIN_EXECUTOR.execute(() -> callback.accept(mContext));
}
}
diff --git a/src/com/android/launcher3/util/DefaultDisplay.java b/src/com/android/launcher3/util/DefaultDisplay.java
index 7719f084d..4080e212b 100644
--- a/src/com/android/launcher3/util/DefaultDisplay.java
+++ b/src/com/android/launcher3/util/DefaultDisplay.java
@@ -15,6 +15,8 @@
*/
package com.android.launcher3.util;
+import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
+
import android.content.Context;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
@@ -54,7 +56,7 @@ public class DefaultDisplay implements DisplayListener {
mChangeHandler = new Handler(this::onChange);
context.getSystemService(DisplayManager.class)
- .registerDisplayListener(this, new Handler(UiThreadHelper.getBackgroundLooper()));
+ .registerDisplayListener(this, UI_HELPER_EXECUTOR.getHandler());
}
@Override
diff --git a/src/com/android/launcher3/util/Executors.java b/src/com/android/launcher3/util/Executors.java
new file mode 100644
index 000000000..4d5ee49e8
--- /dev/null
+++ b/src/com/android/launcher3/util/Executors.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2008 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.HandlerThread;
+import android.os.Looper;
+import android.os.Process;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Various different executors used in Launcher
+ */
+public class Executors {
+
+ // These values are same as that in {@link AsyncTask}.
+ private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
+ private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
+ private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
+ private static final int KEEP_ALIVE = 1;
+
+ /**
+ * An {@link Executor} to be used with async task with no limit on the queue size.
+ */
+ public static final Executor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
+ CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
+ TimeUnit.SECONDS, new LinkedBlockingQueue<>());
+
+ /**
+ * Returns the executor for running tasks on the main thread.
+ */
+ public static final LooperExecutor MAIN_EXECUTOR =
+ new LooperExecutor(Looper.getMainLooper());
+
+ /**
+ * A background executor for using time sensitive actions where user is waiting for response.
+ */
+ public static final LooperExecutor UI_HELPER_EXECUTOR =
+ new LooperExecutor(createAndStartNewForegroundLooper("UiThreadHelper"));
+
+ /**
+ * Utility method to get a started handler thread statically
+ */
+ public static Looper createAndStartNewLooper(String name) {
+ return createAndStartNewLooper(name, Process.THREAD_PRIORITY_DEFAULT);
+ }
+
+ /**
+ * Utility method to get a started handler thread statically with the provided priority
+ */
+ public static Looper createAndStartNewLooper(String name, int priority) {
+ HandlerThread thread = new HandlerThread(name, priority);
+ thread.start();
+ return thread.getLooper();
+ }
+
+ /**
+ * Similar to {@link #createAndStartNewLooper(String)}, but starts the thread with
+ * foreground priority.
+ * Think before using
+ */
+ public static Looper createAndStartNewForegroundLooper(String name) {
+ return createAndStartNewLooper(name, Process.THREAD_PRIORITY_FOREGROUND);
+ }
+
+ /**
+ * Executor used for running Launcher model related tasks (eg loading icons or updated db)
+ */
+ public static final LooperExecutor MODEL_EXECUTOR =
+ new LooperExecutor(createAndStartNewLooper("launcher-loader"));
+}
diff --git a/src/com/android/launcher3/util/LooperExecutor.java b/src/com/android/launcher3/util/LooperExecutor.java
index cc0746997..8ac600f73 100644
--- a/src/com/android/launcher3/util/LooperExecutor.java
+++ b/src/com/android/launcher3/util/LooperExecutor.java
@@ -16,7 +16,9 @@
package com.android.launcher3.util;
import android.os.Handler;
+import android.os.HandlerThread;
import android.os.Looper;
+import android.os.Process;
import java.util.List;
import java.util.concurrent.AbstractExecutorService;
@@ -47,6 +49,13 @@ public class LooperExecutor extends AbstractExecutorService {
}
/**
+ * Same as execute, but never runs the action inline.
+ */
+ public void post(Runnable runnable) {
+ mHandler.post(runnable);
+ }
+
+ /**
* Not supported and throws an exception when used.
*/
@Override
@@ -79,7 +88,31 @@ public class LooperExecutor extends AbstractExecutorService {
*/
@Override
@Deprecated
- public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException {
+ public boolean awaitTermination(long l, TimeUnit timeUnit) {
throw new UnsupportedOperationException();
}
+
+ /**
+ * Returns the thread for this executor
+ */
+ public Thread getThread() {
+ return mHandler.getLooper().getThread();
+ }
+
+ /**
+ * Returns the looper for this executor
+ */
+ public Looper getLooper() {
+ return mHandler.getLooper();
+ }
+
+ /**
+ * Set the priority of a thread, based on Linux priorities.
+ * @param priority Linux priority level, from -20 for highest scheduling priority
+ * to 19 for lowest scheduling priority.
+ * @see Process#setThreadPriority(int, int)
+ */
+ public void setThreadPriority(int priority) {
+ Process.setThreadPriority(((HandlerThread) getThread()).getThreadId(), priority);
+ }
}
diff --git a/src/com/android/launcher3/util/MainThreadInitializedObject.java b/src/com/android/launcher3/util/MainThreadInitializedObject.java
index e185a3199..fe9c2c468 100644
--- a/src/com/android/launcher3/util/MainThreadInitializedObject.java
+++ b/src/com/android/launcher3/util/MainThreadInitializedObject.java
@@ -15,12 +15,13 @@
*/
package com.android.launcher3.util;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+
import android.content.Context;
import android.os.Looper;
import androidx.annotation.VisibleForTesting;
-import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.util.ResourceBasedOverride.Overrides;
import java.util.concurrent.ExecutionException;
@@ -43,7 +44,7 @@ public class MainThreadInitializedObject<T> {
mValue = mProvider.get(context.getApplicationContext());
} else {
try {
- return new MainThreadExecutor().submit(() -> get(context)).get();
+ return MAIN_EXECUTOR.submit(() -> get(context)).get();
} catch (InterruptedException|ExecutionException e) {
throw new RuntimeException(e);
}
diff --git a/src/com/android/launcher3/util/Preconditions.java b/src/com/android/launcher3/util/Preconditions.java
index 7ab0d3103..ed66422be 100644
--- a/src/com/android/launcher3/util/Preconditions.java
+++ b/src/com/android/launcher3/util/Preconditions.java
@@ -16,9 +16,10 @@
package com.android.launcher3.util;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+
import android.os.Looper;
-import com.android.launcher3.LauncherModel;
import com.android.launcher3.config.FeatureFlags;
/**
@@ -33,7 +34,7 @@ public class Preconditions {
}
public static void assertWorkerThread() {
- if (FeatureFlags.IS_DOGFOOD_BUILD && !isSameLooper(LauncherModel.getWorkerLooper())) {
+ if (FeatureFlags.IS_DOGFOOD_BUILD && !isSameLooper(MODEL_EXECUTOR.getLooper())) {
throw new IllegalStateException();
}
}
diff --git a/src/com/android/launcher3/util/UiThreadHelper.java b/src/com/android/launcher3/util/UiThreadHelper.java
index cc442f988..f8d163230 100644
--- a/src/com/android/launcher3/util/UiThreadHelper.java
+++ b/src/com/android/launcher3/util/UiThreadHelper.java
@@ -15,14 +15,13 @@
*/
package com.android.launcher3.util;
+import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
+
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
-import android.os.HandlerThread;
import android.os.IBinder;
-import android.os.Looper;
import android.os.Message;
-import android.os.Process;
import android.view.inputmethod.InputMethodManager;
/**
@@ -30,25 +29,15 @@ import android.view.inputmethod.InputMethodManager;
*/
public class UiThreadHelper {
- private static HandlerThread sHandlerThread;
private static Handler sHandler;
private static final int MSG_HIDE_KEYBOARD = 1;
private static final int MSG_SET_ORIENTATION = 2;
private static final int MSG_RUN_COMMAND = 3;
- public static Looper getBackgroundLooper() {
- if (sHandlerThread == null) {
- sHandlerThread =
- new HandlerThread("UiThreadHelper", Process.THREAD_PRIORITY_FOREGROUND);
- sHandlerThread.start();
- }
- return sHandlerThread.getLooper();
- }
-
private static Handler getHandler(Context context) {
if (sHandler == null) {
- sHandler = new Handler(getBackgroundLooper(),
+ sHandler = new Handler(UI_HELPER_EXECUTOR.getLooper(),
new UiCallbacks(context.getApplicationContext()));
}
return sHandler;
diff --git a/src/com/android/launcher3/util/ViewOnDrawExecutor.java b/src/com/android/launcher3/util/ViewOnDrawExecutor.java
index acce30860..61ba4e566 100644
--- a/src/com/android/launcher3/util/ViewOnDrawExecutor.java
+++ b/src/com/android/launcher3/util/ViewOnDrawExecutor.java
@@ -16,13 +16,14 @@
package com.android.launcher3.util;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+
import android.os.Process;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.ViewTreeObserver.OnDrawListener;
import com.android.launcher3.Launcher;
-import com.android.launcher3.LauncherModel;
import java.util.ArrayList;
import java.util.concurrent.Executor;
@@ -66,7 +67,7 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable,
@Override
public void execute(Runnable command) {
mTasks.add(command);
- LauncherModel.setWorkerPriority(Process.THREAD_PRIORITY_BACKGROUND);
+ MODEL_EXECUTOR.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
}
@Override
@@ -108,7 +109,7 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable,
if (mLauncher != null) {
mLauncher.clearPendingExecutor(this);
}
- LauncherModel.setWorkerPriority(Process.THREAD_PRIORITY_DEFAULT);
+ MODEL_EXECUTOR.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
}
protected boolean isCompleted() {
diff --git a/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java b/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java
index 5c2468740..2ad80cf66 100644
--- a/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java
+++ b/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java
@@ -1,5 +1,7 @@
package com.android.launcher3.util;
+import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
+
import android.app.WallpaperManager;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -198,7 +200,7 @@ public class WallpaperOffsetInterpolator extends BroadcastReceiver {
private float mOffsetX;
public OffsetHandler(Context context) {
- super(UiThreadHelper.getBackgroundLooper());
+ super(UI_HELPER_EXECUTOR.getLooper());
mInterpolator = Interpolators.DEACCEL_1_5;
mWM = WallpaperManager.getInstance(context);
}
diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java
index e09a9e8bf..b146452bd 100644
--- a/src/com/android/launcher3/views/FloatingIconView.java
+++ b/src/com/android/launcher3/views/FloatingIconView.java
@@ -18,11 +18,11 @@ package com.android.launcher3.views;
import static com.android.launcher3.LauncherAnimUtils.DRAWABLE_ALPHA;
import static com.android.launcher3.Utilities.getBadge;
import static com.android.launcher3.Utilities.getFullDrawable;
-import static com.android.launcher3.Utilities.isRtl;
import static com.android.launcher3.Utilities.mapToRange;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM;
import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -42,7 +42,6 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.CancellationSignal;
-import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
@@ -51,11 +50,17 @@ import android.view.ViewOutlineProvider;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.ImageView;
+import androidx.annotation.Nullable;
+import androidx.annotation.UiThread;
+import androidx.annotation.WorkerThread;
+import androidx.dynamicanimation.animation.FloatPropertyCompat;
+import androidx.dynamicanimation.animation.SpringAnimation;
+import androidx.dynamicanimation.animation.SpringForce;
+
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.InsettableFrameLayout.LayoutParams;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
-import com.android.launcher3.LauncherModel;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.dragndrop.DragLayer;
@@ -67,13 +72,6 @@ import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.shortcuts.DeepShortcutView;
-import androidx.annotation.Nullable;
-import androidx.annotation.UiThread;
-import androidx.annotation.WorkerThread;
-import androidx.dynamicanimation.animation.FloatPropertyCompat;
-import androidx.dynamicanimation.animation.SpringAnimation;
-import androidx.dynamicanimation.animation.SpringForce;
-
/**
* A view that is created to look like another view with the purpose of creating fluid animations.
*/
@@ -717,7 +715,7 @@ public class FloatingIconView extends View implements
@UiThread
public static IconLoadResult fetchIcon(Launcher l, View v, ItemInfo info, boolean isOpening) {
IconLoadResult result = new IconLoadResult();
- new Handler(LauncherModel.getWorkerLooper()).postAtFrontOfQueue(() -> {
+ MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() -> {
RectF position = new RectF();
getLocationBoundsForView(l, v, isOpening, position);
getIconResult(l, v, info, position, result);
diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
index dce839f39..f3fd7ca4d 100644
--- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
@@ -44,6 +44,7 @@ import com.android.launcher3.SimpleOnStylusPressListener;
import com.android.launcher3.StylusEventHelper;
import com.android.launcher3.Utilities;
import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.util.Executors;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.BaseDragLayer.TouchCompleteListener;
@@ -96,7 +97,7 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
setBackgroundResource(R.drawable.widget_internal_focus_bg);
if (Utilities.ATLEAST_OREO) {
- setExecutor(Utilities.THREAD_POOL_EXECUTOR);
+ setExecutor(Executors.THREAD_POOL_EXECUTOR);
}
if (Utilities.ATLEAST_Q && Themes.getAttrBoolean(mLauncher, R.attr.isWorkspaceDarkText)) {
setOnLightBackground(true);
@@ -332,12 +333,7 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
if (shouldRegisterAutoAdvance != mIsAutoAdvanceRegistered) {
mIsAutoAdvanceRegistered = shouldRegisterAutoAdvance;
if (mAutoAdvanceRunnable == null) {
- mAutoAdvanceRunnable = new Runnable() {
- @Override
- public void run() {
- runAutoAdvance();
- }
- };
+ mAutoAdvanceRunnable = this::runAutoAdvance;
}
handler.removeCallbacks(mAutoAdvanceRunnable);