blob: 7da55db6d797ffc690fa0f5e438cc1bab98006c1 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Narayan Kamathcb1a4772011-06-28 13:46:59 +010019import android.app.SearchManager;
Romain Guy629de3e2010-01-13 12:20:59 -080020import android.appwidget.AppWidgetManager;
21import android.appwidget.AppWidgetProviderInfo;
Joe Onoratof99f8c12009-10-31 17:27:36 -040022import android.content.BroadcastReceiver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.content.ComponentName;
Romain Guy5c16f3e2010-01-12 17:24:58 -080024import android.content.ContentProviderClient;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025import android.content.ContentResolver;
26import android.content.ContentValues;
Winson Chungaafa03c2010-06-11 17:34:16 -070027import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.content.Intent;
Joe Onorato0589f0f2010-02-08 13:44:00 -080029import android.content.Intent.ShortcutIconResource;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.content.pm.ActivityInfo;
Adam Cohen00fcb492011-11-02 21:53:47 -070031import android.content.pm.PackageInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.content.pm.PackageManager;
Adam Cohen00fcb492011-11-02 21:53:47 -070033import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.pm.ResolveInfo;
Reena Lee93f824a2011-09-23 17:20:28 -070035import android.content.res.Configuration;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.res.Resources;
37import android.database.Cursor;
38import android.graphics.Bitmap;
39import android.graphics.BitmapFactory;
40import android.net.Uri;
Joe Onorato17a89222011-02-08 17:26:11 -080041import android.os.Environment;
Joe Onorato36115782010-06-17 13:28:48 -040042import android.os.Handler;
43import android.os.HandlerThread;
Joe Onorato0589f0f2010-02-08 13:44:00 -080044import android.os.Parcelable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.os.Process;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.os.RemoteException;
Joe Onorato9c1289c2009-08-17 11:03:03 -040047import android.os.SystemClock;
Winson Chungaafa03c2010-06-11 17:34:16 -070048import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049
Winson Chung68846fd2010-10-29 11:00:27 -070050import com.android.launcher.R;
51import com.android.launcher2.InstallWidgetReceiver.WidgetMimeTypeHandlerData;
Romain Guyedcce092010-03-04 13:03:17 -080052
Michael Jurkac2f801e2011-07-12 14:19:46 -070053import java.lang.ref.WeakReference;
54import java.net.URISyntaxException;
55import java.text.Collator;
56import java.util.ArrayList;
57import java.util.Collections;
58import java.util.Comparator;
59import java.util.HashMap;
60import java.util.List;
Michael Jurkac2f801e2011-07-12 14:19:46 -070061
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062/**
63 * Maintains in-memory state of the Launcher. It is expected that there should be only one
64 * LauncherModel object held in a static. Also provide APIs for updating the database state
The Android Open Source Projectbc219c32009-03-09 11:52:14 -070065 * for the Launcher.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066 */
Joe Onoratof99f8c12009-10-31 17:27:36 -040067public class LauncherModel extends BroadcastReceiver {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080068 static final boolean DEBUG_LOADERS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -040069 static final String TAG = "Launcher.Model";
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070070
Joe Onorato36115782010-06-17 13:28:48 -040071 private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons
Joe Onorato17a89222011-02-08 17:26:11 -080072 private final boolean mAppsCanBeOnExternalStorage;
Joe Onoratod65d08e2010-04-20 15:43:37 -040073 private int mBatchSize; // 0 is all apps at once
Daniel Sandler2ff10b32010-04-16 15:06:06 -040074 private int mAllAppsLoadDelay; // milliseconds between batches
Daniel Sandlerdca66122010-04-13 16:23:58 -040075
Joe Onoratof99f8c12009-10-31 17:27:36 -040076 private final LauncherApplication mApp;
Joe Onorato9c1289c2009-08-17 11:03:03 -040077 private final Object mLock = new Object();
78 private DeferredHandler mHandler = new DeferredHandler();
Joe Onorato36115782010-06-17 13:28:48 -040079 private LoaderTask mLoaderTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080
Brad Fitzpatrick700889f2010-10-11 09:40:44 -070081 private static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
82 static {
83 sWorkerThread.start();
84 }
85 private static final Handler sWorker = new Handler(sWorkerThread.getLooper());
86
Joe Onoratocc67f472010-06-08 10:54:30 -070087 // We start off with everything not loaded. After that, we assume that
88 // our monitoring of the package manager provides all updates and we never
89 // need to do a requery. These are only ever touched from the loader thread.
90 private boolean mWorkspaceLoaded;
91 private boolean mAllAppsLoaded;
92
Joe Onorato9c1289c2009-08-17 11:03:03 -040093 private WeakReference<Callbacks> mCallbacks;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094
Michael Jurkaa8c760d2011-04-28 14:59:33 -070095 // < only access in worker thread >
96 private AllAppsList mAllAppsList;
Joe Onorato0589f0f2010-02-08 13:44:00 -080097
Michael Jurkaa8c760d2011-04-28 14:59:33 -070098 // sItemsIdMap maps *all* the ItemInfos (shortcuts, folders, and widgets) created by
99 // LauncherModel to their ids
100 static final HashMap<Long, ItemInfo> sItemsIdMap = new HashMap<Long, ItemInfo>();
101
102 // sItems is passed to bindItems, which expects a list of all folders and shortcuts created by
103 // LauncherModel that are directly on the home screen (however, no widgets or shortcuts
104 // within folders).
Adam Cohen4eac29a2011-07-11 17:53:37 -0700105 static final ArrayList<ItemInfo> sWorkspaceItems = new ArrayList<ItemInfo>();
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700106
107 // sAppWidgets is all LauncherAppWidgetInfo created by LauncherModel. Passed to bindAppWidget()
108 static final ArrayList<LauncherAppWidgetInfo> sAppWidgets =
109 new ArrayList<LauncherAppWidgetInfo>();
110
111 // sFolders is all FolderInfos created by LauncherModel. Passed to bindFolders()
112 static final HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Winson Chungb1094bd2011-08-24 16:14:08 -0700113
114 // sDbIconCache is the set of ItemInfos that need to have their icons updated in the database
115 static final HashMap<Object, byte[]> sDbIconCache = new HashMap<Object, byte[]>();
116
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700117 // </ only access in worker thread >
118
119 private IconCache mIconCache;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800120 private Bitmap mDefaultIcon;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121
Adam Cohend22015c2010-07-26 22:02:18 -0700122 private static int mCellCountX;
123 private static int mCellCountY;
Winson Chungaafa03c2010-06-11 17:34:16 -0700124
Reena Lee99a73f32011-10-24 17:27:37 -0700125 protected int mPreviousConfigMcc;
Reena Lee93f824a2011-09-23 17:20:28 -0700126
Joe Onorato9c1289c2009-08-17 11:03:03 -0400127 public interface Callbacks {
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700128 public boolean setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400129 public int getCurrentWorkspaceScreen();
130 public void startBinding();
131 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end);
Joe Onoratoad72e172009-11-06 16:25:04 -0500132 public void bindFolders(HashMap<Long,FolderInfo> folders);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400133 public void finishBindingItems();
134 public void bindAppWidget(LauncherAppWidgetInfo info);
135 public void bindAllApplications(ArrayList<ApplicationInfo> apps);
Joe Onorato64e6be72010-03-05 15:05:52 -0500136 public void bindAppsAdded(ArrayList<ApplicationInfo> apps);
137 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps);
Joe Onorato36115782010-06-17 13:28:48 -0400138 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent);
Winson Chung80baf5a2010-08-09 16:03:15 -0700139 public void bindPackagesUpdated();
Daniel Sandler843e8602010-06-07 14:59:01 -0400140 public boolean isAllAppsVisible();
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100141 public void bindSearchablesChanged();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400142 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
Joe Onorato0589f0f2010-02-08 13:44:00 -0800144 LauncherModel(LauncherApplication app, IconCache iconCache) {
Joe Onorato17a89222011-02-08 17:26:11 -0800145 mAppsCanBeOnExternalStorage = !Environment.isExternalStorageEmulated();
Joe Onoratof99f8c12009-10-31 17:27:36 -0400146 mApp = app;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800147 mAllAppsList = new AllAppsList(iconCache);
148 mIconCache = iconCache;
149
150 mDefaultIcon = Utilities.createIconBitmap(
Michael Jurkac9a96192010-11-01 11:52:08 -0700151 mIconCache.getFullResDefaultActivityIcon(), app);
Daniel Sandler2ff10b32010-04-16 15:06:06 -0400152
Reena Lee93f824a2011-09-23 17:20:28 -0700153 final Resources res = app.getResources();
154 mAllAppsLoadDelay = res.getInteger(R.integer.config_allAppsBatchLoadDelay);
155 mBatchSize = res.getInteger(R.integer.config_allAppsBatchSize);
Reena Lee99a73f32011-10-24 17:27:37 -0700156 Configuration config = res.getConfiguration();
157 mPreviousConfigMcc = config.mcc;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800158 }
159
Joe Onorato56d82912010-03-07 14:32:10 -0500160 public Bitmap getFallbackIcon() {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800161 return Bitmap.createBitmap(mDefaultIcon);
Joe Onoratof99f8c12009-10-31 17:27:36 -0400162 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163
Winson Chung603bcb92011-09-02 11:45:39 -0700164 public void unbindWorkspaceItems() {
165 sWorker.post(new Runnable() {
166 @Override
167 public void run() {
168 unbindWorkspaceItemsOnMainThread();
169 }
170 });
171 }
172
173 /** Unbinds all the sWorkspaceItems on the main thread, and return a copy of sWorkspaceItems
174 * that is save to reference from the main thread. */
175 private ArrayList<ItemInfo> unbindWorkspaceItemsOnMainThread() {
176 // Ensure that we don't use the same workspace items data structure on the main thread
177 // by making a copy of workspace items first.
178 final ArrayList<ItemInfo> workspaceItems = new ArrayList<ItemInfo>(sWorkspaceItems);
Michael Jurka05bf644e2011-11-30 20:28:53 -0800179 final ArrayList<ItemInfo> appWidgets = new ArrayList<ItemInfo>(sAppWidgets);
Winson Chung603bcb92011-09-02 11:45:39 -0700180 mHandler.post(new Runnable() {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700181 @Override
Winson Chung603bcb92011-09-02 11:45:39 -0700182 public void run() {
183 for (ItemInfo item : workspaceItems) {
184 item.unbind();
185 }
Michael Jurka05bf644e2011-11-30 20:28:53 -0800186 for (ItemInfo item : appWidgets) {
187 item.unbind();
188 }
Winson Chung603bcb92011-09-02 11:45:39 -0700189 }
190 });
191
192 return workspaceItems;
Adam Cohen4eac29a2011-07-11 17:53:37 -0700193 }
194
Joe Onorato9c1289c2009-08-17 11:03:03 -0400195 /**
196 * Adds an item to the DB if it was not created previously, or move it to a new
197 * <container, screen, cellX, cellY>
198 */
199 static void addOrMoveItemInDatabase(Context context, ItemInfo item, long container,
200 int screen, int cellX, int cellY) {
201 if (item.container == ItemInfo.NO_ID) {
202 // From all apps
203 addItemToDatabase(context, item, container, screen, cellX, cellY, false);
204 } else {
205 // From somewhere else
206 moveItemInDatabase(context, item, container, screen, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 }
208 }
209
Michael Jurkac9d95c52011-08-29 14:03:34 -0700210 static void updateItemInDatabaseHelper(Context context, final ContentValues values,
211 final ItemInfo item, final String callingFunction) {
212 final long itemId = item.id;
213 final Uri uri = LauncherSettings.Favorites.getContentUri(itemId, false);
214 final ContentResolver cr = context.getContentResolver();
215
216 Runnable r = new Runnable() {
217 public void run() {
218 cr.update(uri, values, null, null);
219
220 ItemInfo modelItem = sItemsIdMap.get(itemId);
221 if (item != modelItem) {
222 // the modelItem needs to match up perfectly with item if our model is to be
223 // consistent with the database-- for now, just require modelItem == item
224 String msg = "item: " + ((item != null) ? item.toString() : "null") +
225 "modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
226 "Error: ItemInfo passed to " + callingFunction + " doesn't match original";
227 throw new RuntimeException(msg);
228 }
229
230 // Items are added/removed from the corresponding FolderInfo elsewhere, such
231 // as in Workspace.onDrop. Here, we just add/remove them from the list of items
232 // that are on the desktop, as appropriate
233 if (modelItem.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
234 modelItem.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
235 if (!sWorkspaceItems.contains(modelItem)) {
236 sWorkspaceItems.add(modelItem);
237 }
238 } else {
239 sWorkspaceItems.remove(modelItem);
240 }
241 }
242 };
243
244 if (sWorkerThread.getThreadId() == Process.myTid()) {
245 r.run();
246 } else {
247 sWorker.post(r);
248 }
249 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400251 * Move an item in the DB to a new <container, screen, cellX, cellY>
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700252 */
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700253 static void moveItemInDatabase(Context context, final ItemInfo item, final long container,
254 final int screen, final int cellX, final int cellY) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400255 item.container = container;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400256 item.cellX = cellX;
257 item.cellY = cellY;
Michael Jurkac9d95c52011-08-29 14:03:34 -0700258
Winson Chung3d503fb2011-07-13 17:25:49 -0700259 // We store hotseat items in canonical form which is this orientation invariant position
260 // in the hotseat
261 if (context instanceof Launcher && screen < 0 &&
262 container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
263 item.screen = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY);
264 } else {
265 item.screen = screen;
266 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400267
268 final ContentValues values = new ContentValues();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400269 values.put(LauncherSettings.Favorites.CONTAINER, item.container);
Winson Chung3d503fb2011-07-13 17:25:49 -0700270 values.put(LauncherSettings.Favorites.CELLX, item.cellX);
271 values.put(LauncherSettings.Favorites.CELLY, item.cellY);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400272 values.put(LauncherSettings.Favorites.SCREEN, item.screen);
273
Michael Jurkac9d95c52011-08-29 14:03:34 -0700274 updateItemInDatabaseHelper(context, values, item, "moveItemInDatabase");
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700275 }
276
277 /**
Adam Cohen1b607ed2011-03-03 17:26:50 -0800278 * Resize an item in the DB to a new <spanX, spanY, cellX, cellY>
Adam Cohend4844c32011-02-18 19:25:06 -0800279 */
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700280 static void resizeItemInDatabase(Context context, final ItemInfo item, final int cellX,
281 final int cellY, final int spanX, final int spanY) {
Adam Cohend4844c32011-02-18 19:25:06 -0800282 item.spanX = spanX;
283 item.spanY = spanY;
284 item.cellX = cellX;
285 item.cellY = cellY;
286
Adam Cohend4844c32011-02-18 19:25:06 -0800287 final ContentValues values = new ContentValues();
Adam Cohend4844c32011-02-18 19:25:06 -0800288 values.put(LauncherSettings.Favorites.CONTAINER, item.container);
289 values.put(LauncherSettings.Favorites.SPANX, spanX);
290 values.put(LauncherSettings.Favorites.SPANY, spanY);
291 values.put(LauncherSettings.Favorites.CELLX, cellX);
292 values.put(LauncherSettings.Favorites.CELLY, cellY);
Michael Jurkac9d95c52011-08-29 14:03:34 -0700293 updateItemInDatabaseHelper(context, values, item, "resizeItemInDatabase");
294 }
Adam Cohend4844c32011-02-18 19:25:06 -0800295
Michael Jurkac9d95c52011-08-29 14:03:34 -0700296
297 /**
298 * Update an item to the database in a specified container.
299 */
300 static void updateItemInDatabase(Context context, final ItemInfo item) {
301 final ContentValues values = new ContentValues();
302 item.onAddToDatabase(values);
303 item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
304 updateItemInDatabaseHelper(context, values, item, "updateItemInDatabase");
Adam Cohend4844c32011-02-18 19:25:06 -0800305 }
306
307 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400308 * Returns true if the shortcuts already exists in the database.
309 * we identify a shortcut by its title and intent.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800310 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400311 static boolean shortcutExists(Context context, String title, Intent intent) {
312 final ContentResolver cr = context.getContentResolver();
313 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
314 new String[] { "title", "intent" }, "title=? and intent=?",
315 new String[] { title, intent.toUri(0) }, null);
316 boolean result = false;
317 try {
318 result = c.moveToFirst();
319 } finally {
320 c.close();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400322 return result;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700323 }
324
Joe Onorato9c1289c2009-08-17 11:03:03 -0400325 /**
Winson Chungaafa03c2010-06-11 17:34:16 -0700326 * Returns an ItemInfo array containing all the items in the LauncherModel.
327 * The ItemInfo.id is not set through this function.
328 */
329 static ArrayList<ItemInfo> getItemsInLocalCoordinates(Context context) {
330 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
331 final ContentResolver cr = context.getContentResolver();
332 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] {
333 LauncherSettings.Favorites.ITEM_TYPE, LauncherSettings.Favorites.CONTAINER,
334 LauncherSettings.Favorites.SCREEN, LauncherSettings.Favorites.CELLX, LauncherSettings.Favorites.CELLY,
335 LauncherSettings.Favorites.SPANX, LauncherSettings.Favorites.SPANY }, null, null, null);
336
337 final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
338 final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
339 final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
340 final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
341 final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
342 final int spanXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANX);
343 final int spanYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANY);
344
345 try {
346 while (c.moveToNext()) {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700347 ItemInfo item = new ItemInfo();
Winson Chungaafa03c2010-06-11 17:34:16 -0700348 item.cellX = c.getInt(cellXIndex);
349 item.cellY = c.getInt(cellYIndex);
350 item.spanX = c.getInt(spanXIndex);
351 item.spanY = c.getInt(spanYIndex);
352 item.container = c.getInt(containerIndex);
353 item.itemType = c.getInt(itemTypeIndex);
354 item.screen = c.getInt(screenIndex);
355
356 items.add(item);
357 }
358 } catch (Exception e) {
359 items.clear();
360 } finally {
361 c.close();
362 }
363
364 return items;
365 }
366
367 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400368 * Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList.
369 */
370 FolderInfo getFolderById(Context context, HashMap<Long,FolderInfo> folderList, long id) {
371 final ContentResolver cr = context.getContentResolver();
372 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null,
373 "_id=? and (itemType=? or itemType=?)",
374 new String[] { String.valueOf(id),
Adam Cohendf2cc412011-04-27 16:56:57 -0700375 String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)}, null);
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700376
Joe Onorato9c1289c2009-08-17 11:03:03 -0400377 try {
378 if (c.moveToFirst()) {
379 final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
380 final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
381 final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
382 final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
383 final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
384 final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385
Joe Onorato9c1289c2009-08-17 11:03:03 -0400386 FolderInfo folderInfo = null;
387 switch (c.getInt(itemTypeIndex)) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700388 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
389 folderInfo = findOrMakeFolder(folderList, id);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400390 break;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700391 }
392
Joe Onorato9c1289c2009-08-17 11:03:03 -0400393 folderInfo.title = c.getString(titleIndex);
394 folderInfo.id = id;
395 folderInfo.container = c.getInt(containerIndex);
396 folderInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -0700397 folderInfo.cellX = c.getInt(cellXIndex);
398 folderInfo.cellY = c.getInt(cellYIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400399
400 return folderInfo;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700401 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400402 } finally {
403 c.close();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700404 }
405
406 return null;
407 }
408
Joe Onorato9c1289c2009-08-17 11:03:03 -0400409 /**
410 * Add an item to the database in a specified container. Sets the container, screen, cellX and
411 * cellY fields of the item. Also assigns an ID to the item.
412 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700413 static void addItemToDatabase(Context context, final ItemInfo item, final long container,
414 final int screen, final int cellX, final int cellY, final boolean notify) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400415 item.container = container;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400416 item.cellX = cellX;
417 item.cellY = cellY;
Winson Chung3d503fb2011-07-13 17:25:49 -0700418 // We store hotseat items in canonical form which is this orientation invariant position
419 // in the hotseat
420 if (context instanceof Launcher && screen < 0 &&
421 container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
422 item.screen = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY);
423 } else {
424 item.screen = screen;
425 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400426
427 final ContentValues values = new ContentValues();
428 final ContentResolver cr = context.getContentResolver();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400429 item.onAddToDatabase(values);
430
Michael Jurka7578ec62011-08-03 14:11:54 -0700431 LauncherApplication app = (LauncherApplication) context.getApplicationContext();
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700432 item.id = app.getLauncherProvider().generateNewId();
433 values.put(LauncherSettings.Favorites._ID, item.id);
Winson Chung3d503fb2011-07-13 17:25:49 -0700434 item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700435
Michael Jurkac9d95c52011-08-29 14:03:34 -0700436 Runnable r = new Runnable() {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700437 public void run() {
438 cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
439 LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400440
Winson Chungb1094bd2011-08-24 16:14:08 -0700441 if (sItemsIdMap.containsKey(item.id)) {
442 // we should not be adding new items in the db with the same id
443 throw new RuntimeException("Error: ItemInfo id (" + item.id + ") passed to " +
444 "addItemToDatabase already exists." + item.toString());
445 }
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700446 sItemsIdMap.put(item.id, item);
447 switch (item.itemType) {
448 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
449 sFolders.put(item.id, (FolderInfo) item);
Winson Chung3d503fb2011-07-13 17:25:49 -0700450 // Fall through
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700451 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
452 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700453 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
454 item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
Adam Cohen4eac29a2011-07-11 17:53:37 -0700455 sWorkspaceItems.add(item);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700456 }
457 break;
458 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
459 sAppWidgets.add((LauncherAppWidgetInfo) item);
460 break;
461 }
462 }
Michael Jurkac9d95c52011-08-29 14:03:34 -0700463 };
464
465 if (sWorkerThread.getThreadId() == Process.myTid()) {
466 r.run();
467 } else {
468 sWorker.post(r);
469 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700470 }
471
Joe Onorato9c1289c2009-08-17 11:03:03 -0400472 /**
Winson Chungaafa03c2010-06-11 17:34:16 -0700473 * Creates a new unique child id, for a given cell span across all layouts.
474 */
Michael Jurka845ba3b2010-09-28 17:09:46 -0700475 static int getCellLayoutChildId(
Winson Chung3d503fb2011-07-13 17:25:49 -0700476 long container, int screen, int localCellX, int localCellY, int spanX, int spanY) {
477 return (((int) container & 0xFF) << 24)
Michael Jurka845ba3b2010-09-28 17:09:46 -0700478 | (screen & 0xFF) << 16 | (localCellX & 0xFF) << 8 | (localCellY & 0xFF);
Winson Chungaafa03c2010-06-11 17:34:16 -0700479 }
480
Adam Cohend22015c2010-07-26 22:02:18 -0700481 static int getCellCountX() {
482 return mCellCountX;
Winson Chungaafa03c2010-06-11 17:34:16 -0700483 }
484
Adam Cohend22015c2010-07-26 22:02:18 -0700485 static int getCellCountY() {
486 return mCellCountY;
Winson Chungaafa03c2010-06-11 17:34:16 -0700487 }
488
489 /**
490 * Updates the model orientation helper to take into account the current layout dimensions
491 * when performing local/canonical coordinate transformations.
492 */
493 static void updateWorkspaceLayoutCells(int shortAxisCellCount, int longAxisCellCount) {
Adam Cohend22015c2010-07-26 22:02:18 -0700494 mCellCountX = shortAxisCellCount;
495 mCellCountY = longAxisCellCount;
Winson Chungaafa03c2010-06-11 17:34:16 -0700496 }
497
498 /**
Michael Jurkac9d95c52011-08-29 14:03:34 -0700499 * Removes the specified item from the database
500 * @param context
501 * @param item
Joe Onorato9c1289c2009-08-17 11:03:03 -0400502 */
Michael Jurkac9d95c52011-08-29 14:03:34 -0700503 static void deleteItemFromDatabase(Context context, final ItemInfo item) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400504 final ContentResolver cr = context.getContentResolver();
Michael Jurkac9d95c52011-08-29 14:03:34 -0700505 final Uri uriToDelete = LauncherSettings.Favorites.getContentUri(item.id, false);
Michael Jurka83df1882011-08-31 20:59:26 -0700506 Runnable r = new Runnable() {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700507 public void run() {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700508 cr.delete(uriToDelete, null, null);
509 switch (item.itemType) {
510 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
511 sFolders.remove(item.id);
512 sWorkspaceItems.remove(item);
513 break;
514 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
515 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
516 sWorkspaceItems.remove(item);
517 break;
518 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
519 sAppWidgets.remove((LauncherAppWidgetInfo) item);
520 break;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700521 }
Michael Jurkac9d95c52011-08-29 14:03:34 -0700522 sItemsIdMap.remove(item.id);
523 sDbIconCache.remove(item);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700524 }
Michael Jurka83df1882011-08-31 20:59:26 -0700525 };
526 if (sWorkerThread.getThreadId() == Process.myTid()) {
527 r.run();
528 } else {
529 sWorker.post(r);
530 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400531 }
532
533 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400534 * Remove the contents of the specified folder from the database
535 */
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700536 static void deleteFolderContentsFromDatabase(Context context, final FolderInfo info) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400537 final ContentResolver cr = context.getContentResolver();
538
Michael Jurkac9d95c52011-08-29 14:03:34 -0700539 Runnable r = new Runnable() {
540 public void run() {
541 cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
542 sItemsIdMap.remove(info.id);
543 sFolders.remove(info.id);
544 sDbIconCache.remove(info);
545 sWorkspaceItems.remove(info);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700546
Michael Jurkac9d95c52011-08-29 14:03:34 -0700547 cr.delete(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
548 LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
549 for (ItemInfo childInfo : info.contents) {
550 sItemsIdMap.remove(childInfo.id);
551 sDbIconCache.remove(childInfo);
Adam Cohenafb01ee2011-06-23 15:38:03 -0700552 }
Michael Jurkac9d95c52011-08-29 14:03:34 -0700553 }
554 };
555 if (sWorkerThread.getThreadId() == Process.myTid()) {
556 r.run();
557 } else {
558 sWorker.post(r);
559 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400560 }
561
562 /**
563 * Set this as the current Launcher activity object for the loader.
564 */
565 public void initialize(Callbacks callbacks) {
566 synchronized (mLock) {
567 mCallbacks = new WeakReference<Callbacks>(callbacks);
568 }
569 }
570
Joe Onorato1d8e7bb2009-10-15 19:49:43 -0700571 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400572 * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
573 * ACTION_PACKAGE_CHANGED.
574 */
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100575 @Override
Joe Onoratof99f8c12009-10-31 17:27:36 -0400576 public void onReceive(Context context, Intent intent) {
Joe Onorato36115782010-06-17 13:28:48 -0400577 if (DEBUG_LOADERS) Log.d(TAG, "onReceive intent=" + intent);
Winson Chungaafa03c2010-06-11 17:34:16 -0700578
Joe Onorato36115782010-06-17 13:28:48 -0400579 final String action = intent.getAction();
Joe Onoratof99f8c12009-10-31 17:27:36 -0400580
Joe Onorato36115782010-06-17 13:28:48 -0400581 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
582 || Intent.ACTION_PACKAGE_REMOVED.equals(action)
583 || Intent.ACTION_PACKAGE_ADDED.equals(action)) {
584 final String packageName = intent.getData().getSchemeSpecificPart();
585 final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400586
Joe Onorato36115782010-06-17 13:28:48 -0400587 int op = PackageUpdatedTask.OP_NONE;
588
589 if (packageName == null || packageName.length() == 0) {
590 // they sent us a bad intent
591 return;
592 }
593
594 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
595 op = PackageUpdatedTask.OP_UPDATE;
596 } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
597 if (!replacing) {
598 op = PackageUpdatedTask.OP_REMOVE;
599 }
600 // else, we are replacing the package, so a PACKAGE_ADDED will be sent
601 // later, we will update the package at this time
602 } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
603 if (!replacing) {
604 op = PackageUpdatedTask.OP_ADD;
605 } else {
606 op = PackageUpdatedTask.OP_UPDATE;
607 }
608 }
609
610 if (op != PackageUpdatedTask.OP_NONE) {
611 enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packageName }));
612 }
613
614 } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
Joe Onoratocec58332010-10-07 14:37:40 -0400615 // First, schedule to add these apps back in.
616 String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
617 enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_ADD, packages));
618 // Then, rebind everything.
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700619 startLoaderFromBackground();
Joe Onorato36115782010-06-17 13:28:48 -0400620 } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
621 String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
622 enqueuePackageUpdated(new PackageUpdatedTask(
623 PackageUpdatedTask.OP_UNAVAILABLE, packages));
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700624 } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
Reena Lee93f824a2011-09-23 17:20:28 -0700625 // If we have changed locale we need to clear out the labels in all apps/workspace.
626 forceReload();
627 } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
628 // Check if configuration change was an mcc/mnc change which would affect app resources
629 // and we would need to clear out the labels in all apps/workspace. Same handling as
630 // above for ACTION_LOCALE_CHANGED
631 Configuration currentConfig = context.getResources().getConfiguration();
Reena Lee99a73f32011-10-24 17:27:37 -0700632 if (mPreviousConfigMcc != currentConfig.mcc) {
Reena Lee93f824a2011-09-23 17:20:28 -0700633 Log.d(TAG, "Reload apps on config change. curr_mcc:"
Reena Lee99a73f32011-10-24 17:27:37 -0700634 + currentConfig.mcc + " prevmcc:" + mPreviousConfigMcc);
Reena Lee93f824a2011-09-23 17:20:28 -0700635 forceReload();
636 }
637 // Update previousConfig
Reena Lee99a73f32011-10-24 17:27:37 -0700638 mPreviousConfigMcc = currentConfig.mcc;
Winson Chungcbf7c4d2011-08-23 11:58:54 -0700639 } else if (SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED.equals(action) ||
640 SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED.equals(action)) {
Michael Jurkaec9788e2011-08-29 11:24:45 -0700641 if (mCallbacks != null) {
642 Callbacks callbacks = mCallbacks.get();
643 if (callbacks != null) {
644 callbacks.bindSearchablesChanged();
645 }
Winson Chungcfdf7ee2011-08-25 11:38:34 -0700646 }
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700647 }
648 }
649
Reena Lee93f824a2011-09-23 17:20:28 -0700650 private void forceReload() {
651 synchronized (mLock) {
652 // Stop any existing loaders first, so they don't set mAllAppsLoaded or
653 // mWorkspaceLoaded to true later
654 stopLoaderLocked();
655 mAllAppsLoaded = false;
656 mWorkspaceLoaded = false;
657 }
658 // Do this here because if the launcher activity is running it will be restarted.
659 // If it's not running startLoaderFromBackground will merely tell it that it needs
660 // to reload.
661 startLoaderFromBackground();
662 }
663
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700664 /**
665 * When the launcher is in the background, it's possible for it to miss paired
666 * configuration changes. So whenever we trigger the loader from the background
667 * tell the launcher that it needs to re-run the loader when it comes back instead
668 * of doing it now.
669 */
670 public void startLoaderFromBackground() {
671 boolean runLoader = false;
672 if (mCallbacks != null) {
673 Callbacks callbacks = mCallbacks.get();
674 if (callbacks != null) {
675 // Only actually run the loader if they're not paused.
676 if (!callbacks.setLoadOnResume()) {
677 runLoader = true;
678 }
679 }
680 }
681 if (runLoader) {
682 startLoader(mApp, false);
Joe Onorato790c2d92010-06-11 00:14:11 -0700683 }
Joe Onorato36115782010-06-17 13:28:48 -0400684 }
Joe Onoratof99f8c12009-10-31 17:27:36 -0400685
Reena Lee93f824a2011-09-23 17:20:28 -0700686 // If there is already a loader task running, tell it to stop.
687 // returns true if isLaunching() was true on the old task
688 private boolean stopLoaderLocked() {
689 boolean isLaunching = false;
690 LoaderTask oldTask = mLoaderTask;
691 if (oldTask != null) {
692 if (oldTask.isLaunching()) {
693 isLaunching = true;
694 }
695 oldTask.stopLocked();
696 }
697 return isLaunching;
698 }
699
Joe Onorato36115782010-06-17 13:28:48 -0400700 public void startLoader(Context context, boolean isLaunching) {
701 synchronized (mLock) {
702 if (DEBUG_LOADERS) {
703 Log.d(TAG, "startLoader isLaunching=" + isLaunching);
704 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400705
Joe Onorato36115782010-06-17 13:28:48 -0400706 // Don't bother to start the thread if we know it's not going to do anything
707 if (mCallbacks != null && mCallbacks.get() != null) {
708 // If there is already one running, tell it to stop.
Reena Lee93f824a2011-09-23 17:20:28 -0700709 // also, don't downgrade isLaunching if we're already running
710 isLaunching = isLaunching || stopLoaderLocked();
Joe Onorato36115782010-06-17 13:28:48 -0400711 mLoaderTask = new LoaderTask(context, isLaunching);
Winson Chung7ed37742011-09-08 15:45:51 -0700712 sWorkerThread.setPriority(Thread.NORM_PRIORITY);
Brad Fitzpatrick700889f2010-10-11 09:40:44 -0700713 sWorker.post(mLoaderTask);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400714 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400715 }
716 }
717
Joe Onorato36115782010-06-17 13:28:48 -0400718 public void stopLoader() {
719 synchronized (mLock) {
720 if (mLoaderTask != null) {
721 mLoaderTask.stopLocked();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400722 }
723 }
Joe Onorato36115782010-06-17 13:28:48 -0400724 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400725
Michael Jurkac57b7a82011-08-09 22:02:20 -0700726 public boolean isAllAppsLoaded() {
727 return mAllAppsLoaded;
728 }
729
Joe Onorato36115782010-06-17 13:28:48 -0400730 /**
731 * Runnable for the thread that loads the contents of the launcher:
732 * - workspace icons
733 * - widgets
734 * - all apps icons
735 */
736 private class LoaderTask implements Runnable {
737 private Context mContext;
738 private Thread mWaitThread;
739 private boolean mIsLaunching;
740 private boolean mStopped;
741 private boolean mLoadAndBindStepFinished;
Winson Chungc3eecff2011-07-11 17:44:15 -0700742 private HashMap<Object, CharSequence> mLabelCache;
Joe Onorato36115782010-06-17 13:28:48 -0400743
744 LoaderTask(Context context, boolean isLaunching) {
745 mContext = context;
746 mIsLaunching = isLaunching;
Winson Chungc3eecff2011-07-11 17:44:15 -0700747 mLabelCache = new HashMap<Object, CharSequence>();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400748 }
749
Joe Onorato36115782010-06-17 13:28:48 -0400750 boolean isLaunching() {
751 return mIsLaunching;
752 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400753
Joe Onorato36115782010-06-17 13:28:48 -0400754 private void loadAndBindWorkspace() {
755 // Load the workspace
Joe Onorato36115782010-06-17 13:28:48 -0400756 if (DEBUG_LOADERS) {
757 Log.d(TAG, "loadAndBindWorkspace mWorkspaceLoaded=" + mWorkspaceLoaded);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400758 }
Michael Jurka288a36b2011-07-12 16:53:48 -0700759
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700760 if (!mWorkspaceLoaded) {
Joe Onorato36115782010-06-17 13:28:48 -0400761 loadWorkspace();
Reena Lee93f824a2011-09-23 17:20:28 -0700762 synchronized (LoaderTask.this) {
763 if (mStopped) {
764 return;
765 }
766 mWorkspaceLoaded = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400767 }
768 }
769
Joe Onorato36115782010-06-17 13:28:48 -0400770 // Bind the workspace
771 bindWorkspace();
772 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400773
Joe Onorato36115782010-06-17 13:28:48 -0400774 private void waitForIdle() {
775 // Wait until the either we're stopped or the other threads are done.
776 // This way we don't start loading all apps until the workspace has settled
777 // down.
778 synchronized (LoaderTask.this) {
779 final long workspaceWaitTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
Joe Onoratocc67f472010-06-08 10:54:30 -0700780
Joe Onorato36115782010-06-17 13:28:48 -0400781 mHandler.postIdle(new Runnable() {
782 public void run() {
783 synchronized (LoaderTask.this) {
784 mLoadAndBindStepFinished = true;
785 if (DEBUG_LOADERS) {
786 Log.d(TAG, "done with previous binding step");
Daniel Sandler843e8602010-06-07 14:59:01 -0400787 }
Joe Onorato36115782010-06-17 13:28:48 -0400788 LoaderTask.this.notify();
Daniel Sandler843e8602010-06-07 14:59:01 -0400789 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400790 }
Joe Onorato36115782010-06-17 13:28:48 -0400791 });
792
793 while (!mStopped && !mLoadAndBindStepFinished) {
794 try {
795 this.wait();
796 } catch (InterruptedException ex) {
797 // Ignore
Daniel Sandler843e8602010-06-07 14:59:01 -0400798 }
799 }
Joe Onorato36115782010-06-17 13:28:48 -0400800 if (DEBUG_LOADERS) {
801 Log.d(TAG, "waited "
Winson Chungaafa03c2010-06-11 17:34:16 -0700802 + (SystemClock.uptimeMillis()-workspaceWaitTime)
Joe Onorato36115782010-06-17 13:28:48 -0400803 + "ms for previous step to finish binding");
804 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400805 }
Joe Onorato36115782010-06-17 13:28:48 -0400806 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400807
Joe Onorato36115782010-06-17 13:28:48 -0400808 public void run() {
809 // Optimize for end-user experience: if the Launcher is up and // running with the
810 // All Apps interface in the foreground, load All Apps first. Otherwise, load the
811 // workspace first (default).
812 final Callbacks cbk = mCallbacks.get();
813 final boolean loadWorkspaceFirst = cbk != null ? (!cbk.isAllAppsVisible()) : true;
Daniel Sandler843e8602010-06-07 14:59:01 -0400814
Joe Onorato36115782010-06-17 13:28:48 -0400815 keep_running: {
Daniel Sandler843e8602010-06-07 14:59:01 -0400816 // Elevate priority when Home launches for the first time to avoid
817 // starving at boot time. Staring at a blank home is not cool.
818 synchronized (mLock) {
Winson Chungaac01e12011-08-17 10:37:13 -0700819 if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to " +
820 (mIsLaunching ? "DEFAULT" : "BACKGROUND"));
Daniel Sandler843e8602010-06-07 14:59:01 -0400821 android.os.Process.setThreadPriority(mIsLaunching
822 ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
823 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400824 if (loadWorkspaceFirst) {
825 if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace");
826 loadAndBindWorkspace();
827 } else {
828 if (DEBUG_LOADERS) Log.d(TAG, "step 1: special: loading all apps");
Joe Onoratocc67f472010-06-08 10:54:30 -0700829 loadAndBindAllApps();
Daniel Sandler843e8602010-06-07 14:59:01 -0400830 }
831
Joe Onorato36115782010-06-17 13:28:48 -0400832 if (mStopped) {
833 break keep_running;
834 }
835
836 // Whew! Hard work done. Slow us down, and wait until the UI thread has
837 // settled down.
Daniel Sandler843e8602010-06-07 14:59:01 -0400838 synchronized (mLock) {
839 if (mIsLaunching) {
Winson Chungaac01e12011-08-17 10:37:13 -0700840 if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to BACKGROUND");
Daniel Sandler843e8602010-06-07 14:59:01 -0400841 android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
842 }
843 }
Joe Onorato36115782010-06-17 13:28:48 -0400844 waitForIdle();
Daniel Sandler843e8602010-06-07 14:59:01 -0400845
846 // second step
847 if (loadWorkspaceFirst) {
848 if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps");
Joe Onoratocc67f472010-06-08 10:54:30 -0700849 loadAndBindAllApps();
Daniel Sandler843e8602010-06-07 14:59:01 -0400850 } else {
851 if (DEBUG_LOADERS) Log.d(TAG, "step 2: special: loading workspace");
852 loadAndBindWorkspace();
853 }
Winson Chung7ed37742011-09-08 15:45:51 -0700854
855 // Restore the default thread priority after we are done loading items
856 synchronized (mLock) {
857 android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
858 }
Joe Onorato36115782010-06-17 13:28:48 -0400859 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400860
Winson Chungaac01e12011-08-17 10:37:13 -0700861
862 // Update the saved icons if necessary
863 if (DEBUG_LOADERS) Log.d(TAG, "Comparing loaded icons to database icons");
Winson Chungb1094bd2011-08-24 16:14:08 -0700864 for (Object key : sDbIconCache.keySet()) {
865 updateSavedIcon(mContext, (ShortcutInfo) key, sDbIconCache.get(key));
Winson Chungaac01e12011-08-17 10:37:13 -0700866 }
Winson Chungb1094bd2011-08-24 16:14:08 -0700867 sDbIconCache.clear();
Winson Chungaac01e12011-08-17 10:37:13 -0700868
Joe Onorato36115782010-06-17 13:28:48 -0400869 // Clear out this reference, otherwise we end up holding it until all of the
870 // callback runnables are done.
871 mContext = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400872
Joe Onorato36115782010-06-17 13:28:48 -0400873 synchronized (mLock) {
874 // If we are still the last one to be scheduled, remove ourselves.
875 if (mLoaderTask == this) {
876 mLoaderTask = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400877 }
Joe Onorato36115782010-06-17 13:28:48 -0400878 }
Joe Onorato36115782010-06-17 13:28:48 -0400879 }
880
881 public void stopLocked() {
882 synchronized (LoaderTask.this) {
883 mStopped = true;
884 this.notify();
885 }
886 }
887
888 /**
889 * Gets the callbacks object. If we've been stopped, or if the launcher object
890 * has somehow been garbage collected, return null instead. Pass in the Callbacks
891 * object that was around when the deferred message was scheduled, and if there's
892 * a new Callbacks object around then also return null. This will save us from
893 * calling onto it with data that will be ignored.
894 */
895 Callbacks tryGetCallbacks(Callbacks oldCallbacks) {
896 synchronized (mLock) {
897 if (mStopped) {
898 return null;
Daniel Sandler8802e962010-05-26 16:28:16 -0400899 }
Joe Onorato36115782010-06-17 13:28:48 -0400900
901 if (mCallbacks == null) {
902 return null;
Daniel Sandler8802e962010-05-26 16:28:16 -0400903 }
Joe Onorato36115782010-06-17 13:28:48 -0400904
905 final Callbacks callbacks = mCallbacks.get();
906 if (callbacks != oldCallbacks) {
907 return null;
908 }
909 if (callbacks == null) {
910 Log.w(TAG, "no mCallbacks");
911 return null;
912 }
913
914 return callbacks;
915 }
916 }
917
918 // check & update map of what's occupied; used to discard overlapping/invalid items
919 private boolean checkItemPlacement(ItemInfo occupied[][][], ItemInfo item) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700920 int containerIndex = item.screen;
921 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700922 // Return early if we detect that an item is under the hotseat button
923 if (Hotseat.isAllAppsButtonRank(item.screen)) {
924 return false;
925 }
Winson Chung6ba2a1b2011-09-02 16:22:11 -0700926
927 // We use the last index to refer to the hotseat and the screen as the rank, so
928 // test and update the occupied state accordingly
929 if (occupied[Launcher.SCREEN_COUNT][item.screen][0] != null) {
930 Log.e(TAG, "Error loading shortcut into hotseat " + item
931 + " into position (" + item.screen + ":" + item.cellX + "," + item.cellY
932 + ") occupied by " + occupied[Launcher.SCREEN_COUNT][item.screen][0]);
933 return false;
934 } else {
935 occupied[Launcher.SCREEN_COUNT][item.screen][0] = item;
936 return true;
937 }
Winson Chungf30ad5f2011-08-08 10:55:42 -0700938 } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
939 // Skip further checking if it is not the hotseat or workspace container
Daniel Sandler8802e962010-05-26 16:28:16 -0400940 return true;
941 }
Winson Chungf30ad5f2011-08-08 10:55:42 -0700942
Winson Chung6ba2a1b2011-09-02 16:22:11 -0700943 // Check if any workspace icons overlap with each other
Joe Onorato36115782010-06-17 13:28:48 -0400944 for (int x = item.cellX; x < (item.cellX+item.spanX); x++) {
945 for (int y = item.cellY; y < (item.cellY+item.spanY); y++) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700946 if (occupied[containerIndex][x][y] != null) {
Joe Onorato36115782010-06-17 13:28:48 -0400947 Log.e(TAG, "Error loading shortcut " + item
Winson Chungf30ad5f2011-08-08 10:55:42 -0700948 + " into cell (" + containerIndex + "-" + item.screen + ":"
Joe Onorato36115782010-06-17 13:28:48 -0400949 + x + "," + y
Winson Chungaafa03c2010-06-11 17:34:16 -0700950 + ") occupied by "
Winson Chungf30ad5f2011-08-08 10:55:42 -0700951 + occupied[containerIndex][x][y]);
Joe Onorato36115782010-06-17 13:28:48 -0400952 return false;
953 }
954 }
955 }
956 for (int x = item.cellX; x < (item.cellX+item.spanX); x++) {
957 for (int y = item.cellY; y < (item.cellY+item.spanY); y++) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700958 occupied[containerIndex][x][y] = item;
Joe Onorato36115782010-06-17 13:28:48 -0400959 }
960 }
Winson Chungf30ad5f2011-08-08 10:55:42 -0700961
Joe Onorato36115782010-06-17 13:28:48 -0400962 return true;
963 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400964
Joe Onorato36115782010-06-17 13:28:48 -0400965 private void loadWorkspace() {
966 final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400967
Joe Onorato36115782010-06-17 13:28:48 -0400968 final Context context = mContext;
969 final ContentResolver contentResolver = context.getContentResolver();
970 final PackageManager manager = context.getPackageManager();
971 final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
972 final boolean isSafeMode = manager.isSafeMode();
Joe Onorato3c2f7e12009-10-31 19:17:31 -0400973
Adam Cohen4eac29a2011-07-11 17:53:37 -0700974 sWorkspaceItems.clear();
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700975 sAppWidgets.clear();
976 sFolders.clear();
977 sItemsIdMap.clear();
Winson Chungb1094bd2011-08-24 16:14:08 -0700978 sDbIconCache.clear();
Romain Guy5c16f3e2010-01-12 17:24:58 -0800979
Joe Onorato36115782010-06-17 13:28:48 -0400980 final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400981
Joe Onorato36115782010-06-17 13:28:48 -0400982 final Cursor c = contentResolver.query(
Winson Chunge61e93e2011-09-12 10:59:49 -0700983 LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
Daniel Sandler8802e962010-05-26 16:28:16 -0400984
Winson Chungf30ad5f2011-08-08 10:55:42 -0700985 // +1 for the hotseat (it can be larger than the workspace)
Winson Chung36f97362011-09-07 11:20:10 -0700986 // Load workspace in reverse order to ensure that latest items are loaded first (and
987 // before any earlier duplicates)
Adam Cohend22015c2010-07-26 22:02:18 -0700988 final ItemInfo occupied[][][] =
Winson Chungf30ad5f2011-08-08 10:55:42 -0700989 new ItemInfo[Launcher.SCREEN_COUNT + 1][mCellCountX + 1][mCellCountY + 1];
Joe Onorato9c1289c2009-08-17 11:03:03 -0400990
Joe Onorato36115782010-06-17 13:28:48 -0400991 try {
992 final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
993 final int intentIndex = c.getColumnIndexOrThrow
994 (LauncherSettings.Favorites.INTENT);
995 final int titleIndex = c.getColumnIndexOrThrow
996 (LauncherSettings.Favorites.TITLE);
997 final int iconTypeIndex = c.getColumnIndexOrThrow(
998 LauncherSettings.Favorites.ICON_TYPE);
999 final int iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
1000 final int iconPackageIndex = c.getColumnIndexOrThrow(
1001 LauncherSettings.Favorites.ICON_PACKAGE);
1002 final int iconResourceIndex = c.getColumnIndexOrThrow(
1003 LauncherSettings.Favorites.ICON_RESOURCE);
1004 final int containerIndex = c.getColumnIndexOrThrow(
1005 LauncherSettings.Favorites.CONTAINER);
1006 final int itemTypeIndex = c.getColumnIndexOrThrow(
1007 LauncherSettings.Favorites.ITEM_TYPE);
1008 final int appWidgetIdIndex = c.getColumnIndexOrThrow(
1009 LauncherSettings.Favorites.APPWIDGET_ID);
1010 final int screenIndex = c.getColumnIndexOrThrow(
1011 LauncherSettings.Favorites.SCREEN);
1012 final int cellXIndex = c.getColumnIndexOrThrow
1013 (LauncherSettings.Favorites.CELLX);
1014 final int cellYIndex = c.getColumnIndexOrThrow
1015 (LauncherSettings.Favorites.CELLY);
1016 final int spanXIndex = c.getColumnIndexOrThrow
1017 (LauncherSettings.Favorites.SPANX);
1018 final int spanYIndex = c.getColumnIndexOrThrow(
1019 LauncherSettings.Favorites.SPANY);
1020 final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI);
1021 final int displayModeIndex = c.getColumnIndexOrThrow(
1022 LauncherSettings.Favorites.DISPLAY_MODE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001023
Joe Onorato36115782010-06-17 13:28:48 -04001024 ShortcutInfo info;
1025 String intentDescription;
1026 LauncherAppWidgetInfo appWidgetInfo;
1027 int container;
1028 long id;
1029 Intent intent;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001030
Joe Onorato36115782010-06-17 13:28:48 -04001031 while (!mStopped && c.moveToNext()) {
1032 try {
1033 int itemType = c.getInt(itemTypeIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001034
Joe Onorato36115782010-06-17 13:28:48 -04001035 switch (itemType) {
1036 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1037 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
1038 intentDescription = c.getString(intentIndex);
1039 try {
1040 intent = Intent.parseUri(intentDescription, 0);
1041 } catch (URISyntaxException e) {
1042 continue;
1043 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001044
Joe Onorato36115782010-06-17 13:28:48 -04001045 if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
1046 info = getShortcutInfo(manager, intent, context, c, iconIndex,
Winson Chungc3eecff2011-07-11 17:44:15 -07001047 titleIndex, mLabelCache);
Joe Onorato36115782010-06-17 13:28:48 -04001048 } else {
1049 info = getShortcutInfo(c, context, iconTypeIndex,
1050 iconPackageIndex, iconResourceIndex, iconIndex,
1051 titleIndex);
1052 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001053
Joe Onorato36115782010-06-17 13:28:48 -04001054 if (info != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001055 info.intent = intent;
1056 info.id = c.getLong(idIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001057 container = c.getInt(containerIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001058 info.container = container;
1059 info.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -07001060 info.cellX = c.getInt(cellXIndex);
1061 info.cellY = c.getInt(cellYIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001062
Daniel Sandler8802e962010-05-26 16:28:16 -04001063 // check & update map of what's occupied
Joe Onorato36115782010-06-17 13:28:48 -04001064 if (!checkItemPlacement(occupied, info)) {
Daniel Sandler8802e962010-05-26 16:28:16 -04001065 break;
1066 }
1067
Joe Onorato9c1289c2009-08-17 11:03:03 -04001068 switch (container) {
Joe Onorato36115782010-06-17 13:28:48 -04001069 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
Winson Chung3d503fb2011-07-13 17:25:49 -07001070 case LauncherSettings.Favorites.CONTAINER_HOTSEAT:
Adam Cohen4eac29a2011-07-11 17:53:37 -07001071 sWorkspaceItems.add(info);
Joe Onorato36115782010-06-17 13:28:48 -04001072 break;
1073 default:
1074 // Item is in a user folder
Adam Cohendf2cc412011-04-27 16:56:57 -07001075 FolderInfo folderInfo =
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001076 findOrMakeFolder(sFolders, container);
Joe Onorato36115782010-06-17 13:28:48 -04001077 folderInfo.add(info);
1078 break;
1079 }
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001080 sItemsIdMap.put(info.id, info);
Joe Onorato17a89222011-02-08 17:26:11 -08001081
1082 // now that we've loaded everthing re-save it with the
1083 // icon in case it disappears somehow.
Winson Chungb1094bd2011-08-24 16:14:08 -07001084 queueIconToBeChecked(sDbIconCache, info, c, iconIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001085 } else {
1086 // Failed to load the shortcut, probably because the
1087 // activity manager couldn't resolve it (maybe the app
1088 // was uninstalled), or the db row was somehow screwed up.
1089 // Delete it.
1090 id = c.getLong(idIndex);
1091 Log.e(TAG, "Error loading shortcut " + id + ", removing it");
1092 contentResolver.delete(LauncherSettings.Favorites.getContentUri(
1093 id, false), null, null);
1094 }
1095 break;
1096
Adam Cohendf2cc412011-04-27 16:56:57 -07001097 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Joe Onorato36115782010-06-17 13:28:48 -04001098 id = c.getLong(idIndex);
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001099 FolderInfo folderInfo = findOrMakeFolder(sFolders, id);
Joe Onorato36115782010-06-17 13:28:48 -04001100
Winson Chungaafa03c2010-06-11 17:34:16 -07001101 folderInfo.title = c.getString(titleIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001102 folderInfo.id = id;
1103 container = c.getInt(containerIndex);
1104 folderInfo.container = container;
1105 folderInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -07001106 folderInfo.cellX = c.getInt(cellXIndex);
1107 folderInfo.cellY = c.getInt(cellYIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001108
1109 // check & update map of what's occupied
1110 if (!checkItemPlacement(occupied, folderInfo)) {
1111 break;
1112 }
Joe Onorato36115782010-06-17 13:28:48 -04001113 switch (container) {
1114 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
Winson Chung3d503fb2011-07-13 17:25:49 -07001115 case LauncherSettings.Favorites.CONTAINER_HOTSEAT:
Adam Cohen4eac29a2011-07-11 17:53:37 -07001116 sWorkspaceItems.add(folderInfo);
Joe Onorato36115782010-06-17 13:28:48 -04001117 break;
1118 }
1119
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001120 sItemsIdMap.put(folderInfo.id, folderInfo);
1121 sFolders.put(folderInfo.id, folderInfo);
Joe Onorato36115782010-06-17 13:28:48 -04001122 break;
1123
Joe Onorato36115782010-06-17 13:28:48 -04001124 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
1125 // Read all Launcher-specific widget details
1126 int appWidgetId = c.getInt(appWidgetIdIndex);
1127 id = c.getLong(idIndex);
1128
1129 final AppWidgetProviderInfo provider =
1130 widgets.getAppWidgetInfo(appWidgetId);
Winson Chungaafa03c2010-06-11 17:34:16 -07001131
Joe Onorato36115782010-06-17 13:28:48 -04001132 if (!isSafeMode && (provider == null || provider.provider == null ||
1133 provider.provider.getPackageName() == null)) {
Adam Cohen16d7ffc2011-10-05 17:49:14 -07001134 String log = "Deleting widget that isn't installed anymore: id="
1135 + id + " appWidgetId=" + appWidgetId;
1136 Log.e(TAG, log);
1137 Launcher.sDumpLogs.add(log);
Joe Onorato36115782010-06-17 13:28:48 -04001138 itemsToRemove.add(id);
1139 } else {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001140 appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId);
Joe Onorato36115782010-06-17 13:28:48 -04001141 appWidgetInfo.id = id;
1142 appWidgetInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -07001143 appWidgetInfo.cellX = c.getInt(cellXIndex);
1144 appWidgetInfo.cellY = c.getInt(cellYIndex);
1145 appWidgetInfo.spanX = c.getInt(spanXIndex);
1146 appWidgetInfo.spanY = c.getInt(spanYIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001147
1148 container = c.getInt(containerIndex);
Winson Chung3d503fb2011-07-13 17:25:49 -07001149 if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP &&
1150 container != LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
Joe Onorato36115782010-06-17 13:28:48 -04001151 Log.e(TAG, "Widget found where container "
Winson Chung3d503fb2011-07-13 17:25:49 -07001152 + "!= CONTAINER_DESKTOP nor CONTAINER_HOTSEAT - ignoring!");
Joe Onorato36115782010-06-17 13:28:48 -04001153 continue;
1154 }
1155 appWidgetInfo.container = c.getInt(containerIndex);
1156
1157 // check & update map of what's occupied
1158 if (!checkItemPlacement(occupied, appWidgetInfo)) {
1159 break;
1160 }
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001161 sItemsIdMap.put(appWidgetInfo.id, appWidgetInfo);
1162 sAppWidgets.add(appWidgetInfo);
Joe Onorato36115782010-06-17 13:28:48 -04001163 }
1164 break;
Romain Guy5c16f3e2010-01-12 17:24:58 -08001165 }
Joe Onorato36115782010-06-17 13:28:48 -04001166 } catch (Exception e) {
1167 Log.w(TAG, "Desktop items loading interrupted:", e);
Romain Guy5c16f3e2010-01-12 17:24:58 -08001168 }
1169 }
Joe Onorato36115782010-06-17 13:28:48 -04001170 } finally {
1171 c.close();
1172 }
Romain Guy5c16f3e2010-01-12 17:24:58 -08001173
Joe Onorato36115782010-06-17 13:28:48 -04001174 if (itemsToRemove.size() > 0) {
1175 ContentProviderClient client = contentResolver.acquireContentProviderClient(
1176 LauncherSettings.Favorites.CONTENT_URI);
1177 // Remove dead items
1178 for (long id : itemsToRemove) {
1179 if (DEBUG_LOADERS) {
1180 Log.d(TAG, "Removed id = " + id);
1181 }
1182 // Don't notify content observers
1183 try {
1184 client.delete(LauncherSettings.Favorites.getContentUri(id, false),
1185 null, null);
1186 } catch (RemoteException e) {
1187 Log.w(TAG, "Could not remove id = " + id);
Daniel Sandler8802e962010-05-26 16:28:16 -04001188 }
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001189 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001190 }
1191
Joe Onorato36115782010-06-17 13:28:48 -04001192 if (DEBUG_LOADERS) {
1193 Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms");
1194 Log.d(TAG, "workspace layout: ");
Adam Cohend22015c2010-07-26 22:02:18 -07001195 for (int y = 0; y < mCellCountY; y++) {
Joe Onorato36115782010-06-17 13:28:48 -04001196 String line = "";
1197 for (int s = 0; s < Launcher.SCREEN_COUNT; s++) {
1198 if (s > 0) {
1199 line += " | ";
1200 }
Adam Cohend22015c2010-07-26 22:02:18 -07001201 for (int x = 0; x < mCellCountX; x++) {
Joe Onorato36115782010-06-17 13:28:48 -04001202 line += ((occupied[s][x][y] != null) ? "#" : ".");
1203 }
1204 }
1205 Log.d(TAG, "[ " + line + " ]");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001206 }
Joe Onorato36115782010-06-17 13:28:48 -04001207 }
1208 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001209
Joe Onorato36115782010-06-17 13:28:48 -04001210 /**
1211 * Read everything out of our database.
1212 */
1213 private void bindWorkspace() {
1214 final long t = SystemClock.uptimeMillis();
1215
1216 // Don't use these two variables in any of the callback runnables.
1217 // Otherwise we hold a reference to them.
1218 final Callbacks oldCallbacks = mCallbacks.get();
1219 if (oldCallbacks == null) {
1220 // This launcher has exited and nobody bothered to tell us. Just bail.
1221 Log.w(TAG, "LoaderTask running with no launcher");
1222 return;
1223 }
1224
1225 int N;
1226 // Tell the workspace that we're about to start firing items at it
1227 mHandler.post(new Runnable() {
1228 public void run() {
1229 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1230 if (callbacks != null) {
1231 callbacks.startBinding();
1232 }
1233 }
1234 });
Winson Chung603bcb92011-09-02 11:45:39 -07001235
Winson Chung603bcb92011-09-02 11:45:39 -07001236 final ArrayList<ItemInfo> workspaceItems = unbindWorkspaceItemsOnMainThread();
1237
Joe Onorato36115782010-06-17 13:28:48 -04001238 // Add the items to the workspace.
Winson Chung603bcb92011-09-02 11:45:39 -07001239 N = workspaceItems.size();
Joe Onorato36115782010-06-17 13:28:48 -04001240 for (int i=0; i<N; i+=ITEMS_CHUNK) {
1241 final int start = i;
1242 final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001243 mHandler.post(new Runnable() {
1244 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -08001245 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001246 if (callbacks != null) {
Winson Chung603bcb92011-09-02 11:45:39 -07001247 callbacks.bindItems(workspaceItems, start, start+chunkSize);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001248 }
1249 }
1250 });
Joe Onorato36115782010-06-17 13:28:48 -04001251 }
Winson Chung603bcb92011-09-02 11:45:39 -07001252 // Ensure that we don't use the same folders data structure on the main thread
1253 final HashMap<Long, FolderInfo> folders = new HashMap<Long, FolderInfo>(sFolders);
Joe Onorato36115782010-06-17 13:28:48 -04001254 mHandler.post(new Runnable() {
1255 public void run() {
1256 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1257 if (callbacks != null) {
Winson Chung603bcb92011-09-02 11:45:39 -07001258 callbacks.bindFolders(folders);
Joe Onorato36115782010-06-17 13:28:48 -04001259 }
1260 }
1261 });
1262 // Wait until the queue goes empty.
1263 mHandler.post(new Runnable() {
1264 public void run() {
1265 if (DEBUG_LOADERS) {
1266 Log.d(TAG, "Going to start binding widgets soon.");
1267 }
1268 }
1269 });
1270 // Bind the widgets, one at a time.
1271 // WARNING: this is calling into the workspace from the background thread,
1272 // but since getCurrentScreen() just returns the int, we should be okay. This
1273 // is just a hint for the order, and if it's wrong, we'll be okay.
1274 // TODO: instead, we should have that push the current screen into here.
1275 final int currentScreen = oldCallbacks.getCurrentWorkspaceScreen();
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001276 N = sAppWidgets.size();
Joe Onorato36115782010-06-17 13:28:48 -04001277 // once for the current screen
1278 for (int i=0; i<N; i++) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001279 final LauncherAppWidgetInfo widget = sAppWidgets.get(i);
Joe Onorato36115782010-06-17 13:28:48 -04001280 if (widget.screen == currentScreen) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001281 mHandler.post(new Runnable() {
1282 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -08001283 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001284 if (callbacks != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001285 callbacks.bindAppWidget(widget);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001286 }
1287 }
1288 });
1289 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001290 }
Joe Onorato36115782010-06-17 13:28:48 -04001291 // once for the other screens
1292 for (int i=0; i<N; i++) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001293 final LauncherAppWidgetInfo widget = sAppWidgets.get(i);
Joe Onorato36115782010-06-17 13:28:48 -04001294 if (widget.screen != currentScreen) {
1295 mHandler.post(new Runnable() {
1296 public void run() {
1297 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1298 if (callbacks != null) {
1299 callbacks.bindAppWidget(widget);
1300 }
1301 }
1302 });
Joe Onoratocc67f472010-06-08 10:54:30 -07001303 }
1304 }
Joe Onorato36115782010-06-17 13:28:48 -04001305 // Tell the workspace that we're done.
1306 mHandler.post(new Runnable() {
1307 public void run() {
1308 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1309 if (callbacks != null) {
1310 callbacks.finishBindingItems();
1311 }
1312 }
1313 });
1314 // If we're profiling, this is the last thing in the queue.
1315 mHandler.post(new Runnable() {
1316 public void run() {
1317 if (DEBUG_LOADERS) {
1318 Log.d(TAG, "bound workspace in "
1319 + (SystemClock.uptimeMillis()-t) + "ms");
1320 }
1321 }
1322 });
1323 }
Joe Onoratocc67f472010-06-08 10:54:30 -07001324
Joe Onorato36115782010-06-17 13:28:48 -04001325 private void loadAndBindAllApps() {
1326 if (DEBUG_LOADERS) {
1327 Log.d(TAG, "loadAndBindAllApps mAllAppsLoaded=" + mAllAppsLoaded);
1328 }
1329 if (!mAllAppsLoaded) {
1330 loadAllAppsByBatch();
Reena Lee93f824a2011-09-23 17:20:28 -07001331 synchronized (LoaderTask.this) {
1332 if (mStopped) {
1333 return;
1334 }
1335 mAllAppsLoaded = true;
Joe Onoratocc67f472010-06-08 10:54:30 -07001336 }
Joe Onorato36115782010-06-17 13:28:48 -04001337 } else {
1338 onlyBindAllApps();
1339 }
1340 }
Joe Onoratocc67f472010-06-08 10:54:30 -07001341
Joe Onorato36115782010-06-17 13:28:48 -04001342 private void onlyBindAllApps() {
1343 final Callbacks oldCallbacks = mCallbacks.get();
1344 if (oldCallbacks == null) {
1345 // This launcher has exited and nobody bothered to tell us. Just bail.
1346 Log.w(TAG, "LoaderTask running with no launcher (onlyBindAllApps)");
1347 return;
1348 }
1349
1350 // shallow copy
1351 final ArrayList<ApplicationInfo> list
Michael Jurka92f3d462011-11-22 21:02:29 -08001352 = (ArrayList<ApplicationInfo>) mAllAppsList.data.clone();
Joe Onorato36115782010-06-17 13:28:48 -04001353 mHandler.post(new Runnable() {
1354 public void run() {
1355 final long t = SystemClock.uptimeMillis();
1356 final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1357 if (callbacks != null) {
1358 callbacks.bindAllApplications(list);
1359 }
1360 if (DEBUG_LOADERS) {
1361 Log.d(TAG, "bound all " + list.size() + " apps from cache in "
1362 + (SystemClock.uptimeMillis()-t) + "ms");
1363 }
1364 }
1365 });
1366
1367 }
1368
1369 private void loadAllAppsByBatch() {
1370 final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1371
1372 // Don't use these two variables in any of the callback runnables.
1373 // Otherwise we hold a reference to them.
1374 final Callbacks oldCallbacks = mCallbacks.get();
1375 if (oldCallbacks == null) {
1376 // This launcher has exited and nobody bothered to tell us. Just bail.
1377 Log.w(TAG, "LoaderTask running with no launcher (loadAllAppsByBatch)");
1378 return;
1379 }
1380
1381 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1382 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
1383
1384 final PackageManager packageManager = mContext.getPackageManager();
1385 List<ResolveInfo> apps = null;
1386
1387 int N = Integer.MAX_VALUE;
1388
1389 int startIndex;
1390 int i=0;
1391 int batchSize = -1;
1392 while (i < N && !mStopped) {
1393 if (i == 0) {
1394 mAllAppsList.clear();
1395 final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1396 apps = packageManager.queryIntentActivities(mainIntent, 0);
1397 if (DEBUG_LOADERS) {
1398 Log.d(TAG, "queryIntentActivities took "
1399 + (SystemClock.uptimeMillis()-qiaTime) + "ms");
1400 }
1401 if (apps == null) {
1402 return;
1403 }
1404 N = apps.size();
1405 if (DEBUG_LOADERS) {
1406 Log.d(TAG, "queryIntentActivities got " + N + " apps");
1407 }
1408 if (N == 0) {
1409 // There are no apps?!?
1410 return;
1411 }
1412 if (mBatchSize == 0) {
1413 batchSize = N;
1414 } else {
1415 batchSize = mBatchSize;
1416 }
1417
1418 final long sortTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1419 Collections.sort(apps,
Winson Chungc3eecff2011-07-11 17:44:15 -07001420 new LauncherModel.ShortcutNameComparator(packageManager, mLabelCache));
Joe Onorato36115782010-06-17 13:28:48 -04001421 if (DEBUG_LOADERS) {
1422 Log.d(TAG, "sort took "
1423 + (SystemClock.uptimeMillis()-sortTime) + "ms");
1424 }
1425 }
1426
1427 final long t2 = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1428
1429 startIndex = i;
1430 for (int j=0; i<N && j<batchSize; j++) {
1431 // This builds the icon bitmaps.
Winson Chungc3eecff2011-07-11 17:44:15 -07001432 mAllAppsList.add(new ApplicationInfo(packageManager, apps.get(i),
Michael Jurkac9d95c52011-08-29 14:03:34 -07001433 mIconCache, mLabelCache));
Joe Onorato36115782010-06-17 13:28:48 -04001434 i++;
1435 }
1436
1437 final boolean first = i <= batchSize;
1438 final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1439 final ArrayList<ApplicationInfo> added = mAllAppsList.added;
1440 mAllAppsList.added = new ArrayList<ApplicationInfo>();
1441
Joe Onoratocc67f472010-06-08 10:54:30 -07001442 mHandler.post(new Runnable() {
1443 public void run() {
1444 final long t = SystemClock.uptimeMillis();
Joe Onoratocc67f472010-06-08 10:54:30 -07001445 if (callbacks != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001446 if (first) {
1447 callbacks.bindAllApplications(added);
1448 } else {
1449 callbacks.bindAppsAdded(added);
1450 }
1451 if (DEBUG_LOADERS) {
1452 Log.d(TAG, "bound " + added.size() + " apps in "
1453 + (SystemClock.uptimeMillis() - t) + "ms");
1454 }
1455 } else {
1456 Log.i(TAG, "not binding apps: no Launcher activity");
Joe Onoratocc67f472010-06-08 10:54:30 -07001457 }
1458 }
1459 });
1460
Daniel Sandlerdca66122010-04-13 16:23:58 -04001461 if (DEBUG_LOADERS) {
Joe Onorato36115782010-06-17 13:28:48 -04001462 Log.d(TAG, "batch of " + (i-startIndex) + " icons processed in "
1463 + (SystemClock.uptimeMillis()-t2) + "ms");
1464 }
1465
1466 if (mAllAppsLoadDelay > 0 && i < N) {
1467 try {
1468 if (DEBUG_LOADERS) {
1469 Log.d(TAG, "sleeping for " + mAllAppsLoadDelay + "ms");
1470 }
1471 Thread.sleep(mAllAppsLoadDelay);
1472 } catch (InterruptedException exc) { }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001473 }
1474 }
1475
Joe Onorato36115782010-06-17 13:28:48 -04001476 if (DEBUG_LOADERS) {
1477 Log.d(TAG, "cached all " + N + " apps in "
1478 + (SystemClock.uptimeMillis()-t) + "ms"
1479 + (mAllAppsLoadDelay > 0 ? " (including delay)" : ""));
Joe Onoratobe386092009-11-17 17:32:16 -08001480 }
1481 }
1482
1483 public void dumpState() {
Joe Onorato36115782010-06-17 13:28:48 -04001484 Log.d(TAG, "mLoaderTask.mContext=" + mContext);
1485 Log.d(TAG, "mLoaderTask.mWaitThread=" + mWaitThread);
1486 Log.d(TAG, "mLoaderTask.mIsLaunching=" + mIsLaunching);
1487 Log.d(TAG, "mLoaderTask.mStopped=" + mStopped);
1488 Log.d(TAG, "mLoaderTask.mLoadAndBindStepFinished=" + mLoadAndBindStepFinished);
Adam Cohen4eac29a2011-07-11 17:53:37 -07001489 Log.d(TAG, "mItems size=" + sWorkspaceItems.size());
Joe Onorato36115782010-06-17 13:28:48 -04001490 }
1491 }
1492
1493 void enqueuePackageUpdated(PackageUpdatedTask task) {
Brad Fitzpatrick700889f2010-10-11 09:40:44 -07001494 sWorker.post(task);
Joe Onorato36115782010-06-17 13:28:48 -04001495 }
1496
1497 private class PackageUpdatedTask implements Runnable {
1498 int mOp;
1499 String[] mPackages;
1500
1501 public static final int OP_NONE = 0;
1502 public static final int OP_ADD = 1;
1503 public static final int OP_UPDATE = 2;
1504 public static final int OP_REMOVE = 3; // uninstlled
1505 public static final int OP_UNAVAILABLE = 4; // external media unmounted
1506
1507
1508 public PackageUpdatedTask(int op, String[] packages) {
1509 mOp = op;
1510 mPackages = packages;
1511 }
1512
1513 public void run() {
1514 final Context context = mApp;
1515
1516 final String[] packages = mPackages;
1517 final int N = packages.length;
1518 switch (mOp) {
1519 case OP_ADD:
1520 for (int i=0; i<N; i++) {
1521 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
1522 mAllAppsList.addPackage(context, packages[i]);
1523 }
1524 break;
1525 case OP_UPDATE:
1526 for (int i=0; i<N; i++) {
1527 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
1528 mAllAppsList.updatePackage(context, packages[i]);
1529 }
1530 break;
1531 case OP_REMOVE:
1532 case OP_UNAVAILABLE:
1533 for (int i=0; i<N; i++) {
1534 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
1535 mAllAppsList.removePackage(packages[i]);
1536 }
1537 break;
1538 }
1539
1540 ArrayList<ApplicationInfo> added = null;
1541 ArrayList<ApplicationInfo> removed = null;
1542 ArrayList<ApplicationInfo> modified = null;
1543
1544 if (mAllAppsList.added.size() > 0) {
1545 added = mAllAppsList.added;
1546 mAllAppsList.added = new ArrayList<ApplicationInfo>();
1547 }
1548 if (mAllAppsList.removed.size() > 0) {
1549 removed = mAllAppsList.removed;
1550 mAllAppsList.removed = new ArrayList<ApplicationInfo>();
1551 for (ApplicationInfo info: removed) {
1552 mIconCache.remove(info.intent.getComponent());
1553 }
1554 }
1555 if (mAllAppsList.modified.size() > 0) {
1556 modified = mAllAppsList.modified;
1557 mAllAppsList.modified = new ArrayList<ApplicationInfo>();
1558 }
1559
1560 final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
1561 if (callbacks == null) {
1562 Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading.");
1563 return;
1564 }
1565
1566 if (added != null) {
1567 final ArrayList<ApplicationInfo> addedFinal = added;
1568 mHandler.post(new Runnable() {
1569 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001570 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1571 if (callbacks == cb && cb != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001572 callbacks.bindAppsAdded(addedFinal);
1573 }
1574 }
1575 });
1576 }
1577 if (modified != null) {
1578 final ArrayList<ApplicationInfo> modifiedFinal = modified;
1579 mHandler.post(new Runnable() {
1580 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001581 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1582 if (callbacks == cb && cb != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001583 callbacks.bindAppsUpdated(modifiedFinal);
1584 }
1585 }
1586 });
1587 }
1588 if (removed != null) {
1589 final boolean permanent = mOp != OP_UNAVAILABLE;
1590 final ArrayList<ApplicationInfo> removedFinal = removed;
1591 mHandler.post(new Runnable() {
1592 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001593 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1594 if (callbacks == cb && cb != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001595 callbacks.bindAppsRemoved(removedFinal, permanent);
1596 }
1597 }
1598 });
Joe Onoratobe386092009-11-17 17:32:16 -08001599 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001600
1601 mHandler.post(new Runnable() {
1602 @Override
1603 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001604 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1605 if (callbacks == cb && cb != null) {
Winson Chung80baf5a2010-08-09 16:03:15 -07001606 callbacks.bindPackagesUpdated();
1607 }
1608 }
1609 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04001610 }
1611 }
1612
1613 /**
Joe Onorato56d82912010-03-07 14:32:10 -05001614 * This is called from the code that adds shortcuts from the intent receiver. This
1615 * doesn't have a Cursor, but
Joe Onorato9c1289c2009-08-17 11:03:03 -04001616 */
Joe Onorato56d82912010-03-07 14:32:10 -05001617 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context) {
Winson Chungc3eecff2011-07-11 17:44:15 -07001618 return getShortcutInfo(manager, intent, context, null, -1, -1, null);
Joe Onorato56d82912010-03-07 14:32:10 -05001619 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001620
Joe Onorato56d82912010-03-07 14:32:10 -05001621 /**
1622 * Make an ShortcutInfo object for a shortcut that is an application.
1623 *
1624 * If c is not null, then it will be used to fill in missing data like the title and icon.
1625 */
1626 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context,
Winson Chungc3eecff2011-07-11 17:44:15 -07001627 Cursor c, int iconIndex, int titleIndex, HashMap<Object, CharSequence> labelCache) {
Joe Onorato56d82912010-03-07 14:32:10 -05001628 Bitmap icon = null;
Michael Jurkac9d95c52011-08-29 14:03:34 -07001629 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato56d82912010-03-07 14:32:10 -05001630
1631 ComponentName componentName = intent.getComponent();
1632 if (componentName == null) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001633 return null;
1634 }
1635
Adam Cohen00fcb492011-11-02 21:53:47 -07001636 try {
1637 PackageInfo pi = manager.getPackageInfo(componentName.getPackageName(), 0);
1638 if (!pi.applicationInfo.enabled) {
1639 // If we return null here, the corresponding item will be removed from the launcher
1640 // db and will not appear in the workspace.
1641 return null;
1642 }
1643 } catch (NameNotFoundException e) {
1644 Log.d(TAG, "getPackInfo failed for package " + componentName.getPackageName());
1645 }
1646
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001647 // TODO: See if the PackageManager knows about this case. If it doesn't
1648 // then return null & delete this.
1649
Joe Onorato56d82912010-03-07 14:32:10 -05001650 // the resource -- This may implicitly give us back the fallback icon,
1651 // but don't worry about that. All we're doing with usingFallbackIcon is
1652 // to avoid saving lots of copies of that in the database, and most apps
1653 // have icons anyway.
1654 final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);
1655 if (resolveInfo != null) {
Winson Chungaac01e12011-08-17 10:37:13 -07001656 icon = mIconCache.getIcon(componentName, resolveInfo, labelCache);
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001657 }
Joe Onorato56d82912010-03-07 14:32:10 -05001658 // the db
1659 if (icon == null) {
1660 if (c != null) {
Michael Jurka931dc972011-08-05 15:08:15 -07001661 icon = getIconFromCursor(c, iconIndex, context);
Joe Onorato56d82912010-03-07 14:32:10 -05001662 }
1663 }
1664 // the fallback icon
1665 if (icon == null) {
1666 icon = getFallbackIcon();
1667 info.usingFallbackIcon = true;
1668 }
1669 info.setIcon(icon);
1670
1671 // from the resource
1672 if (resolveInfo != null) {
Winson Chung5308f242011-08-18 12:12:41 -07001673 ComponentName key = LauncherModel.getComponentNameFromResolveInfo(resolveInfo);
1674 if (labelCache != null && labelCache.containsKey(key)) {
1675 info.title = labelCache.get(key);
Winson Chungc3eecff2011-07-11 17:44:15 -07001676 } else {
1677 info.title = resolveInfo.activityInfo.loadLabel(manager);
1678 if (labelCache != null) {
Winson Chung5308f242011-08-18 12:12:41 -07001679 labelCache.put(key, info.title);
Winson Chungc3eecff2011-07-11 17:44:15 -07001680 }
1681 }
Joe Onorato56d82912010-03-07 14:32:10 -05001682 }
1683 // from the db
Joe Onorato9c1289c2009-08-17 11:03:03 -04001684 if (info.title == null) {
Joe Onorato56d82912010-03-07 14:32:10 -05001685 if (c != null) {
1686 info.title = c.getString(titleIndex);
1687 }
1688 }
1689 // fall back to the class name of the activity
1690 if (info.title == null) {
1691 info.title = componentName.getClassName();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001692 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001693 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
1694 return info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001695 }
The Android Open Source Projectbc219c32009-03-09 11:52:14 -07001696
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001697 /**
Joe Onorato0589f0f2010-02-08 13:44:00 -08001698 * Make an ShortcutInfo object for a shortcut that isn't an application.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001699 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001700 private ShortcutInfo getShortcutInfo(Cursor c, Context context,
Joe Onorato56d82912010-03-07 14:32:10 -05001701 int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex,
1702 int titleIndex) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001703
Joe Onorato56d82912010-03-07 14:32:10 -05001704 Bitmap icon = null;
Michael Jurkac9d95c52011-08-29 14:03:34 -07001705 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001706 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001708 // TODO: If there's an explicit component and we can't install that, delete it.
1709
Joe Onorato56d82912010-03-07 14:32:10 -05001710 info.title = c.getString(titleIndex);
1711
Joe Onorato9c1289c2009-08-17 11:03:03 -04001712 int iconType = c.getInt(iconTypeIndex);
1713 switch (iconType) {
1714 case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
1715 String packageName = c.getString(iconPackageIndex);
1716 String resourceName = c.getString(iconResourceIndex);
1717 PackageManager packageManager = context.getPackageManager();
Joe Onorato56d82912010-03-07 14:32:10 -05001718 info.customIcon = false;
1719 // the resource
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001720 try {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001721 Resources resources = packageManager.getResourcesForApplication(packageName);
Joe Onorato56d82912010-03-07 14:32:10 -05001722 if (resources != null) {
1723 final int id = resources.getIdentifier(resourceName, null, null);
Michael Jurkac9a96192010-11-01 11:52:08 -07001724 icon = Utilities.createIconBitmap(
1725 mIconCache.getFullResIcon(resources, id), context);
Joe Onorato56d82912010-03-07 14:32:10 -05001726 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001727 } catch (Exception e) {
Joe Onorato56d82912010-03-07 14:32:10 -05001728 // drop this. we have other places to look for icons
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 }
Joe Onorato56d82912010-03-07 14:32:10 -05001730 // the db
1731 if (icon == null) {
Michael Jurka931dc972011-08-05 15:08:15 -07001732 icon = getIconFromCursor(c, iconIndex, context);
Joe Onorato56d82912010-03-07 14:32:10 -05001733 }
1734 // the fallback icon
1735 if (icon == null) {
1736 icon = getFallbackIcon();
1737 info.usingFallbackIcon = true;
1738 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001739 break;
1740 case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
Michael Jurka931dc972011-08-05 15:08:15 -07001741 icon = getIconFromCursor(c, iconIndex, context);
Joe Onorato56d82912010-03-07 14:32:10 -05001742 if (icon == null) {
1743 icon = getFallbackIcon();
1744 info.customIcon = false;
1745 info.usingFallbackIcon = true;
1746 } else {
1747 info.customIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001748 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001749 break;
1750 default:
Joe Onoratod8d22da2010-03-11 17:59:11 -08001751 icon = getFallbackIcon();
Joe Onorato56d82912010-03-07 14:32:10 -05001752 info.usingFallbackIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001753 info.customIcon = false;
1754 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001755 }
Joe Onoratod8d22da2010-03-11 17:59:11 -08001756 info.setIcon(icon);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001757 return info;
1758 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001759
Michael Jurka931dc972011-08-05 15:08:15 -07001760 Bitmap getIconFromCursor(Cursor c, int iconIndex, Context context) {
Joe Onorato56d82912010-03-07 14:32:10 -05001761 if (false) {
1762 Log.d(TAG, "getIconFromCursor app="
1763 + c.getString(c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE)));
1764 }
1765 byte[] data = c.getBlob(iconIndex);
1766 try {
Michael Jurka931dc972011-08-05 15:08:15 -07001767 return Utilities.createIconBitmap(
1768 BitmapFactory.decodeByteArray(data, 0, data.length), context);
Joe Onorato56d82912010-03-07 14:32:10 -05001769 } catch (Exception e) {
1770 return null;
1771 }
1772 }
1773
Winson Chung3d503fb2011-07-13 17:25:49 -07001774 ShortcutInfo addShortcut(Context context, Intent data, long container, int screen,
1775 int cellX, int cellY, boolean notify) {
Winson Chunga9abd0e2010-10-27 17:18:37 -07001776 final ShortcutInfo info = infoFromShortcutIntent(context, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001777 if (info == null) {
1778 return null;
1779 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001780 addItemToDatabase(context, info, container, screen, cellX, cellY, notify);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001781
1782 return info;
1783 }
1784
Winson Chunga9abd0e2010-10-27 17:18:37 -07001785 /**
Winson Chung55cef262010-10-28 14:14:18 -07001786 * Attempts to find an AppWidgetProviderInfo that matches the given component.
1787 */
1788 AppWidgetProviderInfo findAppWidgetProviderInfoWithComponent(Context context,
1789 ComponentName component) {
1790 List<AppWidgetProviderInfo> widgets =
1791 AppWidgetManager.getInstance(context).getInstalledProviders();
1792 for (AppWidgetProviderInfo info : widgets) {
1793 if (info.provider.equals(component)) {
1794 return info;
1795 }
1796 }
1797 return null;
Winson Chunga9abd0e2010-10-27 17:18:37 -07001798 }
1799
Winson Chung68846fd2010-10-29 11:00:27 -07001800 /**
1801 * Returns a list of all the widgets that can handle configuration with a particular mimeType.
1802 */
1803 List<WidgetMimeTypeHandlerData> resolveWidgetsForMimeType(Context context, String mimeType) {
1804 final PackageManager packageManager = context.getPackageManager();
1805 final List<WidgetMimeTypeHandlerData> supportedConfigurationActivities =
1806 new ArrayList<WidgetMimeTypeHandlerData>();
1807
1808 final Intent supportsIntent =
1809 new Intent(InstallWidgetReceiver.ACTION_SUPPORTS_CLIPDATA_MIMETYPE);
1810 supportsIntent.setType(mimeType);
1811
1812 // Create a set of widget configuration components that we can test against
1813 final List<AppWidgetProviderInfo> widgets =
1814 AppWidgetManager.getInstance(context).getInstalledProviders();
1815 final HashMap<ComponentName, AppWidgetProviderInfo> configurationComponentToWidget =
1816 new HashMap<ComponentName, AppWidgetProviderInfo>();
1817 for (AppWidgetProviderInfo info : widgets) {
1818 configurationComponentToWidget.put(info.configure, info);
1819 }
1820
1821 // Run through each of the intents that can handle this type of clip data, and cross
1822 // reference them with the components that are actual configuration components
1823 final List<ResolveInfo> activities = packageManager.queryIntentActivities(supportsIntent,
1824 PackageManager.MATCH_DEFAULT_ONLY);
1825 for (ResolveInfo info : activities) {
1826 final ActivityInfo activityInfo = info.activityInfo;
1827 final ComponentName infoComponent = new ComponentName(activityInfo.packageName,
1828 activityInfo.name);
1829 if (configurationComponentToWidget.containsKey(infoComponent)) {
1830 supportedConfigurationActivities.add(
1831 new InstallWidgetReceiver.WidgetMimeTypeHandlerData(info,
1832 configurationComponentToWidget.get(infoComponent)));
1833 }
1834 }
1835 return supportedConfigurationActivities;
1836 }
1837
Winson Chunga9abd0e2010-10-27 17:18:37 -07001838 ShortcutInfo infoFromShortcutIntent(Context context, Intent data, Bitmap fallbackIcon) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001839 Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
1840 String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
1841 Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
1842
Adam Cohend9198822011-11-22 16:42:47 -08001843 if (intent == null) {
1844 // If the intent is null, we can't construct a valid ShortcutInfo, so we return null
1845 Log.e(TAG, "Can't construct ShorcutInfo with null intent");
1846 return null;
1847 }
1848
Joe Onorato0589f0f2010-02-08 13:44:00 -08001849 Bitmap icon = null;
Joe Onorato0589f0f2010-02-08 13:44:00 -08001850 boolean customIcon = false;
1851 ShortcutIconResource iconResource = null;
1852
1853 if (bitmap != null && bitmap instanceof Bitmap) {
1854 icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap)bitmap), context);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001855 customIcon = true;
1856 } else {
1857 Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
1858 if (extra != null && extra instanceof ShortcutIconResource) {
1859 try {
1860 iconResource = (ShortcutIconResource) extra;
1861 final PackageManager packageManager = context.getPackageManager();
1862 Resources resources = packageManager.getResourcesForApplication(
1863 iconResource.packageName);
1864 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
Michael Jurkac9a96192010-11-01 11:52:08 -07001865 icon = Utilities.createIconBitmap(
1866 mIconCache.getFullResIcon(resources, id), context);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001867 } catch (Exception e) {
1868 Log.w(TAG, "Could not load shortcut icon: " + extra);
1869 }
1870 }
1871 }
1872
Michael Jurkac9d95c52011-08-29 14:03:34 -07001873 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato56d82912010-03-07 14:32:10 -05001874
1875 if (icon == null) {
Winson Chunga9abd0e2010-10-27 17:18:37 -07001876 if (fallbackIcon != null) {
1877 icon = fallbackIcon;
1878 } else {
1879 icon = getFallbackIcon();
1880 info.usingFallbackIcon = true;
1881 }
Joe Onorato56d82912010-03-07 14:32:10 -05001882 }
Joe Onorato0589f0f2010-02-08 13:44:00 -08001883 info.setIcon(icon);
Joe Onorato56d82912010-03-07 14:32:10 -05001884
Joe Onorato0589f0f2010-02-08 13:44:00 -08001885 info.title = name;
1886 info.intent = intent;
1887 info.customIcon = customIcon;
1888 info.iconResource = iconResource;
1889
1890 return info;
1891 }
1892
Winson Chungaac01e12011-08-17 10:37:13 -07001893 boolean queueIconToBeChecked(HashMap<Object, byte[]> cache, ShortcutInfo info, Cursor c,
1894 int iconIndex) {
Joe Onorato17a89222011-02-08 17:26:11 -08001895 // If apps can't be on SD, don't even bother.
1896 if (!mAppsCanBeOnExternalStorage) {
Winson Chungaac01e12011-08-17 10:37:13 -07001897 return false;
Joe Onorato17a89222011-02-08 17:26:11 -08001898 }
Joe Onorato56d82912010-03-07 14:32:10 -05001899 // If this icon doesn't have a custom icon, check to see
1900 // what's stored in the DB, and if it doesn't match what
1901 // we're going to show, store what we are going to show back
1902 // into the DB. We do this so when we're loading, if the
1903 // package manager can't find an icon (for example because
1904 // the app is on SD) then we can use that instead.
Joe Onoratoddc9c1f2010-08-30 18:30:15 -07001905 if (!info.customIcon && !info.usingFallbackIcon) {
Winson Chungaac01e12011-08-17 10:37:13 -07001906 cache.put(info, c.getBlob(iconIndex));
1907 return true;
1908 }
1909 return false;
1910 }
1911 void updateSavedIcon(Context context, ShortcutInfo info, byte[] data) {
1912 boolean needSave = false;
1913 try {
1914 if (data != null) {
1915 Bitmap saved = BitmapFactory.decodeByteArray(data, 0, data.length);
1916 Bitmap loaded = info.getIcon(mIconCache);
1917 needSave = !saved.sameAs(loaded);
1918 } else {
Joe Onorato56d82912010-03-07 14:32:10 -05001919 needSave = true;
1920 }
Winson Chungaac01e12011-08-17 10:37:13 -07001921 } catch (Exception e) {
1922 needSave = true;
1923 }
1924 if (needSave) {
1925 Log.d(TAG, "going to save icon bitmap for info=" + info);
1926 // This is slower than is ideal, but this only happens once
1927 // or when the app is updated with a new icon.
1928 updateItemInDatabase(context, info);
Joe Onorato56d82912010-03-07 14:32:10 -05001929 }
1930 }
1931
Joe Onorato9c1289c2009-08-17 11:03:03 -04001932 /**
Adam Cohendf2cc412011-04-27 16:56:57 -07001933 * Return an existing FolderInfo object if we have encountered this ID previously,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001934 * or make a new one.
1935 */
Adam Cohendf2cc412011-04-27 16:56:57 -07001936 private static FolderInfo findOrMakeFolder(HashMap<Long, FolderInfo> folders, long id) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001937 // See if a placeholder was created for us already
1938 FolderInfo folderInfo = folders.get(id);
Adam Cohendf2cc412011-04-27 16:56:57 -07001939 if (folderInfo == null) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001940 // No placeholder -- create a new instance
Michael Jurkac9d95c52011-08-29 14:03:34 -07001941 folderInfo = new FolderInfo();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001942 folders.put(id, folderInfo);
1943 }
Adam Cohendf2cc412011-04-27 16:56:57 -07001944 return folderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001945 }
1946
Joe Onorato9c1289c2009-08-17 11:03:03 -04001947 private static final Collator sCollator = Collator.getInstance();
Joe Onoratob0c27f22009-12-01 16:19:38 -08001948 public static final Comparator<ApplicationInfo> APP_NAME_COMPARATOR
Joe Onorato9c1289c2009-08-17 11:03:03 -04001949 = new Comparator<ApplicationInfo>() {
1950 public final int compare(ApplicationInfo a, ApplicationInfo b) {
Michael Jurka5b1808d2011-07-11 19:59:46 -07001951 int result = sCollator.compare(a.title.toString(), b.title.toString());
1952 if (result == 0) {
1953 result = a.componentName.compareTo(b.componentName);
1954 }
1955 return result;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001956 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001957 };
Winson Chung78403fe2011-01-21 15:38:02 -08001958 public static final Comparator<ApplicationInfo> APP_INSTALL_TIME_COMPARATOR
1959 = new Comparator<ApplicationInfo>() {
1960 public final int compare(ApplicationInfo a, ApplicationInfo b) {
1961 if (a.firstInstallTime < b.firstInstallTime) return 1;
1962 if (a.firstInstallTime > b.firstInstallTime) return -1;
1963 return 0;
1964 }
1965 };
Winson Chung785d2eb2011-04-14 16:08:02 -07001966 public static final Comparator<AppWidgetProviderInfo> WIDGET_NAME_COMPARATOR
1967 = new Comparator<AppWidgetProviderInfo>() {
1968 public final int compare(AppWidgetProviderInfo a, AppWidgetProviderInfo b) {
1969 return sCollator.compare(a.label.toString(), b.label.toString());
1970 }
1971 };
Winson Chung5308f242011-08-18 12:12:41 -07001972 static ComponentName getComponentNameFromResolveInfo(ResolveInfo info) {
1973 if (info.activityInfo != null) {
1974 return new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
1975 } else {
1976 return new ComponentName(info.serviceInfo.packageName, info.serviceInfo.name);
1977 }
1978 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001979 public static class ShortcutNameComparator implements Comparator<ResolveInfo> {
1980 private PackageManager mPackageManager;
Winson Chungc3eecff2011-07-11 17:44:15 -07001981 private HashMap<Object, CharSequence> mLabelCache;
Winson Chung785d2eb2011-04-14 16:08:02 -07001982 ShortcutNameComparator(PackageManager pm) {
1983 mPackageManager = pm;
Winson Chungc3eecff2011-07-11 17:44:15 -07001984 mLabelCache = new HashMap<Object, CharSequence>();
1985 }
1986 ShortcutNameComparator(PackageManager pm, HashMap<Object, CharSequence> labelCache) {
1987 mPackageManager = pm;
1988 mLabelCache = labelCache;
Winson Chung785d2eb2011-04-14 16:08:02 -07001989 }
1990 public final int compare(ResolveInfo a, ResolveInfo b) {
Winson Chungc3eecff2011-07-11 17:44:15 -07001991 CharSequence labelA, labelB;
Winson Chung5308f242011-08-18 12:12:41 -07001992 ComponentName keyA = LauncherModel.getComponentNameFromResolveInfo(a);
1993 ComponentName keyB = LauncherModel.getComponentNameFromResolveInfo(b);
1994 if (mLabelCache.containsKey(keyA)) {
1995 labelA = mLabelCache.get(keyA);
Winson Chungc3eecff2011-07-11 17:44:15 -07001996 } else {
1997 labelA = a.loadLabel(mPackageManager).toString();
1998
Winson Chung5308f242011-08-18 12:12:41 -07001999 mLabelCache.put(keyA, labelA);
Winson Chungc3eecff2011-07-11 17:44:15 -07002000 }
Winson Chung5308f242011-08-18 12:12:41 -07002001 if (mLabelCache.containsKey(keyB)) {
2002 labelB = mLabelCache.get(keyB);
Winson Chungc3eecff2011-07-11 17:44:15 -07002003 } else {
2004 labelB = b.loadLabel(mPackageManager).toString();
2005
Winson Chung5308f242011-08-18 12:12:41 -07002006 mLabelCache.put(keyB, labelB);
Winson Chungc3eecff2011-07-11 17:44:15 -07002007 }
Winson Chung785d2eb2011-04-14 16:08:02 -07002008 return sCollator.compare(labelA, labelB);
2009 }
2010 };
Winson Chung1ed747a2011-05-03 16:18:34 -07002011 public static class WidgetAndShortcutNameComparator implements Comparator<Object> {
2012 private PackageManager mPackageManager;
2013 private HashMap<Object, String> mLabelCache;
2014 WidgetAndShortcutNameComparator(PackageManager pm) {
2015 mPackageManager = pm;
2016 mLabelCache = new HashMap<Object, String>();
2017 }
2018 public final int compare(Object a, Object b) {
2019 String labelA, labelB;
Winson Chungc3eecff2011-07-11 17:44:15 -07002020 if (mLabelCache.containsKey(a)) {
2021 labelA = mLabelCache.get(a);
2022 } else {
2023 labelA = (a instanceof AppWidgetProviderInfo) ?
Winson Chung1ed747a2011-05-03 16:18:34 -07002024 ((AppWidgetProviderInfo) a).label :
2025 ((ResolveInfo) a).loadLabel(mPackageManager).toString();
Winson Chungc3eecff2011-07-11 17:44:15 -07002026 mLabelCache.put(a, labelA);
2027 }
2028 if (mLabelCache.containsKey(b)) {
2029 labelB = mLabelCache.get(b);
2030 } else {
2031 labelB = (b instanceof AppWidgetProviderInfo) ?
Winson Chung1ed747a2011-05-03 16:18:34 -07002032 ((AppWidgetProviderInfo) b).label :
2033 ((ResolveInfo) b).loadLabel(mPackageManager).toString();
Winson Chungc3eecff2011-07-11 17:44:15 -07002034 mLabelCache.put(b, labelB);
2035 }
Winson Chung1ed747a2011-05-03 16:18:34 -07002036 return sCollator.compare(labelA, labelB);
2037 }
2038 };
Joe Onoratobe386092009-11-17 17:32:16 -08002039
2040 public void dumpState() {
Joe Onoratobe386092009-11-17 17:32:16 -08002041 Log.d(TAG, "mCallbacks=" + mCallbacks);
2042 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mAllAppsList.data);
2043 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mAllAppsList.added);
2044 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mAllAppsList.removed);
2045 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mAllAppsList.modified);
Joe Onorato36115782010-06-17 13:28:48 -04002046 if (mLoaderTask != null) {
2047 mLoaderTask.dumpState();
2048 } else {
2049 Log.d(TAG, "mLoaderTask=null");
2050 }
Joe Onoratobe386092009-11-17 17:32:16 -08002051 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052}