blob: 50a36a5b769485d33500cf7c867965b6fbf2889f [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;
61import java.util.Locale;
62
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063/**
64 * Maintains in-memory state of the Launcher. It is expected that there should be only one
65 * LauncherModel object held in a static. Also provide APIs for updating the database state
The Android Open Source Projectbc219c32009-03-09 11:52:14 -070066 * for the Launcher.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067 */
Joe Onoratof99f8c12009-10-31 17:27:36 -040068public class LauncherModel extends BroadcastReceiver {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080069 static final boolean DEBUG_LOADERS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -040070 static final String TAG = "Launcher.Model";
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070071
Joe Onorato36115782010-06-17 13:28:48 -040072 private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons
Joe Onorato17a89222011-02-08 17:26:11 -080073 private final boolean mAppsCanBeOnExternalStorage;
Joe Onoratod65d08e2010-04-20 15:43:37 -040074 private int mBatchSize; // 0 is all apps at once
Daniel Sandler2ff10b32010-04-16 15:06:06 -040075 private int mAllAppsLoadDelay; // milliseconds between batches
Daniel Sandlerdca66122010-04-13 16:23:58 -040076
Joe Onoratof99f8c12009-10-31 17:27:36 -040077 private final LauncherApplication mApp;
Joe Onorato9c1289c2009-08-17 11:03:03 -040078 private final Object mLock = new Object();
79 private DeferredHandler mHandler = new DeferredHandler();
Joe Onorato36115782010-06-17 13:28:48 -040080 private LoaderTask mLoaderTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081
Brad Fitzpatrick700889f2010-10-11 09:40:44 -070082 private static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
83 static {
84 sWorkerThread.start();
85 }
86 private static final Handler sWorker = new Handler(sWorkerThread.getLooper());
87
Joe Onoratocc67f472010-06-08 10:54:30 -070088 // We start off with everything not loaded. After that, we assume that
89 // our monitoring of the package manager provides all updates and we never
90 // need to do a requery. These are only ever touched from the loader thread.
91 private boolean mWorkspaceLoaded;
92 private boolean mAllAppsLoaded;
93
Joe Onorato9c1289c2009-08-17 11:03:03 -040094 private WeakReference<Callbacks> mCallbacks;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095
Michael Jurkaa8c760d2011-04-28 14:59:33 -070096 // < only access in worker thread >
97 private AllAppsList mAllAppsList;
Joe Onorato0589f0f2010-02-08 13:44:00 -080098
Michael Jurkaa8c760d2011-04-28 14:59:33 -070099 // sItemsIdMap maps *all* the ItemInfos (shortcuts, folders, and widgets) created by
100 // LauncherModel to their ids
101 static final HashMap<Long, ItemInfo> sItemsIdMap = new HashMap<Long, ItemInfo>();
102
103 // sItems is passed to bindItems, which expects a list of all folders and shortcuts created by
104 // LauncherModel that are directly on the home screen (however, no widgets or shortcuts
105 // within folders).
Adam Cohen4eac29a2011-07-11 17:53:37 -0700106 static final ArrayList<ItemInfo> sWorkspaceItems = new ArrayList<ItemInfo>();
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700107
108 // sAppWidgets is all LauncherAppWidgetInfo created by LauncherModel. Passed to bindAppWidget()
109 static final ArrayList<LauncherAppWidgetInfo> sAppWidgets =
110 new ArrayList<LauncherAppWidgetInfo>();
111
112 // sFolders is all FolderInfos created by LauncherModel. Passed to bindFolders()
113 static final HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Winson Chungb1094bd2011-08-24 16:14:08 -0700114
115 // sDbIconCache is the set of ItemInfos that need to have their icons updated in the database
116 static final HashMap<Object, byte[]> sDbIconCache = new HashMap<Object, byte[]>();
117
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700118 // </ only access in worker thread >
119
120 private IconCache mIconCache;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800121 private Bitmap mDefaultIcon;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122
Adam Cohend22015c2010-07-26 22:02:18 -0700123 private static int mCellCountX;
124 private static int mCellCountY;
Winson Chungaafa03c2010-06-11 17:34:16 -0700125
Reena Lee99a73f32011-10-24 17:27:37 -0700126 protected int mPreviousConfigMcc;
Reena Lee93f824a2011-09-23 17:20:28 -0700127
Joe Onorato9c1289c2009-08-17 11:03:03 -0400128 public interface Callbacks {
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700129 public boolean setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400130 public int getCurrentWorkspaceScreen();
131 public void startBinding();
132 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end);
Joe Onoratoad72e172009-11-06 16:25:04 -0500133 public void bindFolders(HashMap<Long,FolderInfo> folders);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400134 public void finishBindingItems();
135 public void bindAppWidget(LauncherAppWidgetInfo info);
136 public void bindAllApplications(ArrayList<ApplicationInfo> apps);
Joe Onorato64e6be72010-03-05 15:05:52 -0500137 public void bindAppsAdded(ArrayList<ApplicationInfo> apps);
138 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps);
Joe Onorato36115782010-06-17 13:28:48 -0400139 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent);
Winson Chung80baf5a2010-08-09 16:03:15 -0700140 public void bindPackagesUpdated();
Daniel Sandler843e8602010-06-07 14:59:01 -0400141 public boolean isAllAppsVisible();
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100142 public void bindSearchablesChanged();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400143 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144
Joe Onorato0589f0f2010-02-08 13:44:00 -0800145 LauncherModel(LauncherApplication app, IconCache iconCache) {
Joe Onorato17a89222011-02-08 17:26:11 -0800146 mAppsCanBeOnExternalStorage = !Environment.isExternalStorageEmulated();
Joe Onoratof99f8c12009-10-31 17:27:36 -0400147 mApp = app;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800148 mAllAppsList = new AllAppsList(iconCache);
149 mIconCache = iconCache;
150
151 mDefaultIcon = Utilities.createIconBitmap(
Michael Jurkac9a96192010-11-01 11:52:08 -0700152 mIconCache.getFullResDefaultActivityIcon(), app);
Daniel Sandler2ff10b32010-04-16 15:06:06 -0400153
Reena Lee93f824a2011-09-23 17:20:28 -0700154 final Resources res = app.getResources();
155 mAllAppsLoadDelay = res.getInteger(R.integer.config_allAppsBatchLoadDelay);
156 mBatchSize = res.getInteger(R.integer.config_allAppsBatchSize);
Reena Lee99a73f32011-10-24 17:27:37 -0700157 Configuration config = res.getConfiguration();
158 mPreviousConfigMcc = config.mcc;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800159 }
160
Joe Onorato56d82912010-03-07 14:32:10 -0500161 public Bitmap getFallbackIcon() {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800162 return Bitmap.createBitmap(mDefaultIcon);
Joe Onoratof99f8c12009-10-31 17:27:36 -0400163 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164
Winson Chung603bcb92011-09-02 11:45:39 -0700165 public void unbindWorkspaceItems() {
166 sWorker.post(new Runnable() {
167 @Override
168 public void run() {
169 unbindWorkspaceItemsOnMainThread();
170 }
171 });
172 }
173
174 /** Unbinds all the sWorkspaceItems on the main thread, and return a copy of sWorkspaceItems
175 * that is save to reference from the main thread. */
176 private ArrayList<ItemInfo> unbindWorkspaceItemsOnMainThread() {
177 // Ensure that we don't use the same workspace items data structure on the main thread
178 // by making a copy of workspace items first.
179 final ArrayList<ItemInfo> workspaceItems = new ArrayList<ItemInfo>(sWorkspaceItems);
180 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 }
186 }
187 });
188
189 return workspaceItems;
Adam Cohen4eac29a2011-07-11 17:53:37 -0700190 }
191
Joe Onorato9c1289c2009-08-17 11:03:03 -0400192 /**
193 * Adds an item to the DB if it was not created previously, or move it to a new
194 * <container, screen, cellX, cellY>
195 */
196 static void addOrMoveItemInDatabase(Context context, ItemInfo item, long container,
197 int screen, int cellX, int cellY) {
198 if (item.container == ItemInfo.NO_ID) {
199 // From all apps
200 addItemToDatabase(context, item, container, screen, cellX, cellY, false);
201 } else {
202 // From somewhere else
203 moveItemInDatabase(context, item, container, screen, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204 }
205 }
206
Michael Jurkac9d95c52011-08-29 14:03:34 -0700207 static void updateItemInDatabaseHelper(Context context, final ContentValues values,
208 final ItemInfo item, final String callingFunction) {
209 final long itemId = item.id;
210 final Uri uri = LauncherSettings.Favorites.getContentUri(itemId, false);
211 final ContentResolver cr = context.getContentResolver();
212
213 Runnable r = new Runnable() {
214 public void run() {
215 cr.update(uri, values, null, null);
216
217 ItemInfo modelItem = sItemsIdMap.get(itemId);
218 if (item != modelItem) {
219 // the modelItem needs to match up perfectly with item if our model is to be
220 // consistent with the database-- for now, just require modelItem == item
221 String msg = "item: " + ((item != null) ? item.toString() : "null") +
222 "modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
223 "Error: ItemInfo passed to " + callingFunction + " doesn't match original";
224 throw new RuntimeException(msg);
225 }
226
227 // Items are added/removed from the corresponding FolderInfo elsewhere, such
228 // as in Workspace.onDrop. Here, we just add/remove them from the list of items
229 // that are on the desktop, as appropriate
230 if (modelItem.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
231 modelItem.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
232 if (!sWorkspaceItems.contains(modelItem)) {
233 sWorkspaceItems.add(modelItem);
234 }
235 } else {
236 sWorkspaceItems.remove(modelItem);
237 }
238 }
239 };
240
241 if (sWorkerThread.getThreadId() == Process.myTid()) {
242 r.run();
243 } else {
244 sWorker.post(r);
245 }
246 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800247 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400248 * Move an item in the DB to a new <container, screen, cellX, cellY>
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700249 */
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700250 static void moveItemInDatabase(Context context, final ItemInfo item, final long container,
251 final int screen, final int cellX, final int cellY) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400252 item.container = container;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400253 item.cellX = cellX;
254 item.cellY = cellY;
Michael Jurkac9d95c52011-08-29 14:03:34 -0700255
Winson Chung3d503fb2011-07-13 17:25:49 -0700256 // We store hotseat items in canonical form which is this orientation invariant position
257 // in the hotseat
258 if (context instanceof Launcher && screen < 0 &&
259 container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
260 item.screen = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY);
261 } else {
262 item.screen = screen;
263 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400264
265 final ContentValues values = new ContentValues();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400266 values.put(LauncherSettings.Favorites.CONTAINER, item.container);
Winson Chung3d503fb2011-07-13 17:25:49 -0700267 values.put(LauncherSettings.Favorites.CELLX, item.cellX);
268 values.put(LauncherSettings.Favorites.CELLY, item.cellY);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400269 values.put(LauncherSettings.Favorites.SCREEN, item.screen);
270
Michael Jurkac9d95c52011-08-29 14:03:34 -0700271 updateItemInDatabaseHelper(context, values, item, "moveItemInDatabase");
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700272 }
273
274 /**
Adam Cohen1b607ed2011-03-03 17:26:50 -0800275 * Resize an item in the DB to a new <spanX, spanY, cellX, cellY>
Adam Cohend4844c32011-02-18 19:25:06 -0800276 */
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700277 static void resizeItemInDatabase(Context context, final ItemInfo item, final int cellX,
278 final int cellY, final int spanX, final int spanY) {
Adam Cohend4844c32011-02-18 19:25:06 -0800279 item.spanX = spanX;
280 item.spanY = spanY;
281 item.cellX = cellX;
282 item.cellY = cellY;
283
Adam Cohend4844c32011-02-18 19:25:06 -0800284 final ContentValues values = new ContentValues();
Adam Cohend4844c32011-02-18 19:25:06 -0800285 values.put(LauncherSettings.Favorites.CONTAINER, item.container);
286 values.put(LauncherSettings.Favorites.SPANX, spanX);
287 values.put(LauncherSettings.Favorites.SPANY, spanY);
288 values.put(LauncherSettings.Favorites.CELLX, cellX);
289 values.put(LauncherSettings.Favorites.CELLY, cellY);
Michael Jurkac9d95c52011-08-29 14:03:34 -0700290 updateItemInDatabaseHelper(context, values, item, "resizeItemInDatabase");
291 }
Adam Cohend4844c32011-02-18 19:25:06 -0800292
Michael Jurkac9d95c52011-08-29 14:03:34 -0700293
294 /**
295 * Update an item to the database in a specified container.
296 */
297 static void updateItemInDatabase(Context context, final ItemInfo item) {
298 final ContentValues values = new ContentValues();
299 item.onAddToDatabase(values);
300 item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
301 updateItemInDatabaseHelper(context, values, item, "updateItemInDatabase");
Adam Cohend4844c32011-02-18 19:25:06 -0800302 }
303
304 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400305 * Returns true if the shortcuts already exists in the database.
306 * we identify a shortcut by its title and intent.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800307 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400308 static boolean shortcutExists(Context context, String title, Intent intent) {
309 final ContentResolver cr = context.getContentResolver();
310 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
311 new String[] { "title", "intent" }, "title=? and intent=?",
312 new String[] { title, intent.toUri(0) }, null);
313 boolean result = false;
314 try {
315 result = c.moveToFirst();
316 } finally {
317 c.close();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800318 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400319 return result;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700320 }
321
Joe Onorato9c1289c2009-08-17 11:03:03 -0400322 /**
Winson Chungaafa03c2010-06-11 17:34:16 -0700323 * Returns an ItemInfo array containing all the items in the LauncherModel.
324 * The ItemInfo.id is not set through this function.
325 */
326 static ArrayList<ItemInfo> getItemsInLocalCoordinates(Context context) {
327 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
328 final ContentResolver cr = context.getContentResolver();
329 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] {
330 LauncherSettings.Favorites.ITEM_TYPE, LauncherSettings.Favorites.CONTAINER,
331 LauncherSettings.Favorites.SCREEN, LauncherSettings.Favorites.CELLX, LauncherSettings.Favorites.CELLY,
332 LauncherSettings.Favorites.SPANX, LauncherSettings.Favorites.SPANY }, null, null, null);
333
334 final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
335 final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
336 final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
337 final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
338 final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
339 final int spanXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANX);
340 final int spanYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANY);
341
342 try {
343 while (c.moveToNext()) {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700344 ItemInfo item = new ItemInfo();
Winson Chungaafa03c2010-06-11 17:34:16 -0700345 item.cellX = c.getInt(cellXIndex);
346 item.cellY = c.getInt(cellYIndex);
347 item.spanX = c.getInt(spanXIndex);
348 item.spanY = c.getInt(spanYIndex);
349 item.container = c.getInt(containerIndex);
350 item.itemType = c.getInt(itemTypeIndex);
351 item.screen = c.getInt(screenIndex);
352
353 items.add(item);
354 }
355 } catch (Exception e) {
356 items.clear();
357 } finally {
358 c.close();
359 }
360
361 return items;
362 }
363
364 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400365 * Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList.
366 */
367 FolderInfo getFolderById(Context context, HashMap<Long,FolderInfo> folderList, long id) {
368 final ContentResolver cr = context.getContentResolver();
369 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null,
370 "_id=? and (itemType=? or itemType=?)",
371 new String[] { String.valueOf(id),
Adam Cohendf2cc412011-04-27 16:56:57 -0700372 String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)}, null);
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700373
Joe Onorato9c1289c2009-08-17 11:03:03 -0400374 try {
375 if (c.moveToFirst()) {
376 final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
377 final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
378 final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
379 final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
380 final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
381 final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382
Joe Onorato9c1289c2009-08-17 11:03:03 -0400383 FolderInfo folderInfo = null;
384 switch (c.getInt(itemTypeIndex)) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700385 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
386 folderInfo = findOrMakeFolder(folderList, id);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400387 break;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700388 }
389
Joe Onorato9c1289c2009-08-17 11:03:03 -0400390 folderInfo.title = c.getString(titleIndex);
391 folderInfo.id = id;
392 folderInfo.container = c.getInt(containerIndex);
393 folderInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -0700394 folderInfo.cellX = c.getInt(cellXIndex);
395 folderInfo.cellY = c.getInt(cellYIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400396
397 return folderInfo;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700398 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400399 } finally {
400 c.close();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700401 }
402
403 return null;
404 }
405
Joe Onorato9c1289c2009-08-17 11:03:03 -0400406 /**
407 * Add an item to the database in a specified container. Sets the container, screen, cellX and
408 * cellY fields of the item. Also assigns an ID to the item.
409 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700410 static void addItemToDatabase(Context context, final ItemInfo item, final long container,
411 final int screen, final int cellX, final int cellY, final boolean notify) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400412 item.container = container;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400413 item.cellX = cellX;
414 item.cellY = cellY;
Winson Chung3d503fb2011-07-13 17:25:49 -0700415 // We store hotseat items in canonical form which is this orientation invariant position
416 // in the hotseat
417 if (context instanceof Launcher && screen < 0 &&
418 container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
419 item.screen = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY);
420 } else {
421 item.screen = screen;
422 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400423
424 final ContentValues values = new ContentValues();
425 final ContentResolver cr = context.getContentResolver();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400426 item.onAddToDatabase(values);
427
Michael Jurka7578ec62011-08-03 14:11:54 -0700428 LauncherApplication app = (LauncherApplication) context.getApplicationContext();
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700429 item.id = app.getLauncherProvider().generateNewId();
430 values.put(LauncherSettings.Favorites._ID, item.id);
Winson Chung3d503fb2011-07-13 17:25:49 -0700431 item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700432
Michael Jurkac9d95c52011-08-29 14:03:34 -0700433 Runnable r = new Runnable() {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700434 public void run() {
435 cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
436 LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400437
Winson Chungb1094bd2011-08-24 16:14:08 -0700438 if (sItemsIdMap.containsKey(item.id)) {
439 // we should not be adding new items in the db with the same id
440 throw new RuntimeException("Error: ItemInfo id (" + item.id + ") passed to " +
441 "addItemToDatabase already exists." + item.toString());
442 }
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700443 sItemsIdMap.put(item.id, item);
444 switch (item.itemType) {
445 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
446 sFolders.put(item.id, (FolderInfo) item);
Winson Chung3d503fb2011-07-13 17:25:49 -0700447 // Fall through
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700448 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
449 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700450 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
451 item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
Adam Cohen4eac29a2011-07-11 17:53:37 -0700452 sWorkspaceItems.add(item);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700453 }
454 break;
455 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
456 sAppWidgets.add((LauncherAppWidgetInfo) item);
457 break;
458 }
459 }
Michael Jurkac9d95c52011-08-29 14:03:34 -0700460 };
461
462 if (sWorkerThread.getThreadId() == Process.myTid()) {
463 r.run();
464 } else {
465 sWorker.post(r);
466 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700467 }
468
Joe Onorato9c1289c2009-08-17 11:03:03 -0400469 /**
Winson Chungaafa03c2010-06-11 17:34:16 -0700470 * Creates a new unique child id, for a given cell span across all layouts.
471 */
Michael Jurka845ba3b2010-09-28 17:09:46 -0700472 static int getCellLayoutChildId(
Winson Chung3d503fb2011-07-13 17:25:49 -0700473 long container, int screen, int localCellX, int localCellY, int spanX, int spanY) {
474 return (((int) container & 0xFF) << 24)
Michael Jurka845ba3b2010-09-28 17:09:46 -0700475 | (screen & 0xFF) << 16 | (localCellX & 0xFF) << 8 | (localCellY & 0xFF);
Winson Chungaafa03c2010-06-11 17:34:16 -0700476 }
477
Adam Cohend22015c2010-07-26 22:02:18 -0700478 static int getCellCountX() {
479 return mCellCountX;
Winson Chungaafa03c2010-06-11 17:34:16 -0700480 }
481
Adam Cohend22015c2010-07-26 22:02:18 -0700482 static int getCellCountY() {
483 return mCellCountY;
Winson Chungaafa03c2010-06-11 17:34:16 -0700484 }
485
486 /**
487 * Updates the model orientation helper to take into account the current layout dimensions
488 * when performing local/canonical coordinate transformations.
489 */
490 static void updateWorkspaceLayoutCells(int shortAxisCellCount, int longAxisCellCount) {
Adam Cohend22015c2010-07-26 22:02:18 -0700491 mCellCountX = shortAxisCellCount;
492 mCellCountY = longAxisCellCount;
Winson Chungaafa03c2010-06-11 17:34:16 -0700493 }
494
495 /**
Michael Jurkac9d95c52011-08-29 14:03:34 -0700496 * Removes the specified item from the database
497 * @param context
498 * @param item
Joe Onorato9c1289c2009-08-17 11:03:03 -0400499 */
Michael Jurkac9d95c52011-08-29 14:03:34 -0700500 static void deleteItemFromDatabase(Context context, final ItemInfo item) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400501 final ContentResolver cr = context.getContentResolver();
Michael Jurkac9d95c52011-08-29 14:03:34 -0700502 final Uri uriToDelete = LauncherSettings.Favorites.getContentUri(item.id, false);
Michael Jurka83df1882011-08-31 20:59:26 -0700503 Runnable r = new Runnable() {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700504 public void run() {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700505 cr.delete(uriToDelete, null, null);
506 switch (item.itemType) {
507 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
508 sFolders.remove(item.id);
509 sWorkspaceItems.remove(item);
510 break;
511 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
512 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
513 sWorkspaceItems.remove(item);
514 break;
515 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
516 sAppWidgets.remove((LauncherAppWidgetInfo) item);
517 break;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700518 }
Michael Jurkac9d95c52011-08-29 14:03:34 -0700519 sItemsIdMap.remove(item.id);
520 sDbIconCache.remove(item);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700521 }
Michael Jurka83df1882011-08-31 20:59:26 -0700522 };
523 if (sWorkerThread.getThreadId() == Process.myTid()) {
524 r.run();
525 } else {
526 sWorker.post(r);
527 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400528 }
529
530 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400531 * Remove the contents of the specified folder from the database
532 */
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700533 static void deleteFolderContentsFromDatabase(Context context, final FolderInfo info) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400534 final ContentResolver cr = context.getContentResolver();
535
Michael Jurkac9d95c52011-08-29 14:03:34 -0700536 Runnable r = new Runnable() {
537 public void run() {
538 cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
539 sItemsIdMap.remove(info.id);
540 sFolders.remove(info.id);
541 sDbIconCache.remove(info);
542 sWorkspaceItems.remove(info);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700543
Michael Jurkac9d95c52011-08-29 14:03:34 -0700544 cr.delete(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
545 LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
546 for (ItemInfo childInfo : info.contents) {
547 sItemsIdMap.remove(childInfo.id);
548 sDbIconCache.remove(childInfo);
Adam Cohenafb01ee2011-06-23 15:38:03 -0700549 }
Michael Jurkac9d95c52011-08-29 14:03:34 -0700550 }
551 };
552 if (sWorkerThread.getThreadId() == Process.myTid()) {
553 r.run();
554 } else {
555 sWorker.post(r);
556 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400557 }
558
559 /**
560 * Set this as the current Launcher activity object for the loader.
561 */
562 public void initialize(Callbacks callbacks) {
563 synchronized (mLock) {
564 mCallbacks = new WeakReference<Callbacks>(callbacks);
565 }
566 }
567
Joe Onorato1d8e7bb2009-10-15 19:49:43 -0700568 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400569 * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
570 * ACTION_PACKAGE_CHANGED.
571 */
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100572 @Override
Joe Onoratof99f8c12009-10-31 17:27:36 -0400573 public void onReceive(Context context, Intent intent) {
Joe Onorato36115782010-06-17 13:28:48 -0400574 if (DEBUG_LOADERS) Log.d(TAG, "onReceive intent=" + intent);
Winson Chungaafa03c2010-06-11 17:34:16 -0700575
Joe Onorato36115782010-06-17 13:28:48 -0400576 final String action = intent.getAction();
Joe Onoratof99f8c12009-10-31 17:27:36 -0400577
Joe Onorato36115782010-06-17 13:28:48 -0400578 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
579 || Intent.ACTION_PACKAGE_REMOVED.equals(action)
580 || Intent.ACTION_PACKAGE_ADDED.equals(action)) {
581 final String packageName = intent.getData().getSchemeSpecificPart();
582 final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400583
Joe Onorato36115782010-06-17 13:28:48 -0400584 int op = PackageUpdatedTask.OP_NONE;
585
586 if (packageName == null || packageName.length() == 0) {
587 // they sent us a bad intent
588 return;
589 }
590
591 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
592 op = PackageUpdatedTask.OP_UPDATE;
593 } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
594 if (!replacing) {
595 op = PackageUpdatedTask.OP_REMOVE;
596 }
597 // else, we are replacing the package, so a PACKAGE_ADDED will be sent
598 // later, we will update the package at this time
599 } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
600 if (!replacing) {
601 op = PackageUpdatedTask.OP_ADD;
602 } else {
603 op = PackageUpdatedTask.OP_UPDATE;
604 }
605 }
606
607 if (op != PackageUpdatedTask.OP_NONE) {
608 enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packageName }));
609 }
610
611 } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
Joe Onoratocec58332010-10-07 14:37:40 -0400612 // First, schedule to add these apps back in.
613 String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
614 enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_ADD, packages));
615 // Then, rebind everything.
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700616 startLoaderFromBackground();
Joe Onorato36115782010-06-17 13:28:48 -0400617 } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
618 String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
619 enqueuePackageUpdated(new PackageUpdatedTask(
620 PackageUpdatedTask.OP_UNAVAILABLE, packages));
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700621 } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
Reena Lee93f824a2011-09-23 17:20:28 -0700622 // If we have changed locale we need to clear out the labels in all apps/workspace.
623 forceReload();
624 } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
625 // Check if configuration change was an mcc/mnc change which would affect app resources
626 // and we would need to clear out the labels in all apps/workspace. Same handling as
627 // above for ACTION_LOCALE_CHANGED
628 Configuration currentConfig = context.getResources().getConfiguration();
Reena Lee99a73f32011-10-24 17:27:37 -0700629 if (mPreviousConfigMcc != currentConfig.mcc) {
Reena Lee93f824a2011-09-23 17:20:28 -0700630 Log.d(TAG, "Reload apps on config change. curr_mcc:"
Reena Lee99a73f32011-10-24 17:27:37 -0700631 + currentConfig.mcc + " prevmcc:" + mPreviousConfigMcc);
Reena Lee93f824a2011-09-23 17:20:28 -0700632 forceReload();
633 }
634 // Update previousConfig
Reena Lee99a73f32011-10-24 17:27:37 -0700635 mPreviousConfigMcc = currentConfig.mcc;
Winson Chungcbf7c4d2011-08-23 11:58:54 -0700636 } else if (SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED.equals(action) ||
637 SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED.equals(action)) {
Michael Jurkaec9788e2011-08-29 11:24:45 -0700638 if (mCallbacks != null) {
639 Callbacks callbacks = mCallbacks.get();
640 if (callbacks != null) {
641 callbacks.bindSearchablesChanged();
642 }
Winson Chungcfdf7ee2011-08-25 11:38:34 -0700643 }
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700644 }
645 }
646
Reena Lee93f824a2011-09-23 17:20:28 -0700647 private void forceReload() {
648 synchronized (mLock) {
649 // Stop any existing loaders first, so they don't set mAllAppsLoaded or
650 // mWorkspaceLoaded to true later
651 stopLoaderLocked();
652 mAllAppsLoaded = false;
653 mWorkspaceLoaded = false;
654 }
655 // Do this here because if the launcher activity is running it will be restarted.
656 // If it's not running startLoaderFromBackground will merely tell it that it needs
657 // to reload.
658 startLoaderFromBackground();
659 }
660
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700661 /**
662 * When the launcher is in the background, it's possible for it to miss paired
663 * configuration changes. So whenever we trigger the loader from the background
664 * tell the launcher that it needs to re-run the loader when it comes back instead
665 * of doing it now.
666 */
667 public void startLoaderFromBackground() {
668 boolean runLoader = false;
669 if (mCallbacks != null) {
670 Callbacks callbacks = mCallbacks.get();
671 if (callbacks != null) {
672 // Only actually run the loader if they're not paused.
673 if (!callbacks.setLoadOnResume()) {
674 runLoader = true;
675 }
676 }
677 }
678 if (runLoader) {
679 startLoader(mApp, false);
Joe Onorato790c2d92010-06-11 00:14:11 -0700680 }
Joe Onorato36115782010-06-17 13:28:48 -0400681 }
Joe Onoratof99f8c12009-10-31 17:27:36 -0400682
Reena Lee93f824a2011-09-23 17:20:28 -0700683 // If there is already a loader task running, tell it to stop.
684 // returns true if isLaunching() was true on the old task
685 private boolean stopLoaderLocked() {
686 boolean isLaunching = false;
687 LoaderTask oldTask = mLoaderTask;
688 if (oldTask != null) {
689 if (oldTask.isLaunching()) {
690 isLaunching = true;
691 }
692 oldTask.stopLocked();
693 }
694 return isLaunching;
695 }
696
Joe Onorato36115782010-06-17 13:28:48 -0400697 public void startLoader(Context context, boolean isLaunching) {
698 synchronized (mLock) {
699 if (DEBUG_LOADERS) {
700 Log.d(TAG, "startLoader isLaunching=" + isLaunching);
701 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400702
Joe Onorato36115782010-06-17 13:28:48 -0400703 // Don't bother to start the thread if we know it's not going to do anything
704 if (mCallbacks != null && mCallbacks.get() != null) {
705 // If there is already one running, tell it to stop.
Reena Lee93f824a2011-09-23 17:20:28 -0700706 // also, don't downgrade isLaunching if we're already running
707 isLaunching = isLaunching || stopLoaderLocked();
Joe Onorato36115782010-06-17 13:28:48 -0400708 mLoaderTask = new LoaderTask(context, isLaunching);
Winson Chung7ed37742011-09-08 15:45:51 -0700709 sWorkerThread.setPriority(Thread.NORM_PRIORITY);
Brad Fitzpatrick700889f2010-10-11 09:40:44 -0700710 sWorker.post(mLoaderTask);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400711 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400712 }
713 }
714
Joe Onorato36115782010-06-17 13:28:48 -0400715 public void stopLoader() {
716 synchronized (mLock) {
717 if (mLoaderTask != null) {
718 mLoaderTask.stopLocked();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400719 }
720 }
Joe Onorato36115782010-06-17 13:28:48 -0400721 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400722
Michael Jurkac57b7a82011-08-09 22:02:20 -0700723 public boolean isAllAppsLoaded() {
724 return mAllAppsLoaded;
725 }
726
Joe Onorato36115782010-06-17 13:28:48 -0400727 /**
728 * Runnable for the thread that loads the contents of the launcher:
729 * - workspace icons
730 * - widgets
731 * - all apps icons
732 */
733 private class LoaderTask implements Runnable {
734 private Context mContext;
735 private Thread mWaitThread;
736 private boolean mIsLaunching;
737 private boolean mStopped;
738 private boolean mLoadAndBindStepFinished;
Winson Chungc3eecff2011-07-11 17:44:15 -0700739 private HashMap<Object, CharSequence> mLabelCache;
Joe Onorato36115782010-06-17 13:28:48 -0400740
741 LoaderTask(Context context, boolean isLaunching) {
742 mContext = context;
743 mIsLaunching = isLaunching;
Winson Chungc3eecff2011-07-11 17:44:15 -0700744 mLabelCache = new HashMap<Object, CharSequence>();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400745 }
746
Joe Onorato36115782010-06-17 13:28:48 -0400747 boolean isLaunching() {
748 return mIsLaunching;
749 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400750
Joe Onorato36115782010-06-17 13:28:48 -0400751 private void loadAndBindWorkspace() {
752 // Load the workspace
Joe Onorato36115782010-06-17 13:28:48 -0400753 if (DEBUG_LOADERS) {
754 Log.d(TAG, "loadAndBindWorkspace mWorkspaceLoaded=" + mWorkspaceLoaded);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400755 }
Michael Jurka288a36b2011-07-12 16:53:48 -0700756
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700757 if (!mWorkspaceLoaded) {
Joe Onorato36115782010-06-17 13:28:48 -0400758 loadWorkspace();
Reena Lee93f824a2011-09-23 17:20:28 -0700759 synchronized (LoaderTask.this) {
760 if (mStopped) {
761 return;
762 }
763 mWorkspaceLoaded = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400764 }
765 }
766
Joe Onorato36115782010-06-17 13:28:48 -0400767 // Bind the workspace
768 bindWorkspace();
769 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400770
Joe Onorato36115782010-06-17 13:28:48 -0400771 private void waitForIdle() {
772 // Wait until the either we're stopped or the other threads are done.
773 // This way we don't start loading all apps until the workspace has settled
774 // down.
775 synchronized (LoaderTask.this) {
776 final long workspaceWaitTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
Joe Onoratocc67f472010-06-08 10:54:30 -0700777
Joe Onorato36115782010-06-17 13:28:48 -0400778 mHandler.postIdle(new Runnable() {
779 public void run() {
780 synchronized (LoaderTask.this) {
781 mLoadAndBindStepFinished = true;
782 if (DEBUG_LOADERS) {
783 Log.d(TAG, "done with previous binding step");
Daniel Sandler843e8602010-06-07 14:59:01 -0400784 }
Joe Onorato36115782010-06-17 13:28:48 -0400785 LoaderTask.this.notify();
Daniel Sandler843e8602010-06-07 14:59:01 -0400786 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400787 }
Joe Onorato36115782010-06-17 13:28:48 -0400788 });
789
790 while (!mStopped && !mLoadAndBindStepFinished) {
791 try {
792 this.wait();
793 } catch (InterruptedException ex) {
794 // Ignore
Daniel Sandler843e8602010-06-07 14:59:01 -0400795 }
796 }
Joe Onorato36115782010-06-17 13:28:48 -0400797 if (DEBUG_LOADERS) {
798 Log.d(TAG, "waited "
Winson Chungaafa03c2010-06-11 17:34:16 -0700799 + (SystemClock.uptimeMillis()-workspaceWaitTime)
Joe Onorato36115782010-06-17 13:28:48 -0400800 + "ms for previous step to finish binding");
801 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400802 }
Joe Onorato36115782010-06-17 13:28:48 -0400803 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400804
Joe Onorato36115782010-06-17 13:28:48 -0400805 public void run() {
806 // Optimize for end-user experience: if the Launcher is up and // running with the
807 // All Apps interface in the foreground, load All Apps first. Otherwise, load the
808 // workspace first (default).
809 final Callbacks cbk = mCallbacks.get();
810 final boolean loadWorkspaceFirst = cbk != null ? (!cbk.isAllAppsVisible()) : true;
Daniel Sandler843e8602010-06-07 14:59:01 -0400811
Joe Onorato36115782010-06-17 13:28:48 -0400812 keep_running: {
Daniel Sandler843e8602010-06-07 14:59:01 -0400813 // Elevate priority when Home launches for the first time to avoid
814 // starving at boot time. Staring at a blank home is not cool.
815 synchronized (mLock) {
Winson Chungaac01e12011-08-17 10:37:13 -0700816 if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to " +
817 (mIsLaunching ? "DEFAULT" : "BACKGROUND"));
Daniel Sandler843e8602010-06-07 14:59:01 -0400818 android.os.Process.setThreadPriority(mIsLaunching
819 ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
820 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400821 if (loadWorkspaceFirst) {
822 if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace");
823 loadAndBindWorkspace();
824 } else {
825 if (DEBUG_LOADERS) Log.d(TAG, "step 1: special: loading all apps");
Joe Onoratocc67f472010-06-08 10:54:30 -0700826 loadAndBindAllApps();
Daniel Sandler843e8602010-06-07 14:59:01 -0400827 }
828
Joe Onorato36115782010-06-17 13:28:48 -0400829 if (mStopped) {
830 break keep_running;
831 }
832
833 // Whew! Hard work done. Slow us down, and wait until the UI thread has
834 // settled down.
Daniel Sandler843e8602010-06-07 14:59:01 -0400835 synchronized (mLock) {
836 if (mIsLaunching) {
Winson Chungaac01e12011-08-17 10:37:13 -0700837 if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to BACKGROUND");
Daniel Sandler843e8602010-06-07 14:59:01 -0400838 android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
839 }
840 }
Joe Onorato36115782010-06-17 13:28:48 -0400841 waitForIdle();
Daniel Sandler843e8602010-06-07 14:59:01 -0400842
843 // second step
844 if (loadWorkspaceFirst) {
845 if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps");
Joe Onoratocc67f472010-06-08 10:54:30 -0700846 loadAndBindAllApps();
Daniel Sandler843e8602010-06-07 14:59:01 -0400847 } else {
848 if (DEBUG_LOADERS) Log.d(TAG, "step 2: special: loading workspace");
849 loadAndBindWorkspace();
850 }
Winson Chung7ed37742011-09-08 15:45:51 -0700851
852 // Restore the default thread priority after we are done loading items
853 synchronized (mLock) {
854 android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
855 }
Joe Onorato36115782010-06-17 13:28:48 -0400856 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400857
Winson Chungaac01e12011-08-17 10:37:13 -0700858
859 // Update the saved icons if necessary
860 if (DEBUG_LOADERS) Log.d(TAG, "Comparing loaded icons to database icons");
Winson Chungb1094bd2011-08-24 16:14:08 -0700861 for (Object key : sDbIconCache.keySet()) {
862 updateSavedIcon(mContext, (ShortcutInfo) key, sDbIconCache.get(key));
Winson Chungaac01e12011-08-17 10:37:13 -0700863 }
Winson Chungb1094bd2011-08-24 16:14:08 -0700864 sDbIconCache.clear();
Winson Chungaac01e12011-08-17 10:37:13 -0700865
Joe Onorato36115782010-06-17 13:28:48 -0400866 // Clear out this reference, otherwise we end up holding it until all of the
867 // callback runnables are done.
868 mContext = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400869
Joe Onorato36115782010-06-17 13:28:48 -0400870 synchronized (mLock) {
871 // If we are still the last one to be scheduled, remove ourselves.
872 if (mLoaderTask == this) {
873 mLoaderTask = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400874 }
Joe Onorato36115782010-06-17 13:28:48 -0400875 }
Joe Onorato36115782010-06-17 13:28:48 -0400876 }
877
878 public void stopLocked() {
879 synchronized (LoaderTask.this) {
880 mStopped = true;
881 this.notify();
882 }
883 }
884
885 /**
886 * Gets the callbacks object. If we've been stopped, or if the launcher object
887 * has somehow been garbage collected, return null instead. Pass in the Callbacks
888 * object that was around when the deferred message was scheduled, and if there's
889 * a new Callbacks object around then also return null. This will save us from
890 * calling onto it with data that will be ignored.
891 */
892 Callbacks tryGetCallbacks(Callbacks oldCallbacks) {
893 synchronized (mLock) {
894 if (mStopped) {
895 return null;
Daniel Sandler8802e962010-05-26 16:28:16 -0400896 }
Joe Onorato36115782010-06-17 13:28:48 -0400897
898 if (mCallbacks == null) {
899 return null;
Daniel Sandler8802e962010-05-26 16:28:16 -0400900 }
Joe Onorato36115782010-06-17 13:28:48 -0400901
902 final Callbacks callbacks = mCallbacks.get();
903 if (callbacks != oldCallbacks) {
904 return null;
905 }
906 if (callbacks == null) {
907 Log.w(TAG, "no mCallbacks");
908 return null;
909 }
910
911 return callbacks;
912 }
913 }
914
915 // check & update map of what's occupied; used to discard overlapping/invalid items
916 private boolean checkItemPlacement(ItemInfo occupied[][][], ItemInfo item) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700917 int containerIndex = item.screen;
918 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700919 // Return early if we detect that an item is under the hotseat button
920 if (Hotseat.isAllAppsButtonRank(item.screen)) {
921 return false;
922 }
Winson Chung6ba2a1b2011-09-02 16:22:11 -0700923
924 // We use the last index to refer to the hotseat and the screen as the rank, so
925 // test and update the occupied state accordingly
926 if (occupied[Launcher.SCREEN_COUNT][item.screen][0] != null) {
927 Log.e(TAG, "Error loading shortcut into hotseat " + item
928 + " into position (" + item.screen + ":" + item.cellX + "," + item.cellY
929 + ") occupied by " + occupied[Launcher.SCREEN_COUNT][item.screen][0]);
930 return false;
931 } else {
932 occupied[Launcher.SCREEN_COUNT][item.screen][0] = item;
933 return true;
934 }
Winson Chungf30ad5f2011-08-08 10:55:42 -0700935 } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
936 // Skip further checking if it is not the hotseat or workspace container
Daniel Sandler8802e962010-05-26 16:28:16 -0400937 return true;
938 }
Winson Chungf30ad5f2011-08-08 10:55:42 -0700939
Winson Chung6ba2a1b2011-09-02 16:22:11 -0700940 // Check if any workspace icons overlap with each other
Joe Onorato36115782010-06-17 13:28:48 -0400941 for (int x = item.cellX; x < (item.cellX+item.spanX); x++) {
942 for (int y = item.cellY; y < (item.cellY+item.spanY); y++) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700943 if (occupied[containerIndex][x][y] != null) {
Joe Onorato36115782010-06-17 13:28:48 -0400944 Log.e(TAG, "Error loading shortcut " + item
Winson Chungf30ad5f2011-08-08 10:55:42 -0700945 + " into cell (" + containerIndex + "-" + item.screen + ":"
Joe Onorato36115782010-06-17 13:28:48 -0400946 + x + "," + y
Winson Chungaafa03c2010-06-11 17:34:16 -0700947 + ") occupied by "
Winson Chungf30ad5f2011-08-08 10:55:42 -0700948 + occupied[containerIndex][x][y]);
Joe Onorato36115782010-06-17 13:28:48 -0400949 return false;
950 }
951 }
952 }
953 for (int x = item.cellX; x < (item.cellX+item.spanX); x++) {
954 for (int y = item.cellY; y < (item.cellY+item.spanY); y++) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700955 occupied[containerIndex][x][y] = item;
Joe Onorato36115782010-06-17 13:28:48 -0400956 }
957 }
Winson Chungf30ad5f2011-08-08 10:55:42 -0700958
Joe Onorato36115782010-06-17 13:28:48 -0400959 return true;
960 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400961
Joe Onorato36115782010-06-17 13:28:48 -0400962 private void loadWorkspace() {
963 final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400964
Joe Onorato36115782010-06-17 13:28:48 -0400965 final Context context = mContext;
966 final ContentResolver contentResolver = context.getContentResolver();
967 final PackageManager manager = context.getPackageManager();
968 final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
969 final boolean isSafeMode = manager.isSafeMode();
Joe Onorato3c2f7e12009-10-31 19:17:31 -0400970
Adam Cohen4eac29a2011-07-11 17:53:37 -0700971 sWorkspaceItems.clear();
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700972 sAppWidgets.clear();
973 sFolders.clear();
974 sItemsIdMap.clear();
Winson Chungb1094bd2011-08-24 16:14:08 -0700975 sDbIconCache.clear();
Romain Guy5c16f3e2010-01-12 17:24:58 -0800976
Joe Onorato36115782010-06-17 13:28:48 -0400977 final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400978
Joe Onorato36115782010-06-17 13:28:48 -0400979 final Cursor c = contentResolver.query(
Winson Chunge61e93e2011-09-12 10:59:49 -0700980 LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
Daniel Sandler8802e962010-05-26 16:28:16 -0400981
Winson Chungf30ad5f2011-08-08 10:55:42 -0700982 // +1 for the hotseat (it can be larger than the workspace)
Winson Chung36f97362011-09-07 11:20:10 -0700983 // Load workspace in reverse order to ensure that latest items are loaded first (and
984 // before any earlier duplicates)
Adam Cohend22015c2010-07-26 22:02:18 -0700985 final ItemInfo occupied[][][] =
Winson Chungf30ad5f2011-08-08 10:55:42 -0700986 new ItemInfo[Launcher.SCREEN_COUNT + 1][mCellCountX + 1][mCellCountY + 1];
Joe Onorato9c1289c2009-08-17 11:03:03 -0400987
Joe Onorato36115782010-06-17 13:28:48 -0400988 try {
989 final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
990 final int intentIndex = c.getColumnIndexOrThrow
991 (LauncherSettings.Favorites.INTENT);
992 final int titleIndex = c.getColumnIndexOrThrow
993 (LauncherSettings.Favorites.TITLE);
994 final int iconTypeIndex = c.getColumnIndexOrThrow(
995 LauncherSettings.Favorites.ICON_TYPE);
996 final int iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
997 final int iconPackageIndex = c.getColumnIndexOrThrow(
998 LauncherSettings.Favorites.ICON_PACKAGE);
999 final int iconResourceIndex = c.getColumnIndexOrThrow(
1000 LauncherSettings.Favorites.ICON_RESOURCE);
1001 final int containerIndex = c.getColumnIndexOrThrow(
1002 LauncherSettings.Favorites.CONTAINER);
1003 final int itemTypeIndex = c.getColumnIndexOrThrow(
1004 LauncherSettings.Favorites.ITEM_TYPE);
1005 final int appWidgetIdIndex = c.getColumnIndexOrThrow(
1006 LauncherSettings.Favorites.APPWIDGET_ID);
1007 final int screenIndex = c.getColumnIndexOrThrow(
1008 LauncherSettings.Favorites.SCREEN);
1009 final int cellXIndex = c.getColumnIndexOrThrow
1010 (LauncherSettings.Favorites.CELLX);
1011 final int cellYIndex = c.getColumnIndexOrThrow
1012 (LauncherSettings.Favorites.CELLY);
1013 final int spanXIndex = c.getColumnIndexOrThrow
1014 (LauncherSettings.Favorites.SPANX);
1015 final int spanYIndex = c.getColumnIndexOrThrow(
1016 LauncherSettings.Favorites.SPANY);
1017 final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI);
1018 final int displayModeIndex = c.getColumnIndexOrThrow(
1019 LauncherSettings.Favorites.DISPLAY_MODE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001020
Joe Onorato36115782010-06-17 13:28:48 -04001021 ShortcutInfo info;
1022 String intentDescription;
1023 LauncherAppWidgetInfo appWidgetInfo;
1024 int container;
1025 long id;
1026 Intent intent;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001027
Joe Onorato36115782010-06-17 13:28:48 -04001028 while (!mStopped && c.moveToNext()) {
1029 try {
1030 int itemType = c.getInt(itemTypeIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001031
Joe Onorato36115782010-06-17 13:28:48 -04001032 switch (itemType) {
1033 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1034 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
1035 intentDescription = c.getString(intentIndex);
1036 try {
1037 intent = Intent.parseUri(intentDescription, 0);
1038 } catch (URISyntaxException e) {
1039 continue;
1040 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001041
Joe Onorato36115782010-06-17 13:28:48 -04001042 if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
1043 info = getShortcutInfo(manager, intent, context, c, iconIndex,
Winson Chungc3eecff2011-07-11 17:44:15 -07001044 titleIndex, mLabelCache);
Joe Onorato36115782010-06-17 13:28:48 -04001045 } else {
1046 info = getShortcutInfo(c, context, iconTypeIndex,
1047 iconPackageIndex, iconResourceIndex, iconIndex,
1048 titleIndex);
1049 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001050
Joe Onorato36115782010-06-17 13:28:48 -04001051 if (info != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001052 info.intent = intent;
1053 info.id = c.getLong(idIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001054 container = c.getInt(containerIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001055 info.container = container;
1056 info.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -07001057 info.cellX = c.getInt(cellXIndex);
1058 info.cellY = c.getInt(cellYIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001059
Daniel Sandler8802e962010-05-26 16:28:16 -04001060 // check & update map of what's occupied
Joe Onorato36115782010-06-17 13:28:48 -04001061 if (!checkItemPlacement(occupied, info)) {
Daniel Sandler8802e962010-05-26 16:28:16 -04001062 break;
1063 }
1064
Joe Onorato9c1289c2009-08-17 11:03:03 -04001065 switch (container) {
Joe Onorato36115782010-06-17 13:28:48 -04001066 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
Winson Chung3d503fb2011-07-13 17:25:49 -07001067 case LauncherSettings.Favorites.CONTAINER_HOTSEAT:
Adam Cohen4eac29a2011-07-11 17:53:37 -07001068 sWorkspaceItems.add(info);
Joe Onorato36115782010-06-17 13:28:48 -04001069 break;
1070 default:
1071 // Item is in a user folder
Adam Cohendf2cc412011-04-27 16:56:57 -07001072 FolderInfo folderInfo =
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001073 findOrMakeFolder(sFolders, container);
Joe Onorato36115782010-06-17 13:28:48 -04001074 folderInfo.add(info);
1075 break;
1076 }
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001077 sItemsIdMap.put(info.id, info);
Joe Onorato17a89222011-02-08 17:26:11 -08001078
1079 // now that we've loaded everthing re-save it with the
1080 // icon in case it disappears somehow.
Winson Chungb1094bd2011-08-24 16:14:08 -07001081 queueIconToBeChecked(sDbIconCache, info, c, iconIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001082 } else {
1083 // Failed to load the shortcut, probably because the
1084 // activity manager couldn't resolve it (maybe the app
1085 // was uninstalled), or the db row was somehow screwed up.
1086 // Delete it.
1087 id = c.getLong(idIndex);
1088 Log.e(TAG, "Error loading shortcut " + id + ", removing it");
1089 contentResolver.delete(LauncherSettings.Favorites.getContentUri(
1090 id, false), null, null);
1091 }
1092 break;
1093
Adam Cohendf2cc412011-04-27 16:56:57 -07001094 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Joe Onorato36115782010-06-17 13:28:48 -04001095 id = c.getLong(idIndex);
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001096 FolderInfo folderInfo = findOrMakeFolder(sFolders, id);
Joe Onorato36115782010-06-17 13:28:48 -04001097
Winson Chungaafa03c2010-06-11 17:34:16 -07001098 folderInfo.title = c.getString(titleIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001099 folderInfo.id = id;
1100 container = c.getInt(containerIndex);
1101 folderInfo.container = container;
1102 folderInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -07001103 folderInfo.cellX = c.getInt(cellXIndex);
1104 folderInfo.cellY = c.getInt(cellYIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001105
1106 // check & update map of what's occupied
1107 if (!checkItemPlacement(occupied, folderInfo)) {
1108 break;
1109 }
Joe Onorato36115782010-06-17 13:28:48 -04001110 switch (container) {
1111 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
Winson Chung3d503fb2011-07-13 17:25:49 -07001112 case LauncherSettings.Favorites.CONTAINER_HOTSEAT:
Adam Cohen4eac29a2011-07-11 17:53:37 -07001113 sWorkspaceItems.add(folderInfo);
Joe Onorato36115782010-06-17 13:28:48 -04001114 break;
1115 }
1116
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001117 sItemsIdMap.put(folderInfo.id, folderInfo);
1118 sFolders.put(folderInfo.id, folderInfo);
Joe Onorato36115782010-06-17 13:28:48 -04001119 break;
1120
Joe Onorato36115782010-06-17 13:28:48 -04001121 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
1122 // Read all Launcher-specific widget details
1123 int appWidgetId = c.getInt(appWidgetIdIndex);
1124 id = c.getLong(idIndex);
1125
1126 final AppWidgetProviderInfo provider =
1127 widgets.getAppWidgetInfo(appWidgetId);
Winson Chungaafa03c2010-06-11 17:34:16 -07001128
Joe Onorato36115782010-06-17 13:28:48 -04001129 if (!isSafeMode && (provider == null || provider.provider == null ||
1130 provider.provider.getPackageName() == null)) {
Adam Cohen16d7ffc2011-10-05 17:49:14 -07001131 String log = "Deleting widget that isn't installed anymore: id="
1132 + id + " appWidgetId=" + appWidgetId;
1133 Log.e(TAG, log);
1134 Launcher.sDumpLogs.add(log);
Joe Onorato36115782010-06-17 13:28:48 -04001135 itemsToRemove.add(id);
1136 } else {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001137 appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId);
Joe Onorato36115782010-06-17 13:28:48 -04001138 appWidgetInfo.id = id;
1139 appWidgetInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -07001140 appWidgetInfo.cellX = c.getInt(cellXIndex);
1141 appWidgetInfo.cellY = c.getInt(cellYIndex);
1142 appWidgetInfo.spanX = c.getInt(spanXIndex);
1143 appWidgetInfo.spanY = c.getInt(spanYIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001144
1145 container = c.getInt(containerIndex);
Winson Chung3d503fb2011-07-13 17:25:49 -07001146 if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP &&
1147 container != LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
Joe Onorato36115782010-06-17 13:28:48 -04001148 Log.e(TAG, "Widget found where container "
Winson Chung3d503fb2011-07-13 17:25:49 -07001149 + "!= CONTAINER_DESKTOP nor CONTAINER_HOTSEAT - ignoring!");
Joe Onorato36115782010-06-17 13:28:48 -04001150 continue;
1151 }
1152 appWidgetInfo.container = c.getInt(containerIndex);
1153
1154 // check & update map of what's occupied
1155 if (!checkItemPlacement(occupied, appWidgetInfo)) {
1156 break;
1157 }
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001158 sItemsIdMap.put(appWidgetInfo.id, appWidgetInfo);
1159 sAppWidgets.add(appWidgetInfo);
Joe Onorato36115782010-06-17 13:28:48 -04001160 }
1161 break;
Romain Guy5c16f3e2010-01-12 17:24:58 -08001162 }
Joe Onorato36115782010-06-17 13:28:48 -04001163 } catch (Exception e) {
1164 Log.w(TAG, "Desktop items loading interrupted:", e);
Romain Guy5c16f3e2010-01-12 17:24:58 -08001165 }
1166 }
Joe Onorato36115782010-06-17 13:28:48 -04001167 } finally {
1168 c.close();
1169 }
Romain Guy5c16f3e2010-01-12 17:24:58 -08001170
Joe Onorato36115782010-06-17 13:28:48 -04001171 if (itemsToRemove.size() > 0) {
1172 ContentProviderClient client = contentResolver.acquireContentProviderClient(
1173 LauncherSettings.Favorites.CONTENT_URI);
1174 // Remove dead items
1175 for (long id : itemsToRemove) {
1176 if (DEBUG_LOADERS) {
1177 Log.d(TAG, "Removed id = " + id);
1178 }
1179 // Don't notify content observers
1180 try {
1181 client.delete(LauncherSettings.Favorites.getContentUri(id, false),
1182 null, null);
1183 } catch (RemoteException e) {
1184 Log.w(TAG, "Could not remove id = " + id);
Daniel Sandler8802e962010-05-26 16:28:16 -04001185 }
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001186 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001187 }
1188
Joe Onorato36115782010-06-17 13:28:48 -04001189 if (DEBUG_LOADERS) {
1190 Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms");
1191 Log.d(TAG, "workspace layout: ");
Adam Cohend22015c2010-07-26 22:02:18 -07001192 for (int y = 0; y < mCellCountY; y++) {
Joe Onorato36115782010-06-17 13:28:48 -04001193 String line = "";
1194 for (int s = 0; s < Launcher.SCREEN_COUNT; s++) {
1195 if (s > 0) {
1196 line += " | ";
1197 }
Adam Cohend22015c2010-07-26 22:02:18 -07001198 for (int x = 0; x < mCellCountX; x++) {
Joe Onorato36115782010-06-17 13:28:48 -04001199 line += ((occupied[s][x][y] != null) ? "#" : ".");
1200 }
1201 }
1202 Log.d(TAG, "[ " + line + " ]");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001203 }
Joe Onorato36115782010-06-17 13:28:48 -04001204 }
1205 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001206
Joe Onorato36115782010-06-17 13:28:48 -04001207 /**
1208 * Read everything out of our database.
1209 */
1210 private void bindWorkspace() {
1211 final long t = SystemClock.uptimeMillis();
1212
1213 // Don't use these two variables in any of the callback runnables.
1214 // Otherwise we hold a reference to them.
1215 final Callbacks oldCallbacks = mCallbacks.get();
1216 if (oldCallbacks == null) {
1217 // This launcher has exited and nobody bothered to tell us. Just bail.
1218 Log.w(TAG, "LoaderTask running with no launcher");
1219 return;
1220 }
1221
1222 int N;
1223 // Tell the workspace that we're about to start firing items at it
1224 mHandler.post(new Runnable() {
1225 public void run() {
1226 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1227 if (callbacks != null) {
1228 callbacks.startBinding();
1229 }
1230 }
1231 });
Winson Chung603bcb92011-09-02 11:45:39 -07001232
1233 // Unbind previously bound workspace items to prevent a leak of AppWidgetHostViews.
1234 final ArrayList<ItemInfo> workspaceItems = unbindWorkspaceItemsOnMainThread();
1235
Joe Onorato36115782010-06-17 13:28:48 -04001236 // Add the items to the workspace.
Winson Chung603bcb92011-09-02 11:45:39 -07001237 N = workspaceItems.size();
Joe Onorato36115782010-06-17 13:28:48 -04001238 for (int i=0; i<N; i+=ITEMS_CHUNK) {
1239 final int start = i;
1240 final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001241 mHandler.post(new Runnable() {
1242 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -08001243 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001244 if (callbacks != null) {
Winson Chung603bcb92011-09-02 11:45:39 -07001245 callbacks.bindItems(workspaceItems, start, start+chunkSize);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001246 }
1247 }
1248 });
Joe Onorato36115782010-06-17 13:28:48 -04001249 }
Winson Chung603bcb92011-09-02 11:45:39 -07001250 // Ensure that we don't use the same folders data structure on the main thread
1251 final HashMap<Long, FolderInfo> folders = new HashMap<Long, FolderInfo>(sFolders);
Joe Onorato36115782010-06-17 13:28:48 -04001252 mHandler.post(new Runnable() {
1253 public void run() {
1254 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1255 if (callbacks != null) {
Winson Chung603bcb92011-09-02 11:45:39 -07001256 callbacks.bindFolders(folders);
Joe Onorato36115782010-06-17 13:28:48 -04001257 }
1258 }
1259 });
1260 // Wait until the queue goes empty.
1261 mHandler.post(new Runnable() {
1262 public void run() {
1263 if (DEBUG_LOADERS) {
1264 Log.d(TAG, "Going to start binding widgets soon.");
1265 }
1266 }
1267 });
1268 // Bind the widgets, one at a time.
1269 // WARNING: this is calling into the workspace from the background thread,
1270 // but since getCurrentScreen() just returns the int, we should be okay. This
1271 // is just a hint for the order, and if it's wrong, we'll be okay.
1272 // TODO: instead, we should have that push the current screen into here.
1273 final int currentScreen = oldCallbacks.getCurrentWorkspaceScreen();
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001274 N = sAppWidgets.size();
Joe Onorato36115782010-06-17 13:28:48 -04001275 // once for the current screen
1276 for (int i=0; i<N; i++) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001277 final LauncherAppWidgetInfo widget = sAppWidgets.get(i);
Joe Onorato36115782010-06-17 13:28:48 -04001278 if (widget.screen == currentScreen) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001279 mHandler.post(new Runnable() {
1280 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -08001281 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001282 if (callbacks != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001283 callbacks.bindAppWidget(widget);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001284 }
1285 }
1286 });
1287 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001288 }
Joe Onorato36115782010-06-17 13:28:48 -04001289 // once for the other screens
1290 for (int i=0; i<N; i++) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001291 final LauncherAppWidgetInfo widget = sAppWidgets.get(i);
Joe Onorato36115782010-06-17 13:28:48 -04001292 if (widget.screen != currentScreen) {
1293 mHandler.post(new Runnable() {
1294 public void run() {
1295 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1296 if (callbacks != null) {
1297 callbacks.bindAppWidget(widget);
1298 }
1299 }
1300 });
Joe Onoratocc67f472010-06-08 10:54:30 -07001301 }
1302 }
Joe Onorato36115782010-06-17 13:28:48 -04001303 // Tell the workspace that we're done.
1304 mHandler.post(new Runnable() {
1305 public void run() {
1306 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1307 if (callbacks != null) {
1308 callbacks.finishBindingItems();
1309 }
1310 }
1311 });
1312 // If we're profiling, this is the last thing in the queue.
1313 mHandler.post(new Runnable() {
1314 public void run() {
1315 if (DEBUG_LOADERS) {
1316 Log.d(TAG, "bound workspace in "
1317 + (SystemClock.uptimeMillis()-t) + "ms");
1318 }
1319 }
1320 });
1321 }
Joe Onoratocc67f472010-06-08 10:54:30 -07001322
Joe Onorato36115782010-06-17 13:28:48 -04001323 private void loadAndBindAllApps() {
1324 if (DEBUG_LOADERS) {
1325 Log.d(TAG, "loadAndBindAllApps mAllAppsLoaded=" + mAllAppsLoaded);
1326 }
1327 if (!mAllAppsLoaded) {
1328 loadAllAppsByBatch();
Reena Lee93f824a2011-09-23 17:20:28 -07001329 synchronized (LoaderTask.this) {
1330 if (mStopped) {
1331 return;
1332 }
1333 mAllAppsLoaded = true;
Joe Onoratocc67f472010-06-08 10:54:30 -07001334 }
Joe Onorato36115782010-06-17 13:28:48 -04001335 } else {
1336 onlyBindAllApps();
1337 }
1338 }
Joe Onoratocc67f472010-06-08 10:54:30 -07001339
Joe Onorato36115782010-06-17 13:28:48 -04001340 private void onlyBindAllApps() {
1341 final Callbacks oldCallbacks = mCallbacks.get();
1342 if (oldCallbacks == null) {
1343 // This launcher has exited and nobody bothered to tell us. Just bail.
1344 Log.w(TAG, "LoaderTask running with no launcher (onlyBindAllApps)");
1345 return;
1346 }
1347
1348 // shallow copy
1349 final ArrayList<ApplicationInfo> list
1350 = (ArrayList<ApplicationInfo>)mAllAppsList.data.clone();
1351 mHandler.post(new Runnable() {
1352 public void run() {
1353 final long t = SystemClock.uptimeMillis();
1354 final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1355 if (callbacks != null) {
1356 callbacks.bindAllApplications(list);
1357 }
1358 if (DEBUG_LOADERS) {
1359 Log.d(TAG, "bound all " + list.size() + " apps from cache in "
1360 + (SystemClock.uptimeMillis()-t) + "ms");
1361 }
1362 }
1363 });
1364
1365 }
1366
1367 private void loadAllAppsByBatch() {
1368 final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1369
1370 // Don't use these two variables in any of the callback runnables.
1371 // Otherwise we hold a reference to them.
1372 final Callbacks oldCallbacks = mCallbacks.get();
1373 if (oldCallbacks == null) {
1374 // This launcher has exited and nobody bothered to tell us. Just bail.
1375 Log.w(TAG, "LoaderTask running with no launcher (loadAllAppsByBatch)");
1376 return;
1377 }
1378
1379 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1380 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
1381
1382 final PackageManager packageManager = mContext.getPackageManager();
1383 List<ResolveInfo> apps = null;
1384
1385 int N = Integer.MAX_VALUE;
1386
1387 int startIndex;
1388 int i=0;
1389 int batchSize = -1;
1390 while (i < N && !mStopped) {
1391 if (i == 0) {
1392 mAllAppsList.clear();
1393 final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1394 apps = packageManager.queryIntentActivities(mainIntent, 0);
1395 if (DEBUG_LOADERS) {
1396 Log.d(TAG, "queryIntentActivities took "
1397 + (SystemClock.uptimeMillis()-qiaTime) + "ms");
1398 }
1399 if (apps == null) {
1400 return;
1401 }
1402 N = apps.size();
1403 if (DEBUG_LOADERS) {
1404 Log.d(TAG, "queryIntentActivities got " + N + " apps");
1405 }
1406 if (N == 0) {
1407 // There are no apps?!?
1408 return;
1409 }
1410 if (mBatchSize == 0) {
1411 batchSize = N;
1412 } else {
1413 batchSize = mBatchSize;
1414 }
1415
1416 final long sortTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1417 Collections.sort(apps,
Winson Chungc3eecff2011-07-11 17:44:15 -07001418 new LauncherModel.ShortcutNameComparator(packageManager, mLabelCache));
Joe Onorato36115782010-06-17 13:28:48 -04001419 if (DEBUG_LOADERS) {
1420 Log.d(TAG, "sort took "
1421 + (SystemClock.uptimeMillis()-sortTime) + "ms");
1422 }
1423 }
1424
1425 final long t2 = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1426
1427 startIndex = i;
1428 for (int j=0; i<N && j<batchSize; j++) {
1429 // This builds the icon bitmaps.
Winson Chungc3eecff2011-07-11 17:44:15 -07001430 mAllAppsList.add(new ApplicationInfo(packageManager, apps.get(i),
Michael Jurkac9d95c52011-08-29 14:03:34 -07001431 mIconCache, mLabelCache));
Joe Onorato36115782010-06-17 13:28:48 -04001432 i++;
1433 }
1434
1435 final boolean first = i <= batchSize;
1436 final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1437 final ArrayList<ApplicationInfo> added = mAllAppsList.added;
1438 mAllAppsList.added = new ArrayList<ApplicationInfo>();
1439
Joe Onoratocc67f472010-06-08 10:54:30 -07001440 mHandler.post(new Runnable() {
1441 public void run() {
1442 final long t = SystemClock.uptimeMillis();
Joe Onoratocc67f472010-06-08 10:54:30 -07001443 if (callbacks != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001444 if (first) {
1445 callbacks.bindAllApplications(added);
1446 } else {
1447 callbacks.bindAppsAdded(added);
1448 }
1449 if (DEBUG_LOADERS) {
1450 Log.d(TAG, "bound " + added.size() + " apps in "
1451 + (SystemClock.uptimeMillis() - t) + "ms");
1452 }
1453 } else {
1454 Log.i(TAG, "not binding apps: no Launcher activity");
Joe Onoratocc67f472010-06-08 10:54:30 -07001455 }
1456 }
1457 });
1458
Daniel Sandlerdca66122010-04-13 16:23:58 -04001459 if (DEBUG_LOADERS) {
Joe Onorato36115782010-06-17 13:28:48 -04001460 Log.d(TAG, "batch of " + (i-startIndex) + " icons processed in "
1461 + (SystemClock.uptimeMillis()-t2) + "ms");
1462 }
1463
1464 if (mAllAppsLoadDelay > 0 && i < N) {
1465 try {
1466 if (DEBUG_LOADERS) {
1467 Log.d(TAG, "sleeping for " + mAllAppsLoadDelay + "ms");
1468 }
1469 Thread.sleep(mAllAppsLoadDelay);
1470 } catch (InterruptedException exc) { }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001471 }
1472 }
1473
Joe Onorato36115782010-06-17 13:28:48 -04001474 if (DEBUG_LOADERS) {
1475 Log.d(TAG, "cached all " + N + " apps in "
1476 + (SystemClock.uptimeMillis()-t) + "ms"
1477 + (mAllAppsLoadDelay > 0 ? " (including delay)" : ""));
Joe Onoratobe386092009-11-17 17:32:16 -08001478 }
1479 }
1480
1481 public void dumpState() {
Joe Onorato36115782010-06-17 13:28:48 -04001482 Log.d(TAG, "mLoaderTask.mContext=" + mContext);
1483 Log.d(TAG, "mLoaderTask.mWaitThread=" + mWaitThread);
1484 Log.d(TAG, "mLoaderTask.mIsLaunching=" + mIsLaunching);
1485 Log.d(TAG, "mLoaderTask.mStopped=" + mStopped);
1486 Log.d(TAG, "mLoaderTask.mLoadAndBindStepFinished=" + mLoadAndBindStepFinished);
Adam Cohen4eac29a2011-07-11 17:53:37 -07001487 Log.d(TAG, "mItems size=" + sWorkspaceItems.size());
Joe Onorato36115782010-06-17 13:28:48 -04001488 }
1489 }
1490
1491 void enqueuePackageUpdated(PackageUpdatedTask task) {
Brad Fitzpatrick700889f2010-10-11 09:40:44 -07001492 sWorker.post(task);
Joe Onorato36115782010-06-17 13:28:48 -04001493 }
1494
1495 private class PackageUpdatedTask implements Runnable {
1496 int mOp;
1497 String[] mPackages;
1498
1499 public static final int OP_NONE = 0;
1500 public static final int OP_ADD = 1;
1501 public static final int OP_UPDATE = 2;
1502 public static final int OP_REMOVE = 3; // uninstlled
1503 public static final int OP_UNAVAILABLE = 4; // external media unmounted
1504
1505
1506 public PackageUpdatedTask(int op, String[] packages) {
1507 mOp = op;
1508 mPackages = packages;
1509 }
1510
1511 public void run() {
1512 final Context context = mApp;
1513
1514 final String[] packages = mPackages;
1515 final int N = packages.length;
1516 switch (mOp) {
1517 case OP_ADD:
1518 for (int i=0; i<N; i++) {
1519 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
1520 mAllAppsList.addPackage(context, packages[i]);
1521 }
1522 break;
1523 case OP_UPDATE:
1524 for (int i=0; i<N; i++) {
1525 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
1526 mAllAppsList.updatePackage(context, packages[i]);
1527 }
1528 break;
1529 case OP_REMOVE:
1530 case OP_UNAVAILABLE:
1531 for (int i=0; i<N; i++) {
1532 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
1533 mAllAppsList.removePackage(packages[i]);
1534 }
1535 break;
1536 }
1537
1538 ArrayList<ApplicationInfo> added = null;
1539 ArrayList<ApplicationInfo> removed = null;
1540 ArrayList<ApplicationInfo> modified = null;
1541
1542 if (mAllAppsList.added.size() > 0) {
1543 added = mAllAppsList.added;
1544 mAllAppsList.added = new ArrayList<ApplicationInfo>();
1545 }
1546 if (mAllAppsList.removed.size() > 0) {
1547 removed = mAllAppsList.removed;
1548 mAllAppsList.removed = new ArrayList<ApplicationInfo>();
1549 for (ApplicationInfo info: removed) {
1550 mIconCache.remove(info.intent.getComponent());
1551 }
1552 }
1553 if (mAllAppsList.modified.size() > 0) {
1554 modified = mAllAppsList.modified;
1555 mAllAppsList.modified = new ArrayList<ApplicationInfo>();
1556 }
1557
1558 final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
1559 if (callbacks == null) {
1560 Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading.");
1561 return;
1562 }
1563
1564 if (added != null) {
1565 final ArrayList<ApplicationInfo> addedFinal = added;
1566 mHandler.post(new Runnable() {
1567 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001568 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1569 if (callbacks == cb && cb != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001570 callbacks.bindAppsAdded(addedFinal);
1571 }
1572 }
1573 });
1574 }
1575 if (modified != null) {
1576 final ArrayList<ApplicationInfo> modifiedFinal = modified;
1577 mHandler.post(new Runnable() {
1578 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001579 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1580 if (callbacks == cb && cb != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001581 callbacks.bindAppsUpdated(modifiedFinal);
1582 }
1583 }
1584 });
1585 }
1586 if (removed != null) {
1587 final boolean permanent = mOp != OP_UNAVAILABLE;
1588 final ArrayList<ApplicationInfo> removedFinal = removed;
1589 mHandler.post(new Runnable() {
1590 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001591 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1592 if (callbacks == cb && cb != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001593 callbacks.bindAppsRemoved(removedFinal, permanent);
1594 }
1595 }
1596 });
Joe Onoratobe386092009-11-17 17:32:16 -08001597 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001598
1599 mHandler.post(new Runnable() {
1600 @Override
1601 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001602 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1603 if (callbacks == cb && cb != null) {
Winson Chung80baf5a2010-08-09 16:03:15 -07001604 callbacks.bindPackagesUpdated();
1605 }
1606 }
1607 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04001608 }
1609 }
1610
1611 /**
Joe Onorato56d82912010-03-07 14:32:10 -05001612 * This is called from the code that adds shortcuts from the intent receiver. This
1613 * doesn't have a Cursor, but
Joe Onorato9c1289c2009-08-17 11:03:03 -04001614 */
Joe Onorato56d82912010-03-07 14:32:10 -05001615 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context) {
Winson Chungc3eecff2011-07-11 17:44:15 -07001616 return getShortcutInfo(manager, intent, context, null, -1, -1, null);
Joe Onorato56d82912010-03-07 14:32:10 -05001617 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001618
Joe Onorato56d82912010-03-07 14:32:10 -05001619 /**
1620 * Make an ShortcutInfo object for a shortcut that is an application.
1621 *
1622 * If c is not null, then it will be used to fill in missing data like the title and icon.
1623 */
1624 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context,
Winson Chungc3eecff2011-07-11 17:44:15 -07001625 Cursor c, int iconIndex, int titleIndex, HashMap<Object, CharSequence> labelCache) {
Joe Onorato56d82912010-03-07 14:32:10 -05001626 Bitmap icon = null;
Michael Jurkac9d95c52011-08-29 14:03:34 -07001627 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato56d82912010-03-07 14:32:10 -05001628
1629 ComponentName componentName = intent.getComponent();
1630 if (componentName == null) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001631 return null;
1632 }
1633
Adam Cohen00fcb492011-11-02 21:53:47 -07001634 try {
1635 PackageInfo pi = manager.getPackageInfo(componentName.getPackageName(), 0);
1636 if (!pi.applicationInfo.enabled) {
1637 // If we return null here, the corresponding item will be removed from the launcher
1638 // db and will not appear in the workspace.
1639 return null;
1640 }
1641 } catch (NameNotFoundException e) {
1642 Log.d(TAG, "getPackInfo failed for package " + componentName.getPackageName());
1643 }
1644
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001645 // TODO: See if the PackageManager knows about this case. If it doesn't
1646 // then return null & delete this.
1647
Joe Onorato56d82912010-03-07 14:32:10 -05001648 // the resource -- This may implicitly give us back the fallback icon,
1649 // but don't worry about that. All we're doing with usingFallbackIcon is
1650 // to avoid saving lots of copies of that in the database, and most apps
1651 // have icons anyway.
1652 final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);
1653 if (resolveInfo != null) {
Winson Chungaac01e12011-08-17 10:37:13 -07001654 icon = mIconCache.getIcon(componentName, resolveInfo, labelCache);
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001655 }
Joe Onorato56d82912010-03-07 14:32:10 -05001656 // the db
1657 if (icon == null) {
1658 if (c != null) {
Michael Jurka931dc972011-08-05 15:08:15 -07001659 icon = getIconFromCursor(c, iconIndex, context);
Joe Onorato56d82912010-03-07 14:32:10 -05001660 }
1661 }
1662 // the fallback icon
1663 if (icon == null) {
1664 icon = getFallbackIcon();
1665 info.usingFallbackIcon = true;
1666 }
1667 info.setIcon(icon);
1668
1669 // from the resource
1670 if (resolveInfo != null) {
Winson Chung5308f242011-08-18 12:12:41 -07001671 ComponentName key = LauncherModel.getComponentNameFromResolveInfo(resolveInfo);
1672 if (labelCache != null && labelCache.containsKey(key)) {
1673 info.title = labelCache.get(key);
Winson Chungc3eecff2011-07-11 17:44:15 -07001674 } else {
1675 info.title = resolveInfo.activityInfo.loadLabel(manager);
1676 if (labelCache != null) {
Winson Chung5308f242011-08-18 12:12:41 -07001677 labelCache.put(key, info.title);
Winson Chungc3eecff2011-07-11 17:44:15 -07001678 }
1679 }
Joe Onorato56d82912010-03-07 14:32:10 -05001680 }
1681 // from the db
Joe Onorato9c1289c2009-08-17 11:03:03 -04001682 if (info.title == null) {
Joe Onorato56d82912010-03-07 14:32:10 -05001683 if (c != null) {
1684 info.title = c.getString(titleIndex);
1685 }
1686 }
1687 // fall back to the class name of the activity
1688 if (info.title == null) {
1689 info.title = componentName.getClassName();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001690 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001691 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
1692 return info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001693 }
The Android Open Source Projectbc219c32009-03-09 11:52:14 -07001694
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001695 /**
Joe Onorato0589f0f2010-02-08 13:44:00 -08001696 * Make an ShortcutInfo object for a shortcut that isn't an application.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001697 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001698 private ShortcutInfo getShortcutInfo(Cursor c, Context context,
Joe Onorato56d82912010-03-07 14:32:10 -05001699 int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex,
1700 int titleIndex) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001701
Joe Onorato56d82912010-03-07 14:32:10 -05001702 Bitmap icon = null;
Michael Jurkac9d95c52011-08-29 14:03:34 -07001703 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001704 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001705
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001706 // TODO: If there's an explicit component and we can't install that, delete it.
1707
Joe Onorato56d82912010-03-07 14:32:10 -05001708 info.title = c.getString(titleIndex);
1709
Joe Onorato9c1289c2009-08-17 11:03:03 -04001710 int iconType = c.getInt(iconTypeIndex);
1711 switch (iconType) {
1712 case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
1713 String packageName = c.getString(iconPackageIndex);
1714 String resourceName = c.getString(iconResourceIndex);
1715 PackageManager packageManager = context.getPackageManager();
Joe Onorato56d82912010-03-07 14:32:10 -05001716 info.customIcon = false;
1717 // the resource
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718 try {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001719 Resources resources = packageManager.getResourcesForApplication(packageName);
Joe Onorato56d82912010-03-07 14:32:10 -05001720 if (resources != null) {
1721 final int id = resources.getIdentifier(resourceName, null, null);
Michael Jurkac9a96192010-11-01 11:52:08 -07001722 icon = Utilities.createIconBitmap(
1723 mIconCache.getFullResIcon(resources, id), context);
Joe Onorato56d82912010-03-07 14:32:10 -05001724 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001725 } catch (Exception e) {
Joe Onorato56d82912010-03-07 14:32:10 -05001726 // drop this. we have other places to look for icons
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727 }
Joe Onorato56d82912010-03-07 14:32:10 -05001728 // the db
1729 if (icon == null) {
Michael Jurka931dc972011-08-05 15:08:15 -07001730 icon = getIconFromCursor(c, iconIndex, context);
Joe Onorato56d82912010-03-07 14:32:10 -05001731 }
1732 // the fallback icon
1733 if (icon == null) {
1734 icon = getFallbackIcon();
1735 info.usingFallbackIcon = true;
1736 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001737 break;
1738 case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
Michael Jurka931dc972011-08-05 15:08:15 -07001739 icon = getIconFromCursor(c, iconIndex, context);
Joe Onorato56d82912010-03-07 14:32:10 -05001740 if (icon == null) {
1741 icon = getFallbackIcon();
1742 info.customIcon = false;
1743 info.usingFallbackIcon = true;
1744 } else {
1745 info.customIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001746 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001747 break;
1748 default:
Joe Onoratod8d22da2010-03-11 17:59:11 -08001749 icon = getFallbackIcon();
Joe Onorato56d82912010-03-07 14:32:10 -05001750 info.usingFallbackIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001751 info.customIcon = false;
1752 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001753 }
Joe Onoratod8d22da2010-03-11 17:59:11 -08001754 info.setIcon(icon);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001755 return info;
1756 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001757
Michael Jurka931dc972011-08-05 15:08:15 -07001758 Bitmap getIconFromCursor(Cursor c, int iconIndex, Context context) {
Joe Onorato56d82912010-03-07 14:32:10 -05001759 if (false) {
1760 Log.d(TAG, "getIconFromCursor app="
1761 + c.getString(c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE)));
1762 }
1763 byte[] data = c.getBlob(iconIndex);
1764 try {
Michael Jurka931dc972011-08-05 15:08:15 -07001765 return Utilities.createIconBitmap(
1766 BitmapFactory.decodeByteArray(data, 0, data.length), context);
Joe Onorato56d82912010-03-07 14:32:10 -05001767 } catch (Exception e) {
1768 return null;
1769 }
1770 }
1771
Winson Chung3d503fb2011-07-13 17:25:49 -07001772 ShortcutInfo addShortcut(Context context, Intent data, long container, int screen,
1773 int cellX, int cellY, boolean notify) {
Winson Chunga9abd0e2010-10-27 17:18:37 -07001774 final ShortcutInfo info = infoFromShortcutIntent(context, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001775 if (info == null) {
1776 return null;
1777 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001778 addItemToDatabase(context, info, container, screen, cellX, cellY, notify);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001779
1780 return info;
1781 }
1782
Winson Chunga9abd0e2010-10-27 17:18:37 -07001783 /**
Winson Chung55cef262010-10-28 14:14:18 -07001784 * Attempts to find an AppWidgetProviderInfo that matches the given component.
1785 */
1786 AppWidgetProviderInfo findAppWidgetProviderInfoWithComponent(Context context,
1787 ComponentName component) {
1788 List<AppWidgetProviderInfo> widgets =
1789 AppWidgetManager.getInstance(context).getInstalledProviders();
1790 for (AppWidgetProviderInfo info : widgets) {
1791 if (info.provider.equals(component)) {
1792 return info;
1793 }
1794 }
1795 return null;
Winson Chunga9abd0e2010-10-27 17:18:37 -07001796 }
1797
Winson Chung68846fd2010-10-29 11:00:27 -07001798 /**
1799 * Returns a list of all the widgets that can handle configuration with a particular mimeType.
1800 */
1801 List<WidgetMimeTypeHandlerData> resolveWidgetsForMimeType(Context context, String mimeType) {
1802 final PackageManager packageManager = context.getPackageManager();
1803 final List<WidgetMimeTypeHandlerData> supportedConfigurationActivities =
1804 new ArrayList<WidgetMimeTypeHandlerData>();
1805
1806 final Intent supportsIntent =
1807 new Intent(InstallWidgetReceiver.ACTION_SUPPORTS_CLIPDATA_MIMETYPE);
1808 supportsIntent.setType(mimeType);
1809
1810 // Create a set of widget configuration components that we can test against
1811 final List<AppWidgetProviderInfo> widgets =
1812 AppWidgetManager.getInstance(context).getInstalledProviders();
1813 final HashMap<ComponentName, AppWidgetProviderInfo> configurationComponentToWidget =
1814 new HashMap<ComponentName, AppWidgetProviderInfo>();
1815 for (AppWidgetProviderInfo info : widgets) {
1816 configurationComponentToWidget.put(info.configure, info);
1817 }
1818
1819 // Run through each of the intents that can handle this type of clip data, and cross
1820 // reference them with the components that are actual configuration components
1821 final List<ResolveInfo> activities = packageManager.queryIntentActivities(supportsIntent,
1822 PackageManager.MATCH_DEFAULT_ONLY);
1823 for (ResolveInfo info : activities) {
1824 final ActivityInfo activityInfo = info.activityInfo;
1825 final ComponentName infoComponent = new ComponentName(activityInfo.packageName,
1826 activityInfo.name);
1827 if (configurationComponentToWidget.containsKey(infoComponent)) {
1828 supportedConfigurationActivities.add(
1829 new InstallWidgetReceiver.WidgetMimeTypeHandlerData(info,
1830 configurationComponentToWidget.get(infoComponent)));
1831 }
1832 }
1833 return supportedConfigurationActivities;
1834 }
1835
Winson Chunga9abd0e2010-10-27 17:18:37 -07001836 ShortcutInfo infoFromShortcutIntent(Context context, Intent data, Bitmap fallbackIcon) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001837 Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
1838 String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
1839 Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
1840
Adam Cohend9198822011-11-22 16:42:47 -08001841 if (intent == null) {
1842 // If the intent is null, we can't construct a valid ShortcutInfo, so we return null
1843 Log.e(TAG, "Can't construct ShorcutInfo with null intent");
1844 return null;
1845 }
1846
Joe Onorato0589f0f2010-02-08 13:44:00 -08001847 Bitmap icon = null;
Joe Onorato0589f0f2010-02-08 13:44:00 -08001848 boolean customIcon = false;
1849 ShortcutIconResource iconResource = null;
1850
1851 if (bitmap != null && bitmap instanceof Bitmap) {
1852 icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap)bitmap), context);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001853 customIcon = true;
1854 } else {
1855 Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
1856 if (extra != null && extra instanceof ShortcutIconResource) {
1857 try {
1858 iconResource = (ShortcutIconResource) extra;
1859 final PackageManager packageManager = context.getPackageManager();
1860 Resources resources = packageManager.getResourcesForApplication(
1861 iconResource.packageName);
1862 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
Michael Jurkac9a96192010-11-01 11:52:08 -07001863 icon = Utilities.createIconBitmap(
1864 mIconCache.getFullResIcon(resources, id), context);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001865 } catch (Exception e) {
1866 Log.w(TAG, "Could not load shortcut icon: " + extra);
1867 }
1868 }
1869 }
1870
Michael Jurkac9d95c52011-08-29 14:03:34 -07001871 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato56d82912010-03-07 14:32:10 -05001872
1873 if (icon == null) {
Winson Chunga9abd0e2010-10-27 17:18:37 -07001874 if (fallbackIcon != null) {
1875 icon = fallbackIcon;
1876 } else {
1877 icon = getFallbackIcon();
1878 info.usingFallbackIcon = true;
1879 }
Joe Onorato56d82912010-03-07 14:32:10 -05001880 }
Joe Onorato0589f0f2010-02-08 13:44:00 -08001881 info.setIcon(icon);
Joe Onorato56d82912010-03-07 14:32:10 -05001882
Joe Onorato0589f0f2010-02-08 13:44:00 -08001883 info.title = name;
1884 info.intent = intent;
1885 info.customIcon = customIcon;
1886 info.iconResource = iconResource;
1887
1888 return info;
1889 }
1890
Winson Chungaac01e12011-08-17 10:37:13 -07001891 boolean queueIconToBeChecked(HashMap<Object, byte[]> cache, ShortcutInfo info, Cursor c,
1892 int iconIndex) {
Joe Onorato17a89222011-02-08 17:26:11 -08001893 // If apps can't be on SD, don't even bother.
1894 if (!mAppsCanBeOnExternalStorage) {
Winson Chungaac01e12011-08-17 10:37:13 -07001895 return false;
Joe Onorato17a89222011-02-08 17:26:11 -08001896 }
Joe Onorato56d82912010-03-07 14:32:10 -05001897 // If this icon doesn't have a custom icon, check to see
1898 // what's stored in the DB, and if it doesn't match what
1899 // we're going to show, store what we are going to show back
1900 // into the DB. We do this so when we're loading, if the
1901 // package manager can't find an icon (for example because
1902 // the app is on SD) then we can use that instead.
Joe Onoratoddc9c1f2010-08-30 18:30:15 -07001903 if (!info.customIcon && !info.usingFallbackIcon) {
Winson Chungaac01e12011-08-17 10:37:13 -07001904 cache.put(info, c.getBlob(iconIndex));
1905 return true;
1906 }
1907 return false;
1908 }
1909 void updateSavedIcon(Context context, ShortcutInfo info, byte[] data) {
1910 boolean needSave = false;
1911 try {
1912 if (data != null) {
1913 Bitmap saved = BitmapFactory.decodeByteArray(data, 0, data.length);
1914 Bitmap loaded = info.getIcon(mIconCache);
1915 needSave = !saved.sameAs(loaded);
1916 } else {
Joe Onorato56d82912010-03-07 14:32:10 -05001917 needSave = true;
1918 }
Winson Chungaac01e12011-08-17 10:37:13 -07001919 } catch (Exception e) {
1920 needSave = true;
1921 }
1922 if (needSave) {
1923 Log.d(TAG, "going to save icon bitmap for info=" + info);
1924 // This is slower than is ideal, but this only happens once
1925 // or when the app is updated with a new icon.
1926 updateItemInDatabase(context, info);
Joe Onorato56d82912010-03-07 14:32:10 -05001927 }
1928 }
1929
Joe Onorato9c1289c2009-08-17 11:03:03 -04001930 /**
Adam Cohendf2cc412011-04-27 16:56:57 -07001931 * Return an existing FolderInfo object if we have encountered this ID previously,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001932 * or make a new one.
1933 */
Adam Cohendf2cc412011-04-27 16:56:57 -07001934 private static FolderInfo findOrMakeFolder(HashMap<Long, FolderInfo> folders, long id) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001935 // See if a placeholder was created for us already
1936 FolderInfo folderInfo = folders.get(id);
Adam Cohendf2cc412011-04-27 16:56:57 -07001937 if (folderInfo == null) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001938 // No placeholder -- create a new instance
Michael Jurkac9d95c52011-08-29 14:03:34 -07001939 folderInfo = new FolderInfo();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001940 folders.put(id, folderInfo);
1941 }
Adam Cohendf2cc412011-04-27 16:56:57 -07001942 return folderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001943 }
1944
Joe Onorato9c1289c2009-08-17 11:03:03 -04001945 private static final Collator sCollator = Collator.getInstance();
Joe Onoratob0c27f22009-12-01 16:19:38 -08001946 public static final Comparator<ApplicationInfo> APP_NAME_COMPARATOR
Joe Onorato9c1289c2009-08-17 11:03:03 -04001947 = new Comparator<ApplicationInfo>() {
1948 public final int compare(ApplicationInfo a, ApplicationInfo b) {
Michael Jurka5b1808d2011-07-11 19:59:46 -07001949 int result = sCollator.compare(a.title.toString(), b.title.toString());
1950 if (result == 0) {
1951 result = a.componentName.compareTo(b.componentName);
1952 }
1953 return result;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001955 };
Winson Chung78403fe2011-01-21 15:38:02 -08001956 public static final Comparator<ApplicationInfo> APP_INSTALL_TIME_COMPARATOR
1957 = new Comparator<ApplicationInfo>() {
1958 public final int compare(ApplicationInfo a, ApplicationInfo b) {
1959 if (a.firstInstallTime < b.firstInstallTime) return 1;
1960 if (a.firstInstallTime > b.firstInstallTime) return -1;
1961 return 0;
1962 }
1963 };
Winson Chung785d2eb2011-04-14 16:08:02 -07001964 public static final Comparator<AppWidgetProviderInfo> WIDGET_NAME_COMPARATOR
1965 = new Comparator<AppWidgetProviderInfo>() {
1966 public final int compare(AppWidgetProviderInfo a, AppWidgetProviderInfo b) {
1967 return sCollator.compare(a.label.toString(), b.label.toString());
1968 }
1969 };
Winson Chung5308f242011-08-18 12:12:41 -07001970 static ComponentName getComponentNameFromResolveInfo(ResolveInfo info) {
1971 if (info.activityInfo != null) {
1972 return new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
1973 } else {
1974 return new ComponentName(info.serviceInfo.packageName, info.serviceInfo.name);
1975 }
1976 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001977 public static class ShortcutNameComparator implements Comparator<ResolveInfo> {
1978 private PackageManager mPackageManager;
Winson Chungc3eecff2011-07-11 17:44:15 -07001979 private HashMap<Object, CharSequence> mLabelCache;
Winson Chung785d2eb2011-04-14 16:08:02 -07001980 ShortcutNameComparator(PackageManager pm) {
1981 mPackageManager = pm;
Winson Chungc3eecff2011-07-11 17:44:15 -07001982 mLabelCache = new HashMap<Object, CharSequence>();
1983 }
1984 ShortcutNameComparator(PackageManager pm, HashMap<Object, CharSequence> labelCache) {
1985 mPackageManager = pm;
1986 mLabelCache = labelCache;
Winson Chung785d2eb2011-04-14 16:08:02 -07001987 }
1988 public final int compare(ResolveInfo a, ResolveInfo b) {
Winson Chungc3eecff2011-07-11 17:44:15 -07001989 CharSequence labelA, labelB;
Winson Chung5308f242011-08-18 12:12:41 -07001990 ComponentName keyA = LauncherModel.getComponentNameFromResolveInfo(a);
1991 ComponentName keyB = LauncherModel.getComponentNameFromResolveInfo(b);
1992 if (mLabelCache.containsKey(keyA)) {
1993 labelA = mLabelCache.get(keyA);
Winson Chungc3eecff2011-07-11 17:44:15 -07001994 } else {
1995 labelA = a.loadLabel(mPackageManager).toString();
1996
Winson Chung5308f242011-08-18 12:12:41 -07001997 mLabelCache.put(keyA, labelA);
Winson Chungc3eecff2011-07-11 17:44:15 -07001998 }
Winson Chung5308f242011-08-18 12:12:41 -07001999 if (mLabelCache.containsKey(keyB)) {
2000 labelB = mLabelCache.get(keyB);
Winson Chungc3eecff2011-07-11 17:44:15 -07002001 } else {
2002 labelB = b.loadLabel(mPackageManager).toString();
2003
Winson Chung5308f242011-08-18 12:12:41 -07002004 mLabelCache.put(keyB, labelB);
Winson Chungc3eecff2011-07-11 17:44:15 -07002005 }
Winson Chung785d2eb2011-04-14 16:08:02 -07002006 return sCollator.compare(labelA, labelB);
2007 }
2008 };
Winson Chung1ed747a2011-05-03 16:18:34 -07002009 public static class WidgetAndShortcutNameComparator implements Comparator<Object> {
2010 private PackageManager mPackageManager;
2011 private HashMap<Object, String> mLabelCache;
2012 WidgetAndShortcutNameComparator(PackageManager pm) {
2013 mPackageManager = pm;
2014 mLabelCache = new HashMap<Object, String>();
2015 }
2016 public final int compare(Object a, Object b) {
2017 String labelA, labelB;
Winson Chungc3eecff2011-07-11 17:44:15 -07002018 if (mLabelCache.containsKey(a)) {
2019 labelA = mLabelCache.get(a);
2020 } else {
2021 labelA = (a instanceof AppWidgetProviderInfo) ?
Winson Chung1ed747a2011-05-03 16:18:34 -07002022 ((AppWidgetProviderInfo) a).label :
2023 ((ResolveInfo) a).loadLabel(mPackageManager).toString();
Winson Chungc3eecff2011-07-11 17:44:15 -07002024 mLabelCache.put(a, labelA);
2025 }
2026 if (mLabelCache.containsKey(b)) {
2027 labelB = mLabelCache.get(b);
2028 } else {
2029 labelB = (b instanceof AppWidgetProviderInfo) ?
Winson Chung1ed747a2011-05-03 16:18:34 -07002030 ((AppWidgetProviderInfo) b).label :
2031 ((ResolveInfo) b).loadLabel(mPackageManager).toString();
Winson Chungc3eecff2011-07-11 17:44:15 -07002032 mLabelCache.put(b, labelB);
2033 }
Winson Chung1ed747a2011-05-03 16:18:34 -07002034 return sCollator.compare(labelA, labelB);
2035 }
2036 };
Joe Onoratobe386092009-11-17 17:32:16 -08002037
2038 public void dumpState() {
Joe Onoratobe386092009-11-17 17:32:16 -08002039 Log.d(TAG, "mCallbacks=" + mCallbacks);
2040 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mAllAppsList.data);
2041 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mAllAppsList.added);
2042 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mAllAppsList.removed);
2043 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mAllAppsList.modified);
Joe Onorato36115782010-06-17 13:28:48 -04002044 if (mLoaderTask != null) {
2045 mLoaderTask.dumpState();
2046 } else {
2047 Log.d(TAG, "mLoaderTask=null");
2048 }
Joe Onoratobe386092009-11-17 17:32:16 -08002049 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050}