Moving various common executors to a single location
Change-Id: I44bca49b8adb6fa22c3b48d10f674e42c28d792c
This commit is contained in:
1 parent
4fa6f63ffd
commit
6fe3eec95c
59 files changed
+434
-441
No files matched your search
@@ -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()) {
|
||||
@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();
|
||||
}
|
||||
|
||||
@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 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(() -> {
|
||||
|
||||
Reference in new issue
Block a user