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 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 19 | import android.app.SearchManager; |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 20 | import android.appwidget.AppWidgetProviderInfo; |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
| 22 | import android.content.ComponentName; |
| 23 | import android.content.ContentProviderClient; |
| 24 | import android.content.ContentProviderOperation; |
| 25 | import android.content.ContentResolver; |
| 26 | import android.content.ContentValues; |
| 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 29 | import android.content.Intent.ShortcutIconResource; |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 30 | import android.content.IntentFilter; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
Jason Monk | bbe1e24 | 2014-05-16 17:37:34 -0400 | [diff] [blame] | 32 | import android.content.pm.ProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 33 | import android.content.pm.ResolveInfo; |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 34 | import android.content.res.Configuration; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 35 | import android.content.res.Resources; |
| 36 | import android.database.Cursor; |
| 37 | import android.graphics.Bitmap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | import android.net.Uri; |
Hyunyoung Song | d4af148 | 2015-04-20 20:40:03 -0700 | [diff] [blame] | 39 | import android.os.Build; |
Joe Onorato | 17a8922 | 2011-02-08 17:26:11 -0800 | [diff] [blame] | 40 | import android.os.Environment; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 41 | import android.os.Handler; |
| 42 | import android.os.HandlerThread; |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 43 | import android.os.Looper; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 44 | import android.os.Parcelable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 45 | import android.os.Process; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 46 | import android.os.RemoteException; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 47 | import android.os.SystemClock; |
Chris Wren | c3919c0 | 2013-09-18 09:48:33 -0400 | [diff] [blame] | 48 | import android.provider.BaseColumns; |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 49 | import android.text.TextUtils; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 50 | import android.util.Log; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 51 | import android.util.LongSparseArray; |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 52 | import android.util.Pair; |
Michael Jurka | 34c2e6c | 2013-12-13 16:07:45 +0100 | [diff] [blame] | 53 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 54 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 55 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 56 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 57 | import com.android.launcher3.compat.PackageInstallerCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 58 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 59 | import com.android.launcher3.compat.UserHandleCompat; |
| 60 | import com.android.launcher3.compat.UserManagerCompat; |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 61 | import com.android.launcher3.util.ComponentKey; |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 62 | import com.android.launcher3.util.LongArrayMap; |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 63 | import com.android.launcher3.util.ManagedProfileHeuristic; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 64 | import com.android.launcher3.util.Thunk; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 65 | |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 66 | import java.lang.ref.WeakReference; |
| 67 | import java.net.URISyntaxException; |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 68 | import java.security.InvalidParameterException; |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 69 | import java.text.Collator; |
| 70 | import java.util.ArrayList; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 71 | import java.util.Arrays; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 72 | import java.util.Collection; |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 73 | import java.util.Collections; |
| 74 | import java.util.Comparator; |
| 75 | import java.util.HashMap; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 76 | import java.util.HashSet; |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 77 | import java.util.Iterator; |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 78 | import java.util.List; |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 79 | import java.util.Map.Entry; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 80 | import java.util.Set; |
Michael Jurka | c2f801e | 2011-07-12 14:19:46 -0700 | [diff] [blame] | 81 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 82 | /** |
| 83 | * Maintains in-memory state of the Launcher. It is expected that there should be only one |
| 84 | * 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] | 85 | * for the Launcher. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 86 | */ |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 87 | public class LauncherModel extends BroadcastReceiver |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 88 | implements LauncherAppsCompat.OnAppsChangedCallbackCompat { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 89 | static final boolean DEBUG_LOADERS = false; |
Chris Wren | ee52336 | 2014-09-09 10:09:02 -0400 | [diff] [blame] | 90 | private static final boolean DEBUG_RECEIVER = false; |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 91 | private static final boolean REMOVE_UNRESTORED_ICONS = true; |
Chris Wren | b358f81 | 2014-04-16 13:37:00 -0400 | [diff] [blame] | 92 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 93 | static final String TAG = "Launcher.Model"; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 94 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 95 | public static final int LOADER_FLAG_NONE = 0; |
| 96 | public static final int LOADER_FLAG_CLEAR_WORKSPACE = 1 << 0; |
| 97 | public static final int LOADER_FLAG_MIGRATE_SHORTCUTS = 1 << 1; |
| 98 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 99 | private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 100 | private static final long INVALID_SCREEN_ID = -1L; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 101 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 102 | @Thunk final boolean mAppsCanBeOnRemoveableStorage; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 103 | private final boolean mOldContentProviderExists; |
Daniel Sandler | dca6612 | 2010-04-13 16:23:58 -0400 | [diff] [blame] | 104 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 105 | @Thunk final LauncherAppState mApp; |
| 106 | @Thunk final Object mLock = new Object(); |
| 107 | @Thunk DeferredHandler mHandler = new DeferredHandler(); |
| 108 | @Thunk LoaderTask mLoaderTask; |
| 109 | @Thunk boolean mIsLoaderTaskRunning; |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 110 | @Thunk boolean mHasLoaderCompletedOnce; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 111 | |
Jason Monk | bbe1e24 | 2014-05-16 17:37:34 -0400 | [diff] [blame] | 112 | private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings"; |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 113 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 114 | @Thunk static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader"); |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 115 | static { |
| 116 | sWorkerThread.start(); |
| 117 | } |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 118 | @Thunk static final Handler sWorker = new Handler(sWorkerThread.getLooper()); |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 119 | |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 120 | // We start off with everything not loaded. After that, we assume that |
| 121 | // our monitoring of the package manager provides all updates and we never |
| 122 | // need to do a requery. These are only ever touched from the loader thread. |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 123 | @Thunk boolean mWorkspaceLoaded; |
| 124 | @Thunk boolean mAllAppsLoaded; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 125 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 126 | // When we are loading pages synchronously, we can't just post the binding of items on the side |
| 127 | // pages as this delays the rotation process. Instead, we wait for a callback from the first |
| 128 | // draw (in Workspace) to initiate the binding of the remaining side pages. Any time we start |
| 129 | // a normal load, we also clear this set of Runnables. |
| 130 | static final ArrayList<Runnable> mDeferredBindRunnables = new ArrayList<Runnable>(); |
| 131 | |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 132 | /** |
| 133 | * Set of runnables to be called on the background thread after the workspace binding |
| 134 | * is complete. |
| 135 | */ |
| 136 | static final ArrayList<Runnable> mBindCompleteRunnables = new ArrayList<Runnable>(); |
| 137 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 138 | @Thunk WeakReference<Callbacks> mCallbacks; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 139 | |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 140 | // < only access in worker thread > |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 141 | AllAppsList mBgAllAppsList; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 142 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 143 | // The lock that must be acquired before referencing any static bg data structures. Unlike |
| 144 | // other locks, this one can generally be held long-term because we never expect any of these |
| 145 | // static data structures to be referenced outside of the worker thread except on the first |
| 146 | // load after configuration change. |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 147 | static final Object sBgLock = new Object(); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 148 | |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 149 | // sBgItemsIdMap maps *all* the ItemInfos (shortcuts, folders, and widgets) created by |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 150 | // LauncherModel to their ids |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 151 | static final LongArrayMap<ItemInfo> sBgItemsIdMap = new LongArrayMap<>(); |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 152 | |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 153 | // sBgWorkspaceItems is passed to bindItems, which expects a list of all folders and shortcuts |
| 154 | // created by LauncherModel that are directly on the home screen (however, no widgets or |
| 155 | // shortcuts within folders). |
| 156 | static final ArrayList<ItemInfo> sBgWorkspaceItems = new ArrayList<ItemInfo>(); |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 157 | |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 158 | // sBgAppWidgets is all LauncherAppWidgetInfo created by LauncherModel. Passed to bindAppWidget() |
| 159 | static final ArrayList<LauncherAppWidgetInfo> sBgAppWidgets = |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 160 | new ArrayList<LauncherAppWidgetInfo>(); |
| 161 | |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 162 | // sBgFolders is all FolderInfos created by LauncherModel. Passed to bindFolders() |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 163 | static final LongArrayMap<FolderInfo> sBgFolders = new LongArrayMap<>(); |
Winson Chung | b1094bd | 2011-08-24 16:14:08 -0700 | [diff] [blame] | 164 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 165 | // sBgWorkspaceScreens is the ordered set of workspace screens. |
| 166 | static final ArrayList<Long> sBgWorkspaceScreens = new ArrayList<Long>(); |
| 167 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 168 | // sBgWidgetProviders is the set of widget providers including custom internal widgets |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 169 | public static HashMap<ComponentKey, LauncherAppWidgetProviderInfo> sBgWidgetProviders; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 170 | |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 171 | // sPendingPackages is a set of packages which could be on sdcard and are not available yet |
Sameer Padala | 513edae | 2014-07-29 16:17:08 -0700 | [diff] [blame] | 172 | static final HashMap<UserHandleCompat, HashSet<String>> sPendingPackages = |
| 173 | new HashMap<UserHandleCompat, HashSet<String>>(); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 174 | |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 175 | // </ only access in worker thread > |
| 176 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 177 | @Thunk IconCache mIconCache; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 178 | |
Reena Lee | 99a73f3 | 2011-10-24 17:27:37 -0700 | [diff] [blame] | 179 | protected int mPreviousConfigMcc; |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 180 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 181 | @Thunk final LauncherAppsCompat mLauncherApps; |
| 182 | @Thunk final UserManagerCompat mUserManager; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 183 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 184 | public interface Callbacks { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 185 | public boolean setLoadOnResume(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 186 | public int getCurrentWorkspaceScreen(); |
| 187 | public void startBinding(); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 188 | public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end, |
| 189 | boolean forceAnimateIcons); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 190 | public void bindScreens(ArrayList<Long> orderedScreenIds); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 191 | public void bindAddScreens(ArrayList<Long> orderedScreenIds); |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 192 | public void bindFolders(LongArrayMap<FolderInfo> folders); |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 193 | public void finishBindingItems(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 194 | public void bindAppWidget(LauncherAppWidgetInfo info); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 195 | public void bindAllApplications(ArrayList<AppInfo> apps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 196 | public void bindAppsAdded(ArrayList<Long> newScreens, |
| 197 | ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 198 | ArrayList<ItemInfo> addAnimated, |
| 199 | ArrayList<AppInfo> addedApps); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 200 | public void bindAppsUpdated(ArrayList<AppInfo> apps); |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 201 | public void bindShortcutsChanged(ArrayList<ShortcutInfo> updated, |
| 202 | ArrayList<ShortcutInfo> removed, UserHandleCompat user); |
| 203 | public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets); |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 204 | public void bindRestoreItemsChange(HashSet<ItemInfo> updates); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 205 | public void bindComponentsRemoved(ArrayList<String> packageNames, |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 206 | ArrayList<AppInfo> appInfos, UserHandleCompat user, int reason); |
Hyunyoung Song | 8821ca9 | 2015-05-04 16:28:20 -0700 | [diff] [blame] | 207 | public void bindAllPackages(ArrayList<Object> widgetsAndShortcuts); |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 208 | public void bindSearchablesChanged(); |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 209 | public boolean isAllAppsButtonRank(int rank); |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 210 | public void onPageBoundSynchronously(int page); |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 211 | public void dumpLogsToLocalData(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 212 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 213 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 214 | public interface ItemInfoFilter { |
| 215 | public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn); |
| 216 | } |
| 217 | |
Bjorn Bringert | 1307f63 | 2013-10-03 22:31:03 +0100 | [diff] [blame] | 218 | LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 219 | Context context = app.getContext(); |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 220 | |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 221 | mAppsCanBeOnRemoveableStorage = Environment.isExternalStorageRemovable(); |
Adam Cohen | 71483f4 | 2014-05-15 14:04:01 -0700 | [diff] [blame] | 222 | String oldProvider = context.getString(R.string.old_launcher_provider_uri); |
Jason Monk | bbe1e24 | 2014-05-16 17:37:34 -0400 | [diff] [blame] | 223 | // This may be the same as MIGRATE_AUTHORITY, or it may be replaced by a different |
| 224 | // resource string. |
| 225 | String redirectAuthority = Uri.parse(oldProvider).getAuthority(); |
| 226 | ProviderInfo providerInfo = |
| 227 | context.getPackageManager().resolveContentProvider(MIGRATE_AUTHORITY, 0); |
| 228 | ProviderInfo redirectProvider = |
| 229 | context.getPackageManager().resolveContentProvider(redirectAuthority, 0); |
Adam Cohen | 71483f4 | 2014-05-15 14:04:01 -0700 | [diff] [blame] | 230 | |
| 231 | Log.d(TAG, "Old launcher provider: " + oldProvider); |
Jason Monk | bbe1e24 | 2014-05-16 17:37:34 -0400 | [diff] [blame] | 232 | mOldContentProviderExists = (providerInfo != null) && (redirectProvider != null); |
Adam Cohen | 71483f4 | 2014-05-15 14:04:01 -0700 | [diff] [blame] | 233 | |
| 234 | if (mOldContentProviderExists) { |
| 235 | Log.d(TAG, "Old launcher provider exists."); |
| 236 | } else { |
| 237 | Log.d(TAG, "Old launcher provider does not exist."); |
| 238 | } |
| 239 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 240 | mApp = app; |
Bjorn Bringert | 1307f63 | 2013-10-03 22:31:03 +0100 | [diff] [blame] | 241 | mBgAllAppsList = new AllAppsList(iconCache, appFilter); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 242 | mIconCache = iconCache; |
| 243 | |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 244 | final Resources res = context.getResources(); |
Reena Lee | 99a73f3 | 2011-10-24 17:27:37 -0700 | [diff] [blame] | 245 | Configuration config = res.getConfiguration(); |
| 246 | mPreviousConfigMcc = config.mcc; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 247 | mLauncherApps = LauncherAppsCompat.getInstance(context); |
| 248 | mUserManager = UserManagerCompat.getInstance(context); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 251 | /** Runs the specified runnable immediately if called from the main thread, otherwise it is |
| 252 | * posted on the main thread handler. */ |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 253 | @Thunk void runOnMainThread(Runnable r) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 254 | if (sWorkerThread.getThreadId() == Process.myTid()) { |
| 255 | // If we are on the worker thread, post onto the main handler |
| 256 | mHandler.post(r); |
| 257 | } else { |
| 258 | r.run(); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /** Runs the specified runnable immediately if called from the worker thread, otherwise it is |
| 263 | * posted on the worker thread handler. */ |
| 264 | private static void runOnWorkerThread(Runnable r) { |
| 265 | if (sWorkerThread.getThreadId() == Process.myTid()) { |
| 266 | r.run(); |
| 267 | } else { |
| 268 | // If we are not on the worker thread, then post to the worker handler |
| 269 | sWorker.post(r); |
| 270 | } |
| 271 | } |
| 272 | |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 273 | /** |
| 274 | * Runs the specified runnable after the loader is complete |
| 275 | */ |
| 276 | private void runAfterBindCompletes(Runnable r) { |
| 277 | if (isLoadingWorkspace() || !mHasLoaderCompletedOnce) { |
| 278 | synchronized (mBindCompleteRunnables) { |
| 279 | mBindCompleteRunnables.add(r); |
| 280 | } |
| 281 | } else { |
| 282 | runOnWorkerThread(r); |
| 283 | } |
| 284 | } |
| 285 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 286 | boolean canMigrateFromOldLauncherDb(Launcher launcher) { |
| 287 | return mOldContentProviderExists && !launcher.isLauncherPreinstalled() ; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 288 | } |
| 289 | |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 290 | public void setPackageState(final PackageInstallInfo installInfo) { |
| 291 | Runnable updateRunnable = new Runnable() { |
| 292 | |
| 293 | @Override |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 294 | public void run() { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 295 | synchronized (sBgLock) { |
| 296 | final HashSet<ItemInfo> updates = new HashSet<>(); |
| 297 | |
| 298 | if (installInfo.state == PackageInstallerCompat.STATUS_INSTALLED) { |
| 299 | // Ignore install success events as they are handled by Package add events. |
| 300 | return; |
| 301 | } |
| 302 | |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 303 | for (ItemInfo info : sBgItemsIdMap) { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 304 | if (info instanceof ShortcutInfo) { |
| 305 | ShortcutInfo si = (ShortcutInfo) info; |
| 306 | ComponentName cn = si.getTargetComponent(); |
| 307 | if (si.isPromise() && (cn != null) |
| 308 | && installInfo.packageName.equals(cn.getPackageName())) { |
| 309 | si.setInstallProgress(installInfo.progress); |
| 310 | |
| 311 | if (installInfo.state == PackageInstallerCompat.STATUS_FAILED) { |
| 312 | // Mark this info as broken. |
| 313 | si.status &= ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE; |
| 314 | } |
| 315 | updates.add(si); |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | for (LauncherAppWidgetInfo widget : sBgAppWidgets) { |
| 321 | if (widget.providerName.getPackageName().equals(installInfo.packageName)) { |
| 322 | widget.installProgress = installInfo.progress; |
| 323 | updates.add(widget); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | if (!updates.isEmpty()) { |
| 328 | // Push changes to the callback. |
| 329 | Runnable r = new Runnable() { |
| 330 | public void run() { |
| 331 | Callbacks callbacks = getCallback(); |
| 332 | if (callbacks != null) { |
| 333 | callbacks.bindRestoreItemsChange(updates); |
| 334 | } |
| 335 | } |
| 336 | }; |
| 337 | mHandler.post(r); |
| 338 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | }; |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 342 | runOnWorkerThread(updateRunnable); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 343 | } |
| 344 | |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 345 | /** |
| 346 | * Updates the icons and label of all pending icons for the provided package name. |
| 347 | */ |
| 348 | public void updateSessionDisplayInfo(final String packageName) { |
| 349 | Runnable updateRunnable = new Runnable() { |
| 350 | |
| 351 | @Override |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 352 | public void run() { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 353 | synchronized (sBgLock) { |
| 354 | final ArrayList<ShortcutInfo> updates = new ArrayList<>(); |
| 355 | final UserHandleCompat user = UserHandleCompat.myUserHandle(); |
| 356 | |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 357 | for (ItemInfo info : sBgItemsIdMap) { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 358 | if (info instanceof ShortcutInfo) { |
| 359 | ShortcutInfo si = (ShortcutInfo) info; |
| 360 | ComponentName cn = si.getTargetComponent(); |
| 361 | if (si.isPromise() && (cn != null) |
| 362 | && packageName.equals(cn.getPackageName())) { |
| 363 | if (si.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) { |
| 364 | // For auto install apps update the icon as well as label. |
| 365 | mIconCache.getTitleAndIcon(si, |
| 366 | si.promisedIntent, user, |
| 367 | si.shouldUseLowResIcon()); |
| 368 | } else { |
| 369 | // Only update the icon for restored apps. |
| 370 | si.updateIcon(mIconCache); |
| 371 | } |
| 372 | updates.add(si); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | if (!updates.isEmpty()) { |
| 378 | // Push changes to the callback. |
| 379 | Runnable r = new Runnable() { |
| 380 | public void run() { |
| 381 | Callbacks callbacks = getCallback(); |
| 382 | if (callbacks != null) { |
| 383 | callbacks.bindShortcutsChanged(updates, |
| 384 | new ArrayList<ShortcutInfo>(), user); |
| 385 | } |
| 386 | } |
| 387 | }; |
| 388 | mHandler.post(r); |
| 389 | } |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | }; |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 393 | runOnWorkerThread(updateRunnable); |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 396 | public void addAppsToAllApps(final Context ctx, final ArrayList<AppInfo> allAppsApps) { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 397 | final Callbacks callbacks = getCallback(); |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 398 | |
| 399 | if (allAppsApps == null) { |
| 400 | throw new RuntimeException("allAppsApps must not be null"); |
| 401 | } |
| 402 | if (allAppsApps.isEmpty()) { |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | // Process the newly added applications and add them to the database first |
| 407 | Runnable r = new Runnable() { |
| 408 | public void run() { |
| 409 | runOnMainThread(new Runnable() { |
| 410 | public void run() { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 411 | Callbacks cb = getCallback(); |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 412 | if (callbacks == cb && cb != null) { |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 413 | callbacks.bindAppsAdded(null, null, null, allAppsApps); |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | }); |
| 417 | } |
| 418 | }; |
| 419 | runOnWorkerThread(r); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 420 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 421 | |
Sunny Goyal | a911672 | 2015-04-29 13:55:58 -0700 | [diff] [blame] | 422 | private static boolean findNextAvailableIconSpaceInScreen(ArrayList<ItemInfo> occupiedPos, |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 423 | int[] xy, int spanX, int spanY) { |
| 424 | LauncherAppState app = LauncherAppState.getInstance(); |
| 425 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 426 | final int xCount = (int) grid.numColumns; |
| 427 | final int yCount = (int) grid.numRows; |
| 428 | boolean[][] occupied = new boolean[xCount][yCount]; |
| 429 | if (occupiedPos != null) { |
Sunny Goyal | a911672 | 2015-04-29 13:55:58 -0700 | [diff] [blame] | 430 | for (ItemInfo r : occupiedPos) { |
| 431 | int right = r.cellX + r.spanX; |
| 432 | int bottom = r.cellY + r.spanY; |
| 433 | for (int x = r.cellX; 0 <= x && x < right && x < xCount; x++) { |
| 434 | for (int y = r.cellY; 0 <= y && y < bottom && y < yCount; y++) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 435 | occupied[x][y] = true; |
| 436 | } |
| 437 | } |
| 438 | } |
Winson Chung | fe9d96a | 2013-11-14 11:30:05 -0800 | [diff] [blame] | 439 | } |
Sunny Goyal | f7a29e8 | 2015-04-24 15:20:43 -0700 | [diff] [blame] | 440 | return Utilities.findVacantCell(xy, spanX, spanY, xCount, yCount, occupied); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Find a position on the screen for the given size or adds a new screen. |
| 445 | * @return screenId and the coordinates for the item. |
| 446 | */ |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 447 | @Thunk Pair<Long, int[]> findSpaceForItem( |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 448 | Context context, |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 449 | ArrayList<Long> workspaceScreens, |
| 450 | ArrayList<Long> addedWorkspaceScreensFinal, |
| 451 | int spanX, int spanY) { |
Sunny Goyal | a911672 | 2015-04-29 13:55:58 -0700 | [diff] [blame] | 452 | LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>(); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 453 | |
Sunny Goyal | a911672 | 2015-04-29 13:55:58 -0700 | [diff] [blame] | 454 | // Use sBgItemsIdMap as all the items are already loaded. |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 455 | assertWorkspaceLoaded(); |
Sunny Goyal | a911672 | 2015-04-29 13:55:58 -0700 | [diff] [blame] | 456 | synchronized (sBgLock) { |
| 457 | for (ItemInfo info : sBgItemsIdMap) { |
| 458 | if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 459 | ArrayList<ItemInfo> items = screenItems.get(info.screenId); |
| 460 | if (items == null) { |
| 461 | items = new ArrayList<>(); |
| 462 | screenItems.put(info.screenId, items); |
| 463 | } |
| 464 | items.add(info); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 465 | } |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 466 | } |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | // Find appropriate space for the item. |
| 470 | long screenId = 0; |
| 471 | int[] cordinates = new int[2]; |
| 472 | boolean found = false; |
| 473 | |
| 474 | int screenCount = workspaceScreens.size(); |
| 475 | // First check the preferred screen. |
Sunny Goyal | a911672 | 2015-04-29 13:55:58 -0700 | [diff] [blame] | 476 | int preferredScreenIndex = workspaceScreens.isEmpty() ? 0 : 1; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 477 | if (preferredScreenIndex < screenCount) { |
| 478 | screenId = workspaceScreens.get(preferredScreenIndex); |
| 479 | found = findNextAvailableIconSpaceInScreen( |
| 480 | screenItems.get(screenId), cordinates, spanX, spanY); |
| 481 | } |
| 482 | |
| 483 | if (!found) { |
Sunny Goyal | a911672 | 2015-04-29 13:55:58 -0700 | [diff] [blame] | 484 | // Search on any of the screens starting from the first screen. |
| 485 | for (int screen = 1; screen < screenCount; screen++) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 486 | screenId = workspaceScreens.get(screen); |
| 487 | if (findNextAvailableIconSpaceInScreen( |
| 488 | screenItems.get(screenId), cordinates, spanX, spanY)) { |
| 489 | // We found a space for it |
| 490 | found = true; |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | if (!found) { |
| 497 | // Still no position found. Add a new screen to the end. |
| 498 | screenId = LauncherAppState.getLauncherProvider().generateNewScreenId(); |
| 499 | |
| 500 | // Save the screen id for binding in the workspace |
| 501 | workspaceScreens.add(screenId); |
| 502 | addedWorkspaceScreensFinal.add(screenId); |
| 503 | |
| 504 | // If we still can't find an empty space, then God help us all!!! |
| 505 | if (!findNextAvailableIconSpaceInScreen( |
| 506 | screenItems.get(screenId), cordinates, spanX, spanY)) { |
| 507 | throw new RuntimeException("Can't find space to add the item"); |
| 508 | } |
| 509 | } |
| 510 | return Pair.create(screenId, cordinates); |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Adds the provided items to the workspace. |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 515 | */ |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 516 | public void addAndBindAddedWorkspaceItems(final Context context, |
Sunny Goyal | a214a63 | 2015-05-06 12:23:34 -0700 | [diff] [blame] | 517 | final ArrayList<? extends ItemInfo> workspaceApps) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 518 | final Callbacks callbacks = getCallback(); |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 519 | if (workspaceApps.isEmpty()) { |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 520 | return; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 521 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 522 | // Process the newly added applications and add them to the database first |
| 523 | Runnable r = new Runnable() { |
| 524 | public void run() { |
| 525 | final ArrayList<ItemInfo> addedShortcutsFinal = new ArrayList<ItemInfo>(); |
| 526 | final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<Long>(); |
| 527 | |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 528 | // Get the list of workspace screens. We need to append to this list and |
| 529 | // can not use sBgWorkspaceScreens because loadWorkspace() may not have been |
| 530 | // called. |
Sunny Goyal | c1b7c2e | 2015-01-16 16:19:04 -0800 | [diff] [blame] | 531 | ArrayList<Long> workspaceScreens = loadWorkspaceScreensDb(context); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 532 | synchronized(sBgLock) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 533 | for (ItemInfo item : workspaceApps) { |
Sunny Goyal | a911672 | 2015-04-29 13:55:58 -0700 | [diff] [blame] | 534 | if (item instanceof ShortcutInfo) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 535 | // Short-circuit this logic if the icon exists somewhere on the workspace |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 536 | if (shortcutExists(context, item.getIntent(), item.user)) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 537 | continue; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 538 | } |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 539 | } |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 540 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 541 | // Find appropriate space for the item. |
Sunny Goyal | a911672 | 2015-04-29 13:55:58 -0700 | [diff] [blame] | 542 | Pair<Long, int[]> coords = findSpaceForItem(context, |
| 543 | workspaceScreens, addedWorkspaceScreensFinal, |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 544 | 1, 1); |
| 545 | long screenId = coords.first; |
| 546 | int[] cordinates = coords.second; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 547 | |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 548 | ItemInfo itemInfo; |
| 549 | if (item instanceof ShortcutInfo || item instanceof FolderInfo) { |
| 550 | itemInfo = item; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 551 | } else if (item instanceof AppInfo) { |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 552 | itemInfo = ((AppInfo) item).makeShortcut(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 553 | } else { |
| 554 | throw new RuntimeException("Unexpected info type"); |
| 555 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 556 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 557 | // Add the shortcut to the db |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 558 | addItemToDatabase(context, itemInfo, |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 559 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 560 | screenId, cordinates[0], cordinates[1]); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 561 | // Save the ShortcutInfo for binding in the workspace |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 562 | addedShortcutsFinal.add(itemInfo); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 566 | // Update the workspace screens |
| 567 | updateWorkspaceScreenOrder(context, workspaceScreens); |
| 568 | |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 569 | if (!addedShortcutsFinal.isEmpty()) { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 570 | runOnMainThread(new Runnable() { |
| 571 | public void run() { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 572 | Callbacks cb = getCallback(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 573 | if (callbacks == cb && cb != null) { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 574 | final ArrayList<ItemInfo> addAnimated = new ArrayList<ItemInfo>(); |
| 575 | final ArrayList<ItemInfo> addNotAnimated = new ArrayList<ItemInfo>(); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 576 | if (!addedShortcutsFinal.isEmpty()) { |
| 577 | ItemInfo info = addedShortcutsFinal.get(addedShortcutsFinal.size() - 1); |
| 578 | long lastScreenId = info.screenId; |
| 579 | for (ItemInfo i : addedShortcutsFinal) { |
| 580 | if (i.screenId == lastScreenId) { |
| 581 | addAnimated.add(i); |
| 582 | } else { |
| 583 | addNotAnimated.add(i); |
| 584 | } |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 585 | } |
| 586 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 587 | callbacks.bindAppsAdded(addedWorkspaceScreensFinal, |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 588 | addNotAnimated, addAnimated, null); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 589 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 590 | } |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 591 | }); |
| 592 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 593 | } |
| 594 | }; |
| 595 | runOnWorkerThread(r); |
| 596 | } |
| 597 | |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 598 | private void unbindItemInfosAndClearQueuedBindRunnables() { |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 599 | if (sWorkerThread.getThreadId() == Process.myTid()) { |
| 600 | throw new RuntimeException("Expected unbindLauncherItemInfos() to be called from the " + |
| 601 | "main thread"); |
| 602 | } |
| 603 | |
| 604 | // Clear any deferred bind runnables |
Jason Monk | a0a7a74 | 2014-04-22 09:23:19 -0400 | [diff] [blame] | 605 | synchronized (mDeferredBindRunnables) { |
| 606 | mDeferredBindRunnables.clear(); |
| 607 | } |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 608 | |
| 609 | // Remove any queued UI runnables |
| 610 | mHandler.cancelAll(); |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 611 | // Unbind all the workspace items |
| 612 | unbindWorkspaceItemsOnMainThread(); |
Winson Chung | 603bcb9 | 2011-09-02 11:45:39 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 615 | /** Unbinds all the sBgWorkspaceItems and sBgAppWidgets on the main thread */ |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 616 | void unbindWorkspaceItemsOnMainThread() { |
Winson Chung | 603bcb9 | 2011-09-02 11:45:39 -0700 | [diff] [blame] | 617 | // Ensure that we don't use the same workspace items data structure on the main thread |
| 618 | // by making a copy of workspace items first. |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 619 | final ArrayList<ItemInfo> tmpItems = new ArrayList<ItemInfo>(); |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 620 | synchronized (sBgLock) { |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 621 | tmpItems.addAll(sBgWorkspaceItems); |
| 622 | tmpItems.addAll(sBgAppWidgets); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 623 | } |
| 624 | Runnable r = new Runnable() { |
| 625 | @Override |
| 626 | public void run() { |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 627 | for (ItemInfo item : tmpItems) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 628 | item.unbind(); |
| 629 | } |
| 630 | } |
| 631 | }; |
| 632 | runOnMainThread(r); |
Adam Cohen | 4eac29a | 2011-07-11 17:53:37 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 635 | /** |
| 636 | * Adds an item to the DB if it was not created previously, or move it to a new |
| 637 | * <container, screen, cellX, cellY> |
| 638 | */ |
| 639 | static void addOrMoveItemInDatabase(Context context, ItemInfo item, long container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 640 | long screenId, int cellX, int cellY) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 641 | if (item.container == ItemInfo.NO_ID) { |
| 642 | // From all apps |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 643 | addItemToDatabase(context, item, container, screenId, cellX, cellY); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 644 | } else { |
| 645 | // From somewhere else |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 646 | moveItemInDatabase(context, item, container, screenId, cellX, cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 650 | static void checkItemInfoLocked( |
| 651 | final long itemId, final ItemInfo item, StackTraceElement[] stackTrace) { |
| 652 | ItemInfo modelItem = sBgItemsIdMap.get(itemId); |
| 653 | if (modelItem != null && item != modelItem) { |
| 654 | // check all the data is consistent |
| 655 | if (modelItem instanceof ShortcutInfo && item instanceof ShortcutInfo) { |
| 656 | ShortcutInfo modelShortcut = (ShortcutInfo) modelItem; |
| 657 | ShortcutInfo shortcut = (ShortcutInfo) item; |
| 658 | if (modelShortcut.title.toString().equals(shortcut.title.toString()) && |
| 659 | modelShortcut.intent.filterEquals(shortcut.intent) && |
| 660 | modelShortcut.id == shortcut.id && |
| 661 | modelShortcut.itemType == shortcut.itemType && |
| 662 | modelShortcut.container == shortcut.container && |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 663 | modelShortcut.screenId == shortcut.screenId && |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 664 | modelShortcut.cellX == shortcut.cellX && |
| 665 | modelShortcut.cellY == shortcut.cellY && |
| 666 | modelShortcut.spanX == shortcut.spanX && |
| 667 | modelShortcut.spanY == shortcut.spanY && |
| 668 | ((modelShortcut.dropPos == null && shortcut.dropPos == null) || |
| 669 | (modelShortcut.dropPos != null && |
| 670 | shortcut.dropPos != null && |
| 671 | modelShortcut.dropPos[0] == shortcut.dropPos[0] && |
| 672 | modelShortcut.dropPos[1] == shortcut.dropPos[1]))) { |
| 673 | // For all intents and purposes, this is the same object |
| 674 | return; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | // the modelItem needs to match up perfectly with item if our model is |
| 679 | // to be consistent with the database-- for now, just require |
| 680 | // modelItem == item or the equality check above |
| 681 | String msg = "item: " + ((item != null) ? item.toString() : "null") + |
| 682 | "modelItem: " + |
| 683 | ((modelItem != null) ? modelItem.toString() : "null") + |
| 684 | "Error: ItemInfo passed to checkItemInfo doesn't match original"; |
| 685 | RuntimeException e = new RuntimeException(msg); |
| 686 | if (stackTrace != null) { |
| 687 | e.setStackTrace(stackTrace); |
| 688 | } |
Adam Cohen | b9ada65 | 2013-11-08 08:25:08 -0800 | [diff] [blame] | 689 | throw e; |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Michael Jurka | 816474f | 2012-06-25 14:49:02 -0700 | [diff] [blame] | 693 | static void checkItemInfo(final ItemInfo item) { |
| 694 | final StackTraceElement[] stackTrace = new Throwable().getStackTrace(); |
| 695 | final long itemId = item.id; |
| 696 | Runnable r = new Runnable() { |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 697 | public void run() { |
| 698 | synchronized (sBgLock) { |
| 699 | checkItemInfoLocked(itemId, item, stackTrace); |
Michael Jurka | 816474f | 2012-06-25 14:49:02 -0700 | [diff] [blame] | 700 | } |
Michael Jurka | b2ae8ac | 2012-09-21 12:06:06 -0700 | [diff] [blame] | 701 | } |
| 702 | }; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 703 | runOnWorkerThread(r); |
Michael Jurka | 816474f | 2012-06-25 14:49:02 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 706 | static void updateItemInDatabaseHelper(Context context, final ContentValues values, |
| 707 | final ItemInfo item, final String callingFunction) { |
| 708 | final long itemId = item.id; |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 709 | final Uri uri = LauncherSettings.Favorites.getContentUri(itemId); |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 710 | final ContentResolver cr = context.getContentResolver(); |
| 711 | |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 712 | final StackTraceElement[] stackTrace = new Throwable().getStackTrace(); |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 713 | Runnable r = new Runnable() { |
| 714 | public void run() { |
| 715 | cr.update(uri, values, null, null); |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 716 | updateItemArrays(item, itemId, stackTrace); |
| 717 | } |
| 718 | }; |
| 719 | runOnWorkerThread(r); |
| 720 | } |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 721 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 722 | static void updateItemsInDatabaseHelper(Context context, final ArrayList<ContentValues> valuesList, |
| 723 | final ArrayList<ItemInfo> items, final String callingFunction) { |
| 724 | final ContentResolver cr = context.getContentResolver(); |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 725 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 726 | final StackTraceElement[] stackTrace = new Throwable().getStackTrace(); |
| 727 | Runnable r = new Runnable() { |
| 728 | public void run() { |
| 729 | ArrayList<ContentProviderOperation> ops = |
| 730 | new ArrayList<ContentProviderOperation>(); |
| 731 | int count = items.size(); |
| 732 | for (int i = 0; i < count; i++) { |
| 733 | ItemInfo item = items.get(i); |
| 734 | final long itemId = item.id; |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 735 | final Uri uri = LauncherSettings.Favorites.getContentUri(itemId); |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 736 | ContentValues values = valuesList.get(i); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 737 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 738 | ops.add(ContentProviderOperation.newUpdate(uri).withValues(values).build()); |
| 739 | updateItemArrays(item, itemId, stackTrace); |
| 740 | |
| 741 | } |
| 742 | try { |
| 743 | cr.applyBatch(LauncherProvider.AUTHORITY, ops); |
| 744 | } catch (Exception e) { |
| 745 | e.printStackTrace(); |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | }; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 749 | runOnWorkerThread(r); |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 750 | } |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 751 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 752 | static void updateItemArrays(ItemInfo item, long itemId, StackTraceElement[] stackTrace) { |
| 753 | // Lock on mBgLock *after* the db operation |
| 754 | synchronized (sBgLock) { |
| 755 | checkItemInfoLocked(itemId, item, stackTrace); |
| 756 | |
| 757 | if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP && |
| 758 | item.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 759 | // Item is in a folder, make sure this folder exists |
| 760 | if (!sBgFolders.containsKey(item.container)) { |
| 761 | // An items container is being set to a that of an item which is not in |
| 762 | // the list of Folders. |
| 763 | String msg = "item: " + item + " container being set to: " + |
| 764 | item.container + ", not in the list of folders"; |
| 765 | Log.e(TAG, msg); |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
| 769 | // Items are added/removed from the corresponding FolderInfo elsewhere, such |
| 770 | // as in Workspace.onDrop. Here, we just add/remove them from the list of items |
| 771 | // that are on the desktop, as appropriate |
| 772 | ItemInfo modelItem = sBgItemsIdMap.get(itemId); |
Winson Chung | 33231f5 | 2013-12-09 16:57:45 -0800 | [diff] [blame] | 773 | if (modelItem != null && |
| 774 | (modelItem.container == LauncherSettings.Favorites.CONTAINER_DESKTOP || |
| 775 | modelItem.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT)) { |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 776 | switch (modelItem.itemType) { |
| 777 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 778 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 779 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
| 780 | if (!sBgWorkspaceItems.contains(modelItem)) { |
| 781 | sBgWorkspaceItems.add(modelItem); |
| 782 | } |
| 783 | break; |
| 784 | default: |
| 785 | break; |
| 786 | } |
| 787 | } else { |
| 788 | sBgWorkspaceItems.remove(modelItem); |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 793 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 794 | * Move an item in the DB to a new <container, screen, cellX, cellY> |
The Android Open Source Project | bc219c3 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 795 | */ |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 796 | static void moveItemInDatabase(Context context, final ItemInfo item, final long container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 797 | final long screenId, final int cellX, final int cellY) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 798 | item.container = container; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 799 | item.cellX = cellX; |
| 800 | item.cellY = cellY; |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 801 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 802 | // We store hotseat items in canonical form which is this orientation invariant position |
| 803 | // in the hotseat |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 804 | if (context instanceof Launcher && screenId < 0 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 805 | container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 806 | item.screenId = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 807 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 808 | item.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 809 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 810 | |
| 811 | final ContentValues values = new ContentValues(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 812 | values.put(LauncherSettings.Favorites.CONTAINER, item.container); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 813 | values.put(LauncherSettings.Favorites.CELLX, item.cellX); |
| 814 | values.put(LauncherSettings.Favorites.CELLY, item.cellY); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 815 | values.put(LauncherSettings.Favorites.RANK, item.rank); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 816 | values.put(LauncherSettings.Favorites.SCREEN, item.screenId); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 817 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 818 | updateItemInDatabaseHelper(context, values, item, "moveItemInDatabase"); |
The Android Open Source Project | bc219c3 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /** |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 822 | * Move items in the DB to a new <container, screen, cellX, cellY>. We assume that the |
| 823 | * cellX, cellY have already been updated on the ItemInfos. |
| 824 | */ |
| 825 | static void moveItemsInDatabase(Context context, final ArrayList<ItemInfo> items, |
| 826 | final long container, final int screen) { |
| 827 | |
| 828 | ArrayList<ContentValues> contentValues = new ArrayList<ContentValues>(); |
| 829 | int count = items.size(); |
| 830 | |
| 831 | for (int i = 0; i < count; i++) { |
| 832 | ItemInfo item = items.get(i); |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 833 | item.container = container; |
| 834 | |
| 835 | // We store hotseat items in canonical form which is this orientation invariant position |
| 836 | // in the hotseat |
| 837 | if (context instanceof Launcher && screen < 0 && |
| 838 | container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 839 | item.screenId = ((Launcher) context).getHotseat().getOrderInHotseat(item.cellX, |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 840 | item.cellY); |
| 841 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 842 | item.screenId = screen; |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | final ContentValues values = new ContentValues(); |
| 846 | values.put(LauncherSettings.Favorites.CONTAINER, item.container); |
| 847 | values.put(LauncherSettings.Favorites.CELLX, item.cellX); |
| 848 | values.put(LauncherSettings.Favorites.CELLY, item.cellY); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 849 | values.put(LauncherSettings.Favorites.RANK, item.rank); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 850 | values.put(LauncherSettings.Favorites.SCREEN, item.screenId); |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 851 | |
| 852 | contentValues.add(values); |
| 853 | } |
| 854 | updateItemsInDatabaseHelper(context, contentValues, items, "moveItemInDatabase"); |
| 855 | } |
| 856 | |
| 857 | /** |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 858 | * Move and/or resize item in the DB to a new <container, screen, cellX, cellY, spanX, spanY> |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 859 | */ |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 860 | static void modifyItemInDatabase(Context context, final ItemInfo item, final long container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 861 | final long screenId, final int cellX, final int cellY, final int spanX, final int spanY) { |
Winson Chung | 0f84a60 | 2013-09-30 14:30:58 -0700 | [diff] [blame] | 862 | item.container = container; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 863 | item.cellX = cellX; |
| 864 | item.cellY = cellY; |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 865 | item.spanX = spanX; |
| 866 | item.spanY = spanY; |
| 867 | |
| 868 | // We store hotseat items in canonical form which is this orientation invariant position |
| 869 | // in the hotseat |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 870 | if (context instanceof Launcher && screenId < 0 && |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 871 | container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 872 | item.screenId = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 873 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 874 | item.screenId = screenId; |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 875 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 876 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 877 | final ContentValues values = new ContentValues(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 878 | values.put(LauncherSettings.Favorites.CONTAINER, item.container); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 879 | values.put(LauncherSettings.Favorites.CELLX, item.cellX); |
| 880 | values.put(LauncherSettings.Favorites.CELLY, item.cellY); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 881 | values.put(LauncherSettings.Favorites.RANK, item.rank); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 882 | values.put(LauncherSettings.Favorites.SPANX, item.spanX); |
| 883 | values.put(LauncherSettings.Favorites.SPANY, item.spanY); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 884 | values.put(LauncherSettings.Favorites.SCREEN, item.screenId); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 885 | |
Michael Jurka | 816474f | 2012-06-25 14:49:02 -0700 | [diff] [blame] | 886 | updateItemInDatabaseHelper(context, values, item, "modifyItemInDatabase"); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 887 | } |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 888 | |
| 889 | /** |
| 890 | * Update an item to the database in a specified container. |
| 891 | */ |
| 892 | static void updateItemInDatabase(Context context, final ItemInfo item) { |
| 893 | final ContentValues values = new ContentValues(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 894 | item.onAddToDatabase(context, values); |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 895 | updateItemInDatabaseHelper(context, values, item, "updateItemInDatabase"); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 896 | } |
| 897 | |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 898 | private void assertWorkspaceLoaded() { |
| 899 | if (LauncherAppState.isDogfoodBuild() && (isLoadingWorkspace() || !mHasLoaderCompletedOnce)) { |
| 900 | throw new RuntimeException("Trying to add shortcut while loader is running"); |
| 901 | } |
| 902 | } |
| 903 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 904 | /** |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 905 | * Returns true if the shortcuts already exists on the workspace. This must be called after |
| 906 | * the workspace has been loaded. We identify a shortcut by its intent. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 907 | */ |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 908 | @Thunk boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) { |
| 909 | assertWorkspaceLoaded(); |
Sunny Goyal | dfde999 | 2015-05-01 12:31:32 -0700 | [diff] [blame] | 910 | final String intentWithPkg, intentWithoutPkg; |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 911 | final String packageName; |
Sunny Goyal | 2a6cf09 | 2014-06-26 15:27:14 -0700 | [diff] [blame] | 912 | if (intent.getComponent() != null) { |
| 913 | // If component is not null, an intent with null package will produce |
| 914 | // the same result and should also be a match. |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 915 | packageName = intent.getComponent().getPackageName(); |
Sunny Goyal | 2a6cf09 | 2014-06-26 15:27:14 -0700 | [diff] [blame] | 916 | if (intent.getPackage() != null) { |
Sunny Goyal | dfde999 | 2015-05-01 12:31:32 -0700 | [diff] [blame] | 917 | intentWithPkg = intent.toUri(0); |
| 918 | intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0); |
Sunny Goyal | 2a6cf09 | 2014-06-26 15:27:14 -0700 | [diff] [blame] | 919 | } else { |
Sunny Goyal | dfde999 | 2015-05-01 12:31:32 -0700 | [diff] [blame] | 920 | intentWithPkg = new Intent(intent).setPackage(packageName).toUri(0); |
| 921 | intentWithoutPkg = intent.toUri(0); |
Sunny Goyal | 2a6cf09 | 2014-06-26 15:27:14 -0700 | [diff] [blame] | 922 | } |
| 923 | } else { |
Sunny Goyal | dfde999 | 2015-05-01 12:31:32 -0700 | [diff] [blame] | 924 | intentWithPkg = intent.toUri(0); |
| 925 | intentWithoutPkg = intent.toUri(0); |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 926 | packageName = intent.getPackage(); |
Sunny Goyal | 2a6cf09 | 2014-06-26 15:27:14 -0700 | [diff] [blame] | 927 | } |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 928 | |
| 929 | synchronized (sBgLock) { |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 930 | for (ItemInfo item : sBgItemsIdMap) { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 931 | if (item instanceof ShortcutInfo) { |
| 932 | ShortcutInfo info = (ShortcutInfo) item; |
Sunny Goyal | dfde999 | 2015-05-01 12:31:32 -0700 | [diff] [blame] | 933 | if (info.getIntent() != null && info.user.equals(user)) { |
| 934 | String s = info.getIntent().toUri(0); |
| 935 | if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) { |
| 936 | return true; |
| 937 | } |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 941 | } |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 942 | return false; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 943 | } |
| 944 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 945 | /** |
| 946 | * Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList. |
| 947 | */ |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 948 | FolderInfo getFolderById(Context context, LongArrayMap<FolderInfo> folderList, long id) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 949 | final ContentResolver cr = context.getContentResolver(); |
| 950 | Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null, |
| 951 | "_id=? and (itemType=? or itemType=?)", |
| 952 | new String[] { String.valueOf(id), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 953 | String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)}, null); |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 954 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 955 | try { |
| 956 | if (c.moveToFirst()) { |
| 957 | final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE); |
| 958 | final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE); |
| 959 | final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER); |
| 960 | final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN); |
| 961 | final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX); |
| 962 | final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY); |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 963 | final int optionsIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.OPTIONS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 964 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 965 | FolderInfo folderInfo = null; |
| 966 | switch (c.getInt(itemTypeIndex)) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 967 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
| 968 | folderInfo = findOrMakeFolder(folderList, id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 969 | break; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 972 | folderInfo.title = Utilities.trim(c.getString(titleIndex)); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 973 | folderInfo.id = id; |
| 974 | folderInfo.container = c.getInt(containerIndex); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 975 | folderInfo.screenId = c.getInt(screenIndex); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 976 | folderInfo.cellX = c.getInt(cellXIndex); |
| 977 | folderInfo.cellY = c.getInt(cellYIndex); |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 978 | folderInfo.options = c.getInt(optionsIndex); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 979 | |
| 980 | return folderInfo; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 981 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 982 | } finally { |
| 983 | c.close(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | return null; |
| 987 | } |
| 988 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 989 | /** |
| 990 | * Add an item to the database in a specified container. Sets the container, screen, cellX and |
| 991 | * cellY fields of the item. Also assigns an ID to the item. |
| 992 | */ |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 993 | public static void addItemToDatabase(Context context, final ItemInfo item, final long container, |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 994 | final long screenId, final int cellX, final int cellY) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 995 | item.container = container; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 996 | item.cellX = cellX; |
| 997 | item.cellY = cellY; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 998 | // We store hotseat items in canonical form which is this orientation invariant position |
| 999 | // in the hotseat |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1000 | if (context instanceof Launcher && screenId < 0 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1001 | container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1002 | item.screenId = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1003 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1004 | item.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1005 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1006 | |
| 1007 | final ContentValues values = new ContentValues(); |
| 1008 | final ContentResolver cr = context.getContentResolver(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1009 | item.onAddToDatabase(context, values); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1010 | |
Michael Jurka | 414300a | 2013-08-27 15:42:35 +0200 | [diff] [blame] | 1011 | item.id = LauncherAppState.getLauncherProvider().generateNewItemId(); |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 1012 | values.put(LauncherSettings.Favorites._ID, item.id); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1013 | |
Jason Monk | 8e19cf2 | 2014-03-20 15:06:57 -0400 | [diff] [blame] | 1014 | final StackTraceElement[] stackTrace = new Throwable().getStackTrace(); |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1015 | Runnable r = new Runnable() { |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 1016 | public void run() { |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 1017 | cr.insert(LauncherSettings.Favorites.CONTENT_URI, values); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1018 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1019 | // Lock on mBgLock *after* the db operation |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 1020 | synchronized (sBgLock) { |
Jason Monk | 8e19cf2 | 2014-03-20 15:06:57 -0400 | [diff] [blame] | 1021 | checkItemInfoLocked(item.id, item, stackTrace); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1022 | sBgItemsIdMap.put(item.id, item); |
| 1023 | switch (item.itemType) { |
| 1024 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
| 1025 | sBgFolders.put(item.id, (FolderInfo) item); |
| 1026 | // Fall through |
| 1027 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 1028 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 1029 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP || |
| 1030 | item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 1031 | sBgWorkspaceItems.add(item); |
| 1032 | } else { |
| 1033 | if (!sBgFolders.containsKey(item.container)) { |
| 1034 | // Adding an item to a folder that doesn't exist. |
| 1035 | String msg = "adding item: " + item + " to a folder that " + |
| 1036 | " doesn't exist"; |
Adam Cohen | 28b3e10 | 2012-10-04 17:21:33 -0700 | [diff] [blame] | 1037 | Log.e(TAG, msg); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1038 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 1039 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1040 | break; |
| 1041 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
| 1042 | sBgAppWidgets.add((LauncherAppWidgetInfo) item); |
| 1043 | break; |
| 1044 | } |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 1045 | } |
| 1046 | } |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1047 | }; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1048 | runOnWorkerThread(r); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1051 | /** |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1052 | * Creates a new unique child id, for a given cell span across all layouts. |
| 1053 | */ |
Michael Jurka | 845ba3b | 2010-09-28 17:09:46 -0700 | [diff] [blame] | 1054 | static int getCellLayoutChildId( |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1055 | long container, long screen, int localCellX, int localCellY, int spanX, int spanY) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1056 | return (((int) container & 0xFF) << 24) |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1057 | | ((int) screen & 0xFF) << 16 | (localCellX & 0xFF) << 8 | (localCellY & 0xFF); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 1060 | private static ArrayList<ItemInfo> getItemsByPackageName( |
| 1061 | final String pn, final UserHandleCompat user) { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 1062 | ItemInfoFilter filter = new ItemInfoFilter() { |
| 1063 | @Override |
| 1064 | public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) { |
| 1065 | return cn.getPackageName().equals(pn) && info.user.equals(user); |
| 1066 | } |
| 1067 | }; |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 1068 | return filterItemInfos(sBgItemsIdMap, filter); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * Removes all the items from the database corresponding to the specified package. |
| 1073 | */ |
| 1074 | static void deletePackageFromDatabase(Context context, final String pn, |
| 1075 | final UserHandleCompat user) { |
| 1076 | deleteItemsFromDatabase(context, getItemsByPackageName(pn, user)); |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | /** |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1080 | * Removes the specified item from the database |
| 1081 | * @param context |
| 1082 | * @param item |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1083 | */ |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 1084 | public static void deleteItemFromDatabase(Context context, final ItemInfo item) { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 1085 | ArrayList<ItemInfo> items = new ArrayList<ItemInfo>(); |
| 1086 | items.add(item); |
| 1087 | deleteItemsFromDatabase(context, items); |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * Removes the specified items from the database |
| 1092 | * @param context |
| 1093 | * @param item |
| 1094 | */ |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 1095 | static void deleteItemsFromDatabase(Context context, final ArrayList<? extends ItemInfo> items) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1096 | final ContentResolver cr = context.getContentResolver(); |
Michael Jurka | 83df188 | 2011-08-31 20:59:26 -0700 | [diff] [blame] | 1097 | Runnable r = new Runnable() { |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 1098 | public void run() { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 1099 | for (ItemInfo item : items) { |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 1100 | final Uri uri = LauncherSettings.Favorites.getContentUri(item.id); |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 1101 | cr.delete(uri, null, null); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1102 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 1103 | // Lock on mBgLock *after* the db operation |
| 1104 | synchronized (sBgLock) { |
| 1105 | switch (item.itemType) { |
| 1106 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
| 1107 | sBgFolders.remove(item.id); |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 1108 | for (ItemInfo info: sBgItemsIdMap) { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 1109 | if (info.container == item.id) { |
| 1110 | // We are deleting a folder which still contains items that |
| 1111 | // think they are contained by that folder. |
| 1112 | String msg = "deleting a folder (" + item + ") which still " + |
| 1113 | "contains items (" + info + ")"; |
| 1114 | Log.e(TAG, msg); |
| 1115 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1116 | } |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 1117 | sBgWorkspaceItems.remove(item); |
| 1118 | break; |
| 1119 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 1120 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 1121 | sBgWorkspaceItems.remove(item); |
| 1122 | break; |
| 1123 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
| 1124 | sBgAppWidgets.remove((LauncherAppWidgetInfo) item); |
| 1125 | break; |
| 1126 | } |
| 1127 | sBgItemsIdMap.remove(item.id); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1128 | } |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 1129 | } |
| 1130 | } |
Michael Jurka | 83df188 | 2011-08-31 20:59:26 -0700 | [diff] [blame] | 1131 | }; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1132 | runOnWorkerThread(r); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | /** |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1136 | * Update the order of the workspace screens in the database. The array list contains |
| 1137 | * a list of screen ids in the order that they should appear. |
| 1138 | */ |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 1139 | void updateWorkspaceScreenOrder(Context context, final ArrayList<Long> screens) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 1140 | // Log to disk |
| 1141 | Launcher.addDumpLog(TAG, "11683562 - updateWorkspaceScreenOrder()", true); |
| 1142 | Launcher.addDumpLog(TAG, "11683562 - screens: " + TextUtils.join(", ", screens), true); |
| 1143 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 1144 | final ArrayList<Long> screensCopy = new ArrayList<Long>(screens); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1145 | final ContentResolver cr = context.getContentResolver(); |
| 1146 | final Uri uri = LauncherSettings.WorkspaceScreens.CONTENT_URI; |
| 1147 | |
| 1148 | // Remove any negative screen ids -- these aren't persisted |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 1149 | Iterator<Long> iter = screensCopy.iterator(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1150 | while (iter.hasNext()) { |
| 1151 | long id = iter.next(); |
| 1152 | if (id < 0) { |
| 1153 | iter.remove(); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | Runnable r = new Runnable() { |
| 1158 | @Override |
| 1159 | public void run() { |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 1160 | ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1161 | // Clear the table |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 1162 | ops.add(ContentProviderOperation.newDelete(uri).build()); |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 1163 | int count = screensCopy.size(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1164 | for (int i = 0; i < count; i++) { |
| 1165 | ContentValues v = new ContentValues(); |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 1166 | long screenId = screensCopy.get(i); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1167 | v.put(LauncherSettings.WorkspaceScreens._ID, screenId); |
| 1168 | v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i); |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 1169 | ops.add(ContentProviderOperation.newInsert(uri).withValues(v).build()); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1170 | } |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 1171 | |
| 1172 | try { |
| 1173 | cr.applyBatch(LauncherProvider.AUTHORITY, ops); |
| 1174 | } catch (Exception ex) { |
| 1175 | throw new RuntimeException(ex); |
| 1176 | } |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 1177 | |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 1178 | synchronized (sBgLock) { |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 1179 | sBgWorkspaceScreens.clear(); |
| 1180 | sBgWorkspaceScreens.addAll(screensCopy); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 1181 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1182 | } |
| 1183 | }; |
| 1184 | runOnWorkerThread(r); |
| 1185 | } |
| 1186 | |
| 1187 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1188 | * Remove the contents of the specified folder from the database |
| 1189 | */ |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 1190 | public static void deleteFolderContentsFromDatabase(Context context, final FolderInfo info) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1191 | final ContentResolver cr = context.getContentResolver(); |
| 1192 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1193 | Runnable r = new Runnable() { |
| 1194 | public void run() { |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 1195 | cr.delete(LauncherSettings.Favorites.getContentUri(info.id), null, null); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1196 | // Lock on mBgLock *after* the db operation |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 1197 | synchronized (sBgLock) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1198 | sBgItemsIdMap.remove(info.id); |
| 1199 | sBgFolders.remove(info.id); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1200 | sBgWorkspaceItems.remove(info); |
| 1201 | } |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 1202 | |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 1203 | cr.delete(LauncherSettings.Favorites.CONTENT_URI, |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1204 | LauncherSettings.Favorites.CONTAINER + "=" + info.id, null); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1205 | // Lock on mBgLock *after* the db operation |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 1206 | synchronized (sBgLock) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1207 | for (ItemInfo childInfo : info.contents) { |
| 1208 | sBgItemsIdMap.remove(childInfo.id); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1209 | } |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 1210 | } |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1211 | } |
| 1212 | }; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1213 | runOnWorkerThread(r); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * Set this as the current Launcher activity object for the loader. |
| 1218 | */ |
| 1219 | public void initialize(Callbacks callbacks) { |
| 1220 | synchronized (mLock) { |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 1221 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the |
| 1222 | // workspace to prevent leaking Launcher activities on orientation change. |
| 1223 | unbindItemInfosAndClearQueuedBindRunnables(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1224 | mCallbacks = new WeakReference<Callbacks>(callbacks); |
| 1225 | } |
| 1226 | } |
| 1227 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1228 | @Override |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 1229 | public void onPackageChanged(String packageName, UserHandleCompat user) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1230 | int op = PackageUpdatedTask.OP_UPDATE; |
| 1231 | enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packageName }, |
| 1232 | user)); |
| 1233 | } |
| 1234 | |
| 1235 | @Override |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 1236 | public void onPackageRemoved(String packageName, UserHandleCompat user) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1237 | int op = PackageUpdatedTask.OP_REMOVE; |
| 1238 | enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packageName }, |
| 1239 | user)); |
| 1240 | } |
| 1241 | |
| 1242 | @Override |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 1243 | public void onPackageAdded(String packageName, UserHandleCompat user) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1244 | int op = PackageUpdatedTask.OP_ADD; |
| 1245 | enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packageName }, |
| 1246 | user)); |
| 1247 | } |
| 1248 | |
| 1249 | @Override |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 1250 | public void onPackagesAvailable(String[] packageNames, UserHandleCompat user, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1251 | boolean replacing) { |
| 1252 | if (!replacing) { |
| 1253 | enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_ADD, packageNames, |
| 1254 | user)); |
| 1255 | if (mAppsCanBeOnRemoveableStorage) { |
| 1256 | // Only rebind if we support removable storage. It catches the |
| 1257 | // case where |
| 1258 | // apps on the external sd card need to be reloaded |
| 1259 | startLoaderFromBackground(); |
| 1260 | } |
| 1261 | } else { |
| 1262 | // If we are replacing then just update the packages in the list |
| 1263 | enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_UPDATE, |
| 1264 | packageNames, user)); |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | @Override |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 1269 | public void onPackagesUnavailable(String[] packageNames, UserHandleCompat user, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1270 | boolean replacing) { |
| 1271 | if (!replacing) { |
| 1272 | enqueuePackageUpdated(new PackageUpdatedTask( |
| 1273 | PackageUpdatedTask.OP_UNAVAILABLE, packageNames, |
| 1274 | user)); |
| 1275 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1276 | } |
| 1277 | |
Joe Onorato | 1d8e7bb | 2009-10-15 19:49:43 -0700 | [diff] [blame] | 1278 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1279 | * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and |
| 1280 | * ACTION_PACKAGE_CHANGED. |
| 1281 | */ |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 1282 | @Override |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 1283 | public void onReceive(Context context, Intent intent) { |
Chris Wren | b358f81 | 2014-04-16 13:37:00 -0400 | [diff] [blame] | 1284 | if (DEBUG_RECEIVER) Log.d(TAG, "onReceive intent=" + intent); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1285 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1286 | final String action = intent.getAction(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1287 | if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 1288 | // If we have changed locale we need to clear out the labels in all apps/workspace. |
| 1289 | forceReload(); |
| 1290 | } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { |
| 1291 | // Check if configuration change was an mcc/mnc change which would affect app resources |
| 1292 | // and we would need to clear out the labels in all apps/workspace. Same handling as |
| 1293 | // above for ACTION_LOCALE_CHANGED |
| 1294 | Configuration currentConfig = context.getResources().getConfiguration(); |
Reena Lee | 99a73f3 | 2011-10-24 17:27:37 -0700 | [diff] [blame] | 1295 | if (mPreviousConfigMcc != currentConfig.mcc) { |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 1296 | Log.d(TAG, "Reload apps on config change. curr_mcc:" |
Reena Lee | 99a73f3 | 2011-10-24 17:27:37 -0700 | [diff] [blame] | 1297 | + currentConfig.mcc + " prevmcc:" + mPreviousConfigMcc); |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 1298 | forceReload(); |
| 1299 | } |
| 1300 | // Update previousConfig |
Reena Lee | 99a73f3 | 2011-10-24 17:27:37 -0700 | [diff] [blame] | 1301 | mPreviousConfigMcc = currentConfig.mcc; |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 1302 | } else if (SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED.equals(action) || |
| 1303 | SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED.equals(action)) { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 1304 | Callbacks callbacks = getCallback(); |
| 1305 | if (callbacks != null) { |
| 1306 | callbacks.bindSearchablesChanged(); |
Winson Chung | cfdf7ee | 2011-08-25 11:38:34 -0700 | [diff] [blame] | 1307 | } |
Sunny Goyal | 957c13f | 2015-05-01 13:02:20 -0700 | [diff] [blame] | 1308 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1309 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1310 | forceReload(); |
Joe Onorato | e9ad59e | 2010-10-29 17:35:36 -0700 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1314 | void forceReload() { |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1315 | resetLoadedState(true, true); |
| 1316 | |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 1317 | // Do this here because if the launcher activity is running it will be restarted. |
| 1318 | // If it's not running startLoaderFromBackground will merely tell it that it needs |
| 1319 | // to reload. |
| 1320 | startLoaderFromBackground(); |
| 1321 | } |
| 1322 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1323 | public void resetLoadedState(boolean resetAllAppsLoaded, boolean resetWorkspaceLoaded) { |
| 1324 | synchronized (mLock) { |
| 1325 | // Stop any existing loaders first, so they don't set mAllAppsLoaded or |
| 1326 | // mWorkspaceLoaded to true later |
| 1327 | stopLoaderLocked(); |
| 1328 | if (resetAllAppsLoaded) mAllAppsLoaded = false; |
| 1329 | if (resetWorkspaceLoaded) mWorkspaceLoaded = false; |
| 1330 | } |
| 1331 | } |
| 1332 | |
Joe Onorato | e9ad59e | 2010-10-29 17:35:36 -0700 | [diff] [blame] | 1333 | /** |
| 1334 | * When the launcher is in the background, it's possible for it to miss paired |
| 1335 | * configuration changes. So whenever we trigger the loader from the background |
| 1336 | * tell the launcher that it needs to re-run the loader when it comes back instead |
| 1337 | * of doing it now. |
| 1338 | */ |
| 1339 | public void startLoaderFromBackground() { |
| 1340 | boolean runLoader = false; |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 1341 | Callbacks callbacks = getCallback(); |
| 1342 | if (callbacks != null) { |
| 1343 | // Only actually run the loader if they're not paused. |
| 1344 | if (!callbacks.setLoadOnResume()) { |
| 1345 | runLoader = true; |
Joe Onorato | e9ad59e | 2010-10-29 17:35:36 -0700 | [diff] [blame] | 1346 | } |
| 1347 | } |
| 1348 | if (runLoader) { |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 1349 | startLoader(false, PagedView.INVALID_RESTORE_PAGE); |
Joe Onorato | 790c2d9 | 2010-06-11 00:14:11 -0700 | [diff] [blame] | 1350 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1351 | } |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 1352 | |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 1353 | // If there is already a loader task running, tell it to stop. |
| 1354 | // returns true if isLaunching() was true on the old task |
| 1355 | private boolean stopLoaderLocked() { |
| 1356 | boolean isLaunching = false; |
| 1357 | LoaderTask oldTask = mLoaderTask; |
| 1358 | if (oldTask != null) { |
| 1359 | if (oldTask.isLaunching()) { |
| 1360 | isLaunching = true; |
| 1361 | } |
| 1362 | oldTask.stopLocked(); |
| 1363 | } |
| 1364 | return isLaunching; |
| 1365 | } |
| 1366 | |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 1367 | public boolean isCurrentCallbacks(Callbacks callbacks) { |
| 1368 | return (mCallbacks != null && mCallbacks.get() == callbacks); |
| 1369 | } |
| 1370 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1371 | public void startLoader(boolean isLaunching, int synchronousBindPage) { |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1372 | startLoader(isLaunching, synchronousBindPage, LOADER_FLAG_NONE); |
| 1373 | } |
| 1374 | |
| 1375 | public void startLoader(boolean isLaunching, int synchronousBindPage, int loadFlags) { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 1376 | // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems |
| 1377 | InstallShortcutReceiver.enableInstallQueue(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1378 | synchronized (mLock) { |
| 1379 | if (DEBUG_LOADERS) { |
| 1380 | Log.d(TAG, "startLoader isLaunching=" + isLaunching); |
| 1381 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1382 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1383 | // Clear any deferred bind-runnables from the synchronized load process |
| 1384 | // We must do this before any loading/binding is scheduled below. |
Jason Monk | a0a7a74 | 2014-04-22 09:23:19 -0400 | [diff] [blame] | 1385 | synchronized (mDeferredBindRunnables) { |
| 1386 | mDeferredBindRunnables.clear(); |
| 1387 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1388 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1389 | // Don't bother to start the thread if we know it's not going to do anything |
| 1390 | if (mCallbacks != null && mCallbacks.get() != null) { |
| 1391 | // If there is already one running, tell it to stop. |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 1392 | // also, don't downgrade isLaunching if we're already running |
Sunny Goyal | f5cd998 | 2015-05-18 15:19:29 -0700 | [diff] [blame^] | 1393 | isLaunching = stopLoaderLocked() || isLaunching; |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1394 | mLoaderTask = new LoaderTask(mApp.getContext(), isLaunching, loadFlags); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 1395 | if (synchronousBindPage != PagedView.INVALID_RESTORE_PAGE |
Sunny Goyal | f5cd998 | 2015-05-18 15:19:29 -0700 | [diff] [blame^] | 1396 | && mAllAppsLoaded && mWorkspaceLoaded && !mIsLoaderTaskRunning) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1397 | mLoaderTask.runBindSynchronousPage(synchronousBindPage); |
| 1398 | } else { |
| 1399 | sWorkerThread.setPriority(Thread.NORM_PRIORITY); |
| 1400 | sWorker.post(mLoaderTask); |
| 1401 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1402 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1406 | void bindRemainingSynchronousPages() { |
| 1407 | // Post the remaining side pages to be loaded |
| 1408 | if (!mDeferredBindRunnables.isEmpty()) { |
Jason Monk | a0a7a74 | 2014-04-22 09:23:19 -0400 | [diff] [blame] | 1409 | Runnable[] deferredBindRunnables = null; |
| 1410 | synchronized (mDeferredBindRunnables) { |
| 1411 | deferredBindRunnables = mDeferredBindRunnables.toArray( |
| 1412 | new Runnable[mDeferredBindRunnables.size()]); |
| 1413 | mDeferredBindRunnables.clear(); |
| 1414 | } |
| 1415 | for (final Runnable r : deferredBindRunnables) { |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 1416 | mHandler.post(r); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1417 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1418 | } |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 1419 | |
| 1420 | // Run all the bind complete runnables after workspace is bound. |
| 1421 | if (!mBindCompleteRunnables.isEmpty()) { |
| 1422 | synchronized (mBindCompleteRunnables) { |
| 1423 | for (final Runnable r : mBindCompleteRunnables) { |
| 1424 | runOnWorkerThread(r); |
| 1425 | } |
| 1426 | mBindCompleteRunnables.clear(); |
| 1427 | } |
| 1428 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1431 | public void stopLoader() { |
| 1432 | synchronized (mLock) { |
| 1433 | if (mLoaderTask != null) { |
| 1434 | mLoaderTask.stopLocked(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1435 | } |
| 1436 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1437 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1438 | |
Sunny Goyal | c1b7c2e | 2015-01-16 16:19:04 -0800 | [diff] [blame] | 1439 | /** |
| 1440 | * Loads the workspace screen ids in an ordered list. |
| 1441 | */ |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 1442 | @Thunk static ArrayList<Long> loadWorkspaceScreensDb(Context context) { |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 1443 | final ContentResolver contentResolver = context.getContentResolver(); |
| 1444 | final Uri screensUri = LauncherSettings.WorkspaceScreens.CONTENT_URI; |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 1445 | |
Sunny Goyal | c1b7c2e | 2015-01-16 16:19:04 -0800 | [diff] [blame] | 1446 | // Get screens ordered by rank. |
| 1447 | final Cursor sc = contentResolver.query(screensUri, null, null, null, |
| 1448 | LauncherSettings.WorkspaceScreens.SCREEN_RANK); |
| 1449 | ArrayList<Long> screenIds = new ArrayList<Long>(); |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 1450 | try { |
Sunny Goyal | c1b7c2e | 2015-01-16 16:19:04 -0800 | [diff] [blame] | 1451 | final int idIndex = sc.getColumnIndexOrThrow(LauncherSettings.WorkspaceScreens._ID); |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 1452 | while (sc.moveToNext()) { |
| 1453 | try { |
Sunny Goyal | c1b7c2e | 2015-01-16 16:19:04 -0800 | [diff] [blame] | 1454 | screenIds.add(sc.getLong(idIndex)); |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 1455 | } catch (Exception e) { |
Sunny Goyal | c1b7c2e | 2015-01-16 16:19:04 -0800 | [diff] [blame] | 1456 | Launcher.addDumpLog(TAG, "Desktop items loading interrupted" |
| 1457 | + " - invalid screens: " + e, true); |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | } finally { |
| 1461 | sc.close(); |
| 1462 | } |
Sunny Goyal | c1b7c2e | 2015-01-16 16:19:04 -0800 | [diff] [blame] | 1463 | return screenIds; |
Winson Chung | 76828c8 | 2013-08-19 15:43:29 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Michael Jurka | c57b7a8 | 2011-08-09 22:02:20 -0700 | [diff] [blame] | 1466 | public boolean isAllAppsLoaded() { |
| 1467 | return mAllAppsLoaded; |
| 1468 | } |
| 1469 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 1470 | boolean isLoadingWorkspace() { |
| 1471 | synchronized (mLock) { |
| 1472 | if (mLoaderTask != null) { |
| 1473 | return mLoaderTask.isLoadingWorkspace(); |
| 1474 | } |
| 1475 | } |
| 1476 | return false; |
| 1477 | } |
| 1478 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1479 | /** |
| 1480 | * Runnable for the thread that loads the contents of the launcher: |
| 1481 | * - workspace icons |
| 1482 | * - widgets |
| 1483 | * - all apps icons |
| 1484 | */ |
| 1485 | private class LoaderTask implements Runnable { |
| 1486 | private Context mContext; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1487 | private boolean mIsLaunching; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 1488 | @Thunk boolean mIsLoadingAndBindingWorkspace; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1489 | private boolean mStopped; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 1490 | @Thunk boolean mLoadAndBindStepFinished; |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1491 | private int mFlags; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1492 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1493 | LoaderTask(Context context, boolean isLaunching, int flags) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1494 | mContext = context; |
| 1495 | mIsLaunching = isLaunching; |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1496 | mFlags = flags; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1497 | } |
| 1498 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1499 | boolean isLaunching() { |
| 1500 | return mIsLaunching; |
| 1501 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1502 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 1503 | boolean isLoadingWorkspace() { |
| 1504 | return mIsLoadingAndBindingWorkspace; |
| 1505 | } |
| 1506 | |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1507 | private void loadAndBindWorkspace() { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 1508 | mIsLoadingAndBindingWorkspace = true; |
| 1509 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1510 | // Load the workspace |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1511 | if (DEBUG_LOADERS) { |
| 1512 | Log.d(TAG, "loadAndBindWorkspace mWorkspaceLoaded=" + mWorkspaceLoaded); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1513 | } |
Michael Jurka | 288a36b | 2011-07-12 16:53:48 -0700 | [diff] [blame] | 1514 | |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 1515 | if (!mWorkspaceLoaded) { |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1516 | loadWorkspace(); |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 1517 | synchronized (LoaderTask.this) { |
| 1518 | if (mStopped) { |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1519 | return; |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 1520 | } |
| 1521 | mWorkspaceLoaded = true; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1522 | } |
| 1523 | } |
| 1524 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1525 | // Bind the workspace |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1526 | bindWorkspace(-1); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1527 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1528 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1529 | private void waitForIdle() { |
| 1530 | // Wait until the either we're stopped or the other threads are done. |
| 1531 | // This way we don't start loading all apps until the workspace has settled |
| 1532 | // down. |
| 1533 | synchronized (LoaderTask.this) { |
| 1534 | final long workspaceWaitTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 1535 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1536 | mHandler.postIdle(new Runnable() { |
| 1537 | public void run() { |
| 1538 | synchronized (LoaderTask.this) { |
| 1539 | mLoadAndBindStepFinished = true; |
| 1540 | if (DEBUG_LOADERS) { |
| 1541 | Log.d(TAG, "done with previous binding step"); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1542 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1543 | LoaderTask.this.notify(); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1544 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1545 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1546 | }); |
| 1547 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1548 | while (!mStopped && !mLoadAndBindStepFinished) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1549 | try { |
Michael Jurka | c7700af | 2013-05-14 20:17:58 +0200 | [diff] [blame] | 1550 | // Just in case mFlushingWorkerThread changes but we aren't woken up, |
| 1551 | // wait no longer than 1sec at a time |
| 1552 | this.wait(1000); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1553 | } catch (InterruptedException ex) { |
| 1554 | // Ignore |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1555 | } |
| 1556 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1557 | if (DEBUG_LOADERS) { |
| 1558 | Log.d(TAG, "waited " |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1559 | + (SystemClock.uptimeMillis()-workspaceWaitTime) |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1560 | + "ms for previous step to finish binding"); |
| 1561 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1562 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1563 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1564 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1565 | void runBindSynchronousPage(int synchronousBindPage) { |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 1566 | if (synchronousBindPage == PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1567 | // Ensure that we have a valid page index to load synchronously |
| 1568 | throw new RuntimeException("Should not call runBindSynchronousPage() without " + |
| 1569 | "valid page index"); |
| 1570 | } |
| 1571 | if (!mAllAppsLoaded || !mWorkspaceLoaded) { |
| 1572 | // Ensure that we don't try and bind a specified page when the pages have not been |
| 1573 | // loaded already (we should load everything asynchronously in that case) |
| 1574 | throw new RuntimeException("Expecting AllApps and Workspace to be loaded"); |
| 1575 | } |
| 1576 | synchronized (mLock) { |
| 1577 | if (mIsLoaderTaskRunning) { |
| 1578 | // Ensure that we are never running the background loading at this point since |
| 1579 | // we also touch the background collections |
| 1580 | throw new RuntimeException("Error! Background loading is already running"); |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | // XXX: Throw an exception if we are already loading (since we touch the worker thread |
| 1585 | // data structures, we can't allow any other thread to touch that data, but because |
| 1586 | // this call is synchronous, we can get away with not locking). |
| 1587 | |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 1588 | // The LauncherModel is static in the LauncherAppState and mHandler may have queued |
Adam Cohen | a13a2f2 | 2012-07-23 14:29:15 -0700 | [diff] [blame] | 1589 | // operations from the previous activity. We need to ensure that all queued operations |
| 1590 | // are executed before any synchronous binding work is done. |
| 1591 | mHandler.flush(); |
| 1592 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1593 | // Divide the set of loaded items into those that we are binding synchronously, and |
| 1594 | // everything else that is to be bound normally (asynchronously). |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1595 | bindWorkspace(synchronousBindPage); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1596 | // XXX: For now, continue posting the binding of AllApps as there are other issues that |
| 1597 | // arise from that. |
| 1598 | onlyBindAllApps(); |
| 1599 | } |
| 1600 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1601 | public void run() { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1602 | synchronized (mLock) { |
Sunny Goyal | f5cd998 | 2015-05-18 15:19:29 -0700 | [diff] [blame^] | 1603 | if (mStopped) { |
| 1604 | return; |
| 1605 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1606 | mIsLoaderTaskRunning = true; |
| 1607 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1608 | // Optimize for end-user experience: if the Launcher is up and // running with the |
| 1609 | // All Apps interface in the foreground, load All Apps first. Otherwise, load the |
| 1610 | // workspace first (default). |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1611 | keep_running: { |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1612 | // Elevate priority when Home launches for the first time to avoid |
| 1613 | // starving at boot time. Staring at a blank home is not cool. |
| 1614 | synchronized (mLock) { |
Winson Chung | aac01e1 | 2011-08-17 10:37:13 -0700 | [diff] [blame] | 1615 | if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to " + |
| 1616 | (mIsLaunching ? "DEFAULT" : "BACKGROUND")); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1617 | android.os.Process.setThreadPriority(mIsLaunching |
| 1618 | ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND); |
| 1619 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 1620 | if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace"); |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1621 | loadAndBindWorkspace(); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1622 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1623 | if (mStopped) { |
| 1624 | break keep_running; |
| 1625 | } |
| 1626 | |
| 1627 | // Whew! Hard work done. Slow us down, and wait until the UI thread has |
| 1628 | // settled down. |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1629 | synchronized (mLock) { |
| 1630 | if (mIsLaunching) { |
Winson Chung | aac01e1 | 2011-08-17 10:37:13 -0700 | [diff] [blame] | 1631 | if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to BACKGROUND"); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1632 | android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 1633 | } |
| 1634 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1635 | waitForIdle(); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 1636 | |
| 1637 | // second step |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 1638 | if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps"); |
| 1639 | loadAndBindAllApps(); |
Winson Chung | 7ed3774 | 2011-09-08 15:45:51 -0700 | [diff] [blame] | 1640 | |
| 1641 | // Restore the default thread priority after we are done loading items |
| 1642 | synchronized (mLock) { |
| 1643 | android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
| 1644 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1645 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1646 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1647 | // Clear out this reference, otherwise we end up holding it until all of the |
| 1648 | // callback runnables are done. |
| 1649 | mContext = null; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1650 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1651 | synchronized (mLock) { |
| 1652 | // If we are still the last one to be scheduled, remove ourselves. |
| 1653 | if (mLoaderTask == this) { |
| 1654 | mLoaderTask = null; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1655 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1656 | mIsLoaderTaskRunning = false; |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 1657 | mHasLoaderCompletedOnce = true; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1658 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | public void stopLocked() { |
| 1662 | synchronized (LoaderTask.this) { |
| 1663 | mStopped = true; |
| 1664 | this.notify(); |
| 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | /** |
| 1669 | * Gets the callbacks object. If we've been stopped, or if the launcher object |
| 1670 | * has somehow been garbage collected, return null instead. Pass in the Callbacks |
| 1671 | * object that was around when the deferred message was scheduled, and if there's |
| 1672 | * a new Callbacks object around then also return null. This will save us from |
| 1673 | * calling onto it with data that will be ignored. |
| 1674 | */ |
| 1675 | Callbacks tryGetCallbacks(Callbacks oldCallbacks) { |
| 1676 | synchronized (mLock) { |
| 1677 | if (mStopped) { |
| 1678 | return null; |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 1679 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1680 | |
| 1681 | if (mCallbacks == null) { |
| 1682 | return null; |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 1683 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1684 | |
| 1685 | final Callbacks callbacks = mCallbacks.get(); |
| 1686 | if (callbacks != oldCallbacks) { |
| 1687 | return null; |
| 1688 | } |
| 1689 | if (callbacks == null) { |
| 1690 | Log.w(TAG, "no mCallbacks"); |
| 1691 | return null; |
| 1692 | } |
| 1693 | |
| 1694 | return callbacks; |
| 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | // check & update map of what's occupied; used to discard overlapping/invalid items |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 1699 | private boolean checkItemPlacement(LongArrayMap<ItemInfo[][]> occupied, ItemInfo item) { |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 1700 | LauncherAppState app = LauncherAppState.getInstance(); |
| 1701 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 1702 | final int countX = (int) grid.numColumns; |
| 1703 | final int countY = (int) grid.numRows; |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 1704 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1705 | long containerIndex = item.screenId; |
Winson Chung | f30ad5f | 2011-08-08 10:55:42 -0700 | [diff] [blame] | 1706 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 1707 | // Return early if we detect that an item is under the hotseat button |
| 1708 | if (mCallbacks == null || |
| 1709 | mCallbacks.get().isAllAppsButtonRank((int) item.screenId)) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 1710 | Log.e(TAG, "Error loading shortcut into hotseat " + item |
| 1711 | + " into position (" + item.screenId + ":" + item.cellX + "," |
| 1712 | + item.cellY + ") occupied by all apps"); |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 1713 | return false; |
| 1714 | } |
| 1715 | |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 1716 | final ItemInfo[][] hotseatItems = |
| 1717 | occupied.get((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT); |
| 1718 | |
Adam Cohen | ae4409d | 2013-11-26 10:34:59 -0800 | [diff] [blame] | 1719 | if (item.screenId >= grid.numHotseatIcons) { |
| 1720 | Log.e(TAG, "Error loading shortcut " + item |
| 1721 | + " into hotseat position " + item.screenId |
| 1722 | + ", position out of bounds: (0 to " + (grid.numHotseatIcons - 1) |
| 1723 | + ")"); |
| 1724 | return false; |
| 1725 | } |
| 1726 | |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 1727 | if (hotseatItems != null) { |
| 1728 | if (hotseatItems[(int) item.screenId][0] != null) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1729 | Log.e(TAG, "Error loading shortcut into hotseat " + item |
| 1730 | + " into position (" + item.screenId + ":" + item.cellX + "," |
| 1731 | + item.cellY + ") occupied by " |
| 1732 | + occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT) |
| 1733 | [(int) item.screenId][0]); |
| 1734 | return false; |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 1735 | } else { |
| 1736 | hotseatItems[(int) item.screenId][0] = item; |
| 1737 | return true; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1738 | } |
Winson Chung | 6ba2a1b | 2011-09-02 16:22:11 -0700 | [diff] [blame] | 1739 | } else { |
Adam Cohen | ae4409d | 2013-11-26 10:34:59 -0800 | [diff] [blame] | 1740 | final ItemInfo[][] items = new ItemInfo[(int) grid.numHotseatIcons][1]; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1741 | items[(int) item.screenId][0] = item; |
| 1742 | occupied.put((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT, items); |
Winson Chung | 6ba2a1b | 2011-09-02 16:22:11 -0700 | [diff] [blame] | 1743 | return true; |
| 1744 | } |
Winson Chung | f30ad5f | 2011-08-08 10:55:42 -0700 | [diff] [blame] | 1745 | } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 1746 | // Skip further checking if it is not the hotseat or workspace container |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 1747 | return true; |
| 1748 | } |
Winson Chung | f30ad5f | 2011-08-08 10:55:42 -0700 | [diff] [blame] | 1749 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1750 | if (!occupied.containsKey(item.screenId)) { |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 1751 | ItemInfo[][] items = new ItemInfo[countX + 1][countY + 1]; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1752 | occupied.put(item.screenId, items); |
| 1753 | } |
| 1754 | |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 1755 | final ItemInfo[][] screens = occupied.get(item.screenId); |
Adam Cohen | ae4409d | 2013-11-26 10:34:59 -0800 | [diff] [blame] | 1756 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && |
| 1757 | item.cellX < 0 || item.cellY < 0 || |
| 1758 | item.cellX + item.spanX > countX || item.cellY + item.spanY > countY) { |
| 1759 | Log.e(TAG, "Error loading shortcut " + item |
| 1760 | + " into cell (" + containerIndex + "-" + item.screenId + ":" |
| 1761 | + item.cellX + "," + item.cellY |
| 1762 | + ") out of screen bounds ( " + countX + "x" + countY + ")"); |
| 1763 | return false; |
| 1764 | } |
| 1765 | |
Winson Chung | 6ba2a1b | 2011-09-02 16:22:11 -0700 | [diff] [blame] | 1766 | // Check if any workspace icons overlap with each other |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1767 | for (int x = item.cellX; x < (item.cellX+item.spanX); x++) { |
| 1768 | for (int y = item.cellY; y < (item.cellY+item.spanY); y++) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1769 | if (screens[x][y] != null) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1770 | Log.e(TAG, "Error loading shortcut " + item |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1771 | + " into cell (" + containerIndex + "-" + item.screenId + ":" |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1772 | + x + "," + y |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1773 | + ") occupied by " |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1774 | + screens[x][y]); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1775 | return false; |
| 1776 | } |
| 1777 | } |
| 1778 | } |
| 1779 | for (int x = item.cellX; x < (item.cellX+item.spanX); x++) { |
| 1780 | for (int y = item.cellY; y < (item.cellY+item.spanY); y++) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1781 | screens[x][y] = item; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1782 | } |
| 1783 | } |
Winson Chung | f30ad5f | 2011-08-08 10:55:42 -0700 | [diff] [blame] | 1784 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1785 | return true; |
| 1786 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1787 | |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 1788 | /** Clears all the sBg data structures */ |
| 1789 | private void clearSBgDataStructures() { |
| 1790 | synchronized (sBgLock) { |
| 1791 | sBgWorkspaceItems.clear(); |
| 1792 | sBgAppWidgets.clear(); |
| 1793 | sBgFolders.clear(); |
| 1794 | sBgItemsIdMap.clear(); |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 1795 | sBgWorkspaceScreens.clear(); |
| 1796 | } |
| 1797 | } |
| 1798 | |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 1799 | private void loadWorkspace() { |
Winson Chung | 9f9f00b | 2013-11-15 13:27:00 -0800 | [diff] [blame] | 1800 | // Log to disk |
| 1801 | Launcher.addDumpLog(TAG, "11683562 - loadWorkspace()", true); |
| 1802 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1803 | final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1804 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1805 | final Context context = mContext; |
| 1806 | final ContentResolver contentResolver = context.getContentResolver(); |
| 1807 | final PackageManager manager = context.getPackageManager(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1808 | final boolean isSafeMode = manager.isSafeMode(); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 1809 | final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context); |
| 1810 | final boolean isSdCardReady = context.registerReceiver(null, |
Sunny Goyal | 05e318d | 2014-07-29 11:49:35 -0700 | [diff] [blame] | 1811 | new IntentFilter(StartupReceiver.SYSTEM_READY)) != null; |
Joe Onorato | 3c2f7e1 | 2009-10-31 19:17:31 -0400 | [diff] [blame] | 1812 | |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 1813 | LauncherAppState app = LauncherAppState.getInstance(); |
| 1814 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 1815 | int countX = (int) grid.numColumns; |
| 1816 | int countY = (int) grid.numRows; |
| 1817 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1818 | if ((mFlags & LOADER_FLAG_CLEAR_WORKSPACE) != 0) { |
| 1819 | Launcher.addDumpLog(TAG, "loadWorkspace: resetting launcher database", true); |
| 1820 | LauncherAppState.getLauncherProvider().deleteDatabase(); |
| 1821 | } |
| 1822 | |
| 1823 | if ((mFlags & LOADER_FLAG_MIGRATE_SHORTCUTS) != 0) { |
| 1824 | // append the user's Launcher2 shortcuts |
| 1825 | Launcher.addDumpLog(TAG, "loadWorkspace: migrating from launcher2", true); |
| 1826 | LauncherAppState.getLauncherProvider().migrateLauncher2Shortcuts(); |
| 1827 | } else { |
| 1828 | // Make sure the default workspace is loaded |
| 1829 | Launcher.addDumpLog(TAG, "loadWorkspace: loading default favorites", false); |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 1830 | LauncherAppState.getLauncherProvider().loadDefaultFavoritesIfNecessary(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1831 | } |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 1832 | |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 1833 | synchronized (sBgLock) { |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 1834 | clearSBgDataStructures(); |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 1835 | final HashMap<String, Integer> installingPkgs = PackageInstallerCompat |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 1836 | .getInstance(mContext).updateAndGetActiveSessionCache(); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 1837 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1838 | final ArrayList<Long> itemsToRemove = new ArrayList<Long>(); |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 1839 | final ArrayList<Long> restoredRows = new ArrayList<Long>(); |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 1840 | final Uri contentUri = LauncherSettings.Favorites.CONTENT_URI; |
Chris Wren | e523e70 | 2013-10-09 10:36:55 -0400 | [diff] [blame] | 1841 | if (DEBUG_LOADERS) Log.d(TAG, "loading model from " + contentUri); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 1842 | final Cursor c = contentResolver.query(contentUri, null, null, null, null); |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 1843 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1844 | // +1 for the hotseat (it can be larger than the workspace) |
| 1845 | // Load workspace in reverse order to ensure that latest items are loaded first (and |
| 1846 | // before any earlier duplicates) |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 1847 | final LongArrayMap<ItemInfo[][]> occupied = new LongArrayMap<>(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1848 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1849 | try { |
| 1850 | final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID); |
| 1851 | final int intentIndex = c.getColumnIndexOrThrow |
| 1852 | (LauncherSettings.Favorites.INTENT); |
| 1853 | final int titleIndex = c.getColumnIndexOrThrow |
| 1854 | (LauncherSettings.Favorites.TITLE); |
| 1855 | final int iconTypeIndex = c.getColumnIndexOrThrow( |
| 1856 | LauncherSettings.Favorites.ICON_TYPE); |
| 1857 | final int iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON); |
| 1858 | final int iconPackageIndex = c.getColumnIndexOrThrow( |
| 1859 | LauncherSettings.Favorites.ICON_PACKAGE); |
| 1860 | final int iconResourceIndex = c.getColumnIndexOrThrow( |
| 1861 | LauncherSettings.Favorites.ICON_RESOURCE); |
| 1862 | final int containerIndex = c.getColumnIndexOrThrow( |
| 1863 | LauncherSettings.Favorites.CONTAINER); |
| 1864 | final int itemTypeIndex = c.getColumnIndexOrThrow( |
| 1865 | LauncherSettings.Favorites.ITEM_TYPE); |
| 1866 | final int appWidgetIdIndex = c.getColumnIndexOrThrow( |
| 1867 | LauncherSettings.Favorites.APPWIDGET_ID); |
Chris Wren | c3919c0 | 2013-09-18 09:48:33 -0400 | [diff] [blame] | 1868 | final int appWidgetProviderIndex = c.getColumnIndexOrThrow( |
| 1869 | LauncherSettings.Favorites.APPWIDGET_PROVIDER); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1870 | final int screenIndex = c.getColumnIndexOrThrow( |
| 1871 | LauncherSettings.Favorites.SCREEN); |
| 1872 | final int cellXIndex = c.getColumnIndexOrThrow |
| 1873 | (LauncherSettings.Favorites.CELLX); |
| 1874 | final int cellYIndex = c.getColumnIndexOrThrow |
| 1875 | (LauncherSettings.Favorites.CELLY); |
| 1876 | final int spanXIndex = c.getColumnIndexOrThrow |
| 1877 | (LauncherSettings.Favorites.SPANX); |
| 1878 | final int spanYIndex = c.getColumnIndexOrThrow( |
| 1879 | LauncherSettings.Favorites.SPANY); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 1880 | final int rankIndex = c.getColumnIndexOrThrow( |
| 1881 | LauncherSettings.Favorites.RANK); |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 1882 | final int restoredIndex = c.getColumnIndexOrThrow( |
| 1883 | LauncherSettings.Favorites.RESTORED); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1884 | final int profileIdIndex = c.getColumnIndexOrThrow( |
| 1885 | LauncherSettings.Favorites.PROFILE_ID); |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 1886 | final int optionsIndex = c.getColumnIndexOrThrow( |
| 1887 | LauncherSettings.Favorites.OPTIONS); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1888 | |
Sunny Goyal | 7f834d2 | 2015-04-21 10:10:23 -0700 | [diff] [blame] | 1889 | final LongSparseArray<UserHandleCompat> allUsers = new LongSparseArray<>(); |
| 1890 | for (UserHandleCompat user : mUserManager.getUserProfiles()) { |
| 1891 | allUsers.put(mUserManager.getSerialNumberForUser(user), user); |
| 1892 | } |
| 1893 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1894 | ShortcutInfo info; |
| 1895 | String intentDescription; |
| 1896 | LauncherAppWidgetInfo appWidgetInfo; |
| 1897 | int container; |
| 1898 | long id; |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 1899 | long serialNumber; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1900 | Intent intent; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1901 | UserHandleCompat user; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1902 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1903 | while (!mStopped && c.moveToNext()) { |
| 1904 | try { |
| 1905 | int itemType = c.getInt(itemTypeIndex); |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 1906 | boolean restored = 0 != c.getInt(restoredIndex); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 1907 | boolean allowMissingTarget = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1908 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1909 | switch (itemType) { |
| 1910 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 1911 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 1912 | id = c.getLong(idIndex); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1913 | intentDescription = c.getString(intentIndex); |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 1914 | serialNumber = c.getInt(profileIdIndex); |
Sunny Goyal | 7f834d2 | 2015-04-21 10:10:23 -0700 | [diff] [blame] | 1915 | user = allUsers.get(serialNumber); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 1916 | int promiseType = c.getInt(restoredIndex); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 1917 | int disabledState = 0; |
Sunny Goyal | bb3b02f | 2015-01-15 12:00:14 -0800 | [diff] [blame] | 1918 | boolean itemReplaced = false; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 1919 | if (user == null) { |
| 1920 | // User has been deleted remove the item. |
| 1921 | itemsToRemove.add(id); |
| 1922 | continue; |
| 1923 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1924 | try { |
| 1925 | intent = Intent.parseUri(intentDescription, 0); |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 1926 | ComponentName cn = intent.getComponent(); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 1927 | if (cn != null && cn.getPackageName() != null) { |
| 1928 | boolean validPkg = launcherApps.isPackageEnabledForProfile( |
| 1929 | cn.getPackageName(), user); |
| 1930 | boolean validComponent = validPkg && |
| 1931 | launcherApps.isActivityEnabledForProfile(cn, user); |
| 1932 | |
| 1933 | if (validComponent) { |
| 1934 | if (restored) { |
| 1935 | // no special handling necessary for this item |
| 1936 | restoredRows.add(id); |
| 1937 | restored = false; |
| 1938 | } |
| 1939 | } else if (validPkg) { |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 1940 | intent = null; |
| 1941 | if ((promiseType & ShortcutInfo.FLAG_AUTOINTALL_ICON) != 0) { |
| 1942 | // We allow auto install apps to have their intent |
| 1943 | // updated after an install. |
| 1944 | intent = manager.getLaunchIntentForPackage( |
| 1945 | cn.getPackageName()); |
| 1946 | if (intent != null) { |
| 1947 | ContentValues values = new ContentValues(); |
| 1948 | values.put(LauncherSettings.Favorites.INTENT, |
| 1949 | intent.toUri(0)); |
Sunny Goyal | bb3b02f | 2015-01-15 12:00:14 -0800 | [diff] [blame] | 1950 | updateItem(id, values); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | if (intent == null) { |
| 1955 | // The app is installed but the component is no |
| 1956 | // longer available. |
| 1957 | Launcher.addDumpLog(TAG, |
| 1958 | "Invalid component removed: " + cn, true); |
| 1959 | itemsToRemove.add(id); |
| 1960 | continue; |
| 1961 | } else { |
| 1962 | // no special handling necessary for this item |
| 1963 | restoredRows.add(id); |
| 1964 | restored = false; |
| 1965 | } |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 1966 | } else if (restored) { |
| 1967 | // Package is not yet available but might be |
| 1968 | // installed later. |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 1969 | Launcher.addDumpLog(TAG, |
| 1970 | "package not yet restored: " + cn, true); |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 1971 | |
| 1972 | if ((promiseType & ShortcutInfo.FLAG_RESTORE_STARTED) != 0) { |
| 1973 | // Restore has started once. |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 1974 | } else if (installingPkgs.containsKey(cn.getPackageName())) { |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 1975 | // App restore has started. Update the flag |
| 1976 | promiseType |= ShortcutInfo.FLAG_RESTORE_STARTED; |
| 1977 | ContentValues values = new ContentValues(); |
| 1978 | values.put(LauncherSettings.Favorites.RESTORED, |
| 1979 | promiseType); |
Sunny Goyal | bb3b02f | 2015-01-15 12:00:14 -0800 | [diff] [blame] | 1980 | updateItem(id, values); |
| 1981 | } else if ((promiseType & ShortcutInfo.FLAG_RESTORED_APP_TYPE) != 0) { |
| 1982 | // This is a common app. Try to replace this. |
| 1983 | int appType = CommonAppTypeParser.decodeItemTypeFromFlag(promiseType); |
| 1984 | CommonAppTypeParser parser = new CommonAppTypeParser(id, appType, context); |
| 1985 | if (parser.findDefaultApp()) { |
| 1986 | // Default app found. Replace it. |
| 1987 | intent = parser.parsedIntent; |
| 1988 | cn = intent.getComponent(); |
| 1989 | ContentValues values = parser.parsedValues; |
| 1990 | values.put(LauncherSettings.Favorites.RESTORED, 0); |
| 1991 | updateItem(id, values); |
| 1992 | restored = false; |
| 1993 | itemReplaced = true; |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 1994 | |
Sunny Goyal | bb3b02f | 2015-01-15 12:00:14 -0800 | [diff] [blame] | 1995 | } else if (REMOVE_UNRESTORED_ICONS) { |
| 1996 | Launcher.addDumpLog(TAG, |
| 1997 | "Unrestored package removed: " + cn, true); |
| 1998 | itemsToRemove.add(id); |
| 1999 | continue; |
| 2000 | } |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 2001 | } else if (REMOVE_UNRESTORED_ICONS) { |
| 2002 | Launcher.addDumpLog(TAG, |
| 2003 | "Unrestored package removed: " + cn, true); |
| 2004 | itemsToRemove.add(id); |
| 2005 | continue; |
| 2006 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2007 | } else if (launcherApps.isAppEnabled( |
| 2008 | manager, cn.getPackageName(), |
| 2009 | PackageManager.GET_UNINSTALLED_PACKAGES)) { |
| 2010 | // Package is present but not available. |
| 2011 | allowMissingTarget = true; |
| 2012 | disabledState = ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE; |
| 2013 | } else if (!isSdCardReady) { |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 2014 | // SdCard is not ready yet. Package might get available, |
| 2015 | // once it is ready. |
| 2016 | Launcher.addDumpLog(TAG, "Invalid package: " + cn |
| 2017 | + " (check again later)", true); |
| 2018 | HashSet<String> pkgs = sPendingPackages.get(user); |
| 2019 | if (pkgs == null) { |
Sameer Padala | 513edae | 2014-07-29 16:17:08 -0700 | [diff] [blame] | 2020 | pkgs = new HashSet<String>(); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 2021 | sPendingPackages.put(user, pkgs); |
| 2022 | } |
| 2023 | pkgs.add(cn.getPackageName()); |
| 2024 | allowMissingTarget = true; |
| 2025 | // Add the icon on the workspace anyway. |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2026 | |
| 2027 | } else { |
| 2028 | // Do not wait for external media load anymore. |
| 2029 | // Log the invalid package, and remove it |
| 2030 | Launcher.addDumpLog(TAG, |
| 2031 | "Invalid package removed: " + cn, true); |
| 2032 | itemsToRemove.add(id); |
| 2033 | continue; |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 2034 | } |
Sunny Goyal | 938a53d | 2014-09-05 03:17:45 -0700 | [diff] [blame] | 2035 | } else if (cn == null) { |
| 2036 | // For shortcuts with no component, keep them as they are |
| 2037 | restoredRows.add(id); |
| 2038 | restored = false; |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 2039 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2040 | } catch (URISyntaxException e) { |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 2041 | Launcher.addDumpLog(TAG, |
| 2042 | "Invalid uri: " + intentDescription, true); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2043 | continue; |
| 2044 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2045 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 2046 | container = c.getInt(containerIndex); |
| 2047 | boolean useLowResIcon = container >= 0 && |
| 2048 | c.getInt(rankIndex) >= FolderIcon.NUM_ITEMS_IN_PREVIEW; |
| 2049 | |
Sunny Goyal | bb3b02f | 2015-01-15 12:00:14 -0800 | [diff] [blame] | 2050 | if (itemReplaced) { |
| 2051 | if (user.equals(UserHandleCompat.myUserHandle())) { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 2052 | info = getAppShortcutInfo(manager, intent, user, context, null, |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 2053 | iconIndex, titleIndex, false, useLowResIcon); |
Sunny Goyal | bb3b02f | 2015-01-15 12:00:14 -0800 | [diff] [blame] | 2054 | } else { |
| 2055 | // Don't replace items for other profiles. |
| 2056 | itemsToRemove.add(id); |
| 2057 | continue; |
| 2058 | } |
| 2059 | } else if (restored) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2060 | if (user.equals(UserHandleCompat.myUserHandle())) { |
| 2061 | Launcher.addDumpLog(TAG, |
| 2062 | "constructing info for partially restored package", |
| 2063 | true); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 2064 | info = getRestoredItemInfo(c, titleIndex, intent, |
| 2065 | promiseType, useLowResIcon); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2066 | intent = getRestoredItemIntent(c, context, intent); |
| 2067 | } else { |
| 2068 | // Don't restore items for other profiles. |
| 2069 | itemsToRemove.add(id); |
| 2070 | continue; |
| 2071 | } |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 2072 | } else if (itemType == |
| 2073 | LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 2074 | info = getAppShortcutInfo(manager, intent, user, context, c, |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 2075 | iconIndex, titleIndex, allowMissingTarget, useLowResIcon); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2076 | } else { |
| 2077 | info = getShortcutInfo(c, context, iconTypeIndex, |
| 2078 | iconPackageIndex, iconResourceIndex, iconIndex, |
| 2079 | titleIndex); |
Michael Jurka | 9687956 | 2012-03-22 05:54:33 -0700 | [diff] [blame] | 2080 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2081 | // App shortcuts that used to be automatically added to Launcher |
| 2082 | // didn't always have the correct intent flags set, so do that |
| 2083 | // here |
| 2084 | if (intent.getAction() != null && |
Michael Jurka | 9ad0056 | 2012-05-14 12:24:22 -0700 | [diff] [blame] | 2085 | intent.getCategories() != null && |
| 2086 | intent.getAction().equals(Intent.ACTION_MAIN) && |
Michael Jurka | 9687956 | 2012-03-22 05:54:33 -0700 | [diff] [blame] | 2087 | intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2088 | intent.addFlags( |
| 2089 | Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2090 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 2091 | } |
Michael Jurka | 9687956 | 2012-03-22 05:54:33 -0700 | [diff] [blame] | 2092 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2093 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2094 | if (info != null) { |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 2095 | info.id = id; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2096 | info.intent = intent; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2097 | info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2098 | info.screenId = c.getInt(screenIndex); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2099 | info.cellX = c.getInt(cellXIndex); |
| 2100 | info.cellY = c.getInt(cellYIndex); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 2101 | info.rank = c.getInt(rankIndex); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2102 | info.spanX = 1; |
| 2103 | info.spanY = 1; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2104 | info.intent.putExtra(ItemInfo.EXTRA_PROFILE, serialNumber); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2105 | info.isDisabled = disabledState; |
| 2106 | if (isSafeMode && !Utilities.isSystemApp(context, intent)) { |
| 2107 | info.isDisabled |= ShortcutInfo.FLAG_DISABLED_SAFEMODE; |
| 2108 | } |
Adam Cohen | ae4409d | 2013-11-26 10:34:59 -0800 | [diff] [blame] | 2109 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2110 | // check & update map of what's occupied |
Sunny Goyal | fc0fe6b | 2014-10-16 12:18:37 -0700 | [diff] [blame] | 2111 | if (!checkItemPlacement(occupied, info)) { |
| 2112 | itemsToRemove.add(id); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2113 | break; |
| 2114 | } |
| 2115 | |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 2116 | if (restored) { |
| 2117 | ComponentName cn = info.getTargetComponent(); |
| 2118 | if (cn != null) { |
| 2119 | Integer progress = installingPkgs.get(cn.getPackageName()); |
| 2120 | if (progress != null) { |
| 2121 | info.setInstallProgress(progress); |
| 2122 | } else { |
| 2123 | info.status &= ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE; |
| 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2128 | switch (container) { |
| 2129 | case LauncherSettings.Favorites.CONTAINER_DESKTOP: |
| 2130 | case LauncherSettings.Favorites.CONTAINER_HOTSEAT: |
| 2131 | sBgWorkspaceItems.add(info); |
| 2132 | break; |
| 2133 | default: |
| 2134 | // Item is in a user folder |
| 2135 | FolderInfo folderInfo = |
| 2136 | findOrMakeFolder(sBgFolders, container); |
| 2137 | folderInfo.add(info); |
| 2138 | break; |
| 2139 | } |
| 2140 | sBgItemsIdMap.put(info.id, info); |
Winson Chung | 1323b48 | 2013-08-05 12:41:55 -0700 | [diff] [blame] | 2141 | } else { |
| 2142 | throw new RuntimeException("Unexpected null ShortcutInfo"); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2143 | } |
| 2144 | break; |
| 2145 | |
| 2146 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
| 2147 | id = c.getLong(idIndex); |
| 2148 | FolderInfo folderInfo = findOrMakeFolder(sBgFolders, id); |
| 2149 | |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 2150 | folderInfo.title = Utilities.trim(c.getString(titleIndex)); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2151 | folderInfo.id = id; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2152 | container = c.getInt(containerIndex); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2153 | folderInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2154 | folderInfo.screenId = c.getInt(screenIndex); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2155 | folderInfo.cellX = c.getInt(cellXIndex); |
| 2156 | folderInfo.cellY = c.getInt(cellYIndex); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2157 | folderInfo.spanX = 1; |
| 2158 | folderInfo.spanY = 1; |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 2159 | folderInfo.options = c.getInt(optionsIndex); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2160 | |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 2161 | // check & update map of what's occupied |
Sunny Goyal | fc0fe6b | 2014-10-16 12:18:37 -0700 | [diff] [blame] | 2162 | if (!checkItemPlacement(occupied, folderInfo)) { |
| 2163 | itemsToRemove.add(id); |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 2164 | break; |
| 2165 | } |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2166 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2167 | switch (container) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2168 | case LauncherSettings.Favorites.CONTAINER_DESKTOP: |
| 2169 | case LauncherSettings.Favorites.CONTAINER_HOTSEAT: |
| 2170 | sBgWorkspaceItems.add(folderInfo); |
| 2171 | break; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2172 | } |
Joe Onorato | 17a8922 | 2011-02-08 17:26:11 -0800 | [diff] [blame] | 2173 | |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 2174 | if (restored) { |
| 2175 | // no special handling required for restored folders |
| 2176 | restoredRows.add(id); |
| 2177 | } |
| 2178 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2179 | sBgItemsIdMap.put(folderInfo.id, folderInfo); |
| 2180 | sBgFolders.put(folderInfo.id, folderInfo); |
| 2181 | break; |
| 2182 | |
| 2183 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2184 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2185 | // Read all Launcher-specific widget details |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2186 | boolean customWidget = itemType == |
| 2187 | LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; |
| 2188 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2189 | int appWidgetId = c.getInt(appWidgetIdIndex); |
Sunny Goyal | 7f834d2 | 2015-04-21 10:10:23 -0700 | [diff] [blame] | 2190 | serialNumber = c.getLong(profileIdIndex); |
Chris Wren | c3919c0 | 2013-09-18 09:48:33 -0400 | [diff] [blame] | 2191 | String savedProvider = c.getString(appWidgetProviderIndex); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2192 | id = c.getLong(idIndex); |
Sunny Goyal | 7f834d2 | 2015-04-21 10:10:23 -0700 | [diff] [blame] | 2193 | user = allUsers.get(serialNumber); |
| 2194 | if (user == null) { |
| 2195 | itemsToRemove.add(id); |
| 2196 | continue; |
| 2197 | } |
| 2198 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2199 | final ComponentName component = |
| 2200 | ComponentName.unflattenFromString(savedProvider); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2201 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 2202 | final int restoreStatus = c.getInt(restoredIndex); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2203 | final boolean isIdValid = (restoreStatus & |
| 2204 | LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) == 0; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2205 | final boolean wasProviderReady = (restoreStatus & |
| 2206 | LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 2207 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2208 | final LauncherAppWidgetProviderInfo provider = |
| 2209 | LauncherModel.getProviderInfo(context, |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 2210 | ComponentName.unflattenFromString(savedProvider), |
Sunny Goyal | 7f834d2 | 2015-04-21 10:10:23 -0700 | [diff] [blame] | 2211 | user); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2212 | |
| 2213 | final boolean isProviderReady = isValidProvider(provider); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2214 | if (!isSafeMode && !customWidget && |
| 2215 | wasProviderReady && !isProviderReady) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 2216 | String log = "Deleting widget that isn't installed anymore: " |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2217 | + "id=" + id + " appWidgetId=" + appWidgetId; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2218 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2219 | Log.e(TAG, log); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 2220 | Launcher.addDumpLog(TAG, log, false); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2221 | itemsToRemove.add(id); |
| 2222 | } else { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2223 | if (isProviderReady) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 2224 | appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId, |
| 2225 | provider.provider); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2226 | |
| 2227 | if (!customWidget) { |
| 2228 | int[] minSpan = |
| 2229 | Launcher.getMinSpanForWidget(context, provider); |
| 2230 | appWidgetInfo.minSpanX = minSpan[0]; |
| 2231 | appWidgetInfo.minSpanY = minSpan[1]; |
| 2232 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2233 | |
| 2234 | int status = restoreStatus; |
| 2235 | if (!wasProviderReady) { |
| 2236 | // If provider was not previously ready, update the |
| 2237 | // status and UI flag. |
| 2238 | |
| 2239 | // Id would be valid only if the widget restore broadcast was received. |
| 2240 | if (isIdValid) { |
| 2241 | status = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 2242 | } else { |
| 2243 | status &= ~LauncherAppWidgetInfo |
| 2244 | .FLAG_PROVIDER_NOT_READY; |
| 2245 | } |
| 2246 | } |
| 2247 | appWidgetInfo.restoreStatus = status; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 2248 | } else { |
| 2249 | Log.v(TAG, "Widget restore pending id=" + id |
| 2250 | + " appWidgetId=" + appWidgetId |
| 2251 | + " status =" + restoreStatus); |
| 2252 | appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId, |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2253 | component); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 2254 | appWidgetInfo.restoreStatus = restoreStatus; |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 2255 | Integer installProgress = installingPkgs.get(component.getPackageName()); |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 2256 | |
| 2257 | if ((restoreStatus & LauncherAppWidgetInfo.FLAG_RESTORE_STARTED) != 0) { |
| 2258 | // Restore has started once. |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 2259 | } else if (installProgress != null) { |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 2260 | // App restore has started. Update the flag |
| 2261 | appWidgetInfo.restoreStatus |= |
| 2262 | LauncherAppWidgetInfo.FLAG_RESTORE_STARTED; |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2263 | } else if (REMOVE_UNRESTORED_ICONS && !isSafeMode) { |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 2264 | Launcher.addDumpLog(TAG, |
Sunny Goyal | c5fb59f | 2014-09-25 16:20:38 -0700 | [diff] [blame] | 2265 | "Unrestored widget removed: " + component, true); |
Sunny Goyal | 9448536 | 2014-09-18 16:13:58 -0700 | [diff] [blame] | 2266 | itemsToRemove.add(id); |
| 2267 | continue; |
| 2268 | } |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 2269 | |
| 2270 | appWidgetInfo.installProgress = |
| 2271 | installProgress == null ? 0 : installProgress; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 2272 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2273 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2274 | appWidgetInfo.id = id; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2275 | appWidgetInfo.screenId = c.getInt(screenIndex); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2276 | appWidgetInfo.cellX = c.getInt(cellXIndex); |
| 2277 | appWidgetInfo.cellY = c.getInt(cellYIndex); |
| 2278 | appWidgetInfo.spanX = c.getInt(spanXIndex); |
| 2279 | appWidgetInfo.spanY = c.getInt(spanYIndex); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2280 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2281 | if (!customWidget) { |
| 2282 | int[] minSpan = Launcher.getMinSpanForWidget(context, provider); |
| 2283 | appWidgetInfo.minSpanX = minSpan[0]; |
| 2284 | appWidgetInfo.minSpanY = minSpan[1]; |
| 2285 | } |
| 2286 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2287 | container = c.getInt(containerIndex); |
| 2288 | if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP && |
| 2289 | container != LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 2290 | Log.e(TAG, "Widget found where container != " + |
| 2291 | "CONTAINER_DESKTOP nor CONTAINER_HOTSEAT - ignoring!"); |
| 2292 | continue; |
| 2293 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2294 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 2295 | appWidgetInfo.container = c.getInt(containerIndex); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2296 | // check & update map of what's occupied |
Sunny Goyal | fc0fe6b | 2014-10-16 12:18:37 -0700 | [diff] [blame] | 2297 | if (!checkItemPlacement(occupied, appWidgetInfo)) { |
| 2298 | itemsToRemove.add(id); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2299 | break; |
| 2300 | } |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 2301 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2302 | if (!customWidget) { |
| 2303 | String providerName = |
| 2304 | appWidgetInfo.providerName.flattenToString(); |
| 2305 | if (!providerName.equals(savedProvider) || |
| 2306 | (appWidgetInfo.restoreStatus != restoreStatus)) { |
| 2307 | ContentValues values = new ContentValues(); |
| 2308 | values.put( |
| 2309 | LauncherSettings.Favorites.APPWIDGET_PROVIDER, |
| 2310 | providerName); |
| 2311 | values.put(LauncherSettings.Favorites.RESTORED, |
| 2312 | appWidgetInfo.restoreStatus); |
Sunny Goyal | bb3b02f | 2015-01-15 12:00:14 -0800 | [diff] [blame] | 2313 | updateItem(id, values); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2314 | } |
Chris Wren | c3919c0 | 2013-09-18 09:48:33 -0400 | [diff] [blame] | 2315 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2316 | sBgItemsIdMap.put(appWidgetInfo.id, appWidgetInfo); |
| 2317 | sBgAppWidgets.add(appWidgetInfo); |
| 2318 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2319 | break; |
| 2320 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2321 | } catch (Exception e) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 2322 | Launcher.addDumpLog(TAG, "Desktop items loading interrupted", e, true); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 2323 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2324 | } |
| 2325 | } finally { |
Daniel Sandler | 47b5031 | 2013-07-25 13:16:14 -0400 | [diff] [blame] | 2326 | if (c != null) { |
| 2327 | c.close(); |
| 2328 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 2331 | // Break early if we've stopped loading |
| 2332 | if (mStopped) { |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 2333 | clearSBgDataStructures(); |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 2334 | return; |
Winson Chung | ba9c37f | 2013-08-30 14:11:37 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Sunny Goyal | 1936ec0 | 2015-05-12 11:03:04 -0700 | [diff] [blame] | 2337 | // Remove any empty folder |
| 2338 | LongArrayMap<FolderInfo> emptyFolders = sBgFolders.clone(); |
| 2339 | for (ItemInfo item: sBgItemsIdMap) { |
| 2340 | long container = item.container; |
| 2341 | if (emptyFolders.containsKey(container)) { |
| 2342 | emptyFolders.remove(container); |
| 2343 | } |
| 2344 | } |
| 2345 | for (FolderInfo folder : emptyFolders) { |
| 2346 | long folderId = folder.id; |
| 2347 | sBgFolders.remove(folderId); |
| 2348 | sBgItemsIdMap.remove(folderId); |
| 2349 | sBgWorkspaceItems.remove(folder); |
| 2350 | itemsToRemove.add(folderId); |
| 2351 | } |
| 2352 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2353 | if (itemsToRemove.size() > 0) { |
| 2354 | ContentProviderClient client = contentResolver.acquireContentProviderClient( |
Sunny Goyal | c5fb59f | 2014-09-25 16:20:38 -0700 | [diff] [blame] | 2355 | contentUri); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2356 | // Remove dead items |
| 2357 | for (long id : itemsToRemove) { |
| 2358 | if (DEBUG_LOADERS) { |
| 2359 | Log.d(TAG, "Removed id = " + id); |
| 2360 | } |
| 2361 | // Don't notify content observers |
| 2362 | try { |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 2363 | client.delete(LauncherSettings.Favorites.getContentUri(id), null, null); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2364 | } catch (RemoteException e) { |
| 2365 | Log.w(TAG, "Could not remove id = " + id); |
| 2366 | } |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 2367 | } |
| 2368 | } |
| 2369 | |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 2370 | if (restoredRows.size() > 0) { |
| 2371 | ContentProviderClient updater = contentResolver.acquireContentProviderClient( |
Sunny Goyal | c5fb59f | 2014-09-25 16:20:38 -0700 | [diff] [blame] | 2372 | contentUri); |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 2373 | // Update restored items that no longer require special handling |
| 2374 | try { |
| 2375 | StringBuilder selectionBuilder = new StringBuilder(); |
| 2376 | selectionBuilder.append(LauncherSettings.Favorites._ID); |
| 2377 | selectionBuilder.append(" IN ("); |
| 2378 | selectionBuilder.append(TextUtils.join(", ", restoredRows)); |
| 2379 | selectionBuilder.append(")"); |
| 2380 | ContentValues values = new ContentValues(); |
| 2381 | values.put(LauncherSettings.Favorites.RESTORED, 0); |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 2382 | updater.update(LauncherSettings.Favorites.CONTENT_URI, |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 2383 | values, selectionBuilder.toString(), null); |
| 2384 | } catch (RemoteException e) { |
| 2385 | Log.w(TAG, "Could not update restored rows"); |
| 2386 | } |
| 2387 | } |
| 2388 | |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 2389 | if (!isSdCardReady && !sPendingPackages.isEmpty()) { |
| 2390 | context.registerReceiver(new AppsAvailabilityCheck(), |
Sunny Goyal | 05e318d | 2014-07-29 11:49:35 -0700 | [diff] [blame] | 2391 | new IntentFilter(StartupReceiver.SYSTEM_READY), |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 2392 | null, sWorker); |
| 2393 | } |
| 2394 | |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 2395 | sBgWorkspaceScreens.addAll(loadWorkspaceScreensDb(mContext)); |
| 2396 | // Log to disk |
| 2397 | Launcher.addDumpLog(TAG, "11683562 - sBgWorkspaceScreens: " + |
| 2398 | TextUtils.join(", ", sBgWorkspaceScreens), true); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 2399 | |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 2400 | // Remove any empty screens |
| 2401 | ArrayList<Long> unusedScreens = new ArrayList<Long>(sBgWorkspaceScreens); |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 2402 | for (ItemInfo item: sBgItemsIdMap) { |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 2403 | long screenId = item.screenId; |
| 2404 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && |
| 2405 | unusedScreens.contains(screenId)) { |
| 2406 | unusedScreens.remove(screenId); |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | // If there are any empty screens remove them, and update. |
| 2411 | if (unusedScreens.size() != 0) { |
| 2412 | // Log to disk |
| 2413 | Launcher.addDumpLog(TAG, "11683562 - unusedScreens (to be removed): " + |
| 2414 | TextUtils.join(", ", unusedScreens), true); |
| 2415 | |
| 2416 | sBgWorkspaceScreens.removeAll(unusedScreens); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2417 | updateWorkspaceScreenOrder(context, sBgWorkspaceScreens); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2420 | if (DEBUG_LOADERS) { |
| 2421 | Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms"); |
| 2422 | Log.d(TAG, "workspace layout: "); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2423 | int nScreens = occupied.size(); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 2424 | for (int y = 0; y < countY; y++) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2425 | String line = ""; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2426 | |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 2427 | for (int i = 0; i < nScreens; i++) { |
| 2428 | long screenId = occupied.keyAt(i); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 2429 | if (screenId > 0) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2430 | line += " | "; |
| 2431 | } |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 2432 | ItemInfo[][] screen = occupied.valueAt(i); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 2433 | for (int x = 0; x < countX; x++) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 2434 | if (x < screen.length && y < screen[x].length) { |
| 2435 | line += (screen[x][y] != null) ? "#" : "."; |
| 2436 | } else { |
| 2437 | line += "!"; |
| 2438 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2439 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2440 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2441 | Log.d(TAG, "[ " + line + " ]"); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2442 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2443 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2444 | } |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Sunny Goyal | bb3b02f | 2015-01-15 12:00:14 -0800 | [diff] [blame] | 2447 | /** |
| 2448 | * Partially updates the item without any notification. Must be called on the worker thread. |
| 2449 | */ |
| 2450 | private void updateItem(long itemId, ContentValues update) { |
| 2451 | mContext.getContentResolver().update( |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 2452 | LauncherSettings.Favorites.CONTENT_URI, |
Sunny Goyal | bb3b02f | 2015-01-15 12:00:14 -0800 | [diff] [blame] | 2453 | update, |
| 2454 | BaseColumns._ID + "= ?", |
| 2455 | new String[]{Long.toString(itemId)}); |
| 2456 | } |
| 2457 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2458 | /** Filters the set of items who are directly or indirectly (via another container) on the |
| 2459 | * specified screen. */ |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2460 | private void filterCurrentWorkspaceItems(long currentScreenId, |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2461 | ArrayList<ItemInfo> allWorkspaceItems, |
| 2462 | ArrayList<ItemInfo> currentScreenItems, |
| 2463 | ArrayList<ItemInfo> otherScreenItems) { |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 2464 | // Purge any null ItemInfos |
| 2465 | Iterator<ItemInfo> iter = allWorkspaceItems.iterator(); |
| 2466 | while (iter.hasNext()) { |
| 2467 | ItemInfo i = iter.next(); |
| 2468 | if (i == null) { |
| 2469 | iter.remove(); |
| 2470 | } |
| 2471 | } |
| 2472 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2473 | // Order the set of items by their containers first, this allows use to walk through the |
| 2474 | // list sequentially, build up a list of containers that are in the specified screen, |
| 2475 | // as well as all items in those containers. |
| 2476 | Set<Long> itemsOnScreen = new HashSet<Long>(); |
| 2477 | Collections.sort(allWorkspaceItems, new Comparator<ItemInfo>() { |
| 2478 | @Override |
| 2479 | public int compare(ItemInfo lhs, ItemInfo rhs) { |
| 2480 | return (int) (lhs.container - rhs.container); |
| 2481 | } |
| 2482 | }); |
| 2483 | for (ItemInfo info : allWorkspaceItems) { |
| 2484 | if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2485 | if (info.screenId == currentScreenId) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2486 | currentScreenItems.add(info); |
| 2487 | itemsOnScreen.add(info.id); |
| 2488 | } else { |
| 2489 | otherScreenItems.add(info); |
| 2490 | } |
| 2491 | } else if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 2492 | currentScreenItems.add(info); |
| 2493 | itemsOnScreen.add(info.id); |
| 2494 | } else { |
| 2495 | if (itemsOnScreen.contains(info.container)) { |
| 2496 | currentScreenItems.add(info); |
| 2497 | itemsOnScreen.add(info.id); |
| 2498 | } else { |
| 2499 | otherScreenItems.add(info); |
| 2500 | } |
| 2501 | } |
| 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | /** Filters the set of widgets which are on the specified screen. */ |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2506 | private void filterCurrentAppWidgets(long currentScreenId, |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2507 | ArrayList<LauncherAppWidgetInfo> appWidgets, |
| 2508 | ArrayList<LauncherAppWidgetInfo> currentScreenWidgets, |
| 2509 | ArrayList<LauncherAppWidgetInfo> otherScreenWidgets) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2510 | |
| 2511 | for (LauncherAppWidgetInfo widget : appWidgets) { |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 2512 | if (widget == null) continue; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2513 | if (widget.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2514 | widget.screenId == currentScreenId) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2515 | currentScreenWidgets.add(widget); |
| 2516 | } else { |
| 2517 | otherScreenWidgets.add(widget); |
| 2518 | } |
| 2519 | } |
| 2520 | } |
| 2521 | |
| 2522 | /** Filters the set of folders which are on the specified screen. */ |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2523 | private void filterCurrentFolders(long currentScreenId, |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 2524 | LongArrayMap<ItemInfo> itemsIdMap, |
| 2525 | LongArrayMap<FolderInfo> folders, |
| 2526 | LongArrayMap<FolderInfo> currentScreenFolders, |
| 2527 | LongArrayMap<FolderInfo> otherScreenFolders) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2528 | |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 2529 | int total = folders.size(); |
| 2530 | for (int i = 0; i < total; i++) { |
| 2531 | long id = folders.keyAt(i); |
| 2532 | FolderInfo folder = folders.valueAt(i); |
| 2533 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2534 | ItemInfo info = itemsIdMap.get(id); |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 2535 | if (info == null || folder == null) continue; |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2536 | if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2537 | info.screenId == currentScreenId) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2538 | currentScreenFolders.put(id, folder); |
| 2539 | } else { |
| 2540 | otherScreenFolders.put(id, folder); |
| 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | /** Sorts the set of items by hotseat, workspace (spatially from top to bottom, left to |
| 2546 | * right) */ |
| 2547 | private void sortWorkspaceItemsSpatially(ArrayList<ItemInfo> workspaceItems) { |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 2548 | final LauncherAppState app = LauncherAppState.getInstance(); |
| 2549 | final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2550 | // XXX: review this |
| 2551 | Collections.sort(workspaceItems, new Comparator<ItemInfo>() { |
Winson Chung | db8a894 | 2012-04-03 14:08:41 -0700 | [diff] [blame] | 2552 | @Override |
| 2553 | public int compare(ItemInfo lhs, ItemInfo rhs) { |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 2554 | int cellCountX = (int) grid.numColumns; |
| 2555 | int cellCountY = (int) grid.numRows; |
Winson Chung | db8a894 | 2012-04-03 14:08:41 -0700 | [diff] [blame] | 2556 | int screenOffset = cellCountX * cellCountY; |
| 2557 | int containerOffset = screenOffset * (Launcher.SCREEN_COUNT + 1); // +1 hotseat |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2558 | long lr = (lhs.container * containerOffset + lhs.screenId * screenOffset + |
Winson Chung | db8a894 | 2012-04-03 14:08:41 -0700 | [diff] [blame] | 2559 | lhs.cellY * cellCountX + lhs.cellX); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2560 | long rr = (rhs.container * containerOffset + rhs.screenId * screenOffset + |
Winson Chung | db8a894 | 2012-04-03 14:08:41 -0700 | [diff] [blame] | 2561 | rhs.cellY * cellCountX + rhs.cellX); |
| 2562 | return (int) (lr - rr); |
| 2563 | } |
| 2564 | }); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2565 | } |
Winson Chung | db8a894 | 2012-04-03 14:08:41 -0700 | [diff] [blame] | 2566 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2567 | private void bindWorkspaceScreens(final Callbacks oldCallbacks, |
| 2568 | final ArrayList<Long> orderedScreens) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2569 | final Runnable r = new Runnable() { |
| 2570 | @Override |
| 2571 | public void run() { |
| 2572 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 2573 | if (callbacks != null) { |
| 2574 | callbacks.bindScreens(orderedScreens); |
| 2575 | } |
| 2576 | } |
| 2577 | }; |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 2578 | runOnMainThread(r); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2581 | private void bindWorkspaceItems(final Callbacks oldCallbacks, |
| 2582 | final ArrayList<ItemInfo> workspaceItems, |
| 2583 | final ArrayList<LauncherAppWidgetInfo> appWidgets, |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 2584 | final LongArrayMap<FolderInfo> folders, |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2585 | ArrayList<Runnable> deferredBindRunnables) { |
Winson Chung | 603bcb9 | 2011-09-02 11:45:39 -0700 | [diff] [blame] | 2586 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2587 | final boolean postOnMainThread = (deferredBindRunnables != null); |
| 2588 | |
| 2589 | // Bind the workspace items |
Winson Chung | db8a894 | 2012-04-03 14:08:41 -0700 | [diff] [blame] | 2590 | int N = workspaceItems.size(); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2591 | for (int i = 0; i < N; i += ITEMS_CHUNK) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2592 | final int start = i; |
| 2593 | final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2594 | final Runnable r = new Runnable() { |
| 2595 | @Override |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2596 | public void run() { |
Joe Onorato | c131b74 | 2010-03-11 15:45:05 -0800 | [diff] [blame] | 2597 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2598 | if (callbacks != null) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2599 | callbacks.bindItems(workspaceItems, start, start+chunkSize, |
| 2600 | false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2601 | } |
| 2602 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2603 | }; |
| 2604 | if (postOnMainThread) { |
Jason Monk | a0a7a74 | 2014-04-22 09:23:19 -0400 | [diff] [blame] | 2605 | synchronized (deferredBindRunnables) { |
| 2606 | deferredBindRunnables.add(r); |
| 2607 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2608 | } else { |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 2609 | runOnMainThread(r); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2610 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2611 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2612 | |
| 2613 | // Bind the folders |
| 2614 | if (!folders.isEmpty()) { |
| 2615 | final Runnable r = new Runnable() { |
| 2616 | public void run() { |
| 2617 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 2618 | if (callbacks != null) { |
| 2619 | callbacks.bindFolders(folders); |
| 2620 | } |
| 2621 | } |
| 2622 | }; |
| 2623 | if (postOnMainThread) { |
Jason Monk | a0a7a74 | 2014-04-22 09:23:19 -0400 | [diff] [blame] | 2624 | synchronized (deferredBindRunnables) { |
| 2625 | deferredBindRunnables.add(r); |
| 2626 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2627 | } else { |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 2628 | runOnMainThread(r); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | // Bind the widgets, one at a time |
| 2633 | N = appWidgets.size(); |
| 2634 | for (int i = 0; i < N; i++) { |
| 2635 | final LauncherAppWidgetInfo widget = appWidgets.get(i); |
| 2636 | final Runnable r = new Runnable() { |
| 2637 | public void run() { |
| 2638 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 2639 | if (callbacks != null) { |
| 2640 | callbacks.bindAppWidget(widget); |
| 2641 | } |
| 2642 | } |
| 2643 | }; |
| 2644 | if (postOnMainThread) { |
| 2645 | deferredBindRunnables.add(r); |
| 2646 | } else { |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 2647 | runOnMainThread(r); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | /** |
| 2653 | * Binds all loaded data to actual views on the main thread. |
| 2654 | */ |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 2655 | private void bindWorkspace(int synchronizeBindPage) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2656 | final long t = SystemClock.uptimeMillis(); |
| 2657 | Runnable r; |
| 2658 | |
| 2659 | // Don't use these two variables in any of the callback runnables. |
| 2660 | // Otherwise we hold a reference to them. |
| 2661 | final Callbacks oldCallbacks = mCallbacks.get(); |
| 2662 | if (oldCallbacks == null) { |
| 2663 | // This launcher has exited and nobody bothered to tell us. Just bail. |
| 2664 | Log.w(TAG, "LoaderTask running with no launcher"); |
| 2665 | return; |
| 2666 | } |
| 2667 | |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2668 | // Save a copy of all the bg-thread collections |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2669 | ArrayList<ItemInfo> workspaceItems = new ArrayList<ItemInfo>(); |
| 2670 | ArrayList<LauncherAppWidgetInfo> appWidgets = |
| 2671 | new ArrayList<LauncherAppWidgetInfo>(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2672 | ArrayList<Long> orderedScreenIds = new ArrayList<Long>(); |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 2673 | |
| 2674 | final LongArrayMap<FolderInfo> folders; |
| 2675 | final LongArrayMap<ItemInfo> itemsIdMap; |
| 2676 | |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 2677 | synchronized (sBgLock) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2678 | workspaceItems.addAll(sBgWorkspaceItems); |
| 2679 | appWidgets.addAll(sBgAppWidgets); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2680 | orderedScreenIds.addAll(sBgWorkspaceScreens); |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 2681 | |
| 2682 | folders = sBgFolders.clone(); |
| 2683 | itemsIdMap = sBgItemsIdMap.clone(); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2684 | } |
| 2685 | |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 2686 | final boolean isLoadingSynchronously = |
| 2687 | synchronizeBindPage != PagedView.INVALID_RESTORE_PAGE; |
Adam Cohen | d8dbb46 | 2013-11-27 11:55:48 -0800 | [diff] [blame] | 2688 | int currScreen = isLoadingSynchronously ? synchronizeBindPage : |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2689 | oldCallbacks.getCurrentWorkspaceScreen(); |
Adam Cohen | d8dbb46 | 2013-11-27 11:55:48 -0800 | [diff] [blame] | 2690 | if (currScreen >= orderedScreenIds.size()) { |
| 2691 | // There may be no workspace screens (just hotseat items and an empty page). |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 2692 | currScreen = PagedView.INVALID_RESTORE_PAGE; |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2693 | } |
Adam Cohen | d8dbb46 | 2013-11-27 11:55:48 -0800 | [diff] [blame] | 2694 | final int currentScreen = currScreen; |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 2695 | final long currentScreenId = currentScreen < 0 |
| 2696 | ? INVALID_SCREEN_ID : orderedScreenIds.get(currentScreen); |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2697 | |
| 2698 | // Load all the items that are on the current page first (and in the process, unbind |
| 2699 | // all the existing workspace items before we call startBinding() below. |
| 2700 | unbindWorkspaceItemsOnMainThread(); |
| 2701 | |
| 2702 | // Separate the items that are on the current screen, and all the other remaining items |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2703 | ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<ItemInfo>(); |
| 2704 | ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<ItemInfo>(); |
| 2705 | ArrayList<LauncherAppWidgetInfo> currentAppWidgets = |
| 2706 | new ArrayList<LauncherAppWidgetInfo>(); |
| 2707 | ArrayList<LauncherAppWidgetInfo> otherAppWidgets = |
| 2708 | new ArrayList<LauncherAppWidgetInfo>(); |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 2709 | LongArrayMap<FolderInfo> currentFolders = new LongArrayMap<>(); |
| 2710 | LongArrayMap<FolderInfo> otherFolders = new LongArrayMap<>(); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2711 | |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2712 | filterCurrentWorkspaceItems(currentScreenId, workspaceItems, currentWorkspaceItems, |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2713 | otherWorkspaceItems); |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2714 | filterCurrentAppWidgets(currentScreenId, appWidgets, currentAppWidgets, |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2715 | otherAppWidgets); |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2716 | filterCurrentFolders(currentScreenId, itemsIdMap, folders, currentFolders, |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2717 | otherFolders); |
| 2718 | sortWorkspaceItemsSpatially(currentWorkspaceItems); |
| 2719 | sortWorkspaceItemsSpatially(otherWorkspaceItems); |
| 2720 | |
| 2721 | // Tell the workspace that we're about to start binding items |
| 2722 | r = new Runnable() { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2723 | public void run() { |
| 2724 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 2725 | if (callbacks != null) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2726 | callbacks.startBinding(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2727 | } |
| 2728 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2729 | }; |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 2730 | runOnMainThread(r); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2731 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2732 | bindWorkspaceScreens(oldCallbacks, orderedScreenIds); |
| 2733 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2734 | // Load items on the current page |
| 2735 | bindWorkspaceItems(oldCallbacks, currentWorkspaceItems, currentAppWidgets, |
| 2736 | currentFolders, null); |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 2737 | if (isLoadingSynchronously) { |
| 2738 | r = new Runnable() { |
| 2739 | public void run() { |
| 2740 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 2741 | if (callbacks != null && currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 2742 | callbacks.onPageBoundSynchronously(currentScreen); |
| 2743 | } |
| 2744 | } |
| 2745 | }; |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 2746 | runOnMainThread(r); |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 2747 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2748 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 2749 | // Load all the remaining pages (if we are loading synchronously, we want to defer this |
| 2750 | // work until after the first render) |
Jason Monk | a0a7a74 | 2014-04-22 09:23:19 -0400 | [diff] [blame] | 2751 | synchronized (mDeferredBindRunnables) { |
| 2752 | mDeferredBindRunnables.clear(); |
| 2753 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2754 | bindWorkspaceItems(oldCallbacks, otherWorkspaceItems, otherAppWidgets, otherFolders, |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 2755 | (isLoadingSynchronously ? mDeferredBindRunnables : null)); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2756 | |
| 2757 | // Tell the workspace that we're done binding items |
| 2758 | r = new Runnable() { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2759 | public void run() { |
| 2760 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 2761 | if (callbacks != null) { |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 2762 | callbacks.finishBindingItems(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2763 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2764 | |
Winson Chung | 98e030b | 2012-05-07 16:01:11 -0700 | [diff] [blame] | 2765 | // If we're profiling, ensure this is the last thing in the queue. |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2766 | if (DEBUG_LOADERS) { |
| 2767 | Log.d(TAG, "bound workspace in " |
| 2768 | + (SystemClock.uptimeMillis()-t) + "ms"); |
| 2769 | } |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 2770 | |
| 2771 | mIsLoadingAndBindingWorkspace = false; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2772 | } |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2773 | }; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 2774 | if (isLoadingSynchronously) { |
Jason Monk | a0a7a74 | 2014-04-22 09:23:19 -0400 | [diff] [blame] | 2775 | synchronized (mDeferredBindRunnables) { |
| 2776 | mDeferredBindRunnables.add(r); |
| 2777 | } |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 2778 | } else { |
Sunny Goyal | d33860f | 2015-04-23 16:02:20 -0700 | [diff] [blame] | 2779 | runOnMainThread(r); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 2780 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2781 | } |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 2782 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2783 | private void loadAndBindAllApps() { |
| 2784 | if (DEBUG_LOADERS) { |
| 2785 | Log.d(TAG, "loadAndBindAllApps mAllAppsLoaded=" + mAllAppsLoaded); |
| 2786 | } |
| 2787 | if (!mAllAppsLoaded) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2788 | loadAllApps(); |
Sunny Goyal | f5cd998 | 2015-05-18 15:19:29 -0700 | [diff] [blame^] | 2789 | synchronized (LoaderTask.this) { |
| 2790 | if (mStopped) { |
| 2791 | return; |
| 2792 | } |
| 2793 | } |
Sunny Goyal | 77919b9 | 2015-05-06 16:53:21 -0700 | [diff] [blame] | 2794 | updateAllAppsIconsCache(); |
Reena Lee | 93f824a | 2011-09-23 17:20:28 -0700 | [diff] [blame] | 2795 | synchronized (LoaderTask.this) { |
| 2796 | if (mStopped) { |
| 2797 | return; |
| 2798 | } |
| 2799 | mAllAppsLoaded = true; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 2800 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2801 | } else { |
| 2802 | onlyBindAllApps(); |
| 2803 | } |
| 2804 | } |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 2805 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2806 | private void onlyBindAllApps() { |
| 2807 | final Callbacks oldCallbacks = mCallbacks.get(); |
| 2808 | if (oldCallbacks == null) { |
| 2809 | // This launcher has exited and nobody bothered to tell us. Just bail. |
| 2810 | Log.w(TAG, "LoaderTask running with no launcher (onlyBindAllApps)"); |
| 2811 | return; |
| 2812 | } |
| 2813 | |
| 2814 | // shallow copy |
Winson Chung | c208ff9 | 2012-03-29 17:37:41 -0700 | [diff] [blame] | 2815 | @SuppressWarnings("unchecked") |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2816 | final ArrayList<AppInfo> list |
| 2817 | = (ArrayList<AppInfo>) mBgAllAppsList.data.clone(); |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2818 | Runnable r = new Runnable() { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2819 | public void run() { |
| 2820 | final long t = SystemClock.uptimeMillis(); |
| 2821 | final Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 2822 | if (callbacks != null) { |
| 2823 | callbacks.bindAllApplications(list); |
| 2824 | } |
| 2825 | if (DEBUG_LOADERS) { |
| 2826 | Log.d(TAG, "bound all " + list.size() + " apps from cache in " |
| 2827 | + (SystemClock.uptimeMillis()-t) + "ms"); |
| 2828 | } |
| 2829 | } |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2830 | }; |
| 2831 | boolean isRunningOnMainThread = !(sWorkerThread.getThreadId() == Process.myTid()); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2832 | if (isRunningOnMainThread) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2833 | r.run(); |
| 2834 | } else { |
| 2835 | mHandler.post(r); |
| 2836 | } |
Hyunyoung Song | 219d048 | 2015-05-07 12:51:42 -0700 | [diff] [blame] | 2837 | loadAndBindWidgetsAndShortcuts(mApp.getContext(), tryGetCallbacks(oldCallbacks), |
| 2838 | false /* refresh */); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2839 | } |
| 2840 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2841 | private void loadAllApps() { |
| 2842 | final long loadTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2843 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2844 | final Callbacks oldCallbacks = mCallbacks.get(); |
| 2845 | if (oldCallbacks == null) { |
| 2846 | // This launcher has exited and nobody bothered to tell us. Just bail. |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2847 | Log.w(TAG, "LoaderTask running with no launcher (loadAllApps)"); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2848 | return; |
| 2849 | } |
| 2850 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2851 | final List<UserHandleCompat> profiles = mUserManager.getUserProfiles(); |
| 2852 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2853 | // Clear the list of apps |
| 2854 | mBgAllAppsList.clear(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2855 | for (UserHandleCompat user : profiles) { |
| 2856 | // Query for the set of apps |
| 2857 | final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 2858 | final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2859 | if (DEBUG_LOADERS) { |
| 2860 | Log.d(TAG, "getActivityList took " |
| 2861 | + (SystemClock.uptimeMillis()-qiaTime) + "ms for user " + user); |
| 2862 | Log.d(TAG, "getActivityList got " + apps.size() + " apps for user " + user); |
| 2863 | } |
| 2864 | // Fail if we don't have any apps |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 2865 | // TODO: Fix this. Only fail for the current user. |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2866 | if (apps == null || apps.isEmpty()) { |
| 2867 | return; |
| 2868 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 2869 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2870 | // Create the ApplicationInfos |
| 2871 | for (int i = 0; i < apps.size(); i++) { |
| 2872 | LauncherActivityInfoCompat app = apps.get(i); |
| 2873 | // This builds the icon bitmaps. |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 2874 | mBgAllAppsList.add(new AppInfo(mContext, app, user, mIconCache)); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2875 | } |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 2876 | |
Sunny Goyal | 756a28a | 2015-04-23 17:07:55 -0700 | [diff] [blame] | 2877 | final ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user); |
| 2878 | if (heuristic != null) { |
| 2879 | runAfterBindCompletes(new Runnable() { |
| 2880 | |
| 2881 | @Override |
| 2882 | public void run() { |
| 2883 | heuristic.processUserApps(apps); |
| 2884 | } |
| 2885 | }); |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 2886 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2887 | } |
Bjorn Bringert | 85f418d | 2013-09-06 12:50:05 +0100 | [diff] [blame] | 2888 | // Huh? Shouldn't this be inside the Runnable below? |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2889 | final ArrayList<AppInfo> added = mBgAllAppsList.added; |
| 2890 | mBgAllAppsList.added = new ArrayList<AppInfo>(); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2891 | |
| 2892 | // Post callback on main thread |
| 2893 | mHandler.post(new Runnable() { |
| 2894 | public void run() { |
Hyunyoung Song | 9892e58 | 2015-05-05 10:07:23 -0700 | [diff] [blame] | 2895 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2896 | final long bindTime = SystemClock.uptimeMillis(); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 2897 | final Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2898 | if (callbacks != null) { |
| 2899 | callbacks.bindAllApplications(added); |
| 2900 | if (DEBUG_LOADERS) { |
| 2901 | Log.d(TAG, "bound " + added.size() + " apps in " |
| 2902 | + (SystemClock.uptimeMillis() - bindTime) + "ms"); |
| 2903 | } |
| 2904 | } else { |
| 2905 | Log.i(TAG, "not binding apps: no Launcher activity"); |
| 2906 | } |
| 2907 | } |
| 2908 | }); |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 2909 | // Cleanup any data stored for a deleted user. |
| 2910 | ManagedProfileHeuristic.processAllUsers(profiles, mContext); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2911 | |
Hyunyoung Song | 219d048 | 2015-05-07 12:51:42 -0700 | [diff] [blame] | 2912 | loadAndBindWidgetsAndShortcuts(mApp.getContext(), tryGetCallbacks(oldCallbacks), |
| 2913 | true /* refresh */); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2914 | if (DEBUG_LOADERS) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2915 | Log.d(TAG, "Icons processed in " |
| 2916 | + (SystemClock.uptimeMillis() - loadTime) + "ms"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2917 | } |
| 2918 | } |
| 2919 | |
Sunny Goyal | 77919b9 | 2015-05-06 16:53:21 -0700 | [diff] [blame] | 2920 | private void updateAllAppsIconsCache() { |
| 2921 | final ArrayList<AppInfo> updatedApps = new ArrayList<>(); |
| 2922 | |
| 2923 | for (UserHandleCompat user : mUserManager.getUserProfiles()) { |
| 2924 | // Query for the set of apps |
| 2925 | final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user); |
| 2926 | // Fail if we don't have any apps |
| 2927 | // TODO: Fix this. Only fail for the current user. |
| 2928 | if (apps == null || apps.isEmpty()) { |
| 2929 | return; |
| 2930 | } |
| 2931 | |
| 2932 | // Update icon cache |
| 2933 | HashSet<String> updatedPackages = mIconCache.updateDBIcons(user, apps); |
| 2934 | |
| 2935 | // If any package icon has changed (app was updated while launcher was dead), |
| 2936 | // update the corresponding shortcuts. |
| 2937 | if (!updatedPackages.isEmpty()) { |
| 2938 | final ArrayList<ShortcutInfo> updatedShortcuts = new ArrayList<>(); |
| 2939 | synchronized (sBgLock) { |
| 2940 | for (ItemInfo info : sBgItemsIdMap) { |
| 2941 | if (info instanceof ShortcutInfo && user.equals(info.user) |
| 2942 | && info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { |
| 2943 | ShortcutInfo si = (ShortcutInfo) info; |
| 2944 | ComponentName cn = si.getTargetComponent(); |
| 2945 | if (cn != null && updatedPackages.contains(cn.getPackageName())) { |
| 2946 | si.updateIcon(mIconCache); |
| 2947 | updatedShortcuts.add(si); |
| 2948 | } |
| 2949 | } |
| 2950 | } |
| 2951 | mBgAllAppsList.updateIconsAndLabels(updatedPackages, user, updatedApps); |
| 2952 | } |
| 2953 | |
| 2954 | if (!updatedShortcuts.isEmpty()) { |
| 2955 | final UserHandleCompat userFinal = user; |
| 2956 | mHandler.post(new Runnable() { |
| 2957 | |
| 2958 | public void run() { |
| 2959 | Callbacks cb = getCallback(); |
| 2960 | if (cb != null) { |
| 2961 | cb.bindShortcutsChanged(updatedShortcuts, |
| 2962 | new ArrayList<ShortcutInfo>(), userFinal); |
| 2963 | } |
| 2964 | } |
| 2965 | }); |
| 2966 | } |
| 2967 | } |
| 2968 | } |
| 2969 | if (!updatedApps.isEmpty()) { |
| 2970 | mHandler.post(new Runnable() { |
| 2971 | |
| 2972 | public void run() { |
| 2973 | Callbacks cb = getCallback(); |
| 2974 | if (cb != null) { |
| 2975 | cb.bindAppsUpdated(updatedApps); |
| 2976 | } |
| 2977 | } |
| 2978 | }); |
| 2979 | } |
| 2980 | } |
| 2981 | |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2982 | public void dumpState() { |
Winson Chung | 2abf94d | 2012-07-18 18:16:38 -0700 | [diff] [blame] | 2983 | synchronized (sBgLock) { |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 2984 | Log.d(TAG, "mLoaderTask.mContext=" + mContext); |
| 2985 | Log.d(TAG, "mLoaderTask.mIsLaunching=" + mIsLaunching); |
| 2986 | Log.d(TAG, "mLoaderTask.mStopped=" + mStopped); |
| 2987 | Log.d(TAG, "mLoaderTask.mLoadAndBindStepFinished=" + mLoadAndBindStepFinished); |
| 2988 | Log.d(TAG, "mItems size=" + sBgWorkspaceItems.size()); |
| 2989 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | void enqueuePackageUpdated(PackageUpdatedTask task) { |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 2994 | sWorker.post(task); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2995 | } |
| 2996 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 2997 | @Thunk class AppsAvailabilityCheck extends BroadcastReceiver { |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 2998 | |
| 2999 | @Override |
| 3000 | public void onReceive(Context context, Intent intent) { |
| 3001 | synchronized (sBgLock) { |
| 3002 | final LauncherAppsCompat launcherApps = LauncherAppsCompat |
| 3003 | .getInstance(mApp.getContext()); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3004 | final PackageManager manager = context.getPackageManager(); |
| 3005 | final ArrayList<String> packagesRemoved = new ArrayList<String>(); |
| 3006 | final ArrayList<String> packagesUnavailable = new ArrayList<String>(); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 3007 | for (Entry<UserHandleCompat, HashSet<String>> entry : sPendingPackages.entrySet()) { |
| 3008 | UserHandleCompat user = entry.getKey(); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3009 | packagesRemoved.clear(); |
| 3010 | packagesUnavailable.clear(); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 3011 | for (String pkg : entry.getValue()) { |
| 3012 | if (!launcherApps.isPackageEnabledForProfile(pkg, user)) { |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3013 | boolean packageOnSdcard = launcherApps.isAppEnabled( |
| 3014 | manager, pkg, PackageManager.GET_UNINSTALLED_PACKAGES); |
| 3015 | if (packageOnSdcard) { |
| 3016 | Launcher.addDumpLog(TAG, "Package found on sd-card: " + pkg, true); |
| 3017 | packagesUnavailable.add(pkg); |
| 3018 | } else { |
| 3019 | Launcher.addDumpLog(TAG, "Package not found: " + pkg, true); |
| 3020 | packagesRemoved.add(pkg); |
| 3021 | } |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 3022 | } |
| 3023 | } |
| 3024 | if (!packagesRemoved.isEmpty()) { |
| 3025 | enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_REMOVE, |
| 3026 | packagesRemoved.toArray(new String[packagesRemoved.size()]), user)); |
| 3027 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3028 | if (!packagesUnavailable.isEmpty()) { |
| 3029 | enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_UNAVAILABLE, |
| 3030 | packagesUnavailable.toArray(new String[packagesUnavailable.size()]), user)); |
| 3031 | } |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 3032 | } |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3033 | sPendingPackages.clear(); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 3034 | } |
| 3035 | } |
| 3036 | } |
| 3037 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3038 | private class PackageUpdatedTask implements Runnable { |
| 3039 | int mOp; |
| 3040 | String[] mPackages; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3041 | UserHandleCompat mUser; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3042 | |
| 3043 | public static final int OP_NONE = 0; |
| 3044 | public static final int OP_ADD = 1; |
| 3045 | public static final int OP_UPDATE = 2; |
| 3046 | public static final int OP_REMOVE = 3; // uninstlled |
| 3047 | public static final int OP_UNAVAILABLE = 4; // external media unmounted |
| 3048 | |
| 3049 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3050 | public PackageUpdatedTask(int op, String[] packages, UserHandleCompat user) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3051 | mOp = op; |
| 3052 | mPackages = packages; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3053 | mUser = user; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3054 | } |
| 3055 | |
| 3056 | public void run() { |
Sunny Goyal | c905efc | 2015-05-06 09:54:53 -0700 | [diff] [blame] | 3057 | if (!mHasLoaderCompletedOnce) { |
| 3058 | // Loader has not yet run. |
| 3059 | return; |
| 3060 | } |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 3061 | final Context context = mApp.getContext(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3062 | |
| 3063 | final String[] packages = mPackages; |
| 3064 | final int N = packages.length; |
| 3065 | switch (mOp) { |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 3066 | case OP_ADD: { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3067 | for (int i=0; i<N; i++) { |
| 3068 | if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.addPackage " + packages[i]); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3069 | mIconCache.updateIconsForPkg(packages[i], mUser); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3070 | mBgAllAppsList.addPackage(context, packages[i], mUser); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3071 | } |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3072 | |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 3073 | ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(context, mUser); |
| 3074 | if (heuristic != null) { |
| 3075 | heuristic.processPackageAdd(mPackages); |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3076 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3077 | break; |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 3078 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3079 | case OP_UPDATE: |
| 3080 | for (int i=0; i<N; i++) { |
| 3081 | if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3082 | mIconCache.updateIconsForPkg(packages[i], mUser); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3083 | mBgAllAppsList.updatePackage(context, packages[i], mUser); |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 3084 | mApp.getWidgetCache().removePackage(packages[i], mUser); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3085 | } |
| 3086 | break; |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 3087 | case OP_REMOVE: { |
| 3088 | ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(context, mUser); |
| 3089 | if (heuristic != null) { |
| 3090 | heuristic.processPackageRemoved(mPackages); |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3091 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3092 | for (int i=0; i<N; i++) { |
| 3093 | if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3094 | mIconCache.removeIconsForPkg(packages[i], mUser); |
| 3095 | } |
| 3096 | // Fall through |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 3097 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3098 | case OP_UNAVAILABLE: |
| 3099 | for (int i=0; i<N; i++) { |
| 3100 | if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]); |
| 3101 | mBgAllAppsList.removePackage(packages[i], mUser); |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 3102 | mApp.getWidgetCache().removePackage(packages[i], mUser); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3103 | } |
| 3104 | break; |
| 3105 | } |
| 3106 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 3107 | ArrayList<AppInfo> added = null; |
| 3108 | ArrayList<AppInfo> modified = null; |
| 3109 | final ArrayList<AppInfo> removedApps = new ArrayList<AppInfo>(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3110 | |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 3111 | if (mBgAllAppsList.added.size() > 0) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 3112 | added = new ArrayList<AppInfo>(mBgAllAppsList.added); |
Winson Chung | 5d55f33 | 2012-07-16 20:45:03 -0700 | [diff] [blame] | 3113 | mBgAllAppsList.added.clear(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3114 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 3115 | if (mBgAllAppsList.modified.size() > 0) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 3116 | modified = new ArrayList<AppInfo>(mBgAllAppsList.modified); |
Winson Chung | 5d55f33 | 2012-07-16 20:45:03 -0700 | [diff] [blame] | 3117 | mBgAllAppsList.modified.clear(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3118 | } |
Winson Chung | 5d55f33 | 2012-07-16 20:45:03 -0700 | [diff] [blame] | 3119 | if (mBgAllAppsList.removed.size() > 0) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 3120 | removedApps.addAll(mBgAllAppsList.removed); |
Winson Chung | 5d55f33 | 2012-07-16 20:45:03 -0700 | [diff] [blame] | 3121 | mBgAllAppsList.removed.clear(); |
Winson Chung | cd81073 | 2012-06-18 16:45:43 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3124 | final Callbacks callbacks = getCallback(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3125 | if (callbacks == null) { |
| 3126 | Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading."); |
| 3127 | return; |
| 3128 | } |
| 3129 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3130 | final HashMap<ComponentName, AppInfo> addedOrUpdatedApps = |
| 3131 | new HashMap<ComponentName, AppInfo>(); |
| 3132 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3133 | if (added != null) { |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 3134 | addAppsToAllApps(context, added); |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3135 | for (AppInfo ai : added) { |
| 3136 | addedOrUpdatedApps.put(ai.componentName, ai); |
| 3137 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3138 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 3139 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3140 | if (modified != null) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 3141 | final ArrayList<AppInfo> modifiedFinal = modified; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3142 | for (AppInfo ai : modified) { |
| 3143 | addedOrUpdatedApps.put(ai.componentName, ai); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3146 | mHandler.post(new Runnable() { |
| 3147 | public void run() { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3148 | Callbacks cb = getCallback(); |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 3149 | if (callbacks == cb && cb != null) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3150 | callbacks.bindAppsUpdated(modifiedFinal); |
| 3151 | } |
| 3152 | } |
| 3153 | }); |
| 3154 | } |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 3155 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3156 | // Update shortcut infos |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3157 | if (mOp == OP_ADD || mOp == OP_UPDATE) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3158 | final ArrayList<ShortcutInfo> updatedShortcuts = new ArrayList<ShortcutInfo>(); |
| 3159 | final ArrayList<ShortcutInfo> removedShortcuts = new ArrayList<ShortcutInfo>(); |
| 3160 | final ArrayList<LauncherAppWidgetInfo> widgets = new ArrayList<LauncherAppWidgetInfo>(); |
| 3161 | |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3162 | HashSet<String> packageSet = new HashSet<String>(Arrays.asList(packages)); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3163 | synchronized (sBgLock) { |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 3164 | for (ItemInfo info : sBgItemsIdMap) { |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3165 | if (info instanceof ShortcutInfo && mUser.equals(info.user)) { |
| 3166 | ShortcutInfo si = (ShortcutInfo) info; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3167 | boolean infoUpdated = false; |
| 3168 | boolean shortcutUpdated = false; |
| 3169 | |
| 3170 | // Update shortcuts which use iconResource. |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3171 | if ((si.iconResource != null) |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3172 | && packageSet.contains(si.iconResource.packageName)) { |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3173 | Bitmap icon = Utilities.createIconBitmap(si.iconResource.packageName, |
| 3174 | si.iconResource.resourceName, mIconCache, context); |
| 3175 | if (icon != null) { |
| 3176 | si.setIcon(icon); |
| 3177 | si.usingFallbackIcon = false; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3178 | infoUpdated = true; |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3179 | } |
| 3180 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3181 | |
| 3182 | ComponentName cn = si.getTargetComponent(); |
| 3183 | if (cn != null && packageSet.contains(cn.getPackageName())) { |
| 3184 | AppInfo appInfo = addedOrUpdatedApps.get(cn); |
| 3185 | |
| 3186 | if (si.isPromise()) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3187 | if (si.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) { |
| 3188 | // Auto install icon |
| 3189 | PackageManager pm = context.getPackageManager(); |
| 3190 | ResolveInfo matched = pm.resolveActivity( |
| 3191 | new Intent(Intent.ACTION_MAIN) |
| 3192 | .setComponent(cn).addCategory(Intent.CATEGORY_LAUNCHER), |
| 3193 | PackageManager.MATCH_DEFAULT_ONLY); |
| 3194 | if (matched == null) { |
| 3195 | // Try to find the best match activity. |
| 3196 | Intent intent = pm.getLaunchIntentForPackage( |
| 3197 | cn.getPackageName()); |
| 3198 | if (intent != null) { |
| 3199 | cn = intent.getComponent(); |
| 3200 | appInfo = addedOrUpdatedApps.get(cn); |
| 3201 | } |
| 3202 | |
| 3203 | if ((intent == null) || (appInfo == null)) { |
| 3204 | removedShortcuts.add(si); |
| 3205 | continue; |
| 3206 | } |
| 3207 | si.promisedIntent = intent; |
| 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | // Restore the shortcut. |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 3212 | if (appInfo != null) { |
| 3213 | si.flags = appInfo.flags; |
| 3214 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3215 | |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 3216 | si.intent = si.promisedIntent; |
| 3217 | si.promisedIntent = null; |
| 3218 | si.status = ShortcutInfo.DEFAULT; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3219 | infoUpdated = true; |
| 3220 | si.updateIcon(mIconCache); |
| 3221 | } |
| 3222 | |
| 3223 | if (appInfo != null && Intent.ACTION_MAIN.equals(si.intent.getAction()) |
| 3224 | && si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { |
| 3225 | si.updateIcon(mIconCache); |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3226 | si.title = Utilities.trim(appInfo.title); |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3227 | si.contentDescription = appInfo.contentDescription; |
| 3228 | infoUpdated = true; |
| 3229 | } |
| 3230 | |
| 3231 | if ((si.isDisabled & ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE) != 0) { |
| 3232 | // Since package was just updated, the target must be available now. |
| 3233 | si.isDisabled &= ~ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE; |
| 3234 | shortcutUpdated = true; |
| 3235 | } |
| 3236 | } |
| 3237 | |
| 3238 | if (infoUpdated || shortcutUpdated) { |
| 3239 | updatedShortcuts.add(si); |
| 3240 | } |
| 3241 | if (infoUpdated) { |
| 3242 | updateItemInDatabase(context, si); |
| 3243 | } |
| 3244 | } else if (info instanceof LauncherAppWidgetInfo) { |
| 3245 | LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) info; |
| 3246 | if (mUser.equals(widgetInfo.user) |
| 3247 | && widgetInfo.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) |
| 3248 | && packageSet.contains(widgetInfo.providerName.getPackageName())) { |
| 3249 | widgetInfo.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY; |
| 3250 | widgets.add(widgetInfo); |
| 3251 | updateItemInDatabase(context, widgetInfo); |
| 3252 | } |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3253 | } |
| 3254 | } |
| 3255 | } |
| 3256 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3257 | if (!updatedShortcuts.isEmpty() || !removedShortcuts.isEmpty()) { |
| 3258 | mHandler.post(new Runnable() { |
| 3259 | |
| 3260 | public void run() { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3261 | Callbacks cb = getCallback(); |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3262 | if (callbacks == cb && cb != null) { |
| 3263 | callbacks.bindShortcutsChanged( |
| 3264 | updatedShortcuts, removedShortcuts, mUser); |
| 3265 | } |
| 3266 | } |
| 3267 | }); |
| 3268 | if (!removedShortcuts.isEmpty()) { |
| 3269 | deleteItemsFromDatabase(context, removedShortcuts); |
| 3270 | } |
| 3271 | } |
| 3272 | if (!widgets.isEmpty()) { |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3273 | mHandler.post(new Runnable() { |
| 3274 | public void run() { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3275 | Callbacks cb = getCallback(); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3276 | if (callbacks == cb && cb != null) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3277 | callbacks.bindWidgetsRestored(widgets); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3278 | } |
| 3279 | } |
| 3280 | }); |
| 3281 | } |
| 3282 | } |
| 3283 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3284 | final ArrayList<String> removedPackageNames = |
| 3285 | new ArrayList<String>(); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3286 | if (mOp == OP_REMOVE || mOp == OP_UNAVAILABLE) { |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3287 | // Mark all packages in the broadcast to be removed |
| 3288 | removedPackageNames.addAll(Arrays.asList(packages)); |
| 3289 | } else if (mOp == OP_UPDATE) { |
| 3290 | // Mark disabled packages in the broadcast to be removed |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3291 | for (int i=0; i<N; i++) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3292 | if (isPackageDisabled(context, packages[i], mUser)) { |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3293 | removedPackageNames.add(packages[i]); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3294 | } |
| 3295 | } |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3296 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3297 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3298 | if (!removedPackageNames.isEmpty() || !removedApps.isEmpty()) { |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3299 | final int removeReason; |
| 3300 | if (mOp == OP_UNAVAILABLE) { |
| 3301 | removeReason = ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE; |
| 3302 | } else { |
| 3303 | // Remove all the components associated with this package |
| 3304 | for (String pn : removedPackageNames) { |
| 3305 | deletePackageFromDatabase(context, pn, mUser); |
| 3306 | } |
| 3307 | // Remove all the specific components |
| 3308 | for (AppInfo a : removedApps) { |
| 3309 | ArrayList<ItemInfo> infos = getItemInfoForComponentName(a.componentName, mUser); |
| 3310 | deleteItemsFromDatabase(context, infos); |
| 3311 | } |
| 3312 | removeReason = 0; |
| 3313 | } |
| 3314 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3315 | // Remove any queued items from the install queue |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3316 | InstallShortcutReceiver.removeFromInstallQueue(context, removedPackageNames, mUser); |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3317 | // Call the components-removed callback |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3318 | mHandler.post(new Runnable() { |
| 3319 | public void run() { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3320 | Callbacks cb = getCallback(); |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 3321 | if (callbacks == cb && cb != null) { |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3322 | callbacks.bindComponentsRemoved( |
| 3323 | removedPackageNames, removedApps, mUser, removeReason); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3324 | } |
| 3325 | } |
| 3326 | }); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3327 | } |
Hyunyoung Song | 227239e | 2015-05-04 18:17:35 -0700 | [diff] [blame] | 3328 | |
| 3329 | // onProvidersChanged method (API >= 17) already refreshed the widget list |
| 3330 | loadAndBindWidgetsAndShortcuts(context, callbacks, Build.VERSION.SDK_INT < 17); |
| 3331 | |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 3332 | // Write all the logs to disk |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 3333 | mHandler.post(new Runnable() { |
| 3334 | public void run() { |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3335 | Callbacks cb = getCallback(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 3336 | if (callbacks == cb && cb != null) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 3337 | callbacks.dumpLogsToLocalData(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 3338 | } |
| 3339 | } |
| 3340 | }); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3341 | } |
| 3342 | } |
| 3343 | |
Hyunyoung Song | 70a48be | 2015-03-11 16:36:52 -0700 | [diff] [blame] | 3344 | public static List<LauncherAppWidgetProviderInfo> getWidgetProviders(Context context, |
| 3345 | boolean refresh) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3346 | synchronized (sBgLock) { |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 3347 | if (sBgWidgetProviders == null || refresh) { |
| 3348 | sBgWidgetProviders = new HashMap<>(); |
| 3349 | AppWidgetManagerCompat wm = AppWidgetManagerCompat.getInstance(context); |
| 3350 | LauncherAppWidgetProviderInfo info; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3351 | |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 3352 | List<AppWidgetProviderInfo> widgets = wm.getAllProviders(); |
| 3353 | for (AppWidgetProviderInfo pInfo : widgets) { |
| 3354 | info = LauncherAppWidgetProviderInfo.fromProviderInfo(context, pInfo); |
| 3355 | UserHandleCompat user = wm.getUser(info); |
| 3356 | sBgWidgetProviders.put(new ComponentKey(info.provider, user), info); |
| 3357 | } |
| 3358 | |
| 3359 | Collection<CustomAppWidget> customWidgets = Launcher.getCustomAppWidgets().values(); |
| 3360 | for (CustomAppWidget widget : customWidgets) { |
| 3361 | info = new LauncherAppWidgetProviderInfo(context, widget); |
| 3362 | UserHandleCompat user = wm.getUser(info); |
| 3363 | sBgWidgetProviders.put(new ComponentKey(info.provider, user), info); |
| 3364 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3365 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3366 | return new ArrayList<LauncherAppWidgetProviderInfo>(sBgWidgetProviders.values()); |
| 3367 | } |
| 3368 | } |
| 3369 | |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 3370 | public static LauncherAppWidgetProviderInfo getProviderInfo(Context ctx, ComponentName name, |
| 3371 | UserHandleCompat user) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3372 | synchronized (sBgLock) { |
| 3373 | if (sBgWidgetProviders == null) { |
Hyunyoung Song | 70a48be | 2015-03-11 16:36:52 -0700 | [diff] [blame] | 3374 | getWidgetProviders(ctx, false /* refresh */); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3375 | } |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 3376 | return sBgWidgetProviders.get(new ComponentKey(name, user)); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3377 | } |
| 3378 | } |
| 3379 | |
Hyunyoung Song | 227239e | 2015-05-04 18:17:35 -0700 | [diff] [blame] | 3380 | public void loadAndBindWidgetsAndShortcuts(final Context context, final Callbacks callbacks, |
| 3381 | final boolean refresh) { |
Hyunyoung Song | d4af148 | 2015-04-20 20:40:03 -0700 | [diff] [blame] | 3382 | runOnWorkerThread(new Runnable(){ |
| 3383 | @Override |
| 3384 | public void run() { |
Hyunyoung Song | 227239e | 2015-05-04 18:17:35 -0700 | [diff] [blame] | 3385 | final ArrayList<Object> list = getWidgetsAndShortcuts(context, refresh); |
Hyunyoung Song | d4af148 | 2015-04-20 20:40:03 -0700 | [diff] [blame] | 3386 | mHandler.post(new Runnable() { |
| 3387 | @Override |
| 3388 | public void run() { |
| 3389 | Callbacks cb = getCallback(); |
| 3390 | if (callbacks == cb && cb != null) { |
Hyunyoung Song | 8821ca9 | 2015-05-04 16:28:20 -0700 | [diff] [blame] | 3391 | callbacks.bindAllPackages(list); |
Hyunyoung Song | d4af148 | 2015-04-20 20:40:03 -0700 | [diff] [blame] | 3392 | } |
| 3393 | } |
| 3394 | }); |
Hyunyoung Song | 8821ca9 | 2015-05-04 16:28:20 -0700 | [diff] [blame] | 3395 | // update the Widget entries inside DB on the worker thread. |
| 3396 | LauncherAppState.getInstance().getWidgetCache().removeObsoletePreviews(list); |
Hyunyoung Song | d4af148 | 2015-04-20 20:40:03 -0700 | [diff] [blame] | 3397 | } |
| 3398 | }); |
| 3399 | } |
| 3400 | |
Hyunyoung Song | 8821ca9 | 2015-05-04 16:28:20 -0700 | [diff] [blame] | 3401 | /** |
| 3402 | * Returns a list of ResolveInfos/AppWidgetInfos. |
| 3403 | * |
| 3404 | * @see #loadAndBindWidgetsAndShortcuts |
| 3405 | */ |
| 3406 | private ArrayList<Object> getWidgetsAndShortcuts(Context context, boolean refresh) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 3407 | PackageManager packageManager = context.getPackageManager(); |
| 3408 | final ArrayList<Object> widgetsAndShortcuts = new ArrayList<Object>(); |
Hyunyoung Song | 70a48be | 2015-03-11 16:36:52 -0700 | [diff] [blame] | 3409 | widgetsAndShortcuts.addAll(getWidgetProviders(context, refresh)); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 3410 | Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 3411 | widgetsAndShortcuts.addAll(packageManager.queryIntentActivities(shortcutsIntent, 0)); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 3412 | return widgetsAndShortcuts; |
| 3413 | } |
| 3414 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 3415 | @Thunk static boolean isPackageDisabled(Context context, String packageName, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3416 | UserHandleCompat user) { |
| 3417 | final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context); |
| 3418 | return !launcherApps.isPackageEnabledForProfile(packageName, user); |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3419 | } |
Adam Cohen | 556f613 | 2014-01-15 15:18:08 -0800 | [diff] [blame] | 3420 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3421 | public static boolean isValidPackageActivity(Context context, ComponentName cn, |
| 3422 | UserHandleCompat user) { |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 3423 | if (cn == null) { |
| 3424 | return false; |
| 3425 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3426 | final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context); |
| 3427 | if (!launcherApps.isPackageEnabledForProfile(cn.getPackageName(), user)) { |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3428 | return false; |
| 3429 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3430 | return launcherApps.isActivityEnabledForProfile(cn, user); |
Winson Chung | ee05571 | 2013-07-30 14:46:24 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
Adam Cohen | a28b78e | 2014-05-20 17:03:04 -0700 | [diff] [blame] | 3433 | public static boolean isValidPackage(Context context, String packageName, |
| 3434 | UserHandleCompat user) { |
| 3435 | if (packageName == null) { |
| 3436 | return false; |
| 3437 | } |
| 3438 | final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context); |
| 3439 | return launcherApps.isPackageEnabledForProfile(packageName, user); |
| 3440 | } |
| 3441 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3442 | /** |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 3443 | * Make an ShortcutInfo object for a restored application or shortcut item that points |
| 3444 | * to a package that is not yet installed on the system. |
| 3445 | */ |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3446 | public ShortcutInfo getRestoredItemInfo(Cursor cursor, int titleIndex, Intent intent, |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 3447 | int promiseType, boolean useLowResIcon) { |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 3448 | final ShortcutInfo info = new ShortcutInfo(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3449 | info.user = UserHandleCompat.myUserHandle(); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 3450 | mIconCache.getTitleAndIcon(info, intent, info.user, useLowResIcon); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3451 | |
| 3452 | if ((promiseType & ShortcutInfo.FLAG_RESTORED_ICON) != 0) { |
| 3453 | String title = (cursor != null) ? cursor.getString(titleIndex) : null; |
| 3454 | if (!TextUtils.isEmpty(title)) { |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3455 | info.title = Utilities.trim(title); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3456 | } |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3457 | } else if ((promiseType & ShortcutInfo.FLAG_AUTOINTALL_ICON) != 0) { |
| 3458 | if (TextUtils.isEmpty(info.title)) { |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3459 | info.title = (cursor != null) ? Utilities.trim(cursor.getString(titleIndex)) : ""; |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3460 | } |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3461 | } else { |
| 3462 | throw new InvalidParameterException("Invalid restoreType " + promiseType); |
| 3463 | } |
| 3464 | |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3465 | info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user); |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 3466 | info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3467 | info.promisedIntent = intent; |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 3468 | info.status = promiseType; |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 3469 | return info; |
| 3470 | } |
| 3471 | |
| 3472 | /** |
| 3473 | * Make an Intent object for a restored application or shortcut item that points |
| 3474 | * to the market page for the item. |
| 3475 | */ |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 3476 | @Thunk Intent getRestoredItemIntent(Cursor c, Context context, Intent intent) { |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 3477 | ComponentName componentName = intent.getComponent(); |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 3478 | return getMarketIntent(componentName.getPackageName()); |
| 3479 | } |
| 3480 | |
| 3481 | static Intent getMarketIntent(String packageName) { |
| 3482 | return new Intent(Intent.ACTION_VIEW) |
| 3483 | .setData(new Uri.Builder() |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 3484 | .scheme("market") |
| 3485 | .authority("details") |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 3486 | .appendQueryParameter("id", packageName) |
| 3487 | .build()); |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | /** |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3491 | * Make an ShortcutInfo object for a shortcut that is an application. |
| 3492 | * |
| 3493 | * If c is not null, then it will be used to fill in missing data like the title and icon. |
| 3494 | */ |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3495 | public ShortcutInfo getAppShortcutInfo(PackageManager manager, Intent intent, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3496 | UserHandleCompat user, Context context, Cursor c, int iconIndex, int titleIndex, |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 3497 | boolean allowMissingTarget, boolean useLowResIcon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3498 | if (user == null) { |
| 3499 | Log.d(TAG, "Null user found in getShortcutInfo"); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3500 | return null; |
| 3501 | } |
| 3502 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3503 | ComponentName componentName = intent.getComponent(); |
| 3504 | if (componentName == null) { |
| 3505 | Log.d(TAG, "Missing component found in getShortcutInfo: " + componentName); |
| 3506 | return null; |
| 3507 | } |
| 3508 | |
| 3509 | Intent newIntent = new Intent(intent.getAction(), null); |
| 3510 | newIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 3511 | newIntent.setComponent(componentName); |
| 3512 | LauncherActivityInfoCompat lai = mLauncherApps.resolveActivity(newIntent, user); |
Sunny Goyal | f599ccf | 2014-07-08 13:01:29 -0700 | [diff] [blame] | 3513 | if ((lai == null) && !allowMissingTarget) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3514 | Log.d(TAG, "Missing activity found in getShortcutInfo: " + componentName); |
| 3515 | return null; |
| 3516 | } |
| 3517 | |
| 3518 | final ShortcutInfo info = new ShortcutInfo(); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 3519 | mIconCache.getTitleAndIcon(info, componentName, lai, user, false, useLowResIcon); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3520 | if (mIconCache.isDefaultIcon(info.getIcon(mIconCache), user) && c != null) { |
| 3521 | Bitmap icon = Utilities.createIconBitmap(c, iconIndex, context); |
| 3522 | info.setIcon(icon == null ? mIconCache.getDefaultIcon(user) : icon); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3523 | } |
| 3524 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3525 | // from the db |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3526 | if (TextUtils.isEmpty(info.title) && c != null) { |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3527 | info.title = Utilities.trim(c.getString(titleIndex)); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3528 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3529 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3530 | // fall back to the class name of the activity |
| 3531 | if (info.title == null) { |
| 3532 | info.title = componentName.getClassName(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3533 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3534 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3535 | info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3536 | info.user = user; |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3537 | info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 3538 | if (lai != null) { |
| 3539 | info.flags = AppInfo.initFlags(lai); |
| 3540 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3541 | return info; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3542 | } |
The Android Open Source Project | bc219c3 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 3543 | |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 3544 | static ArrayList<ItemInfo> filterItemInfos(Iterable<ItemInfo> infos, |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3545 | ItemInfoFilter f) { |
| 3546 | HashSet<ItemInfo> filtered = new HashSet<ItemInfo>(); |
| 3547 | for (ItemInfo i : infos) { |
| 3548 | if (i instanceof ShortcutInfo) { |
| 3549 | ShortcutInfo info = (ShortcutInfo) i; |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3550 | ComponentName cn = info.getTargetComponent(); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3551 | if (cn != null && f.filterItem(null, info, cn)) { |
| 3552 | filtered.add(info); |
| 3553 | } |
| 3554 | } else if (i instanceof FolderInfo) { |
| 3555 | FolderInfo info = (FolderInfo) i; |
| 3556 | for (ShortcutInfo s : info.contents) { |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 3557 | ComponentName cn = s.getTargetComponent(); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3558 | if (cn != null && f.filterItem(info, s, cn)) { |
| 3559 | filtered.add(s); |
Winson Chung | 8a43510 | 2012-08-30 17:16:53 -0700 | [diff] [blame] | 3560 | } |
| 3561 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3562 | } else if (i instanceof LauncherAppWidgetInfo) { |
| 3563 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) i; |
| 3564 | ComponentName cn = info.providerName; |
| 3565 | if (cn != null && f.filterItem(null, info, cn)) { |
| 3566 | filtered.add(info); |
| 3567 | } |
Winson Chung | 8a43510 | 2012-08-30 17:16:53 -0700 | [diff] [blame] | 3568 | } |
| 3569 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3570 | return new ArrayList<ItemInfo>(filtered); |
| 3571 | } |
| 3572 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 3573 | @Thunk ArrayList<ItemInfo> getItemInfoForComponentName(final ComponentName cname, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3574 | final UserHandleCompat user) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3575 | ItemInfoFilter filter = new ItemInfoFilter() { |
| 3576 | @Override |
| 3577 | public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3578 | if (info.user == null) { |
| 3579 | return cn.equals(cname); |
| 3580 | } else { |
| 3581 | return cn.equals(cname) && info.user.equals(user); |
| 3582 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3583 | } |
| 3584 | }; |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 3585 | return filterItemInfos(sBgItemsIdMap, filter); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3588 | /** |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3589 | * Make an ShortcutInfo object for a shortcut that isn't an application. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3590 | */ |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 3591 | @Thunk ShortcutInfo getShortcutInfo(Cursor c, Context context, |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3592 | int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex, |
| 3593 | int titleIndex) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3594 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3595 | Bitmap icon = null; |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 3596 | final ShortcutInfo info = new ShortcutInfo(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3597 | // Non-app shortcuts are only supported for current user. |
| 3598 | info.user = UserHandleCompat.myUserHandle(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3599 | info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3600 | |
Joe Onorato | 8ddc4fd | 2010-03-17 09:14:50 -0700 | [diff] [blame] | 3601 | // TODO: If there's an explicit component and we can't install that, delete it. |
| 3602 | |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3603 | info.title = Utilities.trim(c.getString(titleIndex)); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3604 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3605 | int iconType = c.getInt(iconTypeIndex); |
| 3606 | switch (iconType) { |
| 3607 | case LauncherSettings.Favorites.ICON_TYPE_RESOURCE: |
| 3608 | String packageName = c.getString(iconPackageIndex); |
| 3609 | String resourceName = c.getString(iconResourceIndex); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3610 | info.customIcon = false; |
| 3611 | // the resource |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3612 | icon = Utilities.createIconBitmap(packageName, resourceName, mIconCache, context); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3613 | // the db |
| 3614 | if (icon == null) { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3615 | icon = Utilities.createIconBitmap(c, iconIndex, context); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3616 | } |
| 3617 | // the fallback icon |
| 3618 | if (icon == null) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3619 | icon = mIconCache.getDefaultIcon(info.user); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3620 | info.usingFallbackIcon = true; |
| 3621 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3622 | break; |
| 3623 | case LauncherSettings.Favorites.ICON_TYPE_BITMAP: |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 3624 | icon = Utilities.createIconBitmap(c, iconIndex, context); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3625 | if (icon == null) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3626 | icon = mIconCache.getDefaultIcon(info.user); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3627 | info.customIcon = false; |
| 3628 | info.usingFallbackIcon = true; |
| 3629 | } else { |
| 3630 | info.customIcon = true; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3631 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3632 | break; |
| 3633 | default: |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3634 | icon = mIconCache.getDefaultIcon(info.user); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3635 | info.usingFallbackIcon = true; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3636 | info.customIcon = false; |
| 3637 | break; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3638 | } |
Joe Onorato | d8d22da | 2010-03-11 17:59:11 -0800 | [diff] [blame] | 3639 | info.setIcon(icon); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3640 | return info; |
| 3641 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3642 | |
Sunny Goyal | 2350bc9 | 2014-10-14 16:42:54 -0700 | [diff] [blame] | 3643 | ShortcutInfo infoFromShortcutIntent(Context context, Intent data) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3644 | Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); |
| 3645 | String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
| 3646 | Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); |
| 3647 | |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 3648 | if (intent == null) { |
| 3649 | // If the intent is null, we can't construct a valid ShortcutInfo, so we return null |
| 3650 | Log.e(TAG, "Can't construct ShorcutInfo with null intent"); |
| 3651 | return null; |
| 3652 | } |
| 3653 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3654 | Bitmap icon = null; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3655 | boolean customIcon = false; |
| 3656 | ShortcutIconResource iconResource = null; |
| 3657 | |
Sunny Goyal | 2fce90c | 2014-10-07 12:01:58 -0700 | [diff] [blame] | 3658 | if (bitmap instanceof Bitmap) { |
| 3659 | icon = Utilities.createIconBitmap((Bitmap) bitmap, context); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3660 | customIcon = true; |
| 3661 | } else { |
| 3662 | Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3663 | if (extra instanceof ShortcutIconResource) { |
| 3664 | iconResource = (ShortcutIconResource) extra; |
| 3665 | icon = Utilities.createIconBitmap(iconResource.packageName, |
| 3666 | iconResource.resourceName, mIconCache, context); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3667 | } |
| 3668 | } |
| 3669 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 3670 | final ShortcutInfo info = new ShortcutInfo(); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3671 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3672 | // Only support intents for current user for now. Intents sent from other |
| 3673 | // users wouldn't get here without intent forwarding anyway. |
| 3674 | info.user = UserHandleCompat.myUserHandle(); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3675 | if (icon == null) { |
Sunny Goyal | 2350bc9 | 2014-10-14 16:42:54 -0700 | [diff] [blame] | 3676 | icon = mIconCache.getDefaultIcon(info.user); |
| 3677 | info.usingFallbackIcon = true; |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3678 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3679 | info.setIcon(icon); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 3680 | |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3681 | info.title = Utilities.trim(name); |
| 3682 | info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3683 | info.intent = intent; |
| 3684 | info.customIcon = customIcon; |
| 3685 | info.iconResource = iconResource; |
| 3686 | |
| 3687 | return info; |
| 3688 | } |
| 3689 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3690 | /** |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3691 | * Return an existing FolderInfo object if we have encountered this ID previously, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3692 | * or make a new one. |
| 3693 | */ |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 3694 | @Thunk static FolderInfo findOrMakeFolder(LongArrayMap<FolderInfo> folders, long id) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3695 | // See if a placeholder was created for us already |
| 3696 | FolderInfo folderInfo = folders.get(id); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3697 | if (folderInfo == null) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3698 | // No placeholder -- create a new instance |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 3699 | folderInfo = new FolderInfo(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3700 | folders.put(id, folderInfo); |
| 3701 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3702 | return folderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3703 | } |
| 3704 | |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 3705 | public static class WidgetAndShortcutNameComparator implements Comparator<Object> { |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 3706 | private final AppWidgetManagerCompat mManager; |
| 3707 | private final PackageManager mPackageManager; |
| 3708 | private final HashMap<Object, String> mLabelCache; |
| 3709 | private final Collator mCollator; |
| 3710 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 3711 | public WidgetAndShortcutNameComparator(Context context) { |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 3712 | mManager = AppWidgetManagerCompat.getInstance(context); |
| 3713 | mPackageManager = context.getPackageManager(); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 3714 | mLabelCache = new HashMap<Object, String>(); |
Winson Chung | 1190487 | 2012-09-17 16:58:46 -0700 | [diff] [blame] | 3715 | mCollator = Collator.getInstance(); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 3716 | } |
| 3717 | public final int compare(Object a, Object b) { |
| 3718 | String labelA, labelB; |
Winson Chung | c3eecff | 2011-07-11 17:44:15 -0700 | [diff] [blame] | 3719 | if (mLabelCache.containsKey(a)) { |
| 3720 | labelA = mLabelCache.get(a); |
| 3721 | } else { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3722 | labelA = (a instanceof LauncherAppWidgetProviderInfo) |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3723 | ? Utilities.trim(mManager.loadLabel((LauncherAppWidgetProviderInfo) a)) |
| 3724 | : Utilities.trim(((ResolveInfo) a).loadLabel(mPackageManager)); |
Winson Chung | c3eecff | 2011-07-11 17:44:15 -0700 | [diff] [blame] | 3725 | mLabelCache.put(a, labelA); |
| 3726 | } |
| 3727 | if (mLabelCache.containsKey(b)) { |
| 3728 | labelB = mLabelCache.get(b); |
| 3729 | } else { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3730 | labelB = (b instanceof LauncherAppWidgetProviderInfo) |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 3731 | ? Utilities.trim(mManager.loadLabel((LauncherAppWidgetProviderInfo) b)) |
| 3732 | : Utilities.trim(((ResolveInfo) b).loadLabel(mPackageManager)); |
Winson Chung | c3eecff | 2011-07-11 17:44:15 -0700 | [diff] [blame] | 3733 | mLabelCache.put(b, labelB); |
| 3734 | } |
Winson Chung | 1190487 | 2012-09-17 16:58:46 -0700 | [diff] [blame] | 3735 | return mCollator.compare(labelA, labelB); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 3736 | } |
| 3737 | }; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3738 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 3739 | static boolean isValidProvider(AppWidgetProviderInfo provider) { |
| 3740 | return (provider != null) && (provider.provider != null) |
| 3741 | && (provider.provider.getPackageName() != null); |
| 3742 | } |
| 3743 | |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3744 | public void dumpState() { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3745 | Log.d(TAG, "mCallbacks=" + mCallbacks); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 3746 | AppInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mBgAllAppsList.data); |
| 3747 | AppInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mBgAllAppsList.added); |
| 3748 | AppInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mBgAllAppsList.removed); |
| 3749 | AppInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mBgAllAppsList.modified); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3750 | if (mLoaderTask != null) { |
| 3751 | mLoaderTask.dumpState(); |
| 3752 | } else { |
| 3753 | Log.d(TAG, "mLoaderTask=null"); |
| 3754 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3755 | } |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 3756 | |
| 3757 | public Callbacks getCallback() { |
| 3758 | return mCallbacks != null ? mCallbacks.get() : null; |
| 3759 | } |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 3760 | |
| 3761 | /** |
| 3762 | * @return {@link FolderInfo} if its already loaded. |
| 3763 | */ |
| 3764 | public FolderInfo findFolderById(Long folderId) { |
| 3765 | synchronized (sBgLock) { |
| 3766 | return sBgFolders.get(folderId); |
| 3767 | } |
| 3768 | } |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 3769 | |
| 3770 | /** |
| 3771 | * @return the looper for the worker thread which can be used to start background tasks. |
| 3772 | */ |
| 3773 | public static Looper getWorkerLooper() { |
| 3774 | return sWorkerThread.getLooper(); |
| 3775 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3776 | } |