2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2017-12-18 13:49:44 -08:00
|
|
|
import static com.android.launcher3.LauncherAppState.ACTION_FORCE_ROLOAD;
|
|
|
|
|
import static com.android.launcher3.config.FeatureFlags.IS_DOGFOOD_BUILD;
|
|
|
|
|
|
2014-07-08 13:01:29 -07:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
|
import android.content.ContentProviderOperation;
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
2009-03-03 19:32:27 -08:00
|
|
|
import android.net.Uri;
|
2010-06-17 13:28:48 -04:00
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.HandlerThread;
|
2015-04-16 15:20:51 -07:00
|
|
|
import android.os.Looper;
|
2009-03-03 19:32:27 -08:00
|
|
|
import android.os.Process;
|
2016-12-15 15:53:17 -08:00
|
|
|
import android.os.UserHandle;
|
2013-11-15 13:05:06 -08:00
|
|
|
import android.text.TextUtils;
|
2010-06-11 17:34:16 -07:00
|
|
|
import android.util.Log;
|
2017-05-04 16:47:11 -07:00
|
|
|
import android.util.Pair;
|
2013-12-13 16:07:45 +01:00
|
|
|
|
2014-04-30 03:02:21 +01:00
|
|
|
import com.android.launcher3.compat.LauncherAppsCompat;
|
2014-07-22 13:48:29 -07:00
|
|
|
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
|
2014-04-30 03:02:21 +01:00
|
|
|
import com.android.launcher3.compat.UserManagerCompat;
|
2018-09-25 17:03:34 -07:00
|
|
|
import com.android.launcher3.icons.LauncherIcons;
|
2018-09-21 14:41:05 -07:00
|
|
|
import com.android.launcher3.icons.IconCache;
|
2016-09-09 15:47:55 -07:00
|
|
|
import com.android.launcher3.model.AddWorkspaceItemsTask;
|
2018-01-31 11:59:00 -08:00
|
|
|
import com.android.launcher3.model.BaseModelUpdateTask;
|
2016-09-01 17:24:47 -07:00
|
|
|
import com.android.launcher3.model.BgDataModel;
|
2016-09-09 15:47:55 -07:00
|
|
|
import com.android.launcher3.model.CacheDataUpdatedTask;
|
2017-06-01 14:26:38 -07:00
|
|
|
import com.android.launcher3.model.LoaderResults;
|
2017-06-06 10:46:59 -07:00
|
|
|
import com.android.launcher3.model.LoaderTask;
|
2017-02-02 13:52:53 -08:00
|
|
|
import com.android.launcher3.model.ModelWriter;
|
2016-09-09 15:47:55 -07:00
|
|
|
import com.android.launcher3.model.PackageInstallStateChangedTask;
|
|
|
|
|
import com.android.launcher3.model.PackageUpdatedTask;
|
|
|
|
|
import com.android.launcher3.model.ShortcutsChangedTask;
|
|
|
|
|
import com.android.launcher3.model.UserLockStateChangedTask;
|
2016-06-10 12:22:04 -07:00
|
|
|
import com.android.launcher3.provider.LauncherDbUtils;
|
2016-05-19 11:19:39 -07:00
|
|
|
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
|
|
|
|
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
|
2015-03-16 19:41:43 +00:00
|
|
|
import com.android.launcher3.util.ComponentKey;
|
2018-10-04 15:11:00 -07:00
|
|
|
import com.android.launcher3.util.IntArray;
|
2017-08-17 03:01:19 -07:00
|
|
|
import com.android.launcher3.util.ItemInfoMatcher;
|
2017-03-29 15:30:43 -07:00
|
|
|
import com.android.launcher3.util.PackageUserKey;
|
2016-05-17 13:38:54 -07:00
|
|
|
import com.android.launcher3.util.Preconditions;
|
2016-11-16 09:23:42 -08:00
|
|
|
import com.android.launcher3.util.Provider;
|
2015-03-18 14:16:05 -07:00
|
|
|
import com.android.launcher3.util.Thunk;
|
2015-08-28 15:19:36 -07:00
|
|
|
import com.android.launcher3.util.ViewOnDrawExecutor;
|
2017-10-10 15:21:15 -07:00
|
|
|
import com.android.launcher3.widget.WidgetListRowEntry;
|
2010-03-04 13:03:17 -08:00
|
|
|
|
2017-01-30 15:11:27 -08:00
|
|
|
import java.io.FileDescriptor;
|
|
|
|
|
import java.io.PrintWriter;
|
2011-07-12 14:19:46 -07:00
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
|
import java.util.ArrayList;
|
2018-10-19 14:21:05 -07:00
|
|
|
import java.util.HashMap;
|
2012-07-12 17:55:31 -07:00
|
|
|
import java.util.HashSet;
|
2012-07-18 18:16:38 -07:00
|
|
|
import java.util.Iterator;
|
2011-07-12 14:19:46 -07:00
|
|
|
import java.util.List;
|
2017-02-17 11:22:34 -08:00
|
|
|
import java.util.concurrent.CancellationException;
|
2015-08-28 15:19:36 -07:00
|
|
|
import java.util.concurrent.Executor;
|
2011-07-12 14:19:46 -07:00
|
|
|
|
2018-08-14 15:21:45 -07:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* 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
|
2009-03-09 11:52:14 -07:00
|
|
|
* for the Launcher.
|
2009-03-03 19:32:27 -08:00
|
|
|
*/
|
2014-04-30 03:02:21 +01:00
|
|
|
public class LauncherModel extends BroadcastReceiver
|
2014-06-30 12:30:31 +01:00
|
|
|
implements LauncherAppsCompat.OnAppsChangedCallbackCompat {
|
2014-09-09 10:09:02 -04:00
|
|
|
private static final boolean DEBUG_RECEIVER = false;
|
2014-04-16 13:37:00 -04:00
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
static final String TAG = "Launcher.Model";
|
|
|
|
|
|
2017-02-14 15:03:45 -08:00
|
|
|
private final MainThreadExecutor mUiExecutor = new MainThreadExecutor();
|
2015-03-18 14:16:05 -07:00
|
|
|
@Thunk final LauncherAppState mApp;
|
|
|
|
|
@Thunk final Object mLock = new Object();
|
2017-06-06 10:46:59 -07:00
|
|
|
@Thunk
|
|
|
|
|
LoaderTask mLoaderTask;
|
2015-03-18 14:16:05 -07:00
|
|
|
@Thunk boolean mIsLoaderTaskRunning;
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2015-03-18 14:16:05 -07:00
|
|
|
@Thunk static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
|
2018-11-07 16:54:02 -08:00
|
|
|
private static final Looper mWorkerLooper;
|
2010-10-11 09:40:44 -07:00
|
|
|
static {
|
|
|
|
|
sWorkerThread.start();
|
2018-11-07 16:54:02 -08:00
|
|
|
mWorkerLooper = sWorkerThread.getLooper();
|
2010-10-11 09:40:44 -07:00
|
|
|
}
|
2018-11-07 16:54:02 -08:00
|
|
|
@Thunk static final Handler sWorker = new Handler(mWorkerLooper);
|
2010-10-11 09:40:44 -07:00
|
|
|
|
2017-02-17 11:22:34 -08:00
|
|
|
// Indicates whether the current model data is valid or not.
|
|
|
|
|
// We start off with everything not loaded. After that, we assume that
|
2010-06-08 10:54:30 -07:00
|
|
|
// our monitoring of the package manager provides all updates and we never
|
2017-02-17 11:22:34 -08:00
|
|
|
// need to do a requery. This is only ever touched from the loader thread.
|
|
|
|
|
private boolean mModelLoaded;
|
2017-02-06 10:46:24 -08:00
|
|
|
public boolean isModelLoaded() {
|
|
|
|
|
synchronized (mLock) {
|
|
|
|
|
return mModelLoaded && mLoaderTask == null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-06-08 10:54:30 -07:00
|
|
|
|
2015-03-18 14:16:05 -07:00
|
|
|
@Thunk WeakReference<Callbacks> mCallbacks;
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2011-04-28 14:59:33 -07:00
|
|
|
// < only access in worker thread >
|
2016-03-03 16:58:55 -08:00
|
|
|
private final AllAppsList mBgAllAppsList;
|
2011-04-28 14:59:33 -07:00
|
|
|
|
2017-06-02 13:46:55 -07:00
|
|
|
/**
|
|
|
|
|
* All the static data should be accessed on the background thread, A lock should be acquired
|
|
|
|
|
* on this object when accessing any data from this model.
|
|
|
|
|
*/
|
|
|
|
|
static final BgDataModel sBgDataModel = new BgDataModel();
|
|
|
|
|
|
2016-08-10 16:09:29 -07:00
|
|
|
// Runnable to check if the shortcuts permission has changed.
|
|
|
|
|
private final Runnable mShortcutPermissionCheckRunnable = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
2017-02-17 11:22:34 -08:00
|
|
|
if (mModelLoaded) {
|
2016-11-21 16:02:39 +05:30
|
|
|
boolean hasShortcutHostPermission =
|
|
|
|
|
DeepShortcutManager.getInstance(mApp.getContext()).hasHostPermission();
|
2017-06-02 13:46:55 -07:00
|
|
|
if (hasShortcutHostPermission != sBgDataModel.hasShortcutHostPermission) {
|
2017-02-17 11:22:34 -08:00
|
|
|
forceReload();
|
2016-08-10 16:09:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
public interface Callbacks {
|
2018-03-02 15:16:12 -08:00
|
|
|
public void rebindModel();
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
public int getCurrentWorkspaceScreen();
|
2015-08-28 15:19:36 -07:00
|
|
|
public void clearPendingBinds();
|
2009-08-17 11:03:03 -04:00
|
|
|
public void startBinding();
|
2017-08-17 07:45:25 -07:00
|
|
|
public void bindItems(List<ItemInfo> shortcuts, boolean forceAnimateIcons);
|
2018-10-04 15:11:00 -07:00
|
|
|
public void bindScreens(IntArray orderedScreenIds);
|
2016-04-02 11:23:39 -07:00
|
|
|
public void finishFirstPageBind(ViewOnDrawExecutor executor);
|
2018-08-21 11:40:23 -07:00
|
|
|
public void finishBindingItems(int currentScreen);
|
2013-09-04 00:45:37 +02:00
|
|
|
public void bindAllApplications(ArrayList<AppInfo> apps);
|
2017-08-17 07:45:25 -07:00
|
|
|
public void bindAppsAddedOrUpdated(ArrayList<AppInfo> apps);
|
2018-08-21 11:40:23 -07:00
|
|
|
public void preAddApps();
|
2018-10-04 15:11:00 -07:00
|
|
|
public void bindAppsAdded(IntArray newScreens,
|
|
|
|
|
ArrayList<ItemInfo> addNotAnimated, ArrayList<ItemInfo> addAnimated);
|
2017-03-20 11:30:27 -07:00
|
|
|
public void bindPromiseAppProgressUpdated(PromiseAppInfo app);
|
2017-08-17 03:01:19 -07:00
|
|
|
public void bindShortcutsChanged(ArrayList<ShortcutInfo> updated, UserHandle user);
|
2014-10-13 11:33:11 -07:00
|
|
|
public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets);
|
2015-04-16 15:20:51 -07:00
|
|
|
public void bindRestoreItemsChange(HashSet<ItemInfo> updates);
|
2017-08-17 03:01:19 -07:00
|
|
|
public void bindWorkspaceComponentsRemoved(ItemInfoMatcher matcher);
|
2016-03-15 09:16:30 -07:00
|
|
|
public void bindAppInfosRemoved(ArrayList<AppInfo> appInfos);
|
2017-10-10 15:21:15 -07:00
|
|
|
public void bindAllWidgets(ArrayList<WidgetListRowEntry> widgets);
|
2012-07-24 22:34:36 -07:00
|
|
|
public void onPageBoundSynchronously(int page);
|
2015-08-28 15:19:36 -07:00
|
|
|
public void executeOnNextDraw(ViewOnDrawExecutor executor);
|
2018-10-19 14:21:05 -07:00
|
|
|
public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMap);
|
2009-08-17 11:03:03 -04:00
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2016-11-21 16:02:39 +05:30
|
|
|
LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) {
|
2013-06-25 15:13:26 -04:00
|
|
|
mApp = app;
|
2013-10-03 22:31:03 +01:00
|
|
|
mBgAllAppsList = new AllAppsList(iconCache, appFilter);
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
2012-07-12 17:55:31 -07:00
|
|
|
/** Runs the specified runnable immediately if called from the worker thread, otherwise it is
|
|
|
|
|
* posted on the worker thread handler. */
|
2016-06-29 18:12:15 -07:00
|
|
|
private static void runOnWorkerThread(Runnable r) {
|
2012-07-12 17:55:31 -07:00
|
|
|
if (sWorkerThread.getThreadId() == Process.myTid()) {
|
|
|
|
|
r.run();
|
|
|
|
|
} else {
|
|
|
|
|
// If we are not on the worker thread, then post to the worker handler
|
|
|
|
|
sWorker.post(r);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 15:47:55 -07:00
|
|
|
public void setPackageState(PackageInstallInfo installInfo) {
|
|
|
|
|
enqueueModelUpdateTask(new PackageInstallStateChangedTask(installInfo));
|
2014-02-14 16:59:24 -05:00
|
|
|
}
|
|
|
|
|
|
2015-04-16 15:20:51 -07:00
|
|
|
/**
|
|
|
|
|
* Updates the icons and label of all pending icons for the provided package name.
|
|
|
|
|
*/
|
|
|
|
|
public void updateSessionDisplayInfo(final String packageName) {
|
2016-09-09 15:47:55 -07:00
|
|
|
HashSet<String> packages = new HashSet<>();
|
|
|
|
|
packages.add(packageName);
|
|
|
|
|
enqueueModelUpdateTask(new CacheDataUpdatedTask(
|
2016-12-15 15:53:17 -08:00
|
|
|
CacheDataUpdatedTask.OP_SESSION_UPDATE, Process.myUserHandle(), packages));
|
2015-01-08 16:59:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds the provided items to the workspace.
|
|
|
|
|
*/
|
2017-10-05 15:57:40 -07:00
|
|
|
public void addAndBindAddedWorkspaceItems(List<Pair<ItemInfo, Object>> itemList) {
|
2018-08-21 11:40:23 -07:00
|
|
|
Callbacks callbacks = getCallback();
|
|
|
|
|
if (callbacks != null) {
|
|
|
|
|
callbacks.preAddApps();
|
|
|
|
|
}
|
2017-10-05 15:57:40 -07:00
|
|
|
enqueueModelUpdateTask(new AddWorkspaceItemsTask(itemList));
|
2013-07-08 17:17:08 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-02 15:16:12 -08:00
|
|
|
public ModelWriter getWriter(boolean hasVerticalHotseat, boolean verifyChanges) {
|
|
|
|
|
return new ModelWriter(mApp.getContext(), this, sBgDataModel,
|
|
|
|
|
hasVerticalHotseat, verifyChanges);
|
2009-08-17 11:03:03 -04:00
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2012-09-21 12:06:06 -07:00
|
|
|
static void checkItemInfoLocked(
|
2018-10-04 15:11:00 -07:00
|
|
|
final int itemId, final ItemInfo item, StackTraceElement[] stackTrace) {
|
2018-10-05 15:17:42 -07:00
|
|
|
if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
|
|
|
|
|
&& com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
|
|
|
|
|
android.util.Log.d("b/117332845",
|
|
|
|
|
"Checking item: " + android.util.Log.getStackTraceString(new Throwable()));
|
|
|
|
|
}
|
2016-09-01 17:24:47 -07:00
|
|
|
ItemInfo modelItem = sBgDataModel.itemsIdMap.get(itemId);
|
2012-09-21 12:06:06 -07:00
|
|
|
if (modelItem != null && item != modelItem) {
|
|
|
|
|
// check all the data is consistent
|
|
|
|
|
if (modelItem instanceof ShortcutInfo && item instanceof ShortcutInfo) {
|
|
|
|
|
ShortcutInfo modelShortcut = (ShortcutInfo) modelItem;
|
|
|
|
|
ShortcutInfo shortcut = (ShortcutInfo) item;
|
|
|
|
|
if (modelShortcut.title.toString().equals(shortcut.title.toString()) &&
|
|
|
|
|
modelShortcut.intent.filterEquals(shortcut.intent) &&
|
|
|
|
|
modelShortcut.id == shortcut.id &&
|
|
|
|
|
modelShortcut.itemType == shortcut.itemType &&
|
|
|
|
|
modelShortcut.container == shortcut.container &&
|
2013-06-18 13:13:40 -07:00
|
|
|
modelShortcut.screenId == shortcut.screenId &&
|
2012-09-21 12:06:06 -07:00
|
|
|
modelShortcut.cellX == shortcut.cellX &&
|
|
|
|
|
modelShortcut.cellY == shortcut.cellY &&
|
|
|
|
|
modelShortcut.spanX == shortcut.spanX &&
|
2015-06-12 20:04:41 -07:00
|
|
|
modelShortcut.spanY == shortcut.spanY) {
|
2012-09-21 12:06:06 -07:00
|
|
|
// For all intents and purposes, this is the same object
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the modelItem needs to match up perfectly with item if our model is
|
|
|
|
|
// to be consistent with the database-- for now, just require
|
|
|
|
|
// modelItem == item or the equality check above
|
|
|
|
|
String msg = "item: " + ((item != null) ? item.toString() : "null") +
|
|
|
|
|
"modelItem: " +
|
|
|
|
|
((modelItem != null) ? modelItem.toString() : "null") +
|
|
|
|
|
"Error: ItemInfo passed to checkItemInfo doesn't match original";
|
|
|
|
|
RuntimeException e = new RuntimeException(msg);
|
|
|
|
|
if (stackTrace != null) {
|
|
|
|
|
e.setStackTrace(stackTrace);
|
|
|
|
|
}
|
2013-11-08 08:25:08 -08:00
|
|
|
throw e;
|
2012-09-21 12:06:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-25 14:49:02 -07:00
|
|
|
static void checkItemInfo(final ItemInfo item) {
|
|
|
|
|
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
|
2018-10-04 15:11:00 -07:00
|
|
|
final int itemId = item.id;
|
2012-06-25 14:49:02 -07:00
|
|
|
Runnable r = new Runnable() {
|
2012-09-21 12:06:06 -07:00
|
|
|
public void run() {
|
2016-09-01 17:24:47 -07:00
|
|
|
synchronized (sBgDataModel) {
|
2012-09-21 12:06:06 -07:00
|
|
|
checkItemInfoLocked(itemId, item, stackTrace);
|
2012-06-25 14:49:02 -07:00
|
|
|
}
|
2012-09-21 12:06:06 -07:00
|
|
|
}
|
|
|
|
|
};
|
2012-07-12 17:55:31 -07:00
|
|
|
runOnWorkerThread(r);
|
2012-06-25 14:49:02 -07:00
|
|
|
}
|
|
|
|
|
|
2013-06-18 13:13:40 -07:00
|
|
|
/**
|
|
|
|
|
* Update the order of the workspace screens in the database. The array list contains
|
|
|
|
|
* a list of screen ids in the order that they should appear.
|
|
|
|
|
*/
|
2018-10-04 15:11:00 -07:00
|
|
|
public static void updateWorkspaceScreenOrder(Context context, IntArray screens) {
|
2013-06-18 13:13:40 -07:00
|
|
|
final ContentResolver cr = context.getContentResolver();
|
|
|
|
|
final Uri uri = LauncherSettings.WorkspaceScreens.CONTENT_URI;
|
|
|
|
|
|
2018-10-04 15:11:00 -07:00
|
|
|
// Create a copy with only non-negative values
|
|
|
|
|
final IntArray screensCopy = new IntArray();
|
|
|
|
|
for (int i = 0; i < screens.size(); i++) {
|
|
|
|
|
int id = screens.get(i);
|
|
|
|
|
if (id >= 0) {
|
|
|
|
|
screensCopy.add(id);
|
2013-06-18 13:13:40 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Runnable r = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
2014-02-11 15:15:29 +00:00
|
|
|
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
2013-06-18 13:13:40 -07:00
|
|
|
// Clear the table
|
2014-02-11 15:15:29 +00:00
|
|
|
ops.add(ContentProviderOperation.newDelete(uri).build());
|
2013-08-19 15:43:29 -07:00
|
|
|
int count = screensCopy.size();
|
2013-06-18 13:13:40 -07:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
ContentValues v = new ContentValues();
|
2018-10-04 15:11:00 -07:00
|
|
|
int screenId = screensCopy.get(i);
|
2013-06-18 13:13:40 -07:00
|
|
|
v.put(LauncherSettings.WorkspaceScreens._ID, screenId);
|
|
|
|
|
v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
|
2014-02-11 15:15:29 +00:00
|
|
|
ops.add(ContentProviderOperation.newInsert(uri).withValues(v).build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
cr.applyBatch(LauncherProvider.AUTHORITY, ops);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
throw new RuntimeException(ex);
|
2013-06-18 13:13:40 -07:00
|
|
|
}
|
2013-08-27 11:58:12 -07:00
|
|
|
|
2016-09-01 17:24:47 -07:00
|
|
|
synchronized (sBgDataModel) {
|
|
|
|
|
sBgDataModel.workspaceScreens.clear();
|
|
|
|
|
sBgDataModel.workspaceScreens.addAll(screensCopy);
|
2013-08-20 18:54:31 -07:00
|
|
|
}
|
2013-06-18 13:13:40 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
runOnWorkerThread(r);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/**
|
|
|
|
|
* Set this as the current Launcher activity object for the loader.
|
|
|
|
|
*/
|
|
|
|
|
public void initialize(Callbacks callbacks) {
|
|
|
|
|
synchronized (mLock) {
|
2016-05-17 13:38:54 -07:00
|
|
|
Preconditions.assertUIThread();
|
|
|
|
|
mCallbacks = new WeakReference<>(callbacks);
|
2009-03-18 17:39:48 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 03:02:21 +01:00
|
|
|
@Override
|
2016-12-15 15:53:17 -08:00
|
|
|
public void onPackageChanged(String packageName, UserHandle user) {
|
2014-04-30 03:02:21 +01:00
|
|
|
int op = PackageUpdatedTask.OP_UPDATE;
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new PackageUpdatedTask(op, user, packageName));
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-12-15 15:53:17 -08:00
|
|
|
public void onPackageRemoved(String packageName, UserHandle user) {
|
2016-09-01 15:50:36 -07:00
|
|
|
onPackagesRemoved(user, packageName);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 15:53:17 -08:00
|
|
|
public void onPackagesRemoved(UserHandle user, String... packages) {
|
2014-04-30 03:02:21 +01:00
|
|
|
int op = PackageUpdatedTask.OP_REMOVE;
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new PackageUpdatedTask(op, user, packages));
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-12-15 15:53:17 -08:00
|
|
|
public void onPackageAdded(String packageName, UserHandle user) {
|
2014-04-30 03:02:21 +01:00
|
|
|
int op = PackageUpdatedTask.OP_ADD;
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new PackageUpdatedTask(op, user, packageName));
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-12-15 15:53:17 -08:00
|
|
|
public void onPackagesAvailable(String[] packageNames, UserHandle user,
|
2014-04-30 03:02:21 +01:00
|
|
|
boolean replacing) {
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(
|
|
|
|
|
new PackageUpdatedTask(PackageUpdatedTask.OP_UPDATE, user, packageNames));
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-12-15 15:53:17 -08:00
|
|
|
public void onPackagesUnavailable(String[] packageNames, UserHandle user,
|
2014-04-30 03:02:21 +01:00
|
|
|
boolean replacing) {
|
|
|
|
|
if (!replacing) {
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new PackageUpdatedTask(
|
|
|
|
|
PackageUpdatedTask.OP_UNAVAILABLE, user, packageNames));
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 19:50:02 +00:00
|
|
|
@Override
|
2016-12-15 15:53:17 -08:00
|
|
|
public void onPackagesSuspended(String[] packageNames, UserHandle user) {
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new PackageUpdatedTask(
|
|
|
|
|
PackageUpdatedTask.OP_SUSPEND, user, packageNames));
|
2016-01-21 19:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-12-15 15:53:17 -08:00
|
|
|
public void onPackagesUnsuspended(String[] packageNames, UserHandle user) {
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new PackageUpdatedTask(
|
|
|
|
|
PackageUpdatedTask.OP_UNSUSPEND, user, packageNames));
|
2016-01-21 19:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-19 11:19:39 -07:00
|
|
|
@Override
|
|
|
|
|
public void onShortcutsChanged(String packageName, List<ShortcutInfoCompat> shortcuts,
|
2016-12-15 15:53:17 -08:00
|
|
|
UserHandle user) {
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new ShortcutsChangedTask(packageName, shortcuts, user, true));
|
2016-08-04 12:03:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updatePinnedShortcuts(String packageName, List<ShortcutInfoCompat> shortcuts,
|
2016-12-15 15:53:17 -08:00
|
|
|
UserHandle user) {
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new ShortcutsChangedTask(packageName, shortcuts, user, false));
|
2016-05-19 11:19:39 -07:00
|
|
|
}
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/**
|
|
|
|
|
* Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
|
|
|
|
|
* ACTION_PACKAGE_CHANGED.
|
|
|
|
|
*/
|
2011-06-28 13:46:59 +01:00
|
|
|
@Override
|
2009-10-31 17:27:36 -04:00
|
|
|
public void onReceive(Context context, Intent intent) {
|
2014-04-16 13:37:00 -04:00
|
|
|
if (DEBUG_RECEIVER) Log.d(TAG, "onReceive intent=" + intent);
|
2010-06-11 17:34:16 -07:00
|
|
|
|
2010-06-17 13:28:48 -04:00
|
|
|
final String action = intent.getAction();
|
2014-04-30 03:02:21 +01:00
|
|
|
if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
|
2011-09-23 17:20:28 -07:00
|
|
|
// If we have changed locale we need to clear out the labels in all apps/workspace.
|
|
|
|
|
forceReload();
|
2016-07-28 12:11:54 -07:00
|
|
|
} else if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action)
|
|
|
|
|
|| Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
|
2015-08-04 11:40:13 -07:00
|
|
|
UserManagerCompat.getInstance(context).enableAndResetCache();
|
2015-05-01 13:02:20 -07:00
|
|
|
forceReload();
|
2016-07-28 12:11:54 -07:00
|
|
|
} else if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
|
|
|
|
|
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) ||
|
|
|
|
|
Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
|
2016-12-15 15:53:17 -08:00
|
|
|
UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
|
2016-03-18 18:29:24 -07:00
|
|
|
if (user != null) {
|
2016-07-28 12:11:54 -07:00
|
|
|
if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
|
|
|
|
|
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)) {
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new PackageUpdatedTask(
|
|
|
|
|
PackageUpdatedTask.OP_USER_AVAILABILITY_CHANGE, user));
|
2016-07-28 12:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ACTION_MANAGED_PROFILE_UNAVAILABLE sends the profile back to locked mode, so
|
|
|
|
|
// we need to run the state change task again.
|
|
|
|
|
if (Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) ||
|
|
|
|
|
Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new UserLockStateChangedTask(user));
|
2016-07-28 12:11:54 -07:00
|
|
|
}
|
2016-03-18 18:29:24 -07:00
|
|
|
}
|
2017-12-18 13:49:44 -08:00
|
|
|
} else if (IS_DOGFOOD_BUILD && ACTION_FORCE_ROLOAD.equals(action)) {
|
|
|
|
|
forceReload();
|
2010-10-29 17:35:36 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 11:22:34 -08:00
|
|
|
/**
|
|
|
|
|
* Reloads the workspace items from the DB and re-binds the workspace. This should generally
|
|
|
|
|
* not be called as DB updates are automatically followed by UI update
|
|
|
|
|
*/
|
|
|
|
|
public void forceReload() {
|
|
|
|
|
synchronized (mLock) {
|
|
|
|
|
// Stop any existing loaders first, so they don't set mModelLoaded to true later
|
2017-06-06 14:33:18 -07:00
|
|
|
stopLoader();
|
2017-02-17 11:22:34 -08:00
|
|
|
mModelLoaded = false;
|
|
|
|
|
}
|
2012-03-21 16:10:31 -07:00
|
|
|
|
2017-12-18 13:49:44 -08:00
|
|
|
// Start the loader if launcher is already running, otherwise the loader will run,
|
|
|
|
|
// the next time launcher starts
|
2014-11-10 18:05:31 -08:00
|
|
|
Callbacks callbacks = getCallback();
|
|
|
|
|
if (callbacks != null) {
|
2017-12-18 13:49:44 -08:00
|
|
|
startLoader(callbacks.getCurrentWorkspaceScreen());
|
2010-10-29 17:35:36 -07:00
|
|
|
}
|
2010-06-17 13:28:48 -04:00
|
|
|
}
|
2009-03-18 17:39:48 -07:00
|
|
|
|
2014-09-30 09:48:49 -07:00
|
|
|
public boolean isCurrentCallbacks(Callbacks callbacks) {
|
|
|
|
|
return (mCallbacks != null && mCallbacks.get() == callbacks);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-02 11:23:39 -07:00
|
|
|
/**
|
|
|
|
|
* Starts the loader. Tries to bind {@params synchronousBindPage} synchronously if possible.
|
|
|
|
|
* @return true if the page could be bound synchronously.
|
|
|
|
|
*/
|
|
|
|
|
public boolean startLoader(int synchronousBindPage) {
|
2018-10-09 18:46:45 -07:00
|
|
|
if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
|
|
|
|
|
&& com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
|
|
|
|
|
android.util.Log.d("b/117332845",
|
|
|
|
|
android.util.Log.getStackTraceString(new Throwable()));
|
|
|
|
|
}
|
2015-04-16 15:20:51 -07:00
|
|
|
// Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
|
2017-05-04 16:47:11 -07:00
|
|
|
InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_LOADER_RUNNING);
|
2010-06-17 13:28:48 -04:00
|
|
|
synchronized (mLock) {
|
|
|
|
|
// Don't bother to start the thread if we know it's not going to do anything
|
|
|
|
|
if (mCallbacks != null && mCallbacks.get() != null) {
|
2015-08-28 15:19:36 -07:00
|
|
|
final Callbacks oldCallbacks = mCallbacks.get();
|
|
|
|
|
// Clear any pending bind-runnables from the synchronized load process.
|
2018-02-22 13:22:21 -08:00
|
|
|
mUiExecutor.execute(oldCallbacks::clearPendingBinds);
|
2015-08-28 15:19:36 -07:00
|
|
|
|
2010-06-17 13:28:48 -04:00
|
|
|
// If there is already one running, tell it to stop.
|
2017-06-06 14:33:18 -07:00
|
|
|
stopLoader();
|
2017-06-01 14:26:38 -07:00
|
|
|
LoaderResults loaderResults = new LoaderResults(mApp, sBgDataModel,
|
|
|
|
|
mBgAllAppsList, synchronousBindPage, mCallbacks);
|
2017-06-06 14:33:18 -07:00
|
|
|
if (mModelLoaded && !mIsLoaderTaskRunning) {
|
2017-06-01 14:26:38 -07:00
|
|
|
// Divide the set of loaded items into those that we are binding synchronously,
|
|
|
|
|
// and everything else that is to be bound normally (asynchronously).
|
|
|
|
|
loaderResults.bindWorkspace();
|
|
|
|
|
// For now, continue posting the binding of AllApps as there are other
|
|
|
|
|
// issues that arise from that.
|
|
|
|
|
loaderResults.bindAllApps();
|
|
|
|
|
loaderResults.bindDeepShortcuts();
|
2017-06-02 13:46:55 -07:00
|
|
|
loaderResults.bindWidgets();
|
2016-04-02 11:23:39 -07:00
|
|
|
return true;
|
2012-07-12 17:55:31 -07:00
|
|
|
} else {
|
2017-06-06 14:33:18 -07:00
|
|
|
startLoaderForResults(loaderResults);
|
2012-07-12 17:55:31 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-02 11:23:39 -07:00
|
|
|
return false;
|
2012-07-12 17:55:31 -07:00
|
|
|
}
|
|
|
|
|
|
2017-06-06 14:33:18 -07:00
|
|
|
/**
|
|
|
|
|
* If there is already a loader task running, tell it to stop.
|
|
|
|
|
*/
|
2010-06-17 13:28:48 -04:00
|
|
|
public void stopLoader() {
|
|
|
|
|
synchronized (mLock) {
|
2017-06-06 14:33:18 -07:00
|
|
|
LoaderTask oldTask = mLoaderTask;
|
|
|
|
|
mLoaderTask = null;
|
|
|
|
|
if (oldTask != null) {
|
|
|
|
|
oldTask.stopLocked();
|
2009-08-17 11:03:03 -04:00
|
|
|
}
|
2009-03-18 17:39:48 -07:00
|
|
|
}
|
2010-06-17 13:28:48 -04:00
|
|
|
}
|
2009-06-24 13:45:46 -07:00
|
|
|
|
2017-06-06 14:33:18 -07:00
|
|
|
public void startLoaderForResults(LoaderResults results) {
|
|
|
|
|
synchronized (mLock) {
|
|
|
|
|
stopLoader();
|
|
|
|
|
mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, sBgDataModel, results);
|
|
|
|
|
runOnWorkerThread(mLoaderTask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 03:23:51 +00:00
|
|
|
public void startLoaderForResultsIfNotLoaded(LoaderResults results) {
|
|
|
|
|
synchronized (mLock) {
|
|
|
|
|
if (!isModelLoaded()) {
|
|
|
|
|
Log.d(TAG, "Workspace not loaded, loading now");
|
|
|
|
|
startLoaderForResults(results);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-16 16:19:04 -08:00
|
|
|
/**
|
|
|
|
|
* Loads the workspace screen ids in an ordered list.
|
|
|
|
|
*/
|
2018-10-04 15:11:00 -07:00
|
|
|
public static IntArray loadWorkspaceScreensDb(Context context) {
|
2013-08-19 15:43:29 -07:00
|
|
|
final ContentResolver contentResolver = context.getContentResolver();
|
|
|
|
|
final Uri screensUri = LauncherSettings.WorkspaceScreens.CONTENT_URI;
|
|
|
|
|
|
2015-01-16 16:19:04 -08:00
|
|
|
// Get screens ordered by rank.
|
2016-06-10 12:22:04 -07:00
|
|
|
return LauncherDbUtils.getScreenIdsFromCursor(contentResolver.query(
|
|
|
|
|
screensUri, null, null, null, LauncherSettings.WorkspaceScreens.SCREEN_RANK));
|
2013-08-19 15:43:29 -07:00
|
|
|
}
|
|
|
|
|
|
2017-03-15 11:56:47 -07:00
|
|
|
public void onInstallSessionCreated(final PackageInstallInfo sessionInfo) {
|
2017-06-06 14:33:18 -07:00
|
|
|
enqueueModelUpdateTask(new BaseModelUpdateTask() {
|
2017-03-15 11:56:47 -07:00
|
|
|
@Override
|
|
|
|
|
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
|
|
|
|
|
apps.addPromiseApp(app.getContext(), sessionInfo);
|
|
|
|
|
if (!apps.added.isEmpty()) {
|
|
|
|
|
final ArrayList<AppInfo> arrayList = new ArrayList<>(apps.added);
|
|
|
|
|
apps.added.clear();
|
|
|
|
|
scheduleCallbackTask(new CallbackTask() {
|
|
|
|
|
@Override
|
|
|
|
|
public void execute(Callbacks callbacks) {
|
2017-08-17 07:45:25 -07:00
|
|
|
callbacks.bindAppsAddedOrUpdated(arrayList);
|
2017-03-15 11:56:47 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-02 13:46:55 -07:00
|
|
|
public class LoaderTransaction implements AutoCloseable {
|
|
|
|
|
|
|
|
|
|
private final LoaderTask mTask;
|
|
|
|
|
|
|
|
|
|
private LoaderTransaction(LoaderTask task) throws CancellationException {
|
|
|
|
|
synchronized (mLock) {
|
|
|
|
|
if (mLoaderTask != task) {
|
|
|
|
|
throw new CancellationException("Loader already stopped");
|
|
|
|
|
}
|
|
|
|
|
mTask = task;
|
|
|
|
|
mIsLoaderTaskRunning = true;
|
|
|
|
|
mModelLoaded = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void commit() {
|
|
|
|
|
synchronized (mLock) {
|
|
|
|
|
// Everything loaded bind the data.
|
|
|
|
|
mModelLoaded = true;
|
2018-10-05 20:03:57 -07:00
|
|
|
if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
|
|
|
|
|
&& com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
|
|
|
|
|
android.util.Log.d("b/117332845",
|
|
|
|
|
android.util.Log.getStackTraceString(new Throwable()));
|
|
|
|
|
}
|
2017-06-02 13:46:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void close() {
|
|
|
|
|
synchronized (mLock) {
|
|
|
|
|
// If we are still the last one to be scheduled, remove ourselves.
|
|
|
|
|
if (mLoaderTask == mTask) {
|
|
|
|
|
mLoaderTask = null;
|
|
|
|
|
}
|
|
|
|
|
mIsLoaderTaskRunning = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LoaderTransaction beginLoader(LoaderTask task) throws CancellationException {
|
|
|
|
|
return new LoaderTransaction(task);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-10 16:09:29 -07:00
|
|
|
/**
|
|
|
|
|
* Refreshes the cached shortcuts if the shortcut permission has changed.
|
|
|
|
|
* Current implementation simply reloads the workspace, but it can be optimized to
|
|
|
|
|
* use partial updates similar to {@link UserManagerCompat}
|
|
|
|
|
*/
|
|
|
|
|
public void refreshShortcutsIfRequired() {
|
2016-11-02 10:31:24 -07:00
|
|
|
if (Utilities.ATLEAST_NOUGAT_MR1) {
|
2016-08-10 16:09:29 -07:00
|
|
|
sWorker.removeCallbacks(mShortcutPermissionCheckRunnable);
|
|
|
|
|
sWorker.post(mShortcutPermissionCheckRunnable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-20 21:57:06 -07:00
|
|
|
/**
|
|
|
|
|
* Called when the icons for packages have been updated in the icon cache.
|
|
|
|
|
*/
|
2016-12-15 15:53:17 -08:00
|
|
|
public void onPackageIconsUpdated(HashSet<String> updatedPackages, UserHandle user) {
|
2015-05-20 21:57:06 -07:00
|
|
|
// If any package icon has changed (app was updated while launcher was dead),
|
|
|
|
|
// update the corresponding shortcuts.
|
2016-09-09 15:47:55 -07:00
|
|
|
enqueueModelUpdateTask(new CacheDataUpdatedTask(
|
|
|
|
|
CacheDataUpdatedTask.OP_CACHE_UPDATE, user, updatedPackages));
|
2016-05-19 11:19:39 -07:00
|
|
|
}
|
2015-05-06 16:53:21 -07:00
|
|
|
|
2018-09-26 12:00:30 -07:00
|
|
|
/**
|
|
|
|
|
* Called when the labels for the widgets has updated in the icon cache.
|
|
|
|
|
*/
|
|
|
|
|
public void onWidgetLabelsUpdated(HashSet<String> updatedPackages, UserHandle user) {
|
|
|
|
|
enqueueModelUpdateTask(new BaseModelUpdateTask() {
|
|
|
|
|
@Override
|
|
|
|
|
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
|
|
|
|
|
dataModel.widgetsModel.onPackageIconsUpdated(updatedPackages, user, app);
|
|
|
|
|
bindUpdatedWidgets(dataModel);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-06 14:33:18 -07:00
|
|
|
public void enqueueModelUpdateTask(ModelUpdateTask task) {
|
|
|
|
|
task.init(mApp, this, sBgDataModel, mBgAllAppsList, mUiExecutor);
|
2016-09-09 15:47:55 -07:00
|
|
|
runOnWorkerThread(task);
|
2016-07-28 12:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-09 15:47:55 -07:00
|
|
|
/**
|
|
|
|
|
* A task to be executed on the current callbacks on the UI thread.
|
|
|
|
|
* If there is no current callbacks, the task is ignored.
|
|
|
|
|
*/
|
|
|
|
|
public interface CallbackTask {
|
2015-05-20 21:57:06 -07:00
|
|
|
|
2016-09-09 15:47:55 -07:00
|
|
|
void execute(Callbacks callbacks);
|
2010-06-17 13:28:48 -04:00
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2016-09-09 15:47:55 -07:00
|
|
|
/**
|
|
|
|
|
* A runnable which changes/updates the data model of the launcher based on certain events.
|
|
|
|
|
*/
|
2017-06-06 14:33:18 -07:00
|
|
|
public interface ModelUpdateTask extends Runnable {
|
2016-07-28 12:11:54 -07:00
|
|
|
|
2016-09-09 15:47:55 -07:00
|
|
|
/**
|
2017-06-06 14:33:18 -07:00
|
|
|
* Called before the task is posted to initialize the internal state.
|
2016-09-09 15:47:55 -07:00
|
|
|
*/
|
2017-06-06 14:33:18 -07:00
|
|
|
void init(LauncherAppState app, LauncherModel model,
|
|
|
|
|
BgDataModel dataModel, AllAppsList allAppsList, Executor uiExecutor);
|
2014-10-06 16:23:56 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
2017-01-18 11:30:23 -08:00
|
|
|
public void updateAndBindShortcutInfo(final ShortcutInfo si, final ShortcutInfoCompat info) {
|
2018-07-09 16:47:01 -07:00
|
|
|
updateAndBindShortcutInfo(() -> {
|
|
|
|
|
si.updateFromDeepShortcutInfo(info, mApp.getContext());
|
|
|
|
|
LauncherIcons li = LauncherIcons.obtain(mApp.getContext());
|
2018-10-18 15:05:45 -07:00
|
|
|
si.applyFrom(li.createShortcutIcon(info));
|
2018-07-09 16:47:01 -07:00
|
|
|
li.recycle();
|
|
|
|
|
return si;
|
2017-01-18 11:30:23 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-20 15:42:44 -07:00
|
|
|
/**
|
2017-01-06 16:32:57 -08:00
|
|
|
* Utility method to update a shortcut on the background thread.
|
2016-07-20 15:42:44 -07:00
|
|
|
*/
|
2017-01-06 16:32:57 -08:00
|
|
|
public void updateAndBindShortcutInfo(final Provider<ShortcutInfo> shortcutProvider) {
|
2017-06-06 14:33:18 -07:00
|
|
|
enqueueModelUpdateTask(new BaseModelUpdateTask() {
|
2016-07-20 15:42:44 -07:00
|
|
|
@Override
|
2016-09-09 15:47:55 -07:00
|
|
|
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
|
2017-01-06 16:32:57 -08:00
|
|
|
ShortcutInfo info = shortcutProvider.get();
|
2018-06-21 09:59:08 -07:00
|
|
|
getModelWriter().updateItemInDatabase(info);
|
2016-09-09 15:47:55 -07:00
|
|
|
ArrayList<ShortcutInfo> update = new ArrayList<>();
|
2016-07-20 15:42:44 -07:00
|
|
|
update.add(info);
|
2017-01-06 16:32:57 -08:00
|
|
|
bindUpdatedShortcuts(update, info.user);
|
2016-07-20 15:42:44 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-02 13:46:55 -07:00
|
|
|
public void refreshAndBindWidgetsAndShortcuts(@Nullable final PackageUserKey packageUser) {
|
2017-06-06 14:33:18 -07:00
|
|
|
enqueueModelUpdateTask(new BaseModelUpdateTask() {
|
2015-04-20 20:40:03 -07:00
|
|
|
@Override
|
2017-06-02 13:46:55 -07:00
|
|
|
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
|
|
|
|
|
dataModel.widgetsModel.update(app, packageUser);
|
|
|
|
|
bindUpdatedWidgets(dataModel);
|
2015-04-20 20:40:03 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-30 15:11:27 -08:00
|
|
|
public void dumpState(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
|
|
|
|
|
if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
|
|
|
|
|
writer.println(prefix + "All apps list: size=" + mBgAllAppsList.data.size());
|
|
|
|
|
for (AppInfo info : mBgAllAppsList.data) {
|
|
|
|
|
writer.println(prefix + " title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap
|
|
|
|
|
+ " componentName=" + info.componentName.getPackageName());
|
|
|
|
|
}
|
2010-06-17 13:28:48 -04:00
|
|
|
}
|
2017-01-30 15:11:27 -08:00
|
|
|
sBgDataModel.dump(prefix, fd, writer, args);
|
2009-11-17 17:32:16 -08:00
|
|
|
}
|
2014-11-10 18:05:31 -08:00
|
|
|
|
|
|
|
|
public Callbacks getCallback() {
|
|
|
|
|
return mCallbacks != null ? mCallbacks.get() : null;
|
|
|
|
|
}
|
2015-04-08 18:13:46 -07:00
|
|
|
|
2015-04-16 15:20:51 -07:00
|
|
|
/**
|
|
|
|
|
* @return the looper for the worker thread which can be used to start background tasks.
|
|
|
|
|
*/
|
|
|
|
|
public static Looper getWorkerLooper() {
|
2018-11-07 16:54:02 -08:00
|
|
|
return mWorkerLooper;
|
2015-04-16 15:20:51 -07:00
|
|
|
}
|
2017-07-31 23:29:42 -07:00
|
|
|
|
|
|
|
|
public static void setWorkerPriority(final int priority) {
|
|
|
|
|
Process.setThreadPriority(sWorkerThread.getThreadId(), priority);
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|