blob: e2ddf1b49cb2cc1012c231aee7edf3b52c90a5e6 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Narayan Kamathcb1a4772011-06-28 13:46:59 +010019import android.app.SearchManager;
Romain Guy629de3e2010-01-13 12:20:59 -080020import android.appwidget.AppWidgetManager;
21import android.appwidget.AppWidgetProviderInfo;
Joe Onoratof99f8c12009-10-31 17:27:36 -040022import android.content.BroadcastReceiver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.content.ComponentName;
Romain Guy5c16f3e2010-01-12 17:24:58 -080024import android.content.ContentProviderClient;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025import android.content.ContentResolver;
26import android.content.ContentValues;
Winson Chungaafa03c2010-06-11 17:34:16 -070027import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.content.Intent;
Joe Onorato0589f0f2010-02-08 13:44:00 -080029import android.content.Intent.ShortcutIconResource;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.content.pm.ActivityInfo;
Adam Cohen00fcb492011-11-02 21:53:47 -070031import android.content.pm.PackageInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.content.pm.PackageManager;
Adam Cohen00fcb492011-11-02 21:53:47 -070033import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.pm.ResolveInfo;
Reena Lee93f824a2011-09-23 17:20:28 -070035import android.content.res.Configuration;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.res.Resources;
37import android.database.Cursor;
38import android.graphics.Bitmap;
39import android.graphics.BitmapFactory;
40import android.net.Uri;
Joe Onorato17a89222011-02-08 17:26:11 -080041import android.os.Environment;
Joe Onorato36115782010-06-17 13:28:48 -040042import android.os.Handler;
43import android.os.HandlerThread;
Joe Onorato0589f0f2010-02-08 13:44:00 -080044import android.os.Parcelable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.os.Process;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.os.RemoteException;
Joe Onorato9c1289c2009-08-17 11:03:03 -040047import android.os.SystemClock;
Winson Chungaafa03c2010-06-11 17:34:16 -070048import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049
Winson Chung68846fd2010-10-29 11:00:27 -070050import com.android.launcher.R;
51import com.android.launcher2.InstallWidgetReceiver.WidgetMimeTypeHandlerData;
Romain Guyedcce092010-03-04 13:03:17 -080052
Michael Jurkac2f801e2011-07-12 14:19:46 -070053import java.lang.ref.WeakReference;
54import java.net.URISyntaxException;
55import java.text.Collator;
56import java.util.ArrayList;
57import java.util.Collections;
58import java.util.Comparator;
59import java.util.HashMap;
60import java.util.List;
Michael Jurkac2f801e2011-07-12 14:19:46 -070061
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062/**
63 * Maintains in-memory state of the Launcher. It is expected that there should be only one
64 * LauncherModel object held in a static. Also provide APIs for updating the database state
The Android Open Source Projectbc219c32009-03-09 11:52:14 -070065 * for the Launcher.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066 */
Joe Onoratof99f8c12009-10-31 17:27:36 -040067public class LauncherModel extends BroadcastReceiver {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080068 static final boolean DEBUG_LOADERS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -040069 static final String TAG = "Launcher.Model";
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070070
Joe Onorato36115782010-06-17 13:28:48 -040071 private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons
Joe Onorato17a89222011-02-08 17:26:11 -080072 private final boolean mAppsCanBeOnExternalStorage;
Joe Onoratod65d08e2010-04-20 15:43:37 -040073 private int mBatchSize; // 0 is all apps at once
Daniel Sandler2ff10b32010-04-16 15:06:06 -040074 private int mAllAppsLoadDelay; // milliseconds between batches
Daniel Sandlerdca66122010-04-13 16:23:58 -040075
Joe Onoratof99f8c12009-10-31 17:27:36 -040076 private final LauncherApplication mApp;
Joe Onorato9c1289c2009-08-17 11:03:03 -040077 private final Object mLock = new Object();
78 private DeferredHandler mHandler = new DeferredHandler();
Joe Onorato36115782010-06-17 13:28:48 -040079 private LoaderTask mLoaderTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080
Brad Fitzpatrick700889f2010-10-11 09:40:44 -070081 private static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
82 static {
83 sWorkerThread.start();
84 }
85 private static final Handler sWorker = new Handler(sWorkerThread.getLooper());
86
Joe Onoratocc67f472010-06-08 10:54:30 -070087 // We start off with everything not loaded. After that, we assume that
88 // our monitoring of the package manager provides all updates and we never
89 // need to do a requery. These are only ever touched from the loader thread.
90 private boolean mWorkspaceLoaded;
91 private boolean mAllAppsLoaded;
92
Joe Onorato9c1289c2009-08-17 11:03:03 -040093 private WeakReference<Callbacks> mCallbacks;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094
Michael Jurkaa8c760d2011-04-28 14:59:33 -070095 // < only access in worker thread >
96 private AllAppsList mAllAppsList;
Joe Onorato0589f0f2010-02-08 13:44:00 -080097
Michael Jurkaa8c760d2011-04-28 14:59:33 -070098 // sItemsIdMap maps *all* the ItemInfos (shortcuts, folders, and widgets) created by
99 // LauncherModel to their ids
100 static final HashMap<Long, ItemInfo> sItemsIdMap = new HashMap<Long, ItemInfo>();
101
102 // sItems is passed to bindItems, which expects a list of all folders and shortcuts created by
103 // LauncherModel that are directly on the home screen (however, no widgets or shortcuts
104 // within folders).
Adam Cohen4eac29a2011-07-11 17:53:37 -0700105 static final ArrayList<ItemInfo> sWorkspaceItems = new ArrayList<ItemInfo>();
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700106
107 // sAppWidgets is all LauncherAppWidgetInfo created by LauncherModel. Passed to bindAppWidget()
108 static final ArrayList<LauncherAppWidgetInfo> sAppWidgets =
109 new ArrayList<LauncherAppWidgetInfo>();
110
111 // sFolders is all FolderInfos created by LauncherModel. Passed to bindFolders()
112 static final HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Winson Chungb1094bd2011-08-24 16:14:08 -0700113
114 // sDbIconCache is the set of ItemInfos that need to have their icons updated in the database
115 static final HashMap<Object, byte[]> sDbIconCache = new HashMap<Object, byte[]>();
116
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700117 // </ only access in worker thread >
118
119 private IconCache mIconCache;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800120 private Bitmap mDefaultIcon;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121
Adam Cohend22015c2010-07-26 22:02:18 -0700122 private static int mCellCountX;
123 private static int mCellCountY;
Winson Chungaafa03c2010-06-11 17:34:16 -0700124
Reena Lee99a73f32011-10-24 17:27:37 -0700125 protected int mPreviousConfigMcc;
Reena Lee93f824a2011-09-23 17:20:28 -0700126
Joe Onorato9c1289c2009-08-17 11:03:03 -0400127 public interface Callbacks {
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700128 public boolean setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400129 public int getCurrentWorkspaceScreen();
130 public void startBinding();
131 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end);
Joe Onoratoad72e172009-11-06 16:25:04 -0500132 public void bindFolders(HashMap<Long,FolderInfo> folders);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400133 public void finishBindingItems();
134 public void bindAppWidget(LauncherAppWidgetInfo info);
135 public void bindAllApplications(ArrayList<ApplicationInfo> apps);
Joe Onorato64e6be72010-03-05 15:05:52 -0500136 public void bindAppsAdded(ArrayList<ApplicationInfo> apps);
137 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps);
Joe Onorato36115782010-06-17 13:28:48 -0400138 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent);
Winson Chung80baf5a2010-08-09 16:03:15 -0700139 public void bindPackagesUpdated();
Daniel Sandler843e8602010-06-07 14:59:01 -0400140 public boolean isAllAppsVisible();
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100141 public void bindSearchablesChanged();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400142 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
Joe Onorato0589f0f2010-02-08 13:44:00 -0800144 LauncherModel(LauncherApplication app, IconCache iconCache) {
Joe Onorato17a89222011-02-08 17:26:11 -0800145 mAppsCanBeOnExternalStorage = !Environment.isExternalStorageEmulated();
Joe Onoratof99f8c12009-10-31 17:27:36 -0400146 mApp = app;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800147 mAllAppsList = new AllAppsList(iconCache);
148 mIconCache = iconCache;
149
150 mDefaultIcon = Utilities.createIconBitmap(
Michael Jurkac9a96192010-11-01 11:52:08 -0700151 mIconCache.getFullResDefaultActivityIcon(), app);
Daniel Sandler2ff10b32010-04-16 15:06:06 -0400152
Reena Lee93f824a2011-09-23 17:20:28 -0700153 final Resources res = app.getResources();
154 mAllAppsLoadDelay = res.getInteger(R.integer.config_allAppsBatchLoadDelay);
155 mBatchSize = res.getInteger(R.integer.config_allAppsBatchSize);
Reena Lee99a73f32011-10-24 17:27:37 -0700156 Configuration config = res.getConfiguration();
157 mPreviousConfigMcc = config.mcc;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800158 }
159
Joe Onorato56d82912010-03-07 14:32:10 -0500160 public Bitmap getFallbackIcon() {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800161 return Bitmap.createBitmap(mDefaultIcon);
Joe Onoratof99f8c12009-10-31 17:27:36 -0400162 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163
Winson Chung603bcb92011-09-02 11:45:39 -0700164 public void unbindWorkspaceItems() {
165 sWorker.post(new Runnable() {
166 @Override
167 public void run() {
168 unbindWorkspaceItemsOnMainThread();
169 }
170 });
171 }
172
173 /** Unbinds all the sWorkspaceItems on the main thread, and return a copy of sWorkspaceItems
174 * that is save to reference from the main thread. */
175 private ArrayList<ItemInfo> unbindWorkspaceItemsOnMainThread() {
176 // Ensure that we don't use the same workspace items data structure on the main thread
177 // by making a copy of workspace items first.
178 final ArrayList<ItemInfo> workspaceItems = new ArrayList<ItemInfo>(sWorkspaceItems);
179 mHandler.post(new Runnable() {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700180 @Override
Winson Chung603bcb92011-09-02 11:45:39 -0700181 public void run() {
182 for (ItemInfo item : workspaceItems) {
183 item.unbind();
184 }
185 }
186 });
187
188 return workspaceItems;
Adam Cohen4eac29a2011-07-11 17:53:37 -0700189 }
190
Joe Onorato9c1289c2009-08-17 11:03:03 -0400191 /**
192 * Adds an item to the DB if it was not created previously, or move it to a new
193 * <container, screen, cellX, cellY>
194 */
195 static void addOrMoveItemInDatabase(Context context, ItemInfo item, long container,
196 int screen, int cellX, int cellY) {
197 if (item.container == ItemInfo.NO_ID) {
198 // From all apps
199 addItemToDatabase(context, item, container, screen, cellX, cellY, false);
200 } else {
201 // From somewhere else
202 moveItemInDatabase(context, item, container, screen, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800203 }
204 }
205
Michael Jurkac9d95c52011-08-29 14:03:34 -0700206 static void updateItemInDatabaseHelper(Context context, final ContentValues values,
207 final ItemInfo item, final String callingFunction) {
208 final long itemId = item.id;
209 final Uri uri = LauncherSettings.Favorites.getContentUri(itemId, false);
210 final ContentResolver cr = context.getContentResolver();
211
212 Runnable r = new Runnable() {
213 public void run() {
214 cr.update(uri, values, null, null);
215
216 ItemInfo modelItem = sItemsIdMap.get(itemId);
217 if (item != modelItem) {
218 // the modelItem needs to match up perfectly with item if our model is to be
219 // consistent with the database-- for now, just require modelItem == item
220 String msg = "item: " + ((item != null) ? item.toString() : "null") +
221 "modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
222 "Error: ItemInfo passed to " + callingFunction + " doesn't match original";
223 throw new RuntimeException(msg);
224 }
225
226 // Items are added/removed from the corresponding FolderInfo elsewhere, such
227 // as in Workspace.onDrop. Here, we just add/remove them from the list of items
228 // that are on the desktop, as appropriate
229 if (modelItem.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
230 modelItem.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
231 if (!sWorkspaceItems.contains(modelItem)) {
232 sWorkspaceItems.add(modelItem);
233 }
234 } else {
235 sWorkspaceItems.remove(modelItem);
236 }
237 }
238 };
239
240 if (sWorkerThread.getThreadId() == Process.myTid()) {
241 r.run();
242 } else {
243 sWorker.post(r);
244 }
245 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400247 * Move an item in the DB to a new <container, screen, cellX, cellY>
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700248 */
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700249 static void moveItemInDatabase(Context context, final ItemInfo item, final long container,
250 final int screen, final int cellX, final int cellY) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400251 item.container = container;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400252 item.cellX = cellX;
253 item.cellY = cellY;
Michael Jurkac9d95c52011-08-29 14:03:34 -0700254
Winson Chung3d503fb2011-07-13 17:25:49 -0700255 // We store hotseat items in canonical form which is this orientation invariant position
256 // in the hotseat
257 if (context instanceof Launcher && screen < 0 &&
258 container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
259 item.screen = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY);
260 } else {
261 item.screen = screen;
262 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400263
264 final ContentValues values = new ContentValues();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400265 values.put(LauncherSettings.Favorites.CONTAINER, item.container);
Winson Chung3d503fb2011-07-13 17:25:49 -0700266 values.put(LauncherSettings.Favorites.CELLX, item.cellX);
267 values.put(LauncherSettings.Favorites.CELLY, item.cellY);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400268 values.put(LauncherSettings.Favorites.SCREEN, item.screen);
269
Michael Jurkac9d95c52011-08-29 14:03:34 -0700270 updateItemInDatabaseHelper(context, values, item, "moveItemInDatabase");
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700271 }
272
273 /**
Adam Cohen1b607ed2011-03-03 17:26:50 -0800274 * Resize an item in the DB to a new <spanX, spanY, cellX, cellY>
Adam Cohend4844c32011-02-18 19:25:06 -0800275 */
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700276 static void resizeItemInDatabase(Context context, final ItemInfo item, final int cellX,
277 final int cellY, final int spanX, final int spanY) {
Adam Cohend4844c32011-02-18 19:25:06 -0800278 item.spanX = spanX;
279 item.spanY = spanY;
280 item.cellX = cellX;
281 item.cellY = cellY;
282
Adam Cohend4844c32011-02-18 19:25:06 -0800283 final ContentValues values = new ContentValues();
Adam Cohend4844c32011-02-18 19:25:06 -0800284 values.put(LauncherSettings.Favorites.CONTAINER, item.container);
285 values.put(LauncherSettings.Favorites.SPANX, spanX);
286 values.put(LauncherSettings.Favorites.SPANY, spanY);
287 values.put(LauncherSettings.Favorites.CELLX, cellX);
288 values.put(LauncherSettings.Favorites.CELLY, cellY);
Michael Jurkac9d95c52011-08-29 14:03:34 -0700289 updateItemInDatabaseHelper(context, values, item, "resizeItemInDatabase");
290 }
Adam Cohend4844c32011-02-18 19:25:06 -0800291
Michael Jurkac9d95c52011-08-29 14:03:34 -0700292
293 /**
294 * Update an item to the database in a specified container.
295 */
296 static void updateItemInDatabase(Context context, final ItemInfo item) {
297 final ContentValues values = new ContentValues();
298 item.onAddToDatabase(values);
299 item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
300 updateItemInDatabaseHelper(context, values, item, "updateItemInDatabase");
Adam Cohend4844c32011-02-18 19:25:06 -0800301 }
302
303 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400304 * Returns true if the shortcuts already exists in the database.
305 * we identify a shortcut by its title and intent.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800306 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400307 static boolean shortcutExists(Context context, String title, Intent intent) {
308 final ContentResolver cr = context.getContentResolver();
309 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
310 new String[] { "title", "intent" }, "title=? and intent=?",
311 new String[] { title, intent.toUri(0) }, null);
312 boolean result = false;
313 try {
314 result = c.moveToFirst();
315 } finally {
316 c.close();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800317 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400318 return result;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700319 }
320
Joe Onorato9c1289c2009-08-17 11:03:03 -0400321 /**
Winson Chungaafa03c2010-06-11 17:34:16 -0700322 * Returns an ItemInfo array containing all the items in the LauncherModel.
323 * The ItemInfo.id is not set through this function.
324 */
325 static ArrayList<ItemInfo> getItemsInLocalCoordinates(Context context) {
326 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
327 final ContentResolver cr = context.getContentResolver();
328 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] {
329 LauncherSettings.Favorites.ITEM_TYPE, LauncherSettings.Favorites.CONTAINER,
330 LauncherSettings.Favorites.SCREEN, LauncherSettings.Favorites.CELLX, LauncherSettings.Favorites.CELLY,
331 LauncherSettings.Favorites.SPANX, LauncherSettings.Favorites.SPANY }, null, null, null);
332
333 final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
334 final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
335 final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
336 final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
337 final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
338 final int spanXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANX);
339 final int spanYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANY);
340
341 try {
342 while (c.moveToNext()) {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700343 ItemInfo item = new ItemInfo();
Winson Chungaafa03c2010-06-11 17:34:16 -0700344 item.cellX = c.getInt(cellXIndex);
345 item.cellY = c.getInt(cellYIndex);
346 item.spanX = c.getInt(spanXIndex);
347 item.spanY = c.getInt(spanYIndex);
348 item.container = c.getInt(containerIndex);
349 item.itemType = c.getInt(itemTypeIndex);
350 item.screen = c.getInt(screenIndex);
351
352 items.add(item);
353 }
354 } catch (Exception e) {
355 items.clear();
356 } finally {
357 c.close();
358 }
359
360 return items;
361 }
362
363 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400364 * Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList.
365 */
366 FolderInfo getFolderById(Context context, HashMap<Long,FolderInfo> folderList, long id) {
367 final ContentResolver cr = context.getContentResolver();
368 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null,
369 "_id=? and (itemType=? or itemType=?)",
370 new String[] { String.valueOf(id),
Adam Cohendf2cc412011-04-27 16:56:57 -0700371 String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)}, null);
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700372
Joe Onorato9c1289c2009-08-17 11:03:03 -0400373 try {
374 if (c.moveToFirst()) {
375 final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
376 final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
377 final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
378 final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
379 final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
380 final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800381
Joe Onorato9c1289c2009-08-17 11:03:03 -0400382 FolderInfo folderInfo = null;
383 switch (c.getInt(itemTypeIndex)) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700384 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
385 folderInfo = findOrMakeFolder(folderList, id);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400386 break;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700387 }
388
Joe Onorato9c1289c2009-08-17 11:03:03 -0400389 folderInfo.title = c.getString(titleIndex);
390 folderInfo.id = id;
391 folderInfo.container = c.getInt(containerIndex);
392 folderInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -0700393 folderInfo.cellX = c.getInt(cellXIndex);
394 folderInfo.cellY = c.getInt(cellYIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400395
396 return folderInfo;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700397 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400398 } finally {
399 c.close();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700400 }
401
402 return null;
403 }
404
Joe Onorato9c1289c2009-08-17 11:03:03 -0400405 /**
406 * Add an item to the database in a specified container. Sets the container, screen, cellX and
407 * cellY fields of the item. Also assigns an ID to the item.
408 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700409 static void addItemToDatabase(Context context, final ItemInfo item, final long container,
410 final int screen, final int cellX, final int cellY, final boolean notify) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400411 item.container = container;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400412 item.cellX = cellX;
413 item.cellY = cellY;
Winson Chung3d503fb2011-07-13 17:25:49 -0700414 // We store hotseat items in canonical form which is this orientation invariant position
415 // in the hotseat
416 if (context instanceof Launcher && screen < 0 &&
417 container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
418 item.screen = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY);
419 } else {
420 item.screen = screen;
421 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400422
423 final ContentValues values = new ContentValues();
424 final ContentResolver cr = context.getContentResolver();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400425 item.onAddToDatabase(values);
426
Michael Jurka7578ec62011-08-03 14:11:54 -0700427 LauncherApplication app = (LauncherApplication) context.getApplicationContext();
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700428 item.id = app.getLauncherProvider().generateNewId();
429 values.put(LauncherSettings.Favorites._ID, item.id);
Winson Chung3d503fb2011-07-13 17:25:49 -0700430 item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700431
Michael Jurkac9d95c52011-08-29 14:03:34 -0700432 Runnable r = new Runnable() {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700433 public void run() {
434 cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
435 LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400436
Winson Chungb1094bd2011-08-24 16:14:08 -0700437 if (sItemsIdMap.containsKey(item.id)) {
438 // we should not be adding new items in the db with the same id
439 throw new RuntimeException("Error: ItemInfo id (" + item.id + ") passed to " +
440 "addItemToDatabase already exists." + item.toString());
441 }
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700442 sItemsIdMap.put(item.id, item);
443 switch (item.itemType) {
444 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
445 sFolders.put(item.id, (FolderInfo) item);
Winson Chung3d503fb2011-07-13 17:25:49 -0700446 // Fall through
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700447 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
448 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700449 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
450 item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
Adam Cohen4eac29a2011-07-11 17:53:37 -0700451 sWorkspaceItems.add(item);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700452 }
453 break;
454 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
455 sAppWidgets.add((LauncherAppWidgetInfo) item);
456 break;
457 }
458 }
Michael Jurkac9d95c52011-08-29 14:03:34 -0700459 };
460
461 if (sWorkerThread.getThreadId() == Process.myTid()) {
462 r.run();
463 } else {
464 sWorker.post(r);
465 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700466 }
467
Joe Onorato9c1289c2009-08-17 11:03:03 -0400468 /**
Winson Chungaafa03c2010-06-11 17:34:16 -0700469 * Creates a new unique child id, for a given cell span across all layouts.
470 */
Michael Jurka845ba3b2010-09-28 17:09:46 -0700471 static int getCellLayoutChildId(
Winson Chung3d503fb2011-07-13 17:25:49 -0700472 long container, int screen, int localCellX, int localCellY, int spanX, int spanY) {
473 return (((int) container & 0xFF) << 24)
Michael Jurka845ba3b2010-09-28 17:09:46 -0700474 | (screen & 0xFF) << 16 | (localCellX & 0xFF) << 8 | (localCellY & 0xFF);
Winson Chungaafa03c2010-06-11 17:34:16 -0700475 }
476
Adam Cohend22015c2010-07-26 22:02:18 -0700477 static int getCellCountX() {
478 return mCellCountX;
Winson Chungaafa03c2010-06-11 17:34:16 -0700479 }
480
Adam Cohend22015c2010-07-26 22:02:18 -0700481 static int getCellCountY() {
482 return mCellCountY;
Winson Chungaafa03c2010-06-11 17:34:16 -0700483 }
484
485 /**
486 * Updates the model orientation helper to take into account the current layout dimensions
487 * when performing local/canonical coordinate transformations.
488 */
489 static void updateWorkspaceLayoutCells(int shortAxisCellCount, int longAxisCellCount) {
Adam Cohend22015c2010-07-26 22:02:18 -0700490 mCellCountX = shortAxisCellCount;
491 mCellCountY = longAxisCellCount;
Winson Chungaafa03c2010-06-11 17:34:16 -0700492 }
493
494 /**
Michael Jurkac9d95c52011-08-29 14:03:34 -0700495 * Removes the specified item from the database
496 * @param context
497 * @param item
Joe Onorato9c1289c2009-08-17 11:03:03 -0400498 */
Michael Jurkac9d95c52011-08-29 14:03:34 -0700499 static void deleteItemFromDatabase(Context context, final ItemInfo item) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400500 final ContentResolver cr = context.getContentResolver();
Michael Jurkac9d95c52011-08-29 14:03:34 -0700501 final Uri uriToDelete = LauncherSettings.Favorites.getContentUri(item.id, false);
Michael Jurka83df1882011-08-31 20:59:26 -0700502 Runnable r = new Runnable() {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700503 public void run() {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700504 cr.delete(uriToDelete, null, null);
505 switch (item.itemType) {
506 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
507 sFolders.remove(item.id);
508 sWorkspaceItems.remove(item);
509 break;
510 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
511 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
512 sWorkspaceItems.remove(item);
513 break;
514 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
515 sAppWidgets.remove((LauncherAppWidgetInfo) item);
516 break;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700517 }
Michael Jurkac9d95c52011-08-29 14:03:34 -0700518 sItemsIdMap.remove(item.id);
519 sDbIconCache.remove(item);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700520 }
Michael Jurka83df1882011-08-31 20:59:26 -0700521 };
522 if (sWorkerThread.getThreadId() == Process.myTid()) {
523 r.run();
524 } else {
525 sWorker.post(r);
526 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400527 }
528
529 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400530 * Remove the contents of the specified folder from the database
531 */
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700532 static void deleteFolderContentsFromDatabase(Context context, final FolderInfo info) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400533 final ContentResolver cr = context.getContentResolver();
534
Michael Jurkac9d95c52011-08-29 14:03:34 -0700535 Runnable r = new Runnable() {
536 public void run() {
537 cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
538 sItemsIdMap.remove(info.id);
539 sFolders.remove(info.id);
540 sDbIconCache.remove(info);
541 sWorkspaceItems.remove(info);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700542
Michael Jurkac9d95c52011-08-29 14:03:34 -0700543 cr.delete(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
544 LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
545 for (ItemInfo childInfo : info.contents) {
546 sItemsIdMap.remove(childInfo.id);
547 sDbIconCache.remove(childInfo);
Adam Cohenafb01ee2011-06-23 15:38:03 -0700548 }
Michael Jurkac9d95c52011-08-29 14:03:34 -0700549 }
550 };
551 if (sWorkerThread.getThreadId() == Process.myTid()) {
552 r.run();
553 } else {
554 sWorker.post(r);
555 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400556 }
557
558 /**
559 * Set this as the current Launcher activity object for the loader.
560 */
561 public void initialize(Callbacks callbacks) {
562 synchronized (mLock) {
563 mCallbacks = new WeakReference<Callbacks>(callbacks);
564 }
565 }
566
Joe Onorato1d8e7bb2009-10-15 19:49:43 -0700567 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400568 * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
569 * ACTION_PACKAGE_CHANGED.
570 */
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100571 @Override
Joe Onoratof99f8c12009-10-31 17:27:36 -0400572 public void onReceive(Context context, Intent intent) {
Joe Onorato36115782010-06-17 13:28:48 -0400573 if (DEBUG_LOADERS) Log.d(TAG, "onReceive intent=" + intent);
Winson Chungaafa03c2010-06-11 17:34:16 -0700574
Joe Onorato36115782010-06-17 13:28:48 -0400575 final String action = intent.getAction();
Joe Onoratof99f8c12009-10-31 17:27:36 -0400576
Joe Onorato36115782010-06-17 13:28:48 -0400577 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
578 || Intent.ACTION_PACKAGE_REMOVED.equals(action)
579 || Intent.ACTION_PACKAGE_ADDED.equals(action)) {
580 final String packageName = intent.getData().getSchemeSpecificPart();
581 final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400582
Joe Onorato36115782010-06-17 13:28:48 -0400583 int op = PackageUpdatedTask.OP_NONE;
584
585 if (packageName == null || packageName.length() == 0) {
586 // they sent us a bad intent
587 return;
588 }
589
590 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
591 op = PackageUpdatedTask.OP_UPDATE;
592 } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
593 if (!replacing) {
594 op = PackageUpdatedTask.OP_REMOVE;
595 }
596 // else, we are replacing the package, so a PACKAGE_ADDED will be sent
597 // later, we will update the package at this time
598 } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
599 if (!replacing) {
600 op = PackageUpdatedTask.OP_ADD;
601 } else {
602 op = PackageUpdatedTask.OP_UPDATE;
603 }
604 }
605
606 if (op != PackageUpdatedTask.OP_NONE) {
607 enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packageName }));
608 }
609
610 } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
Joe Onoratocec58332010-10-07 14:37:40 -0400611 // First, schedule to add these apps back in.
612 String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
613 enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_ADD, packages));
614 // Then, rebind everything.
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700615 startLoaderFromBackground();
Joe Onorato36115782010-06-17 13:28:48 -0400616 } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
617 String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
618 enqueuePackageUpdated(new PackageUpdatedTask(
619 PackageUpdatedTask.OP_UNAVAILABLE, packages));
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700620 } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
Reena Lee93f824a2011-09-23 17:20:28 -0700621 // If we have changed locale we need to clear out the labels in all apps/workspace.
622 forceReload();
623 } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
624 // Check if configuration change was an mcc/mnc change which would affect app resources
625 // and we would need to clear out the labels in all apps/workspace. Same handling as
626 // above for ACTION_LOCALE_CHANGED
627 Configuration currentConfig = context.getResources().getConfiguration();
Reena Lee99a73f32011-10-24 17:27:37 -0700628 if (mPreviousConfigMcc != currentConfig.mcc) {
Reena Lee93f824a2011-09-23 17:20:28 -0700629 Log.d(TAG, "Reload apps on config change. curr_mcc:"
Reena Lee99a73f32011-10-24 17:27:37 -0700630 + currentConfig.mcc + " prevmcc:" + mPreviousConfigMcc);
Reena Lee93f824a2011-09-23 17:20:28 -0700631 forceReload();
632 }
633 // Update previousConfig
Reena Lee99a73f32011-10-24 17:27:37 -0700634 mPreviousConfigMcc = currentConfig.mcc;
Winson Chungcbf7c4d2011-08-23 11:58:54 -0700635 } else if (SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED.equals(action) ||
636 SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED.equals(action)) {
Michael Jurkaec9788e2011-08-29 11:24:45 -0700637 if (mCallbacks != null) {
638 Callbacks callbacks = mCallbacks.get();
639 if (callbacks != null) {
640 callbacks.bindSearchablesChanged();
641 }
Winson Chungcfdf7ee2011-08-25 11:38:34 -0700642 }
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700643 }
644 }
645
Reena Lee93f824a2011-09-23 17:20:28 -0700646 private void forceReload() {
647 synchronized (mLock) {
648 // Stop any existing loaders first, so they don't set mAllAppsLoaded or
649 // mWorkspaceLoaded to true later
650 stopLoaderLocked();
651 mAllAppsLoaded = false;
652 mWorkspaceLoaded = false;
653 }
654 // Do this here because if the launcher activity is running it will be restarted.
655 // If it's not running startLoaderFromBackground will merely tell it that it needs
656 // to reload.
657 startLoaderFromBackground();
658 }
659
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700660 /**
661 * When the launcher is in the background, it's possible for it to miss paired
662 * configuration changes. So whenever we trigger the loader from the background
663 * tell the launcher that it needs to re-run the loader when it comes back instead
664 * of doing it now.
665 */
666 public void startLoaderFromBackground() {
667 boolean runLoader = false;
668 if (mCallbacks != null) {
669 Callbacks callbacks = mCallbacks.get();
670 if (callbacks != null) {
671 // Only actually run the loader if they're not paused.
672 if (!callbacks.setLoadOnResume()) {
673 runLoader = true;
674 }
675 }
676 }
677 if (runLoader) {
678 startLoader(mApp, false);
Joe Onorato790c2d92010-06-11 00:14:11 -0700679 }
Joe Onorato36115782010-06-17 13:28:48 -0400680 }
Joe Onoratof99f8c12009-10-31 17:27:36 -0400681
Reena Lee93f824a2011-09-23 17:20:28 -0700682 // If there is already a loader task running, tell it to stop.
683 // returns true if isLaunching() was true on the old task
684 private boolean stopLoaderLocked() {
685 boolean isLaunching = false;
686 LoaderTask oldTask = mLoaderTask;
687 if (oldTask != null) {
688 if (oldTask.isLaunching()) {
689 isLaunching = true;
690 }
691 oldTask.stopLocked();
692 }
693 return isLaunching;
694 }
695
Joe Onorato36115782010-06-17 13:28:48 -0400696 public void startLoader(Context context, boolean isLaunching) {
697 synchronized (mLock) {
698 if (DEBUG_LOADERS) {
699 Log.d(TAG, "startLoader isLaunching=" + isLaunching);
700 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400701
Joe Onorato36115782010-06-17 13:28:48 -0400702 // Don't bother to start the thread if we know it's not going to do anything
703 if (mCallbacks != null && mCallbacks.get() != null) {
704 // If there is already one running, tell it to stop.
Reena Lee93f824a2011-09-23 17:20:28 -0700705 // also, don't downgrade isLaunching if we're already running
706 isLaunching = isLaunching || stopLoaderLocked();
Joe Onorato36115782010-06-17 13:28:48 -0400707 mLoaderTask = new LoaderTask(context, isLaunching);
Winson Chung7ed37742011-09-08 15:45:51 -0700708 sWorkerThread.setPriority(Thread.NORM_PRIORITY);
Brad Fitzpatrick700889f2010-10-11 09:40:44 -0700709 sWorker.post(mLoaderTask);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400710 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400711 }
712 }
713
Joe Onorato36115782010-06-17 13:28:48 -0400714 public void stopLoader() {
715 synchronized (mLock) {
716 if (mLoaderTask != null) {
717 mLoaderTask.stopLocked();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400718 }
719 }
Joe Onorato36115782010-06-17 13:28:48 -0400720 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400721
Michael Jurkac57b7a82011-08-09 22:02:20 -0700722 public boolean isAllAppsLoaded() {
723 return mAllAppsLoaded;
724 }
725
Joe Onorato36115782010-06-17 13:28:48 -0400726 /**
727 * Runnable for the thread that loads the contents of the launcher:
728 * - workspace icons
729 * - widgets
730 * - all apps icons
731 */
732 private class LoaderTask implements Runnable {
733 private Context mContext;
734 private Thread mWaitThread;
735 private boolean mIsLaunching;
736 private boolean mStopped;
737 private boolean mLoadAndBindStepFinished;
Winson Chungc3eecff2011-07-11 17:44:15 -0700738 private HashMap<Object, CharSequence> mLabelCache;
Joe Onorato36115782010-06-17 13:28:48 -0400739
740 LoaderTask(Context context, boolean isLaunching) {
741 mContext = context;
742 mIsLaunching = isLaunching;
Winson Chungc3eecff2011-07-11 17:44:15 -0700743 mLabelCache = new HashMap<Object, CharSequence>();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400744 }
745
Joe Onorato36115782010-06-17 13:28:48 -0400746 boolean isLaunching() {
747 return mIsLaunching;
748 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400749
Joe Onorato36115782010-06-17 13:28:48 -0400750 private void loadAndBindWorkspace() {
751 // Load the workspace
Joe Onorato36115782010-06-17 13:28:48 -0400752 if (DEBUG_LOADERS) {
753 Log.d(TAG, "loadAndBindWorkspace mWorkspaceLoaded=" + mWorkspaceLoaded);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400754 }
Michael Jurka288a36b2011-07-12 16:53:48 -0700755
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700756 if (!mWorkspaceLoaded) {
Joe Onorato36115782010-06-17 13:28:48 -0400757 loadWorkspace();
Reena Lee93f824a2011-09-23 17:20:28 -0700758 synchronized (LoaderTask.this) {
759 if (mStopped) {
760 return;
761 }
762 mWorkspaceLoaded = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400763 }
764 }
765
Joe Onorato36115782010-06-17 13:28:48 -0400766 // Bind the workspace
767 bindWorkspace();
768 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400769
Joe Onorato36115782010-06-17 13:28:48 -0400770 private void waitForIdle() {
771 // Wait until the either we're stopped or the other threads are done.
772 // This way we don't start loading all apps until the workspace has settled
773 // down.
774 synchronized (LoaderTask.this) {
775 final long workspaceWaitTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
Joe Onoratocc67f472010-06-08 10:54:30 -0700776
Joe Onorato36115782010-06-17 13:28:48 -0400777 mHandler.postIdle(new Runnable() {
778 public void run() {
779 synchronized (LoaderTask.this) {
780 mLoadAndBindStepFinished = true;
781 if (DEBUG_LOADERS) {
782 Log.d(TAG, "done with previous binding step");
Daniel Sandler843e8602010-06-07 14:59:01 -0400783 }
Joe Onorato36115782010-06-17 13:28:48 -0400784 LoaderTask.this.notify();
Daniel Sandler843e8602010-06-07 14:59:01 -0400785 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400786 }
Joe Onorato36115782010-06-17 13:28:48 -0400787 });
788
789 while (!mStopped && !mLoadAndBindStepFinished) {
790 try {
791 this.wait();
792 } catch (InterruptedException ex) {
793 // Ignore
Daniel Sandler843e8602010-06-07 14:59:01 -0400794 }
795 }
Joe Onorato36115782010-06-17 13:28:48 -0400796 if (DEBUG_LOADERS) {
797 Log.d(TAG, "waited "
Winson Chungaafa03c2010-06-11 17:34:16 -0700798 + (SystemClock.uptimeMillis()-workspaceWaitTime)
Joe Onorato36115782010-06-17 13:28:48 -0400799 + "ms for previous step to finish binding");
800 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400801 }
Joe Onorato36115782010-06-17 13:28:48 -0400802 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400803
Joe Onorato36115782010-06-17 13:28:48 -0400804 public void run() {
805 // Optimize for end-user experience: if the Launcher is up and // running with the
806 // All Apps interface in the foreground, load All Apps first. Otherwise, load the
807 // workspace first (default).
808 final Callbacks cbk = mCallbacks.get();
809 final boolean loadWorkspaceFirst = cbk != null ? (!cbk.isAllAppsVisible()) : true;
Daniel Sandler843e8602010-06-07 14:59:01 -0400810
Joe Onorato36115782010-06-17 13:28:48 -0400811 keep_running: {
Daniel Sandler843e8602010-06-07 14:59:01 -0400812 // Elevate priority when Home launches for the first time to avoid
813 // starving at boot time. Staring at a blank home is not cool.
814 synchronized (mLock) {
Winson Chungaac01e12011-08-17 10:37:13 -0700815 if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to " +
816 (mIsLaunching ? "DEFAULT" : "BACKGROUND"));
Daniel Sandler843e8602010-06-07 14:59:01 -0400817 android.os.Process.setThreadPriority(mIsLaunching
818 ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
819 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400820 if (loadWorkspaceFirst) {
821 if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace");
822 loadAndBindWorkspace();
823 } else {
824 if (DEBUG_LOADERS) Log.d(TAG, "step 1: special: loading all apps");
Joe Onoratocc67f472010-06-08 10:54:30 -0700825 loadAndBindAllApps();
Daniel Sandler843e8602010-06-07 14:59:01 -0400826 }
827
Joe Onorato36115782010-06-17 13:28:48 -0400828 if (mStopped) {
829 break keep_running;
830 }
831
832 // Whew! Hard work done. Slow us down, and wait until the UI thread has
833 // settled down.
Daniel Sandler843e8602010-06-07 14:59:01 -0400834 synchronized (mLock) {
835 if (mIsLaunching) {
Winson Chungaac01e12011-08-17 10:37:13 -0700836 if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to BACKGROUND");
Daniel Sandler843e8602010-06-07 14:59:01 -0400837 android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
838 }
839 }
Joe Onorato36115782010-06-17 13:28:48 -0400840 waitForIdle();
Daniel Sandler843e8602010-06-07 14:59:01 -0400841
842 // second step
843 if (loadWorkspaceFirst) {
844 if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps");
Joe Onoratocc67f472010-06-08 10:54:30 -0700845 loadAndBindAllApps();
Daniel Sandler843e8602010-06-07 14:59:01 -0400846 } else {
847 if (DEBUG_LOADERS) Log.d(TAG, "step 2: special: loading workspace");
848 loadAndBindWorkspace();
849 }
Winson Chung7ed37742011-09-08 15:45:51 -0700850
851 // Restore the default thread priority after we are done loading items
852 synchronized (mLock) {
853 android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
854 }
Joe Onorato36115782010-06-17 13:28:48 -0400855 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400856
Winson Chungaac01e12011-08-17 10:37:13 -0700857
858 // Update the saved icons if necessary
859 if (DEBUG_LOADERS) Log.d(TAG, "Comparing loaded icons to database icons");
Winson Chungb1094bd2011-08-24 16:14:08 -0700860 for (Object key : sDbIconCache.keySet()) {
861 updateSavedIcon(mContext, (ShortcutInfo) key, sDbIconCache.get(key));
Winson Chungaac01e12011-08-17 10:37:13 -0700862 }
Winson Chungb1094bd2011-08-24 16:14:08 -0700863 sDbIconCache.clear();
Winson Chungaac01e12011-08-17 10:37:13 -0700864
Joe Onorato36115782010-06-17 13:28:48 -0400865 // Clear out this reference, otherwise we end up holding it until all of the
866 // callback runnables are done.
867 mContext = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400868
Joe Onorato36115782010-06-17 13:28:48 -0400869 synchronized (mLock) {
870 // If we are still the last one to be scheduled, remove ourselves.
871 if (mLoaderTask == this) {
872 mLoaderTask = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400873 }
Joe Onorato36115782010-06-17 13:28:48 -0400874 }
Joe Onorato36115782010-06-17 13:28:48 -0400875 }
876
877 public void stopLocked() {
878 synchronized (LoaderTask.this) {
879 mStopped = true;
880 this.notify();
881 }
882 }
883
884 /**
885 * Gets the callbacks object. If we've been stopped, or if the launcher object
886 * has somehow been garbage collected, return null instead. Pass in the Callbacks
887 * object that was around when the deferred message was scheduled, and if there's
888 * a new Callbacks object around then also return null. This will save us from
889 * calling onto it with data that will be ignored.
890 */
891 Callbacks tryGetCallbacks(Callbacks oldCallbacks) {
892 synchronized (mLock) {
893 if (mStopped) {
894 return null;
Daniel Sandler8802e962010-05-26 16:28:16 -0400895 }
Joe Onorato36115782010-06-17 13:28:48 -0400896
897 if (mCallbacks == null) {
898 return null;
Daniel Sandler8802e962010-05-26 16:28:16 -0400899 }
Joe Onorato36115782010-06-17 13:28:48 -0400900
901 final Callbacks callbacks = mCallbacks.get();
902 if (callbacks != oldCallbacks) {
903 return null;
904 }
905 if (callbacks == null) {
906 Log.w(TAG, "no mCallbacks");
907 return null;
908 }
909
910 return callbacks;
911 }
912 }
913
914 // check & update map of what's occupied; used to discard overlapping/invalid items
915 private boolean checkItemPlacement(ItemInfo occupied[][][], ItemInfo item) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700916 int containerIndex = item.screen;
917 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700918 // Return early if we detect that an item is under the hotseat button
919 if (Hotseat.isAllAppsButtonRank(item.screen)) {
920 return false;
921 }
Winson Chung6ba2a1b2011-09-02 16:22:11 -0700922
923 // We use the last index to refer to the hotseat and the screen as the rank, so
924 // test and update the occupied state accordingly
925 if (occupied[Launcher.SCREEN_COUNT][item.screen][0] != null) {
926 Log.e(TAG, "Error loading shortcut into hotseat " + item
927 + " into position (" + item.screen + ":" + item.cellX + "," + item.cellY
928 + ") occupied by " + occupied[Launcher.SCREEN_COUNT][item.screen][0]);
929 return false;
930 } else {
931 occupied[Launcher.SCREEN_COUNT][item.screen][0] = item;
932 return true;
933 }
Winson Chungf30ad5f2011-08-08 10:55:42 -0700934 } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
935 // Skip further checking if it is not the hotseat or workspace container
Daniel Sandler8802e962010-05-26 16:28:16 -0400936 return true;
937 }
Winson Chungf30ad5f2011-08-08 10:55:42 -0700938
Winson Chung6ba2a1b2011-09-02 16:22:11 -0700939 // Check if any workspace icons overlap with each other
Joe Onorato36115782010-06-17 13:28:48 -0400940 for (int x = item.cellX; x < (item.cellX+item.spanX); x++) {
941 for (int y = item.cellY; y < (item.cellY+item.spanY); y++) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700942 if (occupied[containerIndex][x][y] != null) {
Joe Onorato36115782010-06-17 13:28:48 -0400943 Log.e(TAG, "Error loading shortcut " + item
Winson Chungf30ad5f2011-08-08 10:55:42 -0700944 + " into cell (" + containerIndex + "-" + item.screen + ":"
Joe Onorato36115782010-06-17 13:28:48 -0400945 + x + "," + y
Winson Chungaafa03c2010-06-11 17:34:16 -0700946 + ") occupied by "
Winson Chungf30ad5f2011-08-08 10:55:42 -0700947 + occupied[containerIndex][x][y]);
Joe Onorato36115782010-06-17 13:28:48 -0400948 return false;
949 }
950 }
951 }
952 for (int x = item.cellX; x < (item.cellX+item.spanX); x++) {
953 for (int y = item.cellY; y < (item.cellY+item.spanY); y++) {
Winson Chungf30ad5f2011-08-08 10:55:42 -0700954 occupied[containerIndex][x][y] = item;
Joe Onorato36115782010-06-17 13:28:48 -0400955 }
956 }
Winson Chungf30ad5f2011-08-08 10:55:42 -0700957
Joe Onorato36115782010-06-17 13:28:48 -0400958 return true;
959 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400960
Joe Onorato36115782010-06-17 13:28:48 -0400961 private void loadWorkspace() {
962 final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400963
Joe Onorato36115782010-06-17 13:28:48 -0400964 final Context context = mContext;
965 final ContentResolver contentResolver = context.getContentResolver();
966 final PackageManager manager = context.getPackageManager();
967 final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
968 final boolean isSafeMode = manager.isSafeMode();
Joe Onorato3c2f7e12009-10-31 19:17:31 -0400969
Adam Cohen4eac29a2011-07-11 17:53:37 -0700970 sWorkspaceItems.clear();
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700971 sAppWidgets.clear();
972 sFolders.clear();
973 sItemsIdMap.clear();
Winson Chungb1094bd2011-08-24 16:14:08 -0700974 sDbIconCache.clear();
Romain Guy5c16f3e2010-01-12 17:24:58 -0800975
Joe Onorato36115782010-06-17 13:28:48 -0400976 final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400977
Joe Onorato36115782010-06-17 13:28:48 -0400978 final Cursor c = contentResolver.query(
Winson Chunge61e93e2011-09-12 10:59:49 -0700979 LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
Daniel Sandler8802e962010-05-26 16:28:16 -0400980
Winson Chungf30ad5f2011-08-08 10:55:42 -0700981 // +1 for the hotseat (it can be larger than the workspace)
Winson Chung36f97362011-09-07 11:20:10 -0700982 // Load workspace in reverse order to ensure that latest items are loaded first (and
983 // before any earlier duplicates)
Adam Cohend22015c2010-07-26 22:02:18 -0700984 final ItemInfo occupied[][][] =
Winson Chungf30ad5f2011-08-08 10:55:42 -0700985 new ItemInfo[Launcher.SCREEN_COUNT + 1][mCellCountX + 1][mCellCountY + 1];
Joe Onorato9c1289c2009-08-17 11:03:03 -0400986
Joe Onorato36115782010-06-17 13:28:48 -0400987 try {
988 final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
989 final int intentIndex = c.getColumnIndexOrThrow
990 (LauncherSettings.Favorites.INTENT);
991 final int titleIndex = c.getColumnIndexOrThrow
992 (LauncherSettings.Favorites.TITLE);
993 final int iconTypeIndex = c.getColumnIndexOrThrow(
994 LauncherSettings.Favorites.ICON_TYPE);
995 final int iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
996 final int iconPackageIndex = c.getColumnIndexOrThrow(
997 LauncherSettings.Favorites.ICON_PACKAGE);
998 final int iconResourceIndex = c.getColumnIndexOrThrow(
999 LauncherSettings.Favorites.ICON_RESOURCE);
1000 final int containerIndex = c.getColumnIndexOrThrow(
1001 LauncherSettings.Favorites.CONTAINER);
1002 final int itemTypeIndex = c.getColumnIndexOrThrow(
1003 LauncherSettings.Favorites.ITEM_TYPE);
1004 final int appWidgetIdIndex = c.getColumnIndexOrThrow(
1005 LauncherSettings.Favorites.APPWIDGET_ID);
1006 final int screenIndex = c.getColumnIndexOrThrow(
1007 LauncherSettings.Favorites.SCREEN);
1008 final int cellXIndex = c.getColumnIndexOrThrow
1009 (LauncherSettings.Favorites.CELLX);
1010 final int cellYIndex = c.getColumnIndexOrThrow
1011 (LauncherSettings.Favorites.CELLY);
1012 final int spanXIndex = c.getColumnIndexOrThrow
1013 (LauncherSettings.Favorites.SPANX);
1014 final int spanYIndex = c.getColumnIndexOrThrow(
1015 LauncherSettings.Favorites.SPANY);
1016 final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI);
1017 final int displayModeIndex = c.getColumnIndexOrThrow(
1018 LauncherSettings.Favorites.DISPLAY_MODE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001019
Joe Onorato36115782010-06-17 13:28:48 -04001020 ShortcutInfo info;
1021 String intentDescription;
1022 LauncherAppWidgetInfo appWidgetInfo;
1023 int container;
1024 long id;
1025 Intent intent;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001026
Joe Onorato36115782010-06-17 13:28:48 -04001027 while (!mStopped && c.moveToNext()) {
1028 try {
1029 int itemType = c.getInt(itemTypeIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001030
Joe Onorato36115782010-06-17 13:28:48 -04001031 switch (itemType) {
1032 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1033 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
1034 intentDescription = c.getString(intentIndex);
1035 try {
1036 intent = Intent.parseUri(intentDescription, 0);
1037 } catch (URISyntaxException e) {
1038 continue;
1039 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001040
Joe Onorato36115782010-06-17 13:28:48 -04001041 if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
1042 info = getShortcutInfo(manager, intent, context, c, iconIndex,
Winson Chungc3eecff2011-07-11 17:44:15 -07001043 titleIndex, mLabelCache);
Joe Onorato36115782010-06-17 13:28:48 -04001044 } else {
1045 info = getShortcutInfo(c, context, iconTypeIndex,
1046 iconPackageIndex, iconResourceIndex, iconIndex,
1047 titleIndex);
1048 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001049
Joe Onorato36115782010-06-17 13:28:48 -04001050 if (info != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001051 info.intent = intent;
1052 info.id = c.getLong(idIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001053 container = c.getInt(containerIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001054 info.container = container;
1055 info.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -07001056 info.cellX = c.getInt(cellXIndex);
1057 info.cellY = c.getInt(cellYIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001058
Daniel Sandler8802e962010-05-26 16:28:16 -04001059 // check & update map of what's occupied
Joe Onorato36115782010-06-17 13:28:48 -04001060 if (!checkItemPlacement(occupied, info)) {
Daniel Sandler8802e962010-05-26 16:28:16 -04001061 break;
1062 }
1063
Joe Onorato9c1289c2009-08-17 11:03:03 -04001064 switch (container) {
Joe Onorato36115782010-06-17 13:28:48 -04001065 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
Winson Chung3d503fb2011-07-13 17:25:49 -07001066 case LauncherSettings.Favorites.CONTAINER_HOTSEAT:
Adam Cohen4eac29a2011-07-11 17:53:37 -07001067 sWorkspaceItems.add(info);
Joe Onorato36115782010-06-17 13:28:48 -04001068 break;
1069 default:
1070 // Item is in a user folder
Adam Cohendf2cc412011-04-27 16:56:57 -07001071 FolderInfo folderInfo =
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001072 findOrMakeFolder(sFolders, container);
Joe Onorato36115782010-06-17 13:28:48 -04001073 folderInfo.add(info);
1074 break;
1075 }
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001076 sItemsIdMap.put(info.id, info);
Joe Onorato17a89222011-02-08 17:26:11 -08001077
1078 // now that we've loaded everthing re-save it with the
1079 // icon in case it disappears somehow.
Winson Chungb1094bd2011-08-24 16:14:08 -07001080 queueIconToBeChecked(sDbIconCache, info, c, iconIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001081 } else {
1082 // Failed to load the shortcut, probably because the
1083 // activity manager couldn't resolve it (maybe the app
1084 // was uninstalled), or the db row was somehow screwed up.
1085 // Delete it.
1086 id = c.getLong(idIndex);
1087 Log.e(TAG, "Error loading shortcut " + id + ", removing it");
1088 contentResolver.delete(LauncherSettings.Favorites.getContentUri(
1089 id, false), null, null);
1090 }
1091 break;
1092
Adam Cohendf2cc412011-04-27 16:56:57 -07001093 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Joe Onorato36115782010-06-17 13:28:48 -04001094 id = c.getLong(idIndex);
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001095 FolderInfo folderInfo = findOrMakeFolder(sFolders, id);
Joe Onorato36115782010-06-17 13:28:48 -04001096
Winson Chungaafa03c2010-06-11 17:34:16 -07001097 folderInfo.title = c.getString(titleIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001098 folderInfo.id = id;
1099 container = c.getInt(containerIndex);
1100 folderInfo.container = container;
1101 folderInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -07001102 folderInfo.cellX = c.getInt(cellXIndex);
1103 folderInfo.cellY = c.getInt(cellYIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001104
1105 // check & update map of what's occupied
1106 if (!checkItemPlacement(occupied, folderInfo)) {
1107 break;
1108 }
Joe Onorato36115782010-06-17 13:28:48 -04001109 switch (container) {
1110 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
Winson Chung3d503fb2011-07-13 17:25:49 -07001111 case LauncherSettings.Favorites.CONTAINER_HOTSEAT:
Adam Cohen4eac29a2011-07-11 17:53:37 -07001112 sWorkspaceItems.add(folderInfo);
Joe Onorato36115782010-06-17 13:28:48 -04001113 break;
1114 }
1115
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001116 sItemsIdMap.put(folderInfo.id, folderInfo);
1117 sFolders.put(folderInfo.id, folderInfo);
Joe Onorato36115782010-06-17 13:28:48 -04001118 break;
1119
Joe Onorato36115782010-06-17 13:28:48 -04001120 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
1121 // Read all Launcher-specific widget details
1122 int appWidgetId = c.getInt(appWidgetIdIndex);
1123 id = c.getLong(idIndex);
1124
1125 final AppWidgetProviderInfo provider =
1126 widgets.getAppWidgetInfo(appWidgetId);
Winson Chungaafa03c2010-06-11 17:34:16 -07001127
Joe Onorato36115782010-06-17 13:28:48 -04001128 if (!isSafeMode && (provider == null || provider.provider == null ||
1129 provider.provider.getPackageName() == null)) {
Adam Cohen16d7ffc2011-10-05 17:49:14 -07001130 String log = "Deleting widget that isn't installed anymore: id="
1131 + id + " appWidgetId=" + appWidgetId;
1132 Log.e(TAG, log);
1133 Launcher.sDumpLogs.add(log);
Joe Onorato36115782010-06-17 13:28:48 -04001134 itemsToRemove.add(id);
1135 } else {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001136 appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId);
Joe Onorato36115782010-06-17 13:28:48 -04001137 appWidgetInfo.id = id;
1138 appWidgetInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -07001139 appWidgetInfo.cellX = c.getInt(cellXIndex);
1140 appWidgetInfo.cellY = c.getInt(cellYIndex);
1141 appWidgetInfo.spanX = c.getInt(spanXIndex);
1142 appWidgetInfo.spanY = c.getInt(spanYIndex);
Joe Onorato36115782010-06-17 13:28:48 -04001143
1144 container = c.getInt(containerIndex);
Winson Chung3d503fb2011-07-13 17:25:49 -07001145 if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP &&
1146 container != LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
Joe Onorato36115782010-06-17 13:28:48 -04001147 Log.e(TAG, "Widget found where container "
Winson Chung3d503fb2011-07-13 17:25:49 -07001148 + "!= CONTAINER_DESKTOP nor CONTAINER_HOTSEAT - ignoring!");
Joe Onorato36115782010-06-17 13:28:48 -04001149 continue;
1150 }
1151 appWidgetInfo.container = c.getInt(containerIndex);
1152
1153 // check & update map of what's occupied
1154 if (!checkItemPlacement(occupied, appWidgetInfo)) {
1155 break;
1156 }
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001157 sItemsIdMap.put(appWidgetInfo.id, appWidgetInfo);
1158 sAppWidgets.add(appWidgetInfo);
Joe Onorato36115782010-06-17 13:28:48 -04001159 }
1160 break;
Romain Guy5c16f3e2010-01-12 17:24:58 -08001161 }
Joe Onorato36115782010-06-17 13:28:48 -04001162 } catch (Exception e) {
1163 Log.w(TAG, "Desktop items loading interrupted:", e);
Romain Guy5c16f3e2010-01-12 17:24:58 -08001164 }
1165 }
Joe Onorato36115782010-06-17 13:28:48 -04001166 } finally {
1167 c.close();
1168 }
Romain Guy5c16f3e2010-01-12 17:24:58 -08001169
Joe Onorato36115782010-06-17 13:28:48 -04001170 if (itemsToRemove.size() > 0) {
1171 ContentProviderClient client = contentResolver.acquireContentProviderClient(
1172 LauncherSettings.Favorites.CONTENT_URI);
1173 // Remove dead items
1174 for (long id : itemsToRemove) {
1175 if (DEBUG_LOADERS) {
1176 Log.d(TAG, "Removed id = " + id);
1177 }
1178 // Don't notify content observers
1179 try {
1180 client.delete(LauncherSettings.Favorites.getContentUri(id, false),
1181 null, null);
1182 } catch (RemoteException e) {
1183 Log.w(TAG, "Could not remove id = " + id);
Daniel Sandler8802e962010-05-26 16:28:16 -04001184 }
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001185 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001186 }
1187
Joe Onorato36115782010-06-17 13:28:48 -04001188 if (DEBUG_LOADERS) {
1189 Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms");
1190 Log.d(TAG, "workspace layout: ");
Adam Cohend22015c2010-07-26 22:02:18 -07001191 for (int y = 0; y < mCellCountY; y++) {
Joe Onorato36115782010-06-17 13:28:48 -04001192 String line = "";
1193 for (int s = 0; s < Launcher.SCREEN_COUNT; s++) {
1194 if (s > 0) {
1195 line += " | ";
1196 }
Adam Cohend22015c2010-07-26 22:02:18 -07001197 for (int x = 0; x < mCellCountX; x++) {
Joe Onorato36115782010-06-17 13:28:48 -04001198 line += ((occupied[s][x][y] != null) ? "#" : ".");
1199 }
1200 }
1201 Log.d(TAG, "[ " + line + " ]");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001202 }
Joe Onorato36115782010-06-17 13:28:48 -04001203 }
1204 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001205
Joe Onorato36115782010-06-17 13:28:48 -04001206 /**
1207 * Read everything out of our database.
1208 */
1209 private void bindWorkspace() {
1210 final long t = SystemClock.uptimeMillis();
1211
1212 // Don't use these two variables in any of the callback runnables.
1213 // Otherwise we hold a reference to them.
1214 final Callbacks oldCallbacks = mCallbacks.get();
1215 if (oldCallbacks == null) {
1216 // This launcher has exited and nobody bothered to tell us. Just bail.
1217 Log.w(TAG, "LoaderTask running with no launcher");
1218 return;
1219 }
1220
1221 int N;
1222 // Tell the workspace that we're about to start firing items at it
1223 mHandler.post(new Runnable() {
1224 public void run() {
1225 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1226 if (callbacks != null) {
1227 callbacks.startBinding();
1228 }
1229 }
1230 });
Winson Chung603bcb92011-09-02 11:45:39 -07001231
1232 // Unbind previously bound workspace items to prevent a leak of AppWidgetHostViews.
1233 final ArrayList<ItemInfo> workspaceItems = unbindWorkspaceItemsOnMainThread();
1234
Joe Onorato36115782010-06-17 13:28:48 -04001235 // Add the items to the workspace.
Winson Chung603bcb92011-09-02 11:45:39 -07001236 N = workspaceItems.size();
Joe Onorato36115782010-06-17 13:28:48 -04001237 for (int i=0; i<N; i+=ITEMS_CHUNK) {
1238 final int start = i;
1239 final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001240 mHandler.post(new Runnable() {
1241 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -08001242 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001243 if (callbacks != null) {
Winson Chung603bcb92011-09-02 11:45:39 -07001244 callbacks.bindItems(workspaceItems, start, start+chunkSize);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001245 }
1246 }
1247 });
Joe Onorato36115782010-06-17 13:28:48 -04001248 }
Winson Chung603bcb92011-09-02 11:45:39 -07001249 // Ensure that we don't use the same folders data structure on the main thread
1250 final HashMap<Long, FolderInfo> folders = new HashMap<Long, FolderInfo>(sFolders);
Joe Onorato36115782010-06-17 13:28:48 -04001251 mHandler.post(new Runnable() {
1252 public void run() {
1253 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1254 if (callbacks != null) {
Winson Chung603bcb92011-09-02 11:45:39 -07001255 callbacks.bindFolders(folders);
Joe Onorato36115782010-06-17 13:28:48 -04001256 }
1257 }
1258 });
1259 // Wait until the queue goes empty.
1260 mHandler.post(new Runnable() {
1261 public void run() {
1262 if (DEBUG_LOADERS) {
1263 Log.d(TAG, "Going to start binding widgets soon.");
1264 }
1265 }
1266 });
1267 // Bind the widgets, one at a time.
1268 // WARNING: this is calling into the workspace from the background thread,
1269 // but since getCurrentScreen() just returns the int, we should be okay. This
1270 // is just a hint for the order, and if it's wrong, we'll be okay.
1271 // TODO: instead, we should have that push the current screen into here.
1272 final int currentScreen = oldCallbacks.getCurrentWorkspaceScreen();
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001273 N = sAppWidgets.size();
Joe Onorato36115782010-06-17 13:28:48 -04001274 // once for the current screen
1275 for (int i=0; i<N; i++) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001276 final LauncherAppWidgetInfo widget = sAppWidgets.get(i);
Joe Onorato36115782010-06-17 13:28:48 -04001277 if (widget.screen == currentScreen) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001278 mHandler.post(new Runnable() {
1279 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -08001280 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001281 if (callbacks != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001282 callbacks.bindAppWidget(widget);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001283 }
1284 }
1285 });
1286 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001287 }
Joe Onorato36115782010-06-17 13:28:48 -04001288 // once for the other screens
1289 for (int i=0; i<N; i++) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001290 final LauncherAppWidgetInfo widget = sAppWidgets.get(i);
Joe Onorato36115782010-06-17 13:28:48 -04001291 if (widget.screen != currentScreen) {
1292 mHandler.post(new Runnable() {
1293 public void run() {
1294 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1295 if (callbacks != null) {
1296 callbacks.bindAppWidget(widget);
1297 }
1298 }
1299 });
Joe Onoratocc67f472010-06-08 10:54:30 -07001300 }
1301 }
Joe Onorato36115782010-06-17 13:28:48 -04001302 // Tell the workspace that we're done.
1303 mHandler.post(new Runnable() {
1304 public void run() {
1305 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1306 if (callbacks != null) {
1307 callbacks.finishBindingItems();
1308 }
1309 }
1310 });
1311 // If we're profiling, this is the last thing in the queue.
1312 mHandler.post(new Runnable() {
1313 public void run() {
1314 if (DEBUG_LOADERS) {
1315 Log.d(TAG, "bound workspace in "
1316 + (SystemClock.uptimeMillis()-t) + "ms");
1317 }
1318 }
1319 });
1320 }
Joe Onoratocc67f472010-06-08 10:54:30 -07001321
Joe Onorato36115782010-06-17 13:28:48 -04001322 private void loadAndBindAllApps() {
1323 if (DEBUG_LOADERS) {
1324 Log.d(TAG, "loadAndBindAllApps mAllAppsLoaded=" + mAllAppsLoaded);
1325 }
1326 if (!mAllAppsLoaded) {
1327 loadAllAppsByBatch();
Reena Lee93f824a2011-09-23 17:20:28 -07001328 synchronized (LoaderTask.this) {
1329 if (mStopped) {
1330 return;
1331 }
1332 mAllAppsLoaded = true;
Joe Onoratocc67f472010-06-08 10:54:30 -07001333 }
Joe Onorato36115782010-06-17 13:28:48 -04001334 } else {
1335 onlyBindAllApps();
1336 }
1337 }
Joe Onoratocc67f472010-06-08 10:54:30 -07001338
Joe Onorato36115782010-06-17 13:28:48 -04001339 private void onlyBindAllApps() {
1340 final Callbacks oldCallbacks = mCallbacks.get();
1341 if (oldCallbacks == null) {
1342 // This launcher has exited and nobody bothered to tell us. Just bail.
1343 Log.w(TAG, "LoaderTask running with no launcher (onlyBindAllApps)");
1344 return;
1345 }
1346
1347 // shallow copy
1348 final ArrayList<ApplicationInfo> list
Michael Jurka92f3d462011-11-22 21:02:29 -08001349 = (ArrayList<ApplicationInfo>) mAllAppsList.data.clone();
Joe Onorato36115782010-06-17 13:28:48 -04001350 mHandler.post(new Runnable() {
1351 public void run() {
1352 final long t = SystemClock.uptimeMillis();
1353 final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1354 if (callbacks != null) {
1355 callbacks.bindAllApplications(list);
1356 }
1357 if (DEBUG_LOADERS) {
1358 Log.d(TAG, "bound all " + list.size() + " apps from cache in "
1359 + (SystemClock.uptimeMillis()-t) + "ms");
1360 }
1361 }
1362 });
1363
1364 }
1365
1366 private void loadAllAppsByBatch() {
1367 final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1368
1369 // Don't use these two variables in any of the callback runnables.
1370 // Otherwise we hold a reference to them.
1371 final Callbacks oldCallbacks = mCallbacks.get();
1372 if (oldCallbacks == null) {
1373 // This launcher has exited and nobody bothered to tell us. Just bail.
1374 Log.w(TAG, "LoaderTask running with no launcher (loadAllAppsByBatch)");
1375 return;
1376 }
1377
1378 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1379 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
1380
1381 final PackageManager packageManager = mContext.getPackageManager();
1382 List<ResolveInfo> apps = null;
1383
1384 int N = Integer.MAX_VALUE;
1385
1386 int startIndex;
1387 int i=0;
1388 int batchSize = -1;
1389 while (i < N && !mStopped) {
1390 if (i == 0) {
1391 mAllAppsList.clear();
1392 final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1393 apps = packageManager.queryIntentActivities(mainIntent, 0);
1394 if (DEBUG_LOADERS) {
1395 Log.d(TAG, "queryIntentActivities took "
1396 + (SystemClock.uptimeMillis()-qiaTime) + "ms");
1397 }
1398 if (apps == null) {
1399 return;
1400 }
1401 N = apps.size();
1402 if (DEBUG_LOADERS) {
1403 Log.d(TAG, "queryIntentActivities got " + N + " apps");
1404 }
1405 if (N == 0) {
1406 // There are no apps?!?
1407 return;
1408 }
1409 if (mBatchSize == 0) {
1410 batchSize = N;
1411 } else {
1412 batchSize = mBatchSize;
1413 }
1414
1415 final long sortTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1416 Collections.sort(apps,
Winson Chungc3eecff2011-07-11 17:44:15 -07001417 new LauncherModel.ShortcutNameComparator(packageManager, mLabelCache));
Joe Onorato36115782010-06-17 13:28:48 -04001418 if (DEBUG_LOADERS) {
1419 Log.d(TAG, "sort took "
1420 + (SystemClock.uptimeMillis()-sortTime) + "ms");
1421 }
1422 }
1423
1424 final long t2 = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1425
1426 startIndex = i;
1427 for (int j=0; i<N && j<batchSize; j++) {
1428 // This builds the icon bitmaps.
Winson Chungc3eecff2011-07-11 17:44:15 -07001429 mAllAppsList.add(new ApplicationInfo(packageManager, apps.get(i),
Michael Jurkac9d95c52011-08-29 14:03:34 -07001430 mIconCache, mLabelCache));
Joe Onorato36115782010-06-17 13:28:48 -04001431 i++;
1432 }
1433
1434 final boolean first = i <= batchSize;
1435 final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1436 final ArrayList<ApplicationInfo> added = mAllAppsList.added;
1437 mAllAppsList.added = new ArrayList<ApplicationInfo>();
1438
Joe Onoratocc67f472010-06-08 10:54:30 -07001439 mHandler.post(new Runnable() {
1440 public void run() {
1441 final long t = SystemClock.uptimeMillis();
Joe Onoratocc67f472010-06-08 10:54:30 -07001442 if (callbacks != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001443 if (first) {
1444 callbacks.bindAllApplications(added);
1445 } else {
1446 callbacks.bindAppsAdded(added);
1447 }
1448 if (DEBUG_LOADERS) {
1449 Log.d(TAG, "bound " + added.size() + " apps in "
1450 + (SystemClock.uptimeMillis() - t) + "ms");
1451 }
1452 } else {
1453 Log.i(TAG, "not binding apps: no Launcher activity");
Joe Onoratocc67f472010-06-08 10:54:30 -07001454 }
1455 }
1456 });
1457
Daniel Sandlerdca66122010-04-13 16:23:58 -04001458 if (DEBUG_LOADERS) {
Joe Onorato36115782010-06-17 13:28:48 -04001459 Log.d(TAG, "batch of " + (i-startIndex) + " icons processed in "
1460 + (SystemClock.uptimeMillis()-t2) + "ms");
1461 }
1462
1463 if (mAllAppsLoadDelay > 0 && i < N) {
1464 try {
1465 if (DEBUG_LOADERS) {
1466 Log.d(TAG, "sleeping for " + mAllAppsLoadDelay + "ms");
1467 }
1468 Thread.sleep(mAllAppsLoadDelay);
1469 } catch (InterruptedException exc) { }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001470 }
1471 }
1472
Joe Onorato36115782010-06-17 13:28:48 -04001473 if (DEBUG_LOADERS) {
1474 Log.d(TAG, "cached all " + N + " apps in "
1475 + (SystemClock.uptimeMillis()-t) + "ms"
1476 + (mAllAppsLoadDelay > 0 ? " (including delay)" : ""));
Joe Onoratobe386092009-11-17 17:32:16 -08001477 }
1478 }
1479
1480 public void dumpState() {
Joe Onorato36115782010-06-17 13:28:48 -04001481 Log.d(TAG, "mLoaderTask.mContext=" + mContext);
1482 Log.d(TAG, "mLoaderTask.mWaitThread=" + mWaitThread);
1483 Log.d(TAG, "mLoaderTask.mIsLaunching=" + mIsLaunching);
1484 Log.d(TAG, "mLoaderTask.mStopped=" + mStopped);
1485 Log.d(TAG, "mLoaderTask.mLoadAndBindStepFinished=" + mLoadAndBindStepFinished);
Adam Cohen4eac29a2011-07-11 17:53:37 -07001486 Log.d(TAG, "mItems size=" + sWorkspaceItems.size());
Joe Onorato36115782010-06-17 13:28:48 -04001487 }
1488 }
1489
1490 void enqueuePackageUpdated(PackageUpdatedTask task) {
Brad Fitzpatrick700889f2010-10-11 09:40:44 -07001491 sWorker.post(task);
Joe Onorato36115782010-06-17 13:28:48 -04001492 }
1493
1494 private class PackageUpdatedTask implements Runnable {
1495 int mOp;
1496 String[] mPackages;
1497
1498 public static final int OP_NONE = 0;
1499 public static final int OP_ADD = 1;
1500 public static final int OP_UPDATE = 2;
1501 public static final int OP_REMOVE = 3; // uninstlled
1502 public static final int OP_UNAVAILABLE = 4; // external media unmounted
1503
1504
1505 public PackageUpdatedTask(int op, String[] packages) {
1506 mOp = op;
1507 mPackages = packages;
1508 }
1509
1510 public void run() {
1511 final Context context = mApp;
1512
1513 final String[] packages = mPackages;
1514 final int N = packages.length;
1515 switch (mOp) {
1516 case OP_ADD:
1517 for (int i=0; i<N; i++) {
1518 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
1519 mAllAppsList.addPackage(context, packages[i]);
1520 }
1521 break;
1522 case OP_UPDATE:
1523 for (int i=0; i<N; i++) {
1524 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
1525 mAllAppsList.updatePackage(context, packages[i]);
1526 }
1527 break;
1528 case OP_REMOVE:
1529 case OP_UNAVAILABLE:
1530 for (int i=0; i<N; i++) {
1531 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
1532 mAllAppsList.removePackage(packages[i]);
1533 }
1534 break;
1535 }
1536
1537 ArrayList<ApplicationInfo> added = null;
1538 ArrayList<ApplicationInfo> removed = null;
1539 ArrayList<ApplicationInfo> modified = null;
1540
1541 if (mAllAppsList.added.size() > 0) {
1542 added = mAllAppsList.added;
1543 mAllAppsList.added = new ArrayList<ApplicationInfo>();
1544 }
1545 if (mAllAppsList.removed.size() > 0) {
1546 removed = mAllAppsList.removed;
1547 mAllAppsList.removed = new ArrayList<ApplicationInfo>();
1548 for (ApplicationInfo info: removed) {
1549 mIconCache.remove(info.intent.getComponent());
1550 }
1551 }
1552 if (mAllAppsList.modified.size() > 0) {
1553 modified = mAllAppsList.modified;
1554 mAllAppsList.modified = new ArrayList<ApplicationInfo>();
1555 }
1556
1557 final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
1558 if (callbacks == null) {
1559 Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading.");
1560 return;
1561 }
1562
1563 if (added != null) {
1564 final ArrayList<ApplicationInfo> addedFinal = added;
1565 mHandler.post(new Runnable() {
1566 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001567 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1568 if (callbacks == cb && cb != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001569 callbacks.bindAppsAdded(addedFinal);
1570 }
1571 }
1572 });
1573 }
1574 if (modified != null) {
1575 final ArrayList<ApplicationInfo> modifiedFinal = modified;
1576 mHandler.post(new Runnable() {
1577 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001578 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1579 if (callbacks == cb && cb != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001580 callbacks.bindAppsUpdated(modifiedFinal);
1581 }
1582 }
1583 });
1584 }
1585 if (removed != null) {
1586 final boolean permanent = mOp != OP_UNAVAILABLE;
1587 final ArrayList<ApplicationInfo> removedFinal = removed;
1588 mHandler.post(new Runnable() {
1589 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001590 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1591 if (callbacks == cb && cb != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001592 callbacks.bindAppsRemoved(removedFinal, permanent);
1593 }
1594 }
1595 });
Joe Onoratobe386092009-11-17 17:32:16 -08001596 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001597
1598 mHandler.post(new Runnable() {
1599 @Override
1600 public void run() {
Winson Chungcd2b0142011-06-08 16:02:26 -07001601 Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
1602 if (callbacks == cb && cb != null) {
Winson Chung80baf5a2010-08-09 16:03:15 -07001603 callbacks.bindPackagesUpdated();
1604 }
1605 }
1606 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04001607 }
1608 }
1609
1610 /**
Joe Onorato56d82912010-03-07 14:32:10 -05001611 * This is called from the code that adds shortcuts from the intent receiver. This
1612 * doesn't have a Cursor, but
Joe Onorato9c1289c2009-08-17 11:03:03 -04001613 */
Joe Onorato56d82912010-03-07 14:32:10 -05001614 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context) {
Winson Chungc3eecff2011-07-11 17:44:15 -07001615 return getShortcutInfo(manager, intent, context, null, -1, -1, null);
Joe Onorato56d82912010-03-07 14:32:10 -05001616 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001617
Joe Onorato56d82912010-03-07 14:32:10 -05001618 /**
1619 * Make an ShortcutInfo object for a shortcut that is an application.
1620 *
1621 * If c is not null, then it will be used to fill in missing data like the title and icon.
1622 */
1623 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context,
Winson Chungc3eecff2011-07-11 17:44:15 -07001624 Cursor c, int iconIndex, int titleIndex, HashMap<Object, CharSequence> labelCache) {
Joe Onorato56d82912010-03-07 14:32:10 -05001625 Bitmap icon = null;
Michael Jurkac9d95c52011-08-29 14:03:34 -07001626 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato56d82912010-03-07 14:32:10 -05001627
1628 ComponentName componentName = intent.getComponent();
1629 if (componentName == null) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001630 return null;
1631 }
1632
Adam Cohen00fcb492011-11-02 21:53:47 -07001633 try {
1634 PackageInfo pi = manager.getPackageInfo(componentName.getPackageName(), 0);
1635 if (!pi.applicationInfo.enabled) {
1636 // If we return null here, the corresponding item will be removed from the launcher
1637 // db and will not appear in the workspace.
1638 return null;
1639 }
1640 } catch (NameNotFoundException e) {
1641 Log.d(TAG, "getPackInfo failed for package " + componentName.getPackageName());
1642 }
1643
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001644 // TODO: See if the PackageManager knows about this case. If it doesn't
1645 // then return null & delete this.
1646
Joe Onorato56d82912010-03-07 14:32:10 -05001647 // the resource -- This may implicitly give us back the fallback icon,
1648 // but don't worry about that. All we're doing with usingFallbackIcon is
1649 // to avoid saving lots of copies of that in the database, and most apps
1650 // have icons anyway.
1651 final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);
1652 if (resolveInfo != null) {
Winson Chungaac01e12011-08-17 10:37:13 -07001653 icon = mIconCache.getIcon(componentName, resolveInfo, labelCache);
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001654 }
Joe Onorato56d82912010-03-07 14:32:10 -05001655 // the db
1656 if (icon == null) {
1657 if (c != null) {
Michael Jurka931dc972011-08-05 15:08:15 -07001658 icon = getIconFromCursor(c, iconIndex, context);
Joe Onorato56d82912010-03-07 14:32:10 -05001659 }
1660 }
1661 // the fallback icon
1662 if (icon == null) {
1663 icon = getFallbackIcon();
1664 info.usingFallbackIcon = true;
1665 }
1666 info.setIcon(icon);
1667
1668 // from the resource
1669 if (resolveInfo != null) {
Winson Chung5308f242011-08-18 12:12:41 -07001670 ComponentName key = LauncherModel.getComponentNameFromResolveInfo(resolveInfo);
1671 if (labelCache != null && labelCache.containsKey(key)) {
1672 info.title = labelCache.get(key);
Winson Chungc3eecff2011-07-11 17:44:15 -07001673 } else {
1674 info.title = resolveInfo.activityInfo.loadLabel(manager);
1675 if (labelCache != null) {
Winson Chung5308f242011-08-18 12:12:41 -07001676 labelCache.put(key, info.title);
Winson Chungc3eecff2011-07-11 17:44:15 -07001677 }
1678 }
Joe Onorato56d82912010-03-07 14:32:10 -05001679 }
1680 // from the db
Joe Onorato9c1289c2009-08-17 11:03:03 -04001681 if (info.title == null) {
Joe Onorato56d82912010-03-07 14:32:10 -05001682 if (c != null) {
1683 info.title = c.getString(titleIndex);
1684 }
1685 }
1686 // fall back to the class name of the activity
1687 if (info.title == null) {
1688 info.title = componentName.getClassName();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001689 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001690 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
1691 return info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001692 }
The Android Open Source Projectbc219c32009-03-09 11:52:14 -07001693
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001694 /**
Joe Onorato0589f0f2010-02-08 13:44:00 -08001695 * Make an ShortcutInfo object for a shortcut that isn't an application.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001696 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001697 private ShortcutInfo getShortcutInfo(Cursor c, Context context,
Joe Onorato56d82912010-03-07 14:32:10 -05001698 int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex,
1699 int titleIndex) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700
Joe Onorato56d82912010-03-07 14:32:10 -05001701 Bitmap icon = null;
Michael Jurkac9d95c52011-08-29 14:03:34 -07001702 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001703 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001705 // TODO: If there's an explicit component and we can't install that, delete it.
1706
Joe Onorato56d82912010-03-07 14:32:10 -05001707 info.title = c.getString(titleIndex);
1708
Joe Onorato9c1289c2009-08-17 11:03:03 -04001709 int iconType = c.getInt(iconTypeIndex);
1710 switch (iconType) {
1711 case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
1712 String packageName = c.getString(iconPackageIndex);
1713 String resourceName = c.getString(iconResourceIndex);
1714 PackageManager packageManager = context.getPackageManager();
Joe Onorato56d82912010-03-07 14:32:10 -05001715 info.customIcon = false;
1716 // the resource
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 try {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001718 Resources resources = packageManager.getResourcesForApplication(packageName);
Joe Onorato56d82912010-03-07 14:32:10 -05001719 if (resources != null) {
1720 final int id = resources.getIdentifier(resourceName, null, null);
Michael Jurkac9a96192010-11-01 11:52:08 -07001721 icon = Utilities.createIconBitmap(
1722 mIconCache.getFullResIcon(resources, id), context);
Joe Onorato56d82912010-03-07 14:32:10 -05001723 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001724 } catch (Exception e) {
Joe Onorato56d82912010-03-07 14:32:10 -05001725 // drop this. we have other places to look for icons
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 }
Joe Onorato56d82912010-03-07 14:32:10 -05001727 // the db
1728 if (icon == null) {
Michael Jurka931dc972011-08-05 15:08:15 -07001729 icon = getIconFromCursor(c, iconIndex, context);
Joe Onorato56d82912010-03-07 14:32:10 -05001730 }
1731 // the fallback icon
1732 if (icon == null) {
1733 icon = getFallbackIcon();
1734 info.usingFallbackIcon = true;
1735 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001736 break;
1737 case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
Michael Jurka931dc972011-08-05 15:08:15 -07001738 icon = getIconFromCursor(c, iconIndex, context);
Joe Onorato56d82912010-03-07 14:32:10 -05001739 if (icon == null) {
1740 icon = getFallbackIcon();
1741 info.customIcon = false;
1742 info.usingFallbackIcon = true;
1743 } else {
1744 info.customIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001745 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001746 break;
1747 default:
Joe Onoratod8d22da2010-03-11 17:59:11 -08001748 icon = getFallbackIcon();
Joe Onorato56d82912010-03-07 14:32:10 -05001749 info.usingFallbackIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001750 info.customIcon = false;
1751 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001752 }
Joe Onoratod8d22da2010-03-11 17:59:11 -08001753 info.setIcon(icon);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001754 return info;
1755 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001756
Michael Jurka931dc972011-08-05 15:08:15 -07001757 Bitmap getIconFromCursor(Cursor c, int iconIndex, Context context) {
Joe Onorato56d82912010-03-07 14:32:10 -05001758 if (false) {
1759 Log.d(TAG, "getIconFromCursor app="
1760 + c.getString(c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE)));
1761 }
1762 byte[] data = c.getBlob(iconIndex);
1763 try {
Michael Jurka931dc972011-08-05 15:08:15 -07001764 return Utilities.createIconBitmap(
1765 BitmapFactory.decodeByteArray(data, 0, data.length), context);
Joe Onorato56d82912010-03-07 14:32:10 -05001766 } catch (Exception e) {
1767 return null;
1768 }
1769 }
1770
Winson Chung3d503fb2011-07-13 17:25:49 -07001771 ShortcutInfo addShortcut(Context context, Intent data, long container, int screen,
1772 int cellX, int cellY, boolean notify) {
Winson Chunga9abd0e2010-10-27 17:18:37 -07001773 final ShortcutInfo info = infoFromShortcutIntent(context, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001774 if (info == null) {
1775 return null;
1776 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001777 addItemToDatabase(context, info, container, screen, cellX, cellY, notify);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001778
1779 return info;
1780 }
1781
Winson Chunga9abd0e2010-10-27 17:18:37 -07001782 /**
Winson Chung55cef262010-10-28 14:14:18 -07001783 * Attempts to find an AppWidgetProviderInfo that matches the given component.
1784 */
1785 AppWidgetProviderInfo findAppWidgetProviderInfoWithComponent(Context context,
1786 ComponentName component) {
1787 List<AppWidgetProviderInfo> widgets =
1788 AppWidgetManager.getInstance(context).getInstalledProviders();
1789 for (AppWidgetProviderInfo info : widgets) {
1790 if (info.provider.equals(component)) {
1791 return info;
1792 }
1793 }
1794 return null;
Winson Chunga9abd0e2010-10-27 17:18:37 -07001795 }
1796
Winson Chung68846fd2010-10-29 11:00:27 -07001797 /**
1798 * Returns a list of all the widgets that can handle configuration with a particular mimeType.
1799 */
1800 List<WidgetMimeTypeHandlerData> resolveWidgetsForMimeType(Context context, String mimeType) {
1801 final PackageManager packageManager = context.getPackageManager();
1802 final List<WidgetMimeTypeHandlerData> supportedConfigurationActivities =
1803 new ArrayList<WidgetMimeTypeHandlerData>();
1804
1805 final Intent supportsIntent =
1806 new Intent(InstallWidgetReceiver.ACTION_SUPPORTS_CLIPDATA_MIMETYPE);
1807 supportsIntent.setType(mimeType);
1808
1809 // Create a set of widget configuration components that we can test against
1810 final List<AppWidgetProviderInfo> widgets =
1811 AppWidgetManager.getInstance(context).getInstalledProviders();
1812 final HashMap<ComponentName, AppWidgetProviderInfo> configurationComponentToWidget =
1813 new HashMap<ComponentName, AppWidgetProviderInfo>();
1814 for (AppWidgetProviderInfo info : widgets) {
1815 configurationComponentToWidget.put(info.configure, info);
1816 }
1817
1818 // Run through each of the intents that can handle this type of clip data, and cross
1819 // reference them with the components that are actual configuration components
1820 final List<ResolveInfo> activities = packageManager.queryIntentActivities(supportsIntent,
1821 PackageManager.MATCH_DEFAULT_ONLY);
1822 for (ResolveInfo info : activities) {
1823 final ActivityInfo activityInfo = info.activityInfo;
1824 final ComponentName infoComponent = new ComponentName(activityInfo.packageName,
1825 activityInfo.name);
1826 if (configurationComponentToWidget.containsKey(infoComponent)) {
1827 supportedConfigurationActivities.add(
1828 new InstallWidgetReceiver.WidgetMimeTypeHandlerData(info,
1829 configurationComponentToWidget.get(infoComponent)));
1830 }
1831 }
1832 return supportedConfigurationActivities;
1833 }
1834
Winson Chunga9abd0e2010-10-27 17:18:37 -07001835 ShortcutInfo infoFromShortcutIntent(Context context, Intent data, Bitmap fallbackIcon) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001836 Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
1837 String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
1838 Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
1839
Adam Cohend9198822011-11-22 16:42:47 -08001840 if (intent == null) {
1841 // If the intent is null, we can't construct a valid ShortcutInfo, so we return null
1842 Log.e(TAG, "Can't construct ShorcutInfo with null intent");
1843 return null;
1844 }
1845
Joe Onorato0589f0f2010-02-08 13:44:00 -08001846 Bitmap icon = null;
Joe Onorato0589f0f2010-02-08 13:44:00 -08001847 boolean customIcon = false;
1848 ShortcutIconResource iconResource = null;
1849
1850 if (bitmap != null && bitmap instanceof Bitmap) {
1851 icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap)bitmap), context);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001852 customIcon = true;
1853 } else {
1854 Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
1855 if (extra != null && extra instanceof ShortcutIconResource) {
1856 try {
1857 iconResource = (ShortcutIconResource) extra;
1858 final PackageManager packageManager = context.getPackageManager();
1859 Resources resources = packageManager.getResourcesForApplication(
1860 iconResource.packageName);
1861 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
Michael Jurkac9a96192010-11-01 11:52:08 -07001862 icon = Utilities.createIconBitmap(
1863 mIconCache.getFullResIcon(resources, id), context);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001864 } catch (Exception e) {
1865 Log.w(TAG, "Could not load shortcut icon: " + extra);
1866 }
1867 }
1868 }
1869
Michael Jurkac9d95c52011-08-29 14:03:34 -07001870 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato56d82912010-03-07 14:32:10 -05001871
1872 if (icon == null) {
Winson Chunga9abd0e2010-10-27 17:18:37 -07001873 if (fallbackIcon != null) {
1874 icon = fallbackIcon;
1875 } else {
1876 icon = getFallbackIcon();
1877 info.usingFallbackIcon = true;
1878 }
Joe Onorato56d82912010-03-07 14:32:10 -05001879 }
Joe Onorato0589f0f2010-02-08 13:44:00 -08001880 info.setIcon(icon);
Joe Onorato56d82912010-03-07 14:32:10 -05001881
Joe Onorato0589f0f2010-02-08 13:44:00 -08001882 info.title = name;
1883 info.intent = intent;
1884 info.customIcon = customIcon;
1885 info.iconResource = iconResource;
1886
1887 return info;
1888 }
1889
Winson Chungaac01e12011-08-17 10:37:13 -07001890 boolean queueIconToBeChecked(HashMap<Object, byte[]> cache, ShortcutInfo info, Cursor c,
1891 int iconIndex) {
Joe Onorato17a89222011-02-08 17:26:11 -08001892 // If apps can't be on SD, don't even bother.
1893 if (!mAppsCanBeOnExternalStorage) {
Winson Chungaac01e12011-08-17 10:37:13 -07001894 return false;
Joe Onorato17a89222011-02-08 17:26:11 -08001895 }
Joe Onorato56d82912010-03-07 14:32:10 -05001896 // If this icon doesn't have a custom icon, check to see
1897 // what's stored in the DB, and if it doesn't match what
1898 // we're going to show, store what we are going to show back
1899 // into the DB. We do this so when we're loading, if the
1900 // package manager can't find an icon (for example because
1901 // the app is on SD) then we can use that instead.
Joe Onoratoddc9c1f2010-08-30 18:30:15 -07001902 if (!info.customIcon && !info.usingFallbackIcon) {
Winson Chungaac01e12011-08-17 10:37:13 -07001903 cache.put(info, c.getBlob(iconIndex));
1904 return true;
1905 }
1906 return false;
1907 }
1908 void updateSavedIcon(Context context, ShortcutInfo info, byte[] data) {
1909 boolean needSave = false;
1910 try {
1911 if (data != null) {
1912 Bitmap saved = BitmapFactory.decodeByteArray(data, 0, data.length);
1913 Bitmap loaded = info.getIcon(mIconCache);
1914 needSave = !saved.sameAs(loaded);
1915 } else {
Joe Onorato56d82912010-03-07 14:32:10 -05001916 needSave = true;
1917 }
Winson Chungaac01e12011-08-17 10:37:13 -07001918 } catch (Exception e) {
1919 needSave = true;
1920 }
1921 if (needSave) {
1922 Log.d(TAG, "going to save icon bitmap for info=" + info);
1923 // This is slower than is ideal, but this only happens once
1924 // or when the app is updated with a new icon.
1925 updateItemInDatabase(context, info);
Joe Onorato56d82912010-03-07 14:32:10 -05001926 }
1927 }
1928
Joe Onorato9c1289c2009-08-17 11:03:03 -04001929 /**
Adam Cohendf2cc412011-04-27 16:56:57 -07001930 * Return an existing FolderInfo object if we have encountered this ID previously,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001931 * or make a new one.
1932 */
Adam Cohendf2cc412011-04-27 16:56:57 -07001933 private static FolderInfo findOrMakeFolder(HashMap<Long, FolderInfo> folders, long id) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001934 // See if a placeholder was created for us already
1935 FolderInfo folderInfo = folders.get(id);
Adam Cohendf2cc412011-04-27 16:56:57 -07001936 if (folderInfo == null) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001937 // No placeholder -- create a new instance
Michael Jurkac9d95c52011-08-29 14:03:34 -07001938 folderInfo = new FolderInfo();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001939 folders.put(id, folderInfo);
1940 }
Adam Cohendf2cc412011-04-27 16:56:57 -07001941 return folderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 }
1943
Joe Onorato9c1289c2009-08-17 11:03:03 -04001944 private static final Collator sCollator = Collator.getInstance();
Joe Onoratob0c27f22009-12-01 16:19:38 -08001945 public static final Comparator<ApplicationInfo> APP_NAME_COMPARATOR
Joe Onorato9c1289c2009-08-17 11:03:03 -04001946 = new Comparator<ApplicationInfo>() {
1947 public final int compare(ApplicationInfo a, ApplicationInfo b) {
Michael Jurka5b1808d2011-07-11 19:59:46 -07001948 int result = sCollator.compare(a.title.toString(), b.title.toString());
1949 if (result == 0) {
1950 result = a.componentName.compareTo(b.componentName);
1951 }
1952 return result;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001953 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001954 };
Winson Chung78403fe2011-01-21 15:38:02 -08001955 public static final Comparator<ApplicationInfo> APP_INSTALL_TIME_COMPARATOR
1956 = new Comparator<ApplicationInfo>() {
1957 public final int compare(ApplicationInfo a, ApplicationInfo b) {
1958 if (a.firstInstallTime < b.firstInstallTime) return 1;
1959 if (a.firstInstallTime > b.firstInstallTime) return -1;
1960 return 0;
1961 }
1962 };
Winson Chung785d2eb2011-04-14 16:08:02 -07001963 public static final Comparator<AppWidgetProviderInfo> WIDGET_NAME_COMPARATOR
1964 = new Comparator<AppWidgetProviderInfo>() {
1965 public final int compare(AppWidgetProviderInfo a, AppWidgetProviderInfo b) {
1966 return sCollator.compare(a.label.toString(), b.label.toString());
1967 }
1968 };
Winson Chung5308f242011-08-18 12:12:41 -07001969 static ComponentName getComponentNameFromResolveInfo(ResolveInfo info) {
1970 if (info.activityInfo != null) {
1971 return new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
1972 } else {
1973 return new ComponentName(info.serviceInfo.packageName, info.serviceInfo.name);
1974 }
1975 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001976 public static class ShortcutNameComparator implements Comparator<ResolveInfo> {
1977 private PackageManager mPackageManager;
Winson Chungc3eecff2011-07-11 17:44:15 -07001978 private HashMap<Object, CharSequence> mLabelCache;
Winson Chung785d2eb2011-04-14 16:08:02 -07001979 ShortcutNameComparator(PackageManager pm) {
1980 mPackageManager = pm;
Winson Chungc3eecff2011-07-11 17:44:15 -07001981 mLabelCache = new HashMap<Object, CharSequence>();
1982 }
1983 ShortcutNameComparator(PackageManager pm, HashMap<Object, CharSequence> labelCache) {
1984 mPackageManager = pm;
1985 mLabelCache = labelCache;
Winson Chung785d2eb2011-04-14 16:08:02 -07001986 }
1987 public final int compare(ResolveInfo a, ResolveInfo b) {
Winson Chungc3eecff2011-07-11 17:44:15 -07001988 CharSequence labelA, labelB;
Winson Chung5308f242011-08-18 12:12:41 -07001989 ComponentName keyA = LauncherModel.getComponentNameFromResolveInfo(a);
1990 ComponentName keyB = LauncherModel.getComponentNameFromResolveInfo(b);
1991 if (mLabelCache.containsKey(keyA)) {
1992 labelA = mLabelCache.get(keyA);
Winson Chungc3eecff2011-07-11 17:44:15 -07001993 } else {
1994 labelA = a.loadLabel(mPackageManager).toString();
1995
Winson Chung5308f242011-08-18 12:12:41 -07001996 mLabelCache.put(keyA, labelA);
Winson Chungc3eecff2011-07-11 17:44:15 -07001997 }
Winson Chung5308f242011-08-18 12:12:41 -07001998 if (mLabelCache.containsKey(keyB)) {
1999 labelB = mLabelCache.get(keyB);
Winson Chungc3eecff2011-07-11 17:44:15 -07002000 } else {
2001 labelB = b.loadLabel(mPackageManager).toString();
2002
Winson Chung5308f242011-08-18 12:12:41 -07002003 mLabelCache.put(keyB, labelB);
Winson Chungc3eecff2011-07-11 17:44:15 -07002004 }
Winson Chung785d2eb2011-04-14 16:08:02 -07002005 return sCollator.compare(labelA, labelB);
2006 }
2007 };
Winson Chung1ed747a2011-05-03 16:18:34 -07002008 public static class WidgetAndShortcutNameComparator implements Comparator<Object> {
2009 private PackageManager mPackageManager;
2010 private HashMap<Object, String> mLabelCache;
2011 WidgetAndShortcutNameComparator(PackageManager pm) {
2012 mPackageManager = pm;
2013 mLabelCache = new HashMap<Object, String>();
2014 }
2015 public final int compare(Object a, Object b) {
2016 String labelA, labelB;
Winson Chungc3eecff2011-07-11 17:44:15 -07002017 if (mLabelCache.containsKey(a)) {
2018 labelA = mLabelCache.get(a);
2019 } else {
2020 labelA = (a instanceof AppWidgetProviderInfo) ?
Winson Chung1ed747a2011-05-03 16:18:34 -07002021 ((AppWidgetProviderInfo) a).label :
2022 ((ResolveInfo) a).loadLabel(mPackageManager).toString();
Winson Chungc3eecff2011-07-11 17:44:15 -07002023 mLabelCache.put(a, labelA);
2024 }
2025 if (mLabelCache.containsKey(b)) {
2026 labelB = mLabelCache.get(b);
2027 } else {
2028 labelB = (b instanceof AppWidgetProviderInfo) ?
Winson Chung1ed747a2011-05-03 16:18:34 -07002029 ((AppWidgetProviderInfo) b).label :
2030 ((ResolveInfo) b).loadLabel(mPackageManager).toString();
Winson Chungc3eecff2011-07-11 17:44:15 -07002031 mLabelCache.put(b, labelB);
2032 }
Winson Chung1ed747a2011-05-03 16:18:34 -07002033 return sCollator.compare(labelA, labelB);
2034 }
2035 };
Joe Onoratobe386092009-11-17 17:32:16 -08002036
2037 public void dumpState() {
Joe Onoratobe386092009-11-17 17:32:16 -08002038 Log.d(TAG, "mCallbacks=" + mCallbacks);
2039 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mAllAppsList.data);
2040 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mAllAppsList.added);
2041 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mAllAppsList.removed);
2042 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mAllAppsList.modified);
Joe Onorato36115782010-06-17 13:28:48 -04002043 if (mLoaderTask != null) {
2044 mLoaderTask.dumpState();
2045 } else {
2046 Log.d(TAG, "mLoaderTask=null");
2047 }
Joe Onoratobe386092009-11-17 17:32:16 -08002048 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049}