The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 19 | import android.appwidget.AppWidgetProviderInfo; |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 20 | import android.content.BroadcastReceiver; |
| 21 | import android.content.ComponentName; |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 22 | import android.content.ContentProviderOperation; |
| 23 | import android.content.ContentResolver; |
| 24 | import android.content.ContentValues; |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 27 | import android.content.IntentFilter; |
Sunny Goyal | 3e9be43 | 2017-01-05 15:22:41 -0800 | [diff] [blame] | 28 | import android.content.pm.LauncherActivityInfo; |
Mario Bertschler | 817afa3 | 2017-03-15 11:56:47 -0700 | [diff] [blame] | 29 | import android.content.pm.PackageInstaller; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.net.Uri; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 31 | import android.os.Handler; |
| 32 | import android.os.HandlerThread; |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 33 | import android.os.Looper; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | import android.os.Process; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 35 | import android.os.SystemClock; |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 36 | import android.os.Trace; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 37 | import android.os.UserHandle; |
Tony Wickham | 86222d2 | 2017-03-29 15:30:43 -0700 | [diff] [blame] | 38 | import android.support.annotation.Nullable; |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 39 | import android.text.TextUtils; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 40 | import android.util.Log; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 41 | import android.util.LongSparseArray; |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 42 | import android.util.MutableInt; |
Sunny Goyal | a474a9b | 2017-05-04 16:47:11 -0700 | [diff] [blame] | 43 | import android.util.Pair; |
Michael Jurka | 34c2e6c | 2013-12-13 16:07:45 +0100 | [diff] [blame] | 44 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 45 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 46 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 47 | import com.android.launcher3.compat.PackageInstallerCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 48 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 49 | import com.android.launcher3.compat.UserManagerCompat; |
Sunny Goyal | 3d706ad | 2017-03-06 16:56:39 -0800 | [diff] [blame] | 50 | import com.android.launcher3.config.FeatureFlags; |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 51 | import com.android.launcher3.dynamicui.ExtractionUtils; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 52 | import com.android.launcher3.folder.Folder; |
| 53 | import com.android.launcher3.folder.FolderIcon; |
Jon Miranda | 655ec42 | 2017-02-07 11:40:22 -0800 | [diff] [blame] | 54 | import com.android.launcher3.folder.FolderIconPreviewVerifier; |
Sunny Goyal | 1b07263 | 2017-01-18 11:30:23 -0800 | [diff] [blame] | 55 | import com.android.launcher3.graphics.LauncherIcons; |
Sunny Goyal | 1acb9e9 | 2016-05-16 12:41:09 -0700 | [diff] [blame] | 56 | import com.android.launcher3.logging.FileLog; |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 57 | import com.android.launcher3.model.AddWorkspaceItemsTask; |
Sunny Goyal | e9956a7 | 2016-09-01 17:24:47 -0700 | [diff] [blame] | 58 | import com.android.launcher3.model.BgDataModel; |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 59 | import com.android.launcher3.model.CacheDataUpdatedTask; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 60 | import com.android.launcher3.model.ExtendedModelTask; |
Sunny Goyal | f862a26 | 2015-12-14 14:27:38 -0800 | [diff] [blame] | 61 | import com.android.launcher3.model.GridSizeMigrationTask; |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 62 | import com.android.launcher3.model.LoaderCursor; |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 63 | import com.android.launcher3.model.LoaderResults; |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 64 | import com.android.launcher3.model.ModelWriter; |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 65 | import com.android.launcher3.model.PackageInstallStateChangedTask; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 66 | import com.android.launcher3.model.PackageItemInfo; |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 67 | import com.android.launcher3.model.PackageUpdatedTask; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 68 | import com.android.launcher3.model.SdCardAvailableReceiver; |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 69 | import com.android.launcher3.model.ShortcutsChangedTask; |
| 70 | import com.android.launcher3.model.UserLockStateChangedTask; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 71 | import com.android.launcher3.model.WidgetItem; |
Sunny Goyal | a5c8a9e | 2016-07-08 08:32:44 -0700 | [diff] [blame] | 72 | import com.android.launcher3.provider.ImportDataTask; |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 73 | import com.android.launcher3.provider.LauncherDbUtils; |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 74 | import com.android.launcher3.shortcuts.DeepShortcutManager; |
| 75 | import com.android.launcher3.shortcuts.ShortcutInfoCompat; |
| 76 | import com.android.launcher3.shortcuts.ShortcutKey; |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 77 | import com.android.launcher3.util.ComponentKey; |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 78 | import com.android.launcher3.util.LooperIdleLock; |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 79 | import com.android.launcher3.util.ManagedProfileHeuristic; |
Tony Wickham | d82a39d | 2016-07-01 15:44:13 -0700 | [diff] [blame] | 80 | import com.android.launcher3.util.MultiHashMap; |
Sunny Goyal | d09c370 | 2016-04-06 16:18:20 -0700 | [diff] [blame] | 81 | import com.android.launcher3.util.PackageManagerHelper; |
Tony Wickham | 86222d2 | 2017-03-29 15:30:43 -0700 | [diff] [blame] | 82 | import com.android.launcher3.util.PackageUserKey; |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 83 | import com.android.launcher3.util.Preconditions; |
Sunny Goyal | 2bcbe13 | 2016-11-16 09:23:42 -0800 | [diff] [blame] | 84 | import com.android.launcher3.util.Provider; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 85 | import com.android.launcher3.util.Thunk; |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 86 | import com.android.launcher3.util.ViewOnDrawExecutor; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 87 | |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 88 | import java.io.FileDescriptor; |
| 89 | import java.io.PrintWriter; |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 90 | import java.lang.ref.WeakReference; |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 91 | import java.util.ArrayList; |
| 92 | import java.util.Collections; |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 93 | import java.util.HashMap; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 94 | import java.util.HashSet; |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 95 | import java.util.Iterator; |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 96 | import java.util.List; |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 97 | import java.util.Map; |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 98 | import java.util.concurrent.CancellationException; |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 99 | import java.util.concurrent.Executor; |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 100 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 101 | /** |
| 102 | * Maintains in-memory state of the Launcher. It is expected that there should be only one |
| 103 | * LauncherModel object held in a static. Also provide APIs for updating the database state |
The Android Open Source Project | bc219c3 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 104 | * for the Launcher. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 105 | */ |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 106 | public class LauncherModel extends BroadcastReceiver |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 107 | implements LauncherAppsCompat.OnAppsChangedCallbackCompat { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 108 | static final boolean DEBUG_LOADERS = false; |
Chris Wren | ee52336 | 2014-09-09 10:09:02 -0400 | [diff] [blame] | 109 | private static final boolean DEBUG_RECEIVER = false; |
Chris Wren | b358f81 | 2014-04-16 13:37:00 -0400 | [diff] [blame] | 110 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 111 | static final String TAG = "Launcher.Model"; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 112 | |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 113 | private final MainThreadExecutor mUiExecutor = new MainThreadExecutor(); |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 114 | @Thunk final LauncherAppState mApp; |
| 115 | @Thunk final Object mLock = new Object(); |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 116 | @Thunk LoaderTask mLoaderTask; |
| 117 | @Thunk boolean mIsLoaderTaskRunning; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 118 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 119 | @Thunk static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader"); |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 120 | static { |
| 121 | sWorkerThread.start(); |
| 122 | } |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 123 | @Thunk static final Handler sWorker = new Handler(sWorkerThread.getLooper()); |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 124 | |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 125 | // Indicates whether the current model data is valid or not. |
| 126 | // We start off with everything not loaded. After that, we assume that |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 127 | // our monitoring of the package manager provides all updates and we never |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 128 | // need to do a requery. This is only ever touched from the loader thread. |
| 129 | private boolean mModelLoaded; |
Hyunyoung Song | 6aa3729 | 2017-02-06 10:46:24 -0800 | [diff] [blame] | 130 | public boolean isModelLoaded() { |
| 131 | synchronized (mLock) { |
| 132 | return mModelLoaded && mLoaderTask == null; |
| 133 | } |
| 134 | } |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 135 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 136 | @Thunk WeakReference<Callbacks> mCallbacks; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 137 | |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 138 | // < only access in worker thread > |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 139 | private final AllAppsList mBgAllAppsList; |
Sunny Goyal | 95f3d6b | 2016-08-10 16:09:29 -0700 | [diff] [blame] | 140 | |
Sunny Goyal | e9956a7 | 2016-09-01 17:24:47 -0700 | [diff] [blame] | 141 | /** |
| 142 | * All the static data should be accessed on the background thread, A lock should be acquired |
| 143 | * on this object when accessing any data from this model. |
| 144 | */ |
| 145 | static final BgDataModel sBgDataModel = new BgDataModel(); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 146 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 147 | // Runnable to check if the shortcuts permission has changed. |
| 148 | private final Runnable mShortcutPermissionCheckRunnable = new Runnable() { |
| 149 | @Override |
| 150 | public void run() { |
| 151 | if (mModelLoaded) { |
| 152 | boolean hasShortcutHostPermission = |
| 153 | DeepShortcutManager.getInstance(mApp.getContext()).hasHostPermission(); |
| 154 | if (hasShortcutHostPermission != sBgDataModel.hasShortcutHostPermission) { |
| 155 | forceReload(); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | }; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 160 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 161 | public interface Callbacks { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 162 | public boolean setLoadOnResume(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 163 | public int getCurrentWorkspaceScreen(); |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 164 | public void clearPendingBinds(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 165 | public void startBinding(); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 166 | public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end, |
| 167 | boolean forceAnimateIcons); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 168 | public void bindScreens(ArrayList<Long> orderedScreenIds); |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 169 | public void finishFirstPageBind(ViewOnDrawExecutor executor); |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 170 | public void finishBindingItems(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 171 | public void bindAppWidget(LauncherAppWidgetInfo info); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 172 | public void bindAllApplications(ArrayList<AppInfo> apps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 173 | public void bindAppsAdded(ArrayList<Long> newScreens, |
| 174 | ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 175 | ArrayList<ItemInfo> addAnimated, |
| 176 | ArrayList<AppInfo> addedApps); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 177 | public void bindAppsUpdated(ArrayList<AppInfo> apps); |
Mario Bertschler | 08ffaae | 2017-03-20 11:30:27 -0700 | [diff] [blame] | 178 | public void bindPromiseAppProgressUpdated(PromiseAppInfo app); |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 179 | public void bindShortcutsChanged(ArrayList<ShortcutInfo> updated, |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 180 | ArrayList<ShortcutInfo> removed, UserHandle user); |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 181 | public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets); |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 182 | public void bindRestoreItemsChange(HashSet<ItemInfo> updates); |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 183 | public void bindWorkspaceComponentsRemoved( |
| 184 | HashSet<String> packageNames, HashSet<ComponentName> components, |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 185 | UserHandle user); |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 186 | public void bindAppInfosRemoved(ArrayList<AppInfo> appInfos); |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 187 | public void notifyWidgetProvidersChanged(); |
Sunny Goyal | d164b7f | 2016-10-12 20:49:31 -0700 | [diff] [blame] | 188 | public void bindAllWidgets(MultiHashMap<PackageItemInfo, WidgetItem> widgets); |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 189 | public void onPageBoundSynchronously(int page); |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 190 | public void executeOnNextDraw(ViewOnDrawExecutor executor); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 191 | public void bindDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMap); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 192 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 193 | |
Sunny Goyal | dde4fd9 | 2016-11-21 16:02:39 +0530 | [diff] [blame] | 194 | LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 195 | mApp = app; |
Bjorn Bringert | 1307f63 | 2013-10-03 22:31:03 +0100 | [diff] [blame] | 196 | mBgAllAppsList = new AllAppsList(iconCache, appFilter); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 199 | /** Runs the specified runnable immediately if called from the worker thread, otherwise it is |
| 200 | * posted on the worker thread handler. */ |
Tony Wickham | 80f5787 | 2016-06-29 18:12:15 -0700 | [diff] [blame] | 201 | private static void runOnWorkerThread(Runnable r) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 202 | if (sWorkerThread.getThreadId() == Process.myTid()) { |
| 203 | r.run(); |
| 204 | } else { |
| 205 | // If we are not on the worker thread, then post to the worker handler |
| 206 | sWorker.post(r); |
| 207 | } |
| 208 | } |
| 209 | |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 210 | public void setPackageState(PackageInstallInfo installInfo) { |
| 211 | enqueueModelUpdateTask(new PackageInstallStateChangedTask(installInfo)); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 212 | } |
| 213 | |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 214 | /** |
| 215 | * Updates the icons and label of all pending icons for the provided package name. |
| 216 | */ |
| 217 | public void updateSessionDisplayInfo(final String packageName) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 218 | HashSet<String> packages = new HashSet<>(); |
| 219 | packages.add(packageName); |
| 220 | enqueueModelUpdateTask(new CacheDataUpdatedTask( |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 221 | CacheDataUpdatedTask.OP_SESSION_UPDATE, Process.myUserHandle(), packages)); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Adds the provided items to the workspace. |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 226 | */ |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 227 | public void addAndBindAddedWorkspaceItems( |
Sunny Goyal | a474a9b | 2017-05-04 16:47:11 -0700 | [diff] [blame] | 228 | Provider<List<Pair<ItemInfo, Object>>> appsProvider) { |
Sunny Goyal | 2bcbe13 | 2016-11-16 09:23:42 -0800 | [diff] [blame] | 229 | enqueueModelUpdateTask(new AddWorkspaceItemsTask(appsProvider)); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 232 | public ModelWriter getWriter(boolean hasVerticalHotseat) { |
| 233 | return new ModelWriter(mApp.getContext(), sBgDataModel, hasVerticalHotseat); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 236 | static void checkItemInfoLocked( |
| 237 | final long itemId, final ItemInfo item, StackTraceElement[] stackTrace) { |
Sunny Goyal | e9956a7 | 2016-09-01 17:24:47 -0700 | [diff] [blame] | 238 | ItemInfo modelItem = sBgDataModel.itemsIdMap.get(itemId); |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 239 | if (modelItem != null && item != modelItem) { |
| 240 | // check all the data is consistent |
| 241 | if (modelItem instanceof ShortcutInfo && item instanceof ShortcutInfo) { |
| 242 | ShortcutInfo modelShortcut = (ShortcutInfo) modelItem; |
| 243 | ShortcutInfo shortcut = (ShortcutInfo) item; |
| 244 | if (modelShortcut.title.toString().equals(shortcut.title.toString()) && |
| 245 | modelShortcut.intent.filterEquals(shortcut.intent) && |
| 246 | modelShortcut.id == shortcut.id && |
| 247 | modelShortcut.itemType == shortcut.itemType && |
| 248 | modelShortcut.container == shortcut.container && |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 249 | modelShortcut.screenId == shortcut.screenId && |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 250 | modelShortcut.cellX == shortcut.cellX && |
| 251 | modelShortcut.cellY == shortcut.cellY && |
| 252 | modelShortcut.spanX == shortcut.spanX && |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 253 | modelShortcut.spanY == shortcut.spanY) { |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 254 | // For all intents and purposes, this is the same object |
| 255 | return; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | // the modelItem needs to match up perfectly with item if our model is |
| 260 | // to be consistent with the database-- for now, just require |
| 261 | // modelItem == item or the equality check above |
| 262 | String msg = "item: " + ((item != null) ? item.toString() : "null") + |
| 263 | "modelItem: " + |
| 264 | ((modelItem != null) ? modelItem.toString() : "null") + |
| 265 | "Error: ItemInfo passed to checkItemInfo doesn't match original"; |
| 266 | RuntimeException e = new RuntimeException(msg); |
| 267 | if (stackTrace != null) { |
| 268 | e.setStackTrace(stackTrace); |
| 269 | } |
Adam Cohen | b9ada65 | 2013-11-08 08:25:08 -0800 | [diff] [blame] | 270 | throw e; |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Michael Jurka | 816474f | 2012-06-25 14:49:02 -0700 | [diff] [blame] | 274 | static void checkItemInfo(final ItemInfo item) { |
| 275 | final StackTraceElement[] stackTrace = new Throwable().getStackTrace(); |
| 276 | final long itemId = item.id; |
| 277 | Runnable r = new Runnable() { |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 278 | public void run() { |
Sunny Goyal | e9956a7 | 2016-09-01 17:24:47 -0700 | [diff] [blame] | 279 | synchronized (sBgDataModel) { |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 280 | checkItemInfoLocked(itemId, item, stackTrace); |
Michael Jurka | 816474f | 2012-06-25 14:49:02 -0700 | [diff] [blame] | 281 | } |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 282 | } |
| 283 | }; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 284 | runOnWorkerThread(r); |
Michael Jurka | 816474f | 2012-06-25 14:49:02 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 287 | /** |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 288 | * Update the order of the workspace screens in the database. The array list contains |
| 289 | * a list of screen ids in the order that they should appear. |
| 290 | */ |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 291 | public static void updateWorkspaceScreenOrder(Context context, final ArrayList<Long> screens) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 292 | final ArrayList<Long> screensCopy = new ArrayList<Long>(screens); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 293 | final ContentResolver cr = context.getContentResolver(); |
| 294 | final Uri uri = LauncherSettings.WorkspaceScreens.CONTENT_URI; |
| 295 | |
| 296 | // Remove any negative screen ids -- these aren't persisted |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 297 | Iterator<Long> iter = screensCopy.iterator(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 298 | while (iter.hasNext()) { |
| 299 | long id = iter.next(); |
| 300 | if (id < 0) { |
| 301 | iter.remove(); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | Runnable r = new Runnable() { |
| 306 | @Override |
| 307 | public void run() { |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 308 | ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 309 | // Clear the table |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 310 | ops.add(ContentProviderOperation.newDelete(uri).build()); |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 311 | int count = screensCopy.size(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 312 | for (int i = 0; i < count; i++) { |
| 313 | ContentValues v = new ContentValues(); |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 314 | long screenId = screensCopy.get(i); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 315 | v.put(LauncherSettings.WorkspaceScreens._ID, screenId); |
| 316 | v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i); |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 317 | ops.add(ContentProviderOperation.newInsert(uri).withValues(v).build()); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 318 | } |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 319 | |
| 320 | try { |
| 321 | cr.applyBatch(LauncherProvider.AUTHORITY, ops); |
| 322 | } catch (Exception ex) { |
| 323 | throw new RuntimeException(ex); |
| 324 | } |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 325 | |
Sunny Goyal | e9956a7 | 2016-09-01 17:24:47 -0700 | [diff] [blame] | 326 | synchronized (sBgDataModel) { |
| 327 | sBgDataModel.workspaceScreens.clear(); |
| 328 | sBgDataModel.workspaceScreens.addAll(screensCopy); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 329 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 330 | } |
| 331 | }; |
| 332 | runOnWorkerThread(r); |
| 333 | } |
| 334 | |
| 335 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 336 | * Set this as the current Launcher activity object for the loader. |
| 337 | */ |
| 338 | public void initialize(Callbacks callbacks) { |
| 339 | synchronized (mLock) { |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 340 | Preconditions.assertUIThread(); |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 341 | mCallbacks = new WeakReference<>(callbacks); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 345 | @Override |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 346 | public void onPackageChanged(String packageName, UserHandle user) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 347 | int op = PackageUpdatedTask.OP_UPDATE; |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 348 | enqueueModelUpdateTask(new PackageUpdatedTask(op, user, packageName)); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | @Override |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 352 | public void onPackageRemoved(String packageName, UserHandle user) { |
Sunny Goyal | c2936bc | 2016-09-01 15:50:36 -0700 | [diff] [blame] | 353 | onPackagesRemoved(user, packageName); |
| 354 | } |
| 355 | |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 356 | public void onPackagesRemoved(UserHandle user, String... packages) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 357 | int op = PackageUpdatedTask.OP_REMOVE; |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 358 | enqueueModelUpdateTask(new PackageUpdatedTask(op, user, packages)); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | @Override |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 362 | public void onPackageAdded(String packageName, UserHandle user) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 363 | int op = PackageUpdatedTask.OP_ADD; |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 364 | enqueueModelUpdateTask(new PackageUpdatedTask(op, user, packageName)); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Override |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 368 | public void onPackagesAvailable(String[] packageNames, UserHandle user, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 369 | boolean replacing) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 370 | enqueueModelUpdateTask( |
| 371 | new PackageUpdatedTask(PackageUpdatedTask.OP_UPDATE, user, packageNames)); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | @Override |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 375 | public void onPackagesUnavailable(String[] packageNames, UserHandle user, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 376 | boolean replacing) { |
| 377 | if (!replacing) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 378 | enqueueModelUpdateTask(new PackageUpdatedTask( |
| 379 | PackageUpdatedTask.OP_UNAVAILABLE, user, packageNames)); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 380 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 381 | } |
| 382 | |
Kenny Guy | 44cba69 | 2016-01-21 19:50:02 +0000 | [diff] [blame] | 383 | @Override |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 384 | public void onPackagesSuspended(String[] packageNames, UserHandle user) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 385 | enqueueModelUpdateTask(new PackageUpdatedTask( |
| 386 | PackageUpdatedTask.OP_SUSPEND, user, packageNames)); |
Kenny Guy | 44cba69 | 2016-01-21 19:50:02 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | @Override |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 390 | public void onPackagesUnsuspended(String[] packageNames, UserHandle user) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 391 | enqueueModelUpdateTask(new PackageUpdatedTask( |
| 392 | PackageUpdatedTask.OP_UNSUSPEND, user, packageNames)); |
Kenny Guy | 44cba69 | 2016-01-21 19:50:02 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 395 | @Override |
| 396 | public void onShortcutsChanged(String packageName, List<ShortcutInfoCompat> shortcuts, |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 397 | UserHandle user) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 398 | enqueueModelUpdateTask(new ShortcutsChangedTask(packageName, shortcuts, user, true)); |
Sunny Goyal | 50941fb | 2016-08-04 12:03:52 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | public void updatePinnedShortcuts(String packageName, List<ShortcutInfoCompat> shortcuts, |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 402 | UserHandle user) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 403 | enqueueModelUpdateTask(new ShortcutsChangedTask(packageName, shortcuts, user, false)); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Joe Onorato | 1d8e7bb | 2009-10-15 19:49:43 -0700 | [diff] [blame] | 406 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 407 | * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and |
| 408 | * ACTION_PACKAGE_CHANGED. |
| 409 | */ |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 410 | @Override |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 411 | public void onReceive(Context context, Intent intent) { |
Chris Wren | b358f81 | 2014-04-16 13:37:00 -0400 | [diff] [blame] | 412 | if (DEBUG_RECEIVER) Log.d(TAG, "onReceive intent=" + intent); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 413 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 414 | final String action = intent.getAction(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 415 | if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 416 | // If we have changed locale we need to clear out the labels in all apps/workspace. |
| 417 | forceReload(); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 418 | } else if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 419 | || Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
Sunny Goyal | 823fd50 | 2015-08-04 11:40:13 -0700 | [diff] [blame] | 420 | UserManagerCompat.getInstance(context).enableAndResetCache(); |
Sunny Goyal | 957c13f | 2015-05-01 13:02:20 -0700 | [diff] [blame] | 421 | forceReload(); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 422 | } else if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) || |
| 423 | Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) || |
| 424 | Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) { |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 425 | UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER); |
Sunny Goyal | da891c1 | 2016-03-18 18:29:24 -0700 | [diff] [blame] | 426 | if (user != null) { |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 427 | if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) || |
| 428 | Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 429 | enqueueModelUpdateTask(new PackageUpdatedTask( |
| 430 | PackageUpdatedTask.OP_USER_AVAILABILITY_CHANGE, user)); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | // ACTION_MANAGED_PROFILE_UNAVAILABLE sends the profile back to locked mode, so |
| 434 | // we need to run the state change task again. |
| 435 | if (Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) || |
| 436 | Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 437 | enqueueModelUpdateTask(new UserLockStateChangedTask(user)); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 438 | } |
Sunny Goyal | da891c1 | 2016-03-18 18:29:24 -0700 | [diff] [blame] | 439 | } |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 440 | } else if (Intent.ACTION_WALLPAPER_CHANGED.equals(action)) { |
| 441 | ExtractionUtils.startColorExtractionServiceIfNecessary(context); |
Joe Onorato | e9ad59e | 2010-10-29 17:35:36 -0700 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 445 | /** |
| 446 | * Reloads the workspace items from the DB and re-binds the workspace. This should generally |
| 447 | * not be called as DB updates are automatically followed by UI update |
| 448 | */ |
| 449 | public void forceReload() { |
| 450 | synchronized (mLock) { |
| 451 | // Stop any existing loaders first, so they don't set mModelLoaded to true later |
| 452 | stopLoaderLocked(); |
| 453 | mModelLoaded = false; |
| 454 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 455 | |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 456 | // Do this here because if the launcher activity is running it will be restarted. |
| 457 | // If it's not running startLoaderFromBackground will merely tell it that it needs |
| 458 | // to reload. |
| 459 | startLoaderFromBackground(); |
| 460 | } |
| 461 | |
Joe Onorato | e9ad59e | 2010-10-29 17:35:36 -0700 | [diff] [blame] | 462 | /** |
| 463 | * When the launcher is in the background, it's possible for it to miss paired |
| 464 | * configuration changes. So whenever we trigger the loader from the background |
| 465 | * tell the launcher that it needs to re-run the loader when it comes back instead |
| 466 | * of doing it now. |
| 467 | */ |
| 468 | public void startLoaderFromBackground() { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 469 | Callbacks callbacks = getCallback(); |
| 470 | if (callbacks != null) { |
| 471 | // Only actually run the loader if they're not paused. |
| 472 | if (!callbacks.setLoadOnResume()) { |
Sunny Goyal | 93f878c | 2016-03-30 17:31:24 -0700 | [diff] [blame] | 473 | startLoader(callbacks.getCurrentWorkspaceScreen()); |
Joe Onorato | e9ad59e | 2010-10-29 17:35:36 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 476 | } |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 477 | |
Sunny Goyal | 2bba4c3 | 2015-05-18 15:42:48 -0700 | [diff] [blame] | 478 | /** |
| 479 | * If there is already a loader task running, tell it to stop. |
| 480 | */ |
| 481 | private void stopLoaderLocked() { |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 482 | LoaderTask oldTask = mLoaderTask; |
| 483 | if (oldTask != null) { |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 484 | oldTask.stopLocked(); |
| 485 | } |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 488 | public boolean isCurrentCallbacks(Callbacks callbacks) { |
| 489 | return (mCallbacks != null && mCallbacks.get() == callbacks); |
| 490 | } |
| 491 | |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 492 | /** |
| 493 | * Starts the loader. Tries to bind {@params synchronousBindPage} synchronously if possible. |
| 494 | * @return true if the page could be bound synchronously. |
| 495 | */ |
| 496 | public boolean startLoader(int synchronousBindPage) { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 497 | // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems |
Sunny Goyal | a474a9b | 2017-05-04 16:47:11 -0700 | [diff] [blame] | 498 | InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_LOADER_RUNNING); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 499 | synchronized (mLock) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 500 | // Don't bother to start the thread if we know it's not going to do anything |
| 501 | if (mCallbacks != null && mCallbacks.get() != null) { |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 502 | final Callbacks oldCallbacks = mCallbacks.get(); |
| 503 | // Clear any pending bind-runnables from the synchronized load process. |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 504 | mUiExecutor.execute(new Runnable() { |
| 505 | public void run() { |
| 506 | oldCallbacks.clearPendingBinds(); |
| 507 | } |
| 508 | }); |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 509 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 510 | // If there is already one running, tell it to stop. |
Sunny Goyal | 2bba4c3 | 2015-05-18 15:42:48 -0700 | [diff] [blame] | 511 | stopLoaderLocked(); |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 512 | LoaderResults loaderResults = new LoaderResults(mApp, sBgDataModel, |
| 513 | mBgAllAppsList, synchronousBindPage, mCallbacks); |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 514 | if (synchronousBindPage != PagedView.INVALID_RESTORE_PAGE |
| 515 | && mModelLoaded && !mIsLoaderTaskRunning) { |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 516 | |
| 517 | // Divide the set of loaded items into those that we are binding synchronously, |
| 518 | // and everything else that is to be bound normally (asynchronously). |
| 519 | loaderResults.bindWorkspace(); |
| 520 | // For now, continue posting the binding of AllApps as there are other |
| 521 | // issues that arise from that. |
| 522 | loaderResults.bindAllApps(); |
| 523 | loaderResults.bindDeepShortcuts(); |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 524 | loaderResults.bindWidgets(); |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 525 | return true; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 526 | } else { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 527 | mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, sBgDataModel, loaderResults); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 528 | sWorker.post(mLoaderTask); |
| 529 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 530 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 531 | } |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 532 | return false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 533 | } |
| 534 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 535 | public void stopLoader() { |
| 536 | synchronized (mLock) { |
| 537 | if (mLoaderTask != null) { |
| 538 | mLoaderTask.stopLocked(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 539 | } |
| 540 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 541 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 542 | |
Sunny Goyal | c1b7c2e | 2015-01-16 16:19:04 -0800 | [diff] [blame] | 543 | /** |
| 544 | * Loads the workspace screen ids in an ordered list. |
| 545 | */ |
Sunny Goyal | e5bb705 | 2015-07-27 14:36:07 -0700 | [diff] [blame] | 546 | public static ArrayList<Long> loadWorkspaceScreensDb(Context context) { |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 547 | final ContentResolver contentResolver = context.getContentResolver(); |
| 548 | final Uri screensUri = LauncherSettings.WorkspaceScreens.CONTENT_URI; |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 549 | |
Sunny Goyal | c1b7c2e | 2015-01-16 16:19:04 -0800 | [diff] [blame] | 550 | // Get screens ordered by rank. |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 551 | return LauncherDbUtils.getScreenIdsFromCursor(contentResolver.query( |
| 552 | screensUri, null, null, null, LauncherSettings.WorkspaceScreens.SCREEN_RANK)); |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Mario Bertschler | 817afa3 | 2017-03-15 11:56:47 -0700 | [diff] [blame] | 555 | public void onInstallSessionCreated(final PackageInstallInfo sessionInfo) { |
| 556 | enqueueModelUpdateTask(new ExtendedModelTask() { |
| 557 | @Override |
| 558 | public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) { |
| 559 | apps.addPromiseApp(app.getContext(), sessionInfo); |
| 560 | if (!apps.added.isEmpty()) { |
| 561 | final ArrayList<AppInfo> arrayList = new ArrayList<>(apps.added); |
| 562 | apps.added.clear(); |
| 563 | scheduleCallbackTask(new CallbackTask() { |
| 564 | @Override |
| 565 | public void execute(Callbacks callbacks) { |
| 566 | callbacks.bindAppsAdded(null, null, null, arrayList); |
| 567 | } |
| 568 | }); |
| 569 | } |
| 570 | } |
| 571 | }); |
| 572 | } |
| 573 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 574 | public class LoaderTransaction implements AutoCloseable { |
| 575 | |
| 576 | private final LoaderTask mTask; |
| 577 | |
| 578 | private LoaderTransaction(LoaderTask task) throws CancellationException { |
| 579 | synchronized (mLock) { |
| 580 | if (mLoaderTask != task) { |
| 581 | throw new CancellationException("Loader already stopped"); |
| 582 | } |
| 583 | mTask = task; |
| 584 | mIsLoaderTaskRunning = true; |
| 585 | mModelLoaded = false; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | public void commit() { |
| 590 | synchronized (mLock) { |
| 591 | // Everything loaded bind the data. |
| 592 | mModelLoaded = true; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | @Override |
| 597 | public void close() { |
| 598 | synchronized (mLock) { |
| 599 | // If we are still the last one to be scheduled, remove ourselves. |
| 600 | if (mLoaderTask == mTask) { |
| 601 | mLoaderTask = null; |
| 602 | } |
| 603 | mIsLoaderTaskRunning = false; |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | public LoaderTransaction beginLoader(LoaderTask task) throws CancellationException { |
| 609 | return new LoaderTransaction(task); |
| 610 | } |
| 611 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 612 | /** |
| 613 | * Runnable for the thread that loads the contents of the launcher: |
| 614 | * - workspace icons |
| 615 | * - widgets |
| 616 | * - all apps icons |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 617 | * - deep shortcuts within apps |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 618 | */ |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 619 | private static class LoaderTask implements Runnable { |
| 620 | private final LauncherAppState mApp; |
| 621 | private final AllAppsList mBgAllAppsList; |
| 622 | private final BgDataModel mBgDataModel; |
| 623 | |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 624 | private final LoaderResults mResults; |
Sunny Goyal | 93f878c | 2016-03-30 17:31:24 -0700 | [diff] [blame] | 625 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 626 | private final LauncherAppsCompat mLauncherApps; |
| 627 | private final UserManagerCompat mUserManager; |
| 628 | private final DeepShortcutManager mShortcutManager; |
| 629 | private final PackageInstallerCompat mPackageInstaller; |
| 630 | private final AppWidgetManagerCompat mAppWidgetManager; |
| 631 | private final IconCache mIconCache; |
| 632 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 633 | private boolean mStopped; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 634 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 635 | LoaderTask(LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel dataModel, |
| 636 | LoaderResults results) { |
| 637 | mApp = app; |
| 638 | mBgAllAppsList = bgAllAppsList; |
| 639 | mBgDataModel = dataModel; |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 640 | mResults = results; |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 641 | |
| 642 | mLauncherApps = LauncherAppsCompat.getInstance(mApp.getContext()); |
| 643 | mUserManager = UserManagerCompat.getInstance(mApp.getContext()); |
| 644 | mShortcutManager = DeepShortcutManager.getInstance(mApp.getContext()); |
| 645 | mPackageInstaller = PackageInstallerCompat.getInstance(mApp.getContext()); |
| 646 | mAppWidgetManager = AppWidgetManagerCompat.getInstance(mApp.getContext()); |
| 647 | mIconCache = mApp.getIconCache(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 648 | } |
| 649 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 650 | private synchronized void waitForIdle() { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 651 | // Wait until the either we're stopped or the other threads are done. |
| 652 | // This way we don't start loading all apps until the workspace has settled |
| 653 | // down. |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 654 | LooperIdleLock idleLock = new LooperIdleLock(this, Looper.getMainLooper()); |
| 655 | // Just in case mFlushingWorkerThread changes but we aren't woken up, |
| 656 | // wait no longer than 1sec at a time |
| 657 | while (!mStopped && idleLock.awaitLocked(1000)); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 658 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 659 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 660 | private synchronized void verifyNotStopped() throws CancellationException { |
| 661 | if (mStopped) { |
| 662 | throw new CancellationException("Loader stopped"); |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 666 | public void run() { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 667 | synchronized (this) { |
| 668 | // Skip fast if we are already stopped. |
Sunny Goyal | f5cd998 | 2015-05-18 15:19:29 -0700 | [diff] [blame] | 669 | if (mStopped) { |
| 670 | return; |
| 671 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 672 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 673 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 674 | try (LoaderTransaction transaction = mApp.getModel().beginLoader(this)) { |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 675 | long now = 0; |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 676 | if (DEBUG_LOADERS) Log.d(TAG, "step 1.1: loading workspace"); |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 677 | loadWorkspace(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 678 | |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 679 | verifyNotStopped(); |
| 680 | if (DEBUG_LOADERS) Log.d(TAG, "step 1.2: bind workspace workspace"); |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 681 | mResults.bindWorkspace(); |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 682 | |
| 683 | // Take a break |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 684 | if (DEBUG_LOADERS) { |
| 685 | Log.d(TAG, "step 1 completed, wait for idle"); |
| 686 | now = SystemClock.uptimeMillis(); |
| 687 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 688 | waitForIdle(); |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 689 | if (DEBUG_LOADERS) Log.d(TAG, "Waited " + (SystemClock.uptimeMillis() - now) + "ms"); |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 690 | verifyNotStopped(); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 691 | |
| 692 | // second step |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 693 | if (DEBUG_LOADERS) Log.d(TAG, "step 2.1: loading all apps"); |
| 694 | loadAllApps(); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 695 | |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 696 | if (DEBUG_LOADERS) Log.d(TAG, "step 2.2: Binding all apps"); |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 697 | verifyNotStopped(); |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 698 | mResults.bindAllApps(); |
| 699 | |
| 700 | verifyNotStopped(); |
| 701 | if (DEBUG_LOADERS) Log.d(TAG, "step 2.3: Update icon cache"); |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 702 | updateIconCache(); |
| 703 | |
| 704 | // Take a break |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 705 | if (DEBUG_LOADERS) { |
| 706 | Log.d(TAG, "step 2 completed, wait for idle"); |
| 707 | now = SystemClock.uptimeMillis(); |
| 708 | } |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 709 | waitForIdle(); |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 710 | if (DEBUG_LOADERS) Log.d(TAG, "Waited " + (SystemClock.uptimeMillis() - now) + "ms"); |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 711 | verifyNotStopped(); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 712 | |
| 713 | // third step |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 714 | if (DEBUG_LOADERS) Log.d(TAG, "step 3.1: loading deep shortcuts"); |
| 715 | loadDeepShortcuts(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 716 | |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 717 | verifyNotStopped(); |
| 718 | if (DEBUG_LOADERS) Log.d(TAG, "step 3.2: bind deep shortcuts"); |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 719 | mResults.bindDeepShortcuts(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 720 | |
Tony Wickham | a7e1c1c | 2017-04-13 16:24:38 -0700 | [diff] [blame] | 721 | // Take a break |
| 722 | if (DEBUG_LOADERS) Log.d(TAG, "step 3 completed, wait for idle"); |
| 723 | waitForIdle(); |
| 724 | verifyNotStopped(); |
| 725 | |
| 726 | // fourth step |
| 727 | if (DEBUG_LOADERS) Log.d(TAG, "step 4.1: loading widgets"); |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 728 | mBgDataModel.widgetsModel.update(mApp, null); |
Tony Wickham | a7e1c1c | 2017-04-13 16:24:38 -0700 | [diff] [blame] | 729 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 730 | verifyNotStopped(); |
| 731 | if (DEBUG_LOADERS) Log.d(TAG, "step 4.2: Binding widgets"); |
| 732 | mResults.bindWidgets(); |
| 733 | |
| 734 | transaction.commit(); |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 735 | } catch (CancellationException e) { |
| 736 | // Loader stopped, ignore |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 737 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 738 | } |
| 739 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 740 | public synchronized void stopLocked() { |
| 741 | mStopped = true; |
| 742 | this.notify(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 743 | } |
| 744 | |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 745 | private void loadWorkspace() { |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 746 | if (LauncherAppState.PROFILE_STARTUP) { |
| 747 | Trace.beginSection("Loading Workspace"); |
| 748 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 749 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 750 | final Context context = mApp.getContext(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 751 | final ContentResolver contentResolver = context.getContentResolver(); |
Sunny Goyal | 342e466 | 2017-02-02 15:21:08 -0800 | [diff] [blame] | 752 | final PackageManagerHelper pmHelper = new PackageManagerHelper(context); |
| 753 | final boolean isSafeMode = pmHelper.isSafeMode(); |
Sunny Goyal | 25aba0a | 2015-07-16 15:07:47 -0700 | [diff] [blame] | 754 | final boolean isSdCardReady = Utilities.isBootCompleted(); |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 755 | final MultiHashMap<UserHandle, String> pendingPackages = new MultiHashMap<>(); |
Joe Onorato | 3c2f7e1 | 2009-10-31 19:17:31 -0400 | [diff] [blame] | 756 | |
Sunny Goyal | ded0fdb | 2016-05-23 15:55:41 -0700 | [diff] [blame] | 757 | boolean clearDb = false; |
Sunny Goyal | a5c8a9e | 2016-07-08 08:32:44 -0700 | [diff] [blame] | 758 | try { |
| 759 | ImportDataTask.performImportIfPossible(context); |
| 760 | } catch (Exception e) { |
| 761 | // Migration failed. Clear workspace. |
| 762 | clearDb = true; |
| 763 | } |
| 764 | |
| 765 | if (!clearDb && GridSizeMigrationTask.ENABLED && |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 766 | !GridSizeMigrationTask.migrateGridIfNeeded(context)) { |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 767 | // Migration failed. Clear workspace. |
Sunny Goyal | ded0fdb | 2016-05-23 15:55:41 -0700 | [diff] [blame] | 768 | clearDb = true; |
Sunny Goyal | e5bb705 | 2015-07-27 14:36:07 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Sunny Goyal | ded0fdb | 2016-05-23 15:55:41 -0700 | [diff] [blame] | 771 | if (clearDb) { |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 772 | Log.d(TAG, "loadWorkspace: resetting launcher database"); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 773 | LauncherSettings.Settings.call(contentResolver, |
Sunny Goyal | e05b08f | 2017-02-23 18:30:22 -0800 | [diff] [blame] | 774 | LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 775 | } |
| 776 | |
Sunny Goyal | ded0fdb | 2016-05-23 15:55:41 -0700 | [diff] [blame] | 777 | Log.d(TAG, "loadWorkspace: loading default favorites"); |
| 778 | LauncherSettings.Settings.call(contentResolver, |
| 779 | LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 780 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 781 | synchronized (mBgDataModel) { |
| 782 | mBgDataModel.clear(); |
Sunny Goyal | e9956a7 | 2016-09-01 17:24:47 -0700 | [diff] [blame] | 783 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 784 | final HashMap<String, Integer> installingPkgs = |
| 785 | mPackageInstaller.updateAndGetActiveSessionCache(); |
| 786 | mBgDataModel.workspaceScreens.addAll(loadWorkspaceScreensDb(context)); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 787 | |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 788 | Map<ShortcutKey, ShortcutInfoCompat> shortcutKeyToPinnedShortcuts = new HashMap<>(); |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 789 | final LoaderCursor c = new LoaderCursor(contentResolver.query( |
| 790 | LauncherSettings.Favorites.CONTENT_URI, null, null, null, null), mApp); |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 791 | |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 792 | HashMap<ComponentKey, AppWidgetProviderInfo> widgetProvidersMap = null; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 793 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 794 | try { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 795 | final int appWidgetIdIndex = c.getColumnIndexOrThrow( |
| 796 | LauncherSettings.Favorites.APPWIDGET_ID); |
Chris Wren | c3919c0 | 2013-09-18 09:48:33 -0400 | [diff] [blame] | 797 | final int appWidgetProviderIndex = c.getColumnIndexOrThrow( |
| 798 | LauncherSettings.Favorites.APPWIDGET_PROVIDER); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 799 | final int spanXIndex = c.getColumnIndexOrThrow |
| 800 | (LauncherSettings.Favorites.SPANX); |
| 801 | final int spanYIndex = c.getColumnIndexOrThrow( |
| 802 | LauncherSettings.Favorites.SPANY); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 803 | final int rankIndex = c.getColumnIndexOrThrow( |
| 804 | LauncherSettings.Favorites.RANK); |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 805 | final int optionsIndex = c.getColumnIndexOrThrow( |
| 806 | LauncherSettings.Favorites.OPTIONS); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 807 | |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 808 | final LongSparseArray<UserHandle> allUsers = c.allUsers; |
Kenny Guy | ff05f43 | 2016-01-22 17:48:29 +0000 | [diff] [blame] | 809 | final LongSparseArray<Boolean> quietMode = new LongSparseArray<>(); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 810 | final LongSparseArray<Boolean> unlockedUsers = new LongSparseArray<>(); |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 811 | for (UserHandle user : mUserManager.getUserProfiles()) { |
Kenny Guy | ff05f43 | 2016-01-22 17:48:29 +0000 | [diff] [blame] | 812 | long serialNo = mUserManager.getSerialNumberForUser(user); |
| 813 | allUsers.put(serialNo, user); |
| 814 | quietMode.put(serialNo, mUserManager.isQuietModeEnabled(user)); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 815 | |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 816 | boolean userUnlocked = mUserManager.isUserUnlocked(user); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 817 | |
| 818 | // We can only query for shortcuts when the user is unlocked. |
| 819 | if (userUnlocked) { |
Sunny Goyal | 49f4f03 | 2016-08-01 15:45:49 -0700 | [diff] [blame] | 820 | List<ShortcutInfoCompat> pinnedShortcuts = |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 821 | mShortcutManager.queryForPinnedShortcuts(null, user); |
| 822 | if (mShortcutManager.wasLastCallSuccess()) { |
Sunny Goyal | 49f4f03 | 2016-08-01 15:45:49 -0700 | [diff] [blame] | 823 | for (ShortcutInfoCompat shortcut : pinnedShortcuts) { |
| 824 | shortcutKeyToPinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), |
| 825 | shortcut); |
| 826 | } |
| 827 | } else { |
| 828 | // Shortcut manager can fail due to some race condition when the |
| 829 | // lock state changes too frequently. For the purpose of the loading |
| 830 | // shortcuts, consider the user is still locked. |
| 831 | userUnlocked = false; |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 832 | } |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 833 | } |
Sunny Goyal | 49f4f03 | 2016-08-01 15:45:49 -0700 | [diff] [blame] | 834 | unlockedUsers.put(serialNo, userUnlocked); |
Sunny Goyal | 7f834d2 | 2015-04-21 10:10:23 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 837 | ShortcutInfo info; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 838 | LauncherAppWidgetInfo appWidgetInfo; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 839 | Intent intent; |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 840 | String targetPkg; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 841 | |
Jon Miranda | 529af30 | 2017-02-28 14:18:54 -0800 | [diff] [blame] | 842 | FolderIconPreviewVerifier verifier = |
| 843 | new FolderIconPreviewVerifier(mApp.getInvariantDeviceProfile()); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 844 | while (!mStopped && c.moveToNext()) { |
| 845 | try { |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 846 | if (c.user == null) { |
| 847 | // User has been deleted, remove the item. |
| 848 | c.markDeleted("User has been deleted"); |
| 849 | continue; |
| 850 | } |
| 851 | |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 852 | boolean allowMissingTarget = false; |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 853 | switch (c.itemType) { |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 854 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 855 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 856 | case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 857 | intent = c.parseIntent(); |
| 858 | if (intent == null) { |
| 859 | c.markDeleted("Invalid or null intent"); |
| 860 | continue; |
| 861 | } |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 862 | |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 863 | int disabledState = quietMode.get(c.serialNumber) ? |
| 864 | ShortcutInfo.FLAG_DISABLED_QUIET_USER : 0; |
| 865 | ComponentName cn = intent.getComponent(); |
| 866 | targetPkg = cn == null ? intent.getPackage() : cn.getPackageName(); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 867 | |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 868 | if (!Process.myUserHandle().equals(c.user)) { |
| 869 | if (c.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { |
| 870 | c.markDeleted("Legacy shortcuts are only allowed for default user"); |
| 871 | continue; |
| 872 | } else if (c.restoreFlag != 0) { |
| 873 | // Don't restore items for other profiles. |
| 874 | c.markDeleted("Restore from managed profile not supported"); |
| 875 | continue; |
| 876 | } |
| 877 | } |
| 878 | if (TextUtils.isEmpty(targetPkg) && |
| 879 | c.itemType != LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { |
| 880 | c.markDeleted("Only legacy shortcuts can have null package"); |
| 881 | continue; |
| 882 | } |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 883 | |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 884 | // If there is no target package, its an implicit intent |
| 885 | // (legacy shortcut) which is always valid |
| 886 | boolean validTarget = TextUtils.isEmpty(targetPkg) || |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 887 | mLauncherApps.isPackageEnabledForProfile(targetPkg, c.user); |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 888 | |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 889 | if (cn != null && validTarget) { |
| 890 | // If the apk is present and the shortcut points to a specific |
| 891 | // component. |
| 892 | |
| 893 | // If the component is already present |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 894 | if (mLauncherApps.isActivityEnabledForProfile(cn, c.user)) { |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 895 | // no special handling necessary for this item |
| 896 | c.markRestored(); |
| 897 | } else { |
Mario Bertschler | c06af33 | 2017-03-28 12:23:22 -0700 | [diff] [blame] | 898 | if (c.hasRestoreFlag(ShortcutInfo.FLAG_AUTOINSTALL_ICON)) { |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 899 | // We allow auto install apps to have their intent |
| 900 | // updated after an install. |
Sunny Goyal | 342e466 | 2017-02-02 15:21:08 -0800 | [diff] [blame] | 901 | intent = pmHelper.getAppLaunchIntent(targetPkg, c.user); |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 902 | if (intent != null) { |
| 903 | c.restoreFlag = 0; |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 904 | c.updater().put( |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 905 | LauncherSettings.Favorites.INTENT, |
| 906 | intent.toUri(0)).commit(); |
| 907 | cn = intent.getComponent(); |
Sunny Goyal | b05a00a | 2016-08-29 10:06:57 -0700 | [diff] [blame] | 908 | } else { |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 909 | c.markDeleted("Unable to find a launch target"); |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 910 | continue; |
| 911 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 912 | } else { |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 913 | // The app is installed but the component is no |
| 914 | // longer available. |
| 915 | c.markDeleted("Invalid component removed: " + cn); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 916 | continue; |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 917 | } |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 918 | } |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 919 | } |
| 920 | // else if cn == null => can't infer much, leave it |
| 921 | // else if !validPkg => could be restored icon or missing sd-card |
| 922 | |
| 923 | if (!TextUtils.isEmpty(targetPkg) && !validTarget) { |
| 924 | // Points to a valid app (superset of cn != null) but the apk |
| 925 | // is not available. |
| 926 | |
| 927 | if (c.restoreFlag != 0) { |
| 928 | // Package is not yet available but might be |
| 929 | // installed later. |
| 930 | FileLog.d(TAG, "package not yet restored: " + targetPkg); |
| 931 | |
| 932 | if (c.hasRestoreFlag(ShortcutInfo.FLAG_RESTORE_STARTED)) { |
| 933 | // Restore has started once. |
| 934 | } else if (installingPkgs.containsKey(targetPkg)) { |
| 935 | // App restore has started. Update the flag |
| 936 | c.restoreFlag |= ShortcutInfo.FLAG_RESTORE_STARTED; |
| 937 | c.updater().commit(); |
| 938 | } else { |
| 939 | c.markDeleted("Unrestored app removed: " + targetPkg); |
| 940 | continue; |
| 941 | } |
Sunny Goyal | ad2e91a | 2017-02-28 15:14:58 -0800 | [diff] [blame] | 942 | } else if (pmHelper.isAppOnSdcard(targetPkg, c.user)) { |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 943 | // Package is present but not available. |
| 944 | disabledState |= ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE; |
| 945 | // Add the icon on the workspace anyway. |
| 946 | allowMissingTarget = true; |
| 947 | } else if (!isSdCardReady) { |
| 948 | // SdCard is not ready yet. Package might get available, |
| 949 | // once it is ready. |
| 950 | Log.d(TAG, "Missing pkg, will check later: " + targetPkg); |
| 951 | pendingPackages.addToList(c.user, targetPkg); |
| 952 | // Add the icon on the workspace anyway. |
| 953 | allowMissingTarget = true; |
| 954 | } else { |
| 955 | // Do not wait for external media load anymore. |
| 956 | c.markDeleted("Invalid package removed: " + targetPkg); |
| 957 | continue; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | if (validTarget) { |
| 962 | // The shortcut points to a valid target (either no target |
| 963 | // or something which is ready to be used) |
| 964 | c.markRestored(); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 965 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 966 | |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 967 | boolean useLowResIcon = !c.isOnWorkspaceOrHotseat() && |
Jon Miranda | 529af30 | 2017-02-28 14:18:54 -0800 | [diff] [blame] | 968 | !verifier.isItemInPreview(c.getInt(rankIndex)); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 969 | |
Sunny Goyal | c1ad0ce | 2017-01-11 14:33:38 -0800 | [diff] [blame] | 970 | if (c.restoreFlag != 0) { |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 971 | // Already verified above that user is same as default user |
| 972 | info = c.getRestoredItemInfo(intent); |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 973 | } else if (c.itemType == |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 974 | LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 975 | info = c.getAppShortcutInfo( |
| 976 | intent, allowMissingTarget, useLowResIcon); |
| 977 | } else if (c.itemType == |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 978 | LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 979 | |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 980 | ShortcutKey key = ShortcutKey.fromIntent(intent, c.user); |
| 981 | if (unlockedUsers.get(c.serialNumber)) { |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 982 | ShortcutInfoCompat pinnedShortcut = |
| 983 | shortcutKeyToPinnedShortcuts.get(key); |
| 984 | if (pinnedShortcut == null) { |
| 985 | // The shortcut is no longer valid. |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 986 | c.markDeleted("Pinned shortcut not found"); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 987 | continue; |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 988 | } |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 989 | info = new ShortcutInfo(pinnedShortcut, context); |
Sunny Goyal | 1b07263 | 2017-01-18 11:30:23 -0800 | [diff] [blame] | 990 | info.iconBitmap = LauncherIcons |
| 991 | .createShortcutIcon(pinnedShortcut, context); |
Charles He | 3ff9047 | 2017-02-15 12:22:56 +0000 | [diff] [blame] | 992 | if (pmHelper.isAppSuspended( |
Sunny Goyal | ad2e91a | 2017-02-28 15:14:58 -0800 | [diff] [blame] | 993 | pinnedShortcut.getPackage(), info.user)) { |
Charles He | 3ff9047 | 2017-02-15 12:22:56 +0000 | [diff] [blame] | 994 | info.isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED; |
| 995 | } |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 996 | intent = info.intent; |
| 997 | } else { |
| 998 | // Create a shortcut info in disabled mode for now. |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 999 | info = c.loadSimpleShortcut(); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 1000 | info.isDisabled |= ShortcutInfo.FLAG_DISABLED_LOCKED_USER; |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1001 | } |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1002 | } else { // item type == ITEM_TYPE_SHORTCUT |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1003 | info = c.loadSimpleShortcut(); |
Michael Jurka | 9687956 | 2012-03-22 05:54:33 -0700 | [diff] [blame] | 1004 | |
Sunny Goyal | d09c370 | 2016-04-06 16:18:20 -0700 | [diff] [blame] | 1005 | // Shortcuts are only available on the primary profile |
Tony Wickham | 431a713 | 2017-05-04 15:39:43 -0700 | [diff] [blame] | 1006 | if (!TextUtils.isEmpty(targetPkg) |
| 1007 | && pmHelper.isAppSuspended(targetPkg, c.user)) { |
Sunny Goyal | d09c370 | 2016-04-06 16:18:20 -0700 | [diff] [blame] | 1008 | disabledState |= ShortcutInfo.FLAG_DISABLED_SUSPENDED; |
| 1009 | } |
| 1010 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1011 | // App shortcuts that used to be automatically added to Launcher |
| 1012 | // didn't always have the correct intent flags set, so do that |
| 1013 | // here |
| 1014 | if (intent.getAction() != null && |
Michael Jurka | 9ad0056 | 2012-05-14 12:24:22 -0700 | [diff] [blame] | 1015 | intent.getCategories() != null && |
| 1016 | intent.getAction().equals(Intent.ACTION_MAIN) && |
Michael Jurka | 9687956 | 2012-03-22 05:54:33 -0700 | [diff] [blame] | 1017 | intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1018 | intent.addFlags( |
| 1019 | Intent.FLAG_ACTIVITY_NEW_TASK | |
| 1020 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1021 | } |
Michael Jurka | 9687956 | 2012-03-22 05:54:33 -0700 | [diff] [blame] | 1022 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1023 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1024 | if (info != null) { |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1025 | c.applyCommonProperties(info); |
| 1026 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1027 | info.intent = intent; |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 1028 | info.rank = c.getInt(rankIndex); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 1029 | info.spanX = 1; |
| 1030 | info.spanY = 1; |
Sunny Goyal | d09c370 | 2016-04-06 16:18:20 -0700 | [diff] [blame] | 1031 | info.isDisabled |= disabledState; |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 1032 | if (isSafeMode && !Utilities.isSystemApp(context, intent)) { |
| 1033 | info.isDisabled |= ShortcutInfo.FLAG_DISABLED_SAFEMODE; |
| 1034 | } |
Adam Cohen | ae4409d | 2013-11-26 10:34:59 -0800 | [diff] [blame] | 1035 | |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 1036 | if (c.restoreFlag != 0 && !TextUtils.isEmpty(targetPkg)) { |
| 1037 | Integer progress = installingPkgs.get(targetPkg); |
| 1038 | if (progress != null) { |
| 1039 | info.setInstallProgress(progress); |
| 1040 | } else { |
| 1041 | info.status &= ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE; |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1045 | c.checkAndAddItem(info, mBgDataModel); |
Winson Chung | 1323b48 | 2013-08-05 12:41:55 -0700 | [diff] [blame] | 1046 | } else { |
| 1047 | throw new RuntimeException("Unexpected null ShortcutInfo"); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1048 | } |
| 1049 | break; |
| 1050 | |
| 1051 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1052 | FolderInfo folderInfo = mBgDataModel.findOrMakeFolder(c.id); |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1053 | c.applyCommonProperties(folderInfo); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1054 | |
Sunny Goyal | a508e4f | 2015-05-21 09:33:57 -0700 | [diff] [blame] | 1055 | // Do not trim the folder label, as is was set by the user. |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1056 | folderInfo.title = c.getString(c.titleIndex); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 1057 | folderInfo.spanX = 1; |
| 1058 | folderInfo.spanY = 1; |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 1059 | folderInfo.options = c.getInt(optionsIndex); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1060 | |
Sunny Goyal | c1ad0ce | 2017-01-11 14:33:38 -0800 | [diff] [blame] | 1061 | // no special handling required for restored folders |
| 1062 | c.markRestored(); |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 1063 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1064 | c.checkAndAddItem(folderInfo, mBgDataModel); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1065 | break; |
| 1066 | |
| 1067 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1068 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1069 | // Read all Launcher-specific widget details |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1070 | boolean customWidget = c.itemType == |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1071 | LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; |
| 1072 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1073 | int appWidgetId = c.getInt(appWidgetIdIndex); |
Chris Wren | c3919c0 | 2013-09-18 09:48:33 -0400 | [diff] [blame] | 1074 | String savedProvider = c.getString(appWidgetProviderIndex); |
Sunny Goyal | 7f834d2 | 2015-04-21 10:10:23 -0700 | [diff] [blame] | 1075 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1076 | final ComponentName component = |
| 1077 | ComponentName.unflattenFromString(savedProvider); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1078 | |
Sunny Goyal | c1ad0ce | 2017-01-11 14:33:38 -0800 | [diff] [blame] | 1079 | final boolean isIdValid = !c.hasRestoreFlag( |
| 1080 | LauncherAppWidgetInfo.FLAG_ID_NOT_VALID); |
| 1081 | final boolean wasProviderReady = !c.hasRestoreFlag( |
| 1082 | LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 1083 | |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 1084 | if (widgetProvidersMap == null) { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1085 | widgetProvidersMap = mAppWidgetManager.getAllProvidersMap(); |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 1086 | } |
| 1087 | final AppWidgetProviderInfo provider = widgetProvidersMap.get( |
| 1088 | new ComponentKey( |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 1089 | ComponentName.unflattenFromString(savedProvider), |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1090 | c.user)); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1091 | |
| 1092 | final boolean isProviderReady = isValidProvider(provider); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1093 | if (!isSafeMode && !customWidget && |
| 1094 | wasProviderReady && !isProviderReady) { |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1095 | c.markDeleted( |
| 1096 | "Deleting widget that isn't installed anymore: " |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 1097 | + provider); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1098 | } else { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1099 | if (isProviderReady) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 1100 | appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId, |
| 1101 | provider.provider); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1102 | |
Sunny Goyal | 53f9672 | 2015-07-13 19:54:53 -0700 | [diff] [blame] | 1103 | // The provider is available. So the widget is either |
| 1104 | // available or not available. We do not need to track |
| 1105 | // any future restore updates. |
Sunny Goyal | c1ad0ce | 2017-01-11 14:33:38 -0800 | [diff] [blame] | 1106 | int status = c.restoreFlag & |
Sunny Goyal | 53f9672 | 2015-07-13 19:54:53 -0700 | [diff] [blame] | 1107 | ~LauncherAppWidgetInfo.FLAG_RESTORE_STARTED; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1108 | if (!wasProviderReady) { |
| 1109 | // If provider was not previously ready, update the |
| 1110 | // status and UI flag. |
| 1111 | |
| 1112 | // Id would be valid only if the widget restore broadcast was received. |
| 1113 | if (isIdValid) { |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 1114 | status |= LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1115 | } else { |
| 1116 | status &= ~LauncherAppWidgetInfo |
| 1117 | .FLAG_PROVIDER_NOT_READY; |
| 1118 | } |
| 1119 | } |
| 1120 | appWidgetInfo.restoreStatus = status; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 1121 | } else { |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1122 | Log.v(TAG, "Widget restore pending id=" + c.id |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 1123 | + " appWidgetId=" + appWidgetId |
Sunny Goyal | c1ad0ce | 2017-01-11 14:33:38 -0800 | [diff] [blame] | 1124 | + " status =" + c.restoreFlag); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 1125 | appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId, |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1126 | component); |
Sunny Goyal | c1ad0ce | 2017-01-11 14:33:38 -0800 | [diff] [blame] | 1127 | appWidgetInfo.restoreStatus = c.restoreFlag; |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 1128 | Integer installProgress = installingPkgs.get(component.getPackageName()); |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 1129 | |
Sunny Goyal | c1ad0ce | 2017-01-11 14:33:38 -0800 | [diff] [blame] | 1130 | if (c.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_RESTORE_STARTED)) { |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 1131 | // Restore has started once. |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 1132 | } else if (installProgress != null) { |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 1133 | // App restore has started. Update the flag |
| 1134 | appWidgetInfo.restoreStatus |= |
| 1135 | LauncherAppWidgetInfo.FLAG_RESTORE_STARTED; |
Sunny Goyal | b05a00a | 2016-08-29 10:06:57 -0700 | [diff] [blame] | 1136 | } else if (!isSafeMode) { |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1137 | c.markDeleted("Unrestored widget removed: " + component); |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 1138 | continue; |
| 1139 | } |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 1140 | |
| 1141 | appWidgetInfo.installProgress = |
| 1142 | installProgress == null ? 0 : installProgress; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 1143 | } |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 1144 | if (appWidgetInfo.hasRestoreFlag( |
| 1145 | LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG)) { |
Sunny Goyal | 81e4491 | 2017-01-14 15:05:14 -0800 | [diff] [blame] | 1146 | appWidgetInfo.bindOptions = c.parseIntent(); |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 1147 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1148 | |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1149 | c.applyCommonProperties(appWidgetInfo); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1150 | appWidgetInfo.spanX = c.getInt(spanXIndex); |
| 1151 | appWidgetInfo.spanY = c.getInt(spanYIndex); |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1152 | appWidgetInfo.user = c.user; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1153 | |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1154 | if (!c.isOnWorkspaceOrHotseat()) { |
| 1155 | c.markDeleted("Widget found where container != " + |
Sunny Goyal | 41cdc8d | 2015-09-04 12:53:04 -0700 | [diff] [blame] | 1156 | "CONTAINER_DESKTOP nor CONTAINER_HOTSEAT - ignoring!"); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1157 | continue; |
| 1158 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1159 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1160 | if (!customWidget) { |
| 1161 | String providerName = |
| 1162 | appWidgetInfo.providerName.flattenToString(); |
| 1163 | if (!providerName.equals(savedProvider) || |
Sunny Goyal | c1ad0ce | 2017-01-11 14:33:38 -0800 | [diff] [blame] | 1164 | (appWidgetInfo.restoreStatus != c.restoreFlag)) { |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1165 | c.updater() |
| 1166 | .put(LauncherSettings.Favorites.APPWIDGET_PROVIDER, |
| 1167 | providerName) |
| 1168 | .put(LauncherSettings.Favorites.RESTORED, |
| 1169 | appWidgetInfo.restoreStatus) |
| 1170 | .commit(); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1171 | } |
Chris Wren | c3919c0 | 2013-09-18 09:48:33 -0400 | [diff] [blame] | 1172 | } |
Jon Miranda | 2b823f4 | 2017-05-02 18:36:18 -0700 | [diff] [blame] | 1173 | |
| 1174 | if (appWidgetInfo.restoreStatus != |
| 1175 | LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
| 1176 | String pkg = appWidgetInfo.providerName.getPackageName(); |
| 1177 | appWidgetInfo.pendingItemInfo = new PackageItemInfo(pkg); |
| 1178 | appWidgetInfo.pendingItemInfo.user = appWidgetInfo.user; |
| 1179 | mIconCache.getTitleAndIconForApp( |
| 1180 | appWidgetInfo.pendingItemInfo, false); |
| 1181 | } |
| 1182 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1183 | c.checkAndAddItem(appWidgetInfo, mBgDataModel); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1184 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1185 | break; |
| 1186 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1187 | } catch (Exception e) { |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 1188 | Log.e(TAG, "Desktop items loading interrupted", e); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 1189 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1190 | } |
| 1191 | } finally { |
Sunny Goyal | 713edfc | 2016-05-06 09:58:34 -0700 | [diff] [blame] | 1192 | Utilities.closeSilently(c); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 1195 | // Break early if we've stopped loading |
| 1196 | if (mStopped) { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1197 | mBgDataModel.clear(); |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1198 | return; |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1201 | // Remove dead items |
| 1202 | if (c.commitDeleted()) { |
Sunny Goyal | b1622cc | 2015-06-10 16:00:42 -0700 | [diff] [blame] | 1203 | // Remove any empty folder |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 1204 | ArrayList<Long> deletedFolderIds = (ArrayList<Long>) LauncherSettings.Settings |
| 1205 | .call(contentResolver, |
| 1206 | LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS) |
| 1207 | .getSerializable(LauncherSettings.Settings.EXTRA_VALUE); |
| 1208 | for (long folderId : deletedFolderIds) { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1209 | mBgDataModel.workspaceItems.remove(mBgDataModel.folders.get(folderId)); |
| 1210 | mBgDataModel.folders.remove(folderId); |
| 1211 | mBgDataModel.itemsIdMap.remove(folderId); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 1212 | } |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 1213 | |
| 1214 | // Remove any ghost widgets |
| 1215 | LauncherSettings.Settings.call(contentResolver, |
| 1216 | LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 1217 | } |
| 1218 | |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1219 | // Unpin shortcuts that don't exist on the workspace. |
Sunny Goyal | f75baa9 | 2016-11-22 03:23:51 +0530 | [diff] [blame] | 1220 | HashSet<ShortcutKey> pendingShortcuts = |
| 1221 | InstallShortcutReceiver.getPendingShortcuts(context); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1222 | for (ShortcutKey key : shortcutKeyToPinnedShortcuts.keySet()) { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1223 | MutableInt numTimesPinned = mBgDataModel.pinnedShortcutCounts.get(key); |
Sunny Goyal | f75baa9 | 2016-11-22 03:23:51 +0530 | [diff] [blame] | 1224 | if ((numTimesPinned == null || numTimesPinned.value == 0) |
| 1225 | && !pendingShortcuts.contains(key)) { |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1226 | // Shortcut is pinned but doesn't exist on the workspace; unpin it. |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1227 | mShortcutManager.unpinShortcut(key); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | |
Jon Miranda | 655ec42 | 2017-02-07 11:40:22 -0800 | [diff] [blame] | 1231 | FolderIconPreviewVerifier verifier = |
| 1232 | new FolderIconPreviewVerifier(mApp.getInvariantDeviceProfile()); |
| 1233 | // Sort the folder items and make sure all items in the preview are high resolution. |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1234 | for (FolderInfo folder : mBgDataModel.folders) { |
Sunny Goyal | 317698b | 2015-07-29 11:45:41 -0700 | [diff] [blame] | 1235 | Collections.sort(folder.contents, Folder.ITEM_POS_COMPARATOR); |
Jon Miranda | 655ec42 | 2017-02-07 11:40:22 -0800 | [diff] [blame] | 1236 | verifier.setFolderInfo(folder); |
| 1237 | |
| 1238 | int numItemsInPreview = 0; |
Sunny Goyal | 317698b | 2015-07-29 11:45:41 -0700 | [diff] [blame] | 1239 | for (ShortcutInfo info : folder.contents) { |
Jon Miranda | 655ec42 | 2017-02-07 11:40:22 -0800 | [diff] [blame] | 1240 | if (info.usingLowResIcon |
| 1241 | && info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION |
| 1242 | && verifier.isItemInPreview(info.rank)) { |
Sunny Goyal | 3fe4a14 | 2016-12-15 17:40:07 -0800 | [diff] [blame] | 1243 | mIconCache.getTitleAndIcon(info, false); |
Jon Miranda | 655ec42 | 2017-02-07 11:40:22 -0800 | [diff] [blame] | 1244 | numItemsInPreview++; |
Sunny Goyal | 317698b | 2015-07-29 11:45:41 -0700 | [diff] [blame] | 1245 | } |
Jon Miranda | 655ec42 | 2017-02-07 11:40:22 -0800 | [diff] [blame] | 1246 | |
| 1247 | if (numItemsInPreview >= FolderIcon.NUM_ITEMS_IN_PREVIEW) { |
Sunny Goyal | 317698b | 2015-07-29 11:45:41 -0700 | [diff] [blame] | 1248 | break; |
| 1249 | } |
| 1250 | } |
| 1251 | } |
| 1252 | |
Sunny Goyal | aaf86fe | 2017-01-05 21:50:27 -0800 | [diff] [blame] | 1253 | c.commitRestoredItems(); |
Sunny Goyal | c2936bc | 2016-09-01 15:50:36 -0700 | [diff] [blame] | 1254 | if (!isSdCardReady && !pendingPackages.isEmpty()) { |
| 1255 | context.registerReceiver( |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1256 | new SdCardAvailableReceiver(mApp, pendingPackages), |
Sunny Goyal | 25aba0a | 2015-07-16 15:07:47 -0700 | [diff] [blame] | 1257 | new IntentFilter(Intent.ACTION_BOOT_COMPLETED), |
Sunny Goyal | c2936bc | 2016-09-01 15:50:36 -0700 | [diff] [blame] | 1258 | null, |
| 1259 | sWorker); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1262 | // Remove any empty screens |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1263 | ArrayList<Long> unusedScreens = new ArrayList<>(mBgDataModel.workspaceScreens); |
| 1264 | for (ItemInfo item: mBgDataModel.itemsIdMap) { |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1265 | long screenId = item.screenId; |
| 1266 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && |
| 1267 | unusedScreens.contains(screenId)) { |
| 1268 | unusedScreens.remove(screenId); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | // If there are any empty screens remove them, and update. |
| 1273 | if (unusedScreens.size() != 0) { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1274 | mBgDataModel.workspaceScreens.removeAll(unusedScreens); |
| 1275 | updateWorkspaceScreenOrder(context, mBgDataModel.workspaceScreens); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1276 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1277 | } |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 1278 | if (LauncherAppState.PROFILE_STARTUP) { |
| 1279 | Trace.endSection(); |
| 1280 | } |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Sunny Goyal | 4e5cc64 | 2015-06-25 16:37:44 -0700 | [diff] [blame] | 1283 | private void updateIconCache() { |
| 1284 | // Ignore packages which have a promise icon. |
| 1285 | HashSet<String> packagesToIgnore = new HashSet<>(); |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1286 | synchronized (mBgDataModel) { |
| 1287 | for (ItemInfo info : mBgDataModel.itemsIdMap) { |
Sunny Goyal | 4e5cc64 | 2015-06-25 16:37:44 -0700 | [diff] [blame] | 1288 | if (info instanceof ShortcutInfo) { |
| 1289 | ShortcutInfo si = (ShortcutInfo) info; |
| 1290 | if (si.isPromise() && si.getTargetComponent() != null) { |
| 1291 | packagesToIgnore.add(si.getTargetComponent().getPackageName()); |
| 1292 | } |
| 1293 | } else if (info instanceof LauncherAppWidgetInfo) { |
| 1294 | LauncherAppWidgetInfo lawi = (LauncherAppWidgetInfo) info; |
| 1295 | if (lawi.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) { |
| 1296 | packagesToIgnore.add(lawi.providerName.getPackageName()); |
| 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | } |
| 1301 | mIconCache.updateDbIcons(packagesToIgnore); |
| 1302 | } |
| 1303 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 1304 | private void loadAllApps() { |
| 1305 | final long loadTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1306 | |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 1307 | final List<UserHandle> profiles = mUserManager.getUserProfiles(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1308 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 1309 | // Clear the list of apps |
| 1310 | mBgAllAppsList.clear(); |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 1311 | for (UserHandle user : profiles) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1312 | // Query for the set of apps |
| 1313 | final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
Sunny Goyal | 3e9be43 | 2017-01-05 15:22:41 -0800 | [diff] [blame] | 1314 | final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null, user); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1315 | if (DEBUG_LOADERS) { |
| 1316 | Log.d(TAG, "getActivityList took " |
| 1317 | + (SystemClock.uptimeMillis()-qiaTime) + "ms for user " + user); |
| 1318 | Log.d(TAG, "getActivityList got " + apps.size() + " apps for user " + user); |
| 1319 | } |
| 1320 | // Fail if we don't have any apps |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 1321 | // TODO: Fix this. Only fail for the current user. |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1322 | if (apps == null || apps.isEmpty()) { |
| 1323 | return; |
| 1324 | } |
Kenny Guy | ff05f43 | 2016-01-22 17:48:29 +0000 | [diff] [blame] | 1325 | boolean quietMode = mUserManager.isQuietModeEnabled(user); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1326 | // Create the ApplicationInfos |
| 1327 | for (int i = 0; i < apps.size(); i++) { |
Sunny Goyal | 3e9be43 | 2017-01-05 15:22:41 -0800 | [diff] [blame] | 1328 | LauncherActivityInfo app = apps.get(i); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1329 | // This builds the icon bitmaps. |
Sunny Goyal | 24bb66a | 2017-03-21 15:12:01 -0700 | [diff] [blame] | 1330 | mBgAllAppsList.add(new AppInfo(app, user, quietMode), app); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1331 | } |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 1332 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1333 | ManagedProfileHeuristic.onAllAppsLoaded(mApp.getContext(), apps, user); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 1334 | } |
Mario Bertschler | 817afa3 | 2017-03-15 11:56:47 -0700 | [diff] [blame] | 1335 | |
| 1336 | if (FeatureFlags.LAUNCHER3_PROMISE_APPS_IN_ALL_APPS) { |
| 1337 | // get all active sessions and add them to the all apps list |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1338 | for (PackageInstaller.SessionInfo info : |
| 1339 | mPackageInstaller.getAllVerifiedSessions()) { |
| 1340 | mBgAllAppsList.addPromiseApp(mApp.getContext(), |
Mario Bertschler | 817afa3 | 2017-03-15 11:56:47 -0700 | [diff] [blame] | 1341 | PackageInstallInfo.fromInstallingState(info)); |
| 1342 | } |
| 1343 | } |
| 1344 | |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 1345 | mBgAllAppsList.added = new ArrayList<>(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1346 | if (DEBUG_LOADERS) { |
Sunny Goyal | f8d6ed2 | 2017-06-01 14:26:38 -0700 | [diff] [blame] | 1347 | Log.d(TAG, "All apps loaded in in " |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 1348 | + (SystemClock.uptimeMillis() - loadTime) + "ms"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 1352 | private void loadDeepShortcuts() { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1353 | mBgDataModel.deepShortcutMap.clear(); |
| 1354 | mBgDataModel.hasShortcutHostPermission = mShortcutManager.hasHostPermission(); |
| 1355 | if (mBgDataModel.hasShortcutHostPermission) { |
Sunny Goyal | 4869bf3 | 2017-05-17 12:05:46 -0700 | [diff] [blame] | 1356 | for (UserHandle user : mUserManager.getUserProfiles()) { |
| 1357 | if (mUserManager.isUserUnlocked(user)) { |
| 1358 | List<ShortcutInfoCompat> shortcuts = |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1359 | mShortcutManager.queryForAllShortcuts(user); |
| 1360 | mBgDataModel.updateDeepShortcutMap(null, user, shortcuts); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 1361 | } |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1362 | } |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1363 | } |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1364 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 1367 | /** |
Sunny Goyal | 95f3d6b | 2016-08-10 16:09:29 -0700 | [diff] [blame] | 1368 | * Refreshes the cached shortcuts if the shortcut permission has changed. |
| 1369 | * Current implementation simply reloads the workspace, but it can be optimized to |
| 1370 | * use partial updates similar to {@link UserManagerCompat} |
| 1371 | */ |
| 1372 | public void refreshShortcutsIfRequired() { |
Sunny Goyal | f5e3744 | 2016-11-02 10:31:24 -0700 | [diff] [blame] | 1373 | if (Utilities.ATLEAST_NOUGAT_MR1) { |
Sunny Goyal | 95f3d6b | 2016-08-10 16:09:29 -0700 | [diff] [blame] | 1374 | sWorker.removeCallbacks(mShortcutPermissionCheckRunnable); |
| 1375 | sWorker.post(mShortcutPermissionCheckRunnable); |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | /** |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 1380 | * Called when the icons for packages have been updated in the icon cache. |
| 1381 | */ |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 1382 | public void onPackageIconsUpdated(HashSet<String> updatedPackages, UserHandle user) { |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 1383 | // If any package icon has changed (app was updated while launcher was dead), |
| 1384 | // update the corresponding shortcuts. |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1385 | enqueueModelUpdateTask(new CacheDataUpdatedTask( |
| 1386 | CacheDataUpdatedTask.OP_CACHE_UPDATE, user, updatedPackages)); |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
Sunny Goyal | 0e947fb | 2017-05-19 12:21:50 -0700 | [diff] [blame] | 1389 | public void enqueueModelUpdateTask(BaseModelUpdateTask task) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1390 | task.init(this); |
| 1391 | runOnWorkerThread(task); |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1394 | /** |
| 1395 | * A task to be executed on the current callbacks on the UI thread. |
| 1396 | * If there is no current callbacks, the task is ignored. |
| 1397 | */ |
| 1398 | public interface CallbackTask { |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1399 | |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1400 | void execute(Callbacks callbacks); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1403 | /** |
| 1404 | * A runnable which changes/updates the data model of the launcher based on certain events. |
| 1405 | */ |
| 1406 | public static abstract class BaseModelUpdateTask implements Runnable { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1407 | |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1408 | private LauncherModel mModel; |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 1409 | private Executor mUiExecutor; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1410 | |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1411 | /* package private */ |
| 1412 | void init(LauncherModel model) { |
| 1413 | mModel = model; |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 1414 | mUiExecutor = mModel.mUiExecutor; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1415 | } |
| 1416 | |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1417 | @Override |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1418 | public final void run() { |
| 1419 | if (!mModel.mModelLoaded) { |
| 1420 | if (DEBUG_LOADERS) { |
| 1421 | Log.d(TAG, "Ignoring model task since loader is pending=" + this); |
| 1422 | } |
Sunny Goyal | c905efc | 2015-05-06 09:54:53 -0700 | [diff] [blame] | 1423 | // Loader has not yet run. |
| 1424 | return; |
| 1425 | } |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1426 | execute(mModel.mApp, sBgDataModel, mModel.mBgAllAppsList); |
| 1427 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1428 | |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1429 | /** |
| 1430 | * Execute the actual task. Called on the worker thread. |
| 1431 | */ |
| 1432 | public abstract void execute( |
| 1433 | LauncherAppState app, BgDataModel dataModel, AllAppsList apps); |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 1434 | |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1435 | /** |
| 1436 | * Schedules a {@param task} to be executed on the current callbacks. |
| 1437 | */ |
| 1438 | public final void scheduleCallbackTask(final CallbackTask task) { |
| 1439 | final Callbacks callbacks = mModel.getCallback(); |
Sunny Goyal | b265ba7 | 2017-02-14 15:03:45 -0800 | [diff] [blame] | 1440 | mUiExecutor.execute(new Runnable() { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1441 | public void run() { |
| 1442 | Callbacks cb = mModel.getCallback(); |
| 1443 | if (callbacks == cb && cb != null) { |
| 1444 | task.execute(callbacks); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 1445 | } |
| 1446 | } |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1447 | }); |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 1448 | } |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1449 | |
| 1450 | public ModelWriter getModelWriter() { |
| 1451 | // Updates from model task, do not deal with icon position in hotseat. |
| 1452 | return mModel.getWriter(false /* hasVerticalHotseat */); |
| 1453 | } |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 1454 | } |
| 1455 | |
Sunny Goyal | 1b07263 | 2017-01-18 11:30:23 -0800 | [diff] [blame] | 1456 | public void updateAndBindShortcutInfo(final ShortcutInfo si, final ShortcutInfoCompat info) { |
| 1457 | updateAndBindShortcutInfo(new Provider<ShortcutInfo>() { |
| 1458 | @Override |
| 1459 | public ShortcutInfo get() { |
| 1460 | si.updateFromDeepShortcutInfo(info, mApp.getContext()); |
| 1461 | si.iconBitmap = LauncherIcons.createShortcutIcon(info, mApp.getContext()); |
| 1462 | return si; |
| 1463 | } |
| 1464 | }); |
| 1465 | } |
| 1466 | |
Sunny Goyal | 10923b3 | 2016-07-20 15:42:44 -0700 | [diff] [blame] | 1467 | /** |
Sunny Goyal | 1cc1c9a | 2017-01-06 16:32:57 -0800 | [diff] [blame] | 1468 | * Utility method to update a shortcut on the background thread. |
Sunny Goyal | 10923b3 | 2016-07-20 15:42:44 -0700 | [diff] [blame] | 1469 | */ |
Sunny Goyal | 1cc1c9a | 2017-01-06 16:32:57 -0800 | [diff] [blame] | 1470 | public void updateAndBindShortcutInfo(final Provider<ShortcutInfo> shortcutProvider) { |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1471 | enqueueModelUpdateTask(new ExtendedModelTask() { |
Sunny Goyal | 10923b3 | 2016-07-20 15:42:44 -0700 | [diff] [blame] | 1472 | @Override |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1473 | public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) { |
Sunny Goyal | 1cc1c9a | 2017-01-06 16:32:57 -0800 | [diff] [blame] | 1474 | ShortcutInfo info = shortcutProvider.get(); |
Sunny Goyal | f0ba8b7 | 2016-09-09 15:47:55 -0700 | [diff] [blame] | 1475 | ArrayList<ShortcutInfo> update = new ArrayList<>(); |
Sunny Goyal | 10923b3 | 2016-07-20 15:42:44 -0700 | [diff] [blame] | 1476 | update.add(info); |
Sunny Goyal | 1cc1c9a | 2017-01-06 16:32:57 -0800 | [diff] [blame] | 1477 | bindUpdatedShortcuts(update, info.user); |
Sunny Goyal | 10923b3 | 2016-07-20 15:42:44 -0700 | [diff] [blame] | 1478 | } |
| 1479 | }); |
| 1480 | } |
| 1481 | |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1482 | public void refreshAndBindWidgetsAndShortcuts(@Nullable final PackageUserKey packageUser) { |
| 1483 | enqueueModelUpdateTask(new ExtendedModelTask() { |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 1484 | @Override |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame^] | 1485 | public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) { |
| 1486 | dataModel.widgetsModel.update(app, packageUser); |
| 1487 | bindUpdatedWidgets(dataModel); |
Sunny Goyal | 3186058 | 2015-09-18 08:38:57 -0700 | [diff] [blame] | 1488 | } |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 1489 | }); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 1492 | static boolean isValidProvider(AppWidgetProviderInfo provider) { |
| 1493 | return (provider != null) && (provider.provider != null) |
| 1494 | && (provider.provider.getPackageName() != null); |
| 1495 | } |
| 1496 | |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 1497 | public void dumpState(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 1498 | if (args.length > 0 && TextUtils.equals(args[0], "--all")) { |
| 1499 | writer.println(prefix + "All apps list: size=" + mBgAllAppsList.data.size()); |
| 1500 | for (AppInfo info : mBgAllAppsList.data) { |
| 1501 | writer.println(prefix + " title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap |
| 1502 | + " componentName=" + info.componentName.getPackageName()); |
| 1503 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1504 | } |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 1505 | sBgDataModel.dump(prefix, fd, writer, args); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1506 | } |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 1507 | |
| 1508 | public Callbacks getCallback() { |
| 1509 | return mCallbacks != null ? mCallbacks.get() : null; |
| 1510 | } |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 1511 | |
| 1512 | /** |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 1513 | * @return the looper for the worker thread which can be used to start background tasks. |
| 1514 | */ |
| 1515 | public static Looper getWorkerLooper() { |
| 1516 | return sWorkerThread.getLooper(); |
| 1517 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1518 | } |