blob: 12f57377e3ed74c5d662e2101ccabd4c10170ee1 [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
Winson Chung68846fd2010-10-29 11:00:27 -070019import java.lang.ref.WeakReference;
20import java.net.URISyntaxException;
21import java.text.Collator;
22import java.util.ArrayList;
23import java.util.Collections;
24import java.util.Comparator;
25import java.util.HashMap;
26import java.util.List;
Winson Chungaafa03c2010-06-11 17:34:16 -070027
Romain Guy629de3e2010-01-13 12:20:59 -080028import android.appwidget.AppWidgetManager;
29import android.appwidget.AppWidgetProviderInfo;
Joe Onoratof99f8c12009-10-31 17:27:36 -040030import android.content.BroadcastReceiver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.content.ComponentName;
Romain Guy5c16f3e2010-01-12 17:24:58 -080032import android.content.ContentProviderClient;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080033import android.content.ContentResolver;
34import android.content.ContentValues;
Winson Chungaafa03c2010-06-11 17:34:16 -070035import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.Intent;
Joe Onorato0589f0f2010-02-08 13:44:00 -080037import android.content.Intent.ShortcutIconResource;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038import android.content.pm.ActivityInfo;
39import android.content.pm.PackageManager;
Romain Guy5c16f3e2010-01-12 17:24:58 -080040import android.content.pm.ProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.pm.ResolveInfo;
42import android.content.res.Resources;
43import android.database.Cursor;
44import android.graphics.Bitmap;
45import android.graphics.BitmapFactory;
46import android.net.Uri;
Joe Onorato17a89222011-02-08 17:26:11 -080047import android.os.Environment;
Joe Onorato36115782010-06-17 13:28:48 -040048import android.os.Handler;
49import android.os.HandlerThread;
Joe Onorato0589f0f2010-02-08 13:44:00 -080050import android.os.Parcelable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051import android.os.Process;
Winson Chungaafa03c2010-06-11 17:34:16 -070052import android.os.RemoteException;
Joe Onorato9c1289c2009-08-17 11:03:03 -040053import android.os.SystemClock;
Winson Chungaafa03c2010-06-11 17:34:16 -070054import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055
Winson Chung68846fd2010-10-29 11:00:27 -070056import com.android.launcher.R;
57import com.android.launcher2.InstallWidgetReceiver.WidgetMimeTypeHandlerData;
Romain Guyedcce092010-03-04 13:03:17 -080058
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059/**
60 * Maintains in-memory state of the Launcher. It is expected that there should be only one
61 * LauncherModel object held in a static. Also provide APIs for updating the database state
The Android Open Source Projectbc219c32009-03-09 11:52:14 -070062 * for the Launcher.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063 */
Joe Onoratof99f8c12009-10-31 17:27:36 -040064public class LauncherModel extends BroadcastReceiver {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080065 static final boolean DEBUG_LOADERS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -040066 static final String TAG = "Launcher.Model";
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070067
Joe Onorato36115782010-06-17 13:28:48 -040068 private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons
Joe Onorato17a89222011-02-08 17:26:11 -080069 private final boolean mAppsCanBeOnExternalStorage;
Joe Onoratod65d08e2010-04-20 15:43:37 -040070 private int mBatchSize; // 0 is all apps at once
Daniel Sandler2ff10b32010-04-16 15:06:06 -040071 private int mAllAppsLoadDelay; // milliseconds between batches
Daniel Sandlerdca66122010-04-13 16:23:58 -040072
Joe Onoratof99f8c12009-10-31 17:27:36 -040073 private final LauncherApplication mApp;
Joe Onorato9c1289c2009-08-17 11:03:03 -040074 private final Object mLock = new Object();
75 private DeferredHandler mHandler = new DeferredHandler();
Joe Onorato36115782010-06-17 13:28:48 -040076 private LoaderTask mLoaderTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077
Brad Fitzpatrick700889f2010-10-11 09:40:44 -070078 private static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
79 static {
80 sWorkerThread.start();
81 }
82 private static final Handler sWorker = new Handler(sWorkerThread.getLooper());
83
Joe Onoratocc67f472010-06-08 10:54:30 -070084 // We start off with everything not loaded. After that, we assume that
85 // our monitoring of the package manager provides all updates and we never
86 // need to do a requery. These are only ever touched from the loader thread.
87 private boolean mWorkspaceLoaded;
88 private boolean mAllAppsLoaded;
89
Joe Onorato9c1289c2009-08-17 11:03:03 -040090 private WeakReference<Callbacks> mCallbacks;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091
Joe Onorato36115782010-06-17 13:28:48 -040092 private AllAppsList mAllAppsList; // only access in worker thread
Joe Onorato0589f0f2010-02-08 13:44:00 -080093 private IconCache mIconCache;
Joe Onorato36115782010-06-17 13:28:48 -040094 final ArrayList<ItemInfo> mItems = new ArrayList<ItemInfo>();
95 final ArrayList<LauncherAppWidgetInfo> mAppWidgets = new ArrayList<LauncherAppWidgetInfo>();
96 final HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
Joe Onorato0589f0f2010-02-08 13:44:00 -080097
98 private Bitmap mDefaultIcon;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080099
Adam Cohend22015c2010-07-26 22:02:18 -0700100 private static int mCellCountX;
101 private static int mCellCountY;
Winson Chungaafa03c2010-06-11 17:34:16 -0700102
Joe Onorato9c1289c2009-08-17 11:03:03 -0400103 public interface Callbacks {
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700104 public boolean setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400105 public int getCurrentWorkspaceScreen();
106 public void startBinding();
107 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end);
Joe Onoratoad72e172009-11-06 16:25:04 -0500108 public void bindFolders(HashMap<Long,FolderInfo> folders);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400109 public void finishBindingItems();
110 public void bindAppWidget(LauncherAppWidgetInfo info);
111 public void bindAllApplications(ArrayList<ApplicationInfo> apps);
Joe Onorato64e6be72010-03-05 15:05:52 -0500112 public void bindAppsAdded(ArrayList<ApplicationInfo> apps);
113 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps);
Joe Onorato36115782010-06-17 13:28:48 -0400114 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent);
Winson Chung80baf5a2010-08-09 16:03:15 -0700115 public void bindPackagesUpdated();
Daniel Sandler843e8602010-06-07 14:59:01 -0400116 public boolean isAllAppsVisible();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400117 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800118
Joe Onorato0589f0f2010-02-08 13:44:00 -0800119 LauncherModel(LauncherApplication app, IconCache iconCache) {
Joe Onorato17a89222011-02-08 17:26:11 -0800120 mAppsCanBeOnExternalStorage = !Environment.isExternalStorageEmulated();
Joe Onoratof99f8c12009-10-31 17:27:36 -0400121 mApp = app;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800122 mAllAppsList = new AllAppsList(iconCache);
123 mIconCache = iconCache;
124
125 mDefaultIcon = Utilities.createIconBitmap(
Michael Jurkac9a96192010-11-01 11:52:08 -0700126 mIconCache.getFullResDefaultActivityIcon(), app);
Daniel Sandler2ff10b32010-04-16 15:06:06 -0400127
128 mAllAppsLoadDelay = app.getResources().getInteger(R.integer.config_allAppsBatchLoadDelay);
Joe Onoratod65d08e2010-04-20 15:43:37 -0400129
130 mBatchSize = app.getResources().getInteger(R.integer.config_allAppsBatchSize);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800131 }
132
Joe Onorato56d82912010-03-07 14:32:10 -0500133 public Bitmap getFallbackIcon() {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800134 return Bitmap.createBitmap(mDefaultIcon);
Joe Onoratof99f8c12009-10-31 17:27:36 -0400135 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136
Joe Onorato9c1289c2009-08-17 11:03:03 -0400137 /**
138 * Adds an item to the DB if it was not created previously, or move it to a new
139 * <container, screen, cellX, cellY>
140 */
141 static void addOrMoveItemInDatabase(Context context, ItemInfo item, long container,
142 int screen, int cellX, int cellY) {
143 if (item.container == ItemInfo.NO_ID) {
144 // From all apps
145 addItemToDatabase(context, item, container, screen, cellX, cellY, false);
146 } else {
147 // From somewhere else
148 moveItemInDatabase(context, item, container, screen, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 }
150 }
151
152 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400153 * Move an item in the DB to a new <container, screen, cellX, cellY>
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700154 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400155 static void moveItemInDatabase(Context context, ItemInfo item, long container, int screen,
156 int cellX, int cellY) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700157
Joe Onorato9c1289c2009-08-17 11:03:03 -0400158 item.container = container;
159 item.screen = screen;
160 item.cellX = cellX;
161 item.cellY = cellY;
162
Brad Fitzpatrickade2f812010-10-10 15:42:06 -0700163 final Uri uri = LauncherSettings.Favorites.getContentUri(item.id, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400164 final ContentValues values = new ContentValues();
165 final ContentResolver cr = context.getContentResolver();
166
167 values.put(LauncherSettings.Favorites.CONTAINER, item.container);
Adam Cohend22015c2010-07-26 22:02:18 -0700168 values.put(LauncherSettings.Favorites.CELLX, cellX);
169 values.put(LauncherSettings.Favorites.CELLY, cellY);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400170 values.put(LauncherSettings.Favorites.SCREEN, item.screen);
171
Brad Fitzpatrick700889f2010-10-11 09:40:44 -0700172 sWorker.post(new Runnable() {
173 public void run() {
174 cr.update(uri, values, null, null);
175 }
176 });
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700177 }
178
179 /**
Adam Cohend4844c32011-02-18 19:25:06 -0800180 * Resize an item in the DB to a new <spanX, spanY>
181 */
182 static void resizeItemInDatabase(Context context, ItemInfo item, int cellX, int cellY,
183 int spanX, int spanY) {
184 item.spanX = spanX;
185 item.spanY = spanY;
186 item.cellX = cellX;
187 item.cellY = cellY;
188
189 final Uri uri = LauncherSettings.Favorites.getContentUri(item.id, false);
190 final ContentValues values = new ContentValues();
191 final ContentResolver cr = context.getContentResolver();
192
193 values.put(LauncherSettings.Favorites.CONTAINER, item.container);
194 values.put(LauncherSettings.Favorites.SPANX, spanX);
195 values.put(LauncherSettings.Favorites.SPANY, spanY);
196 values.put(LauncherSettings.Favorites.CELLX, cellX);
197 values.put(LauncherSettings.Favorites.CELLY, cellY);
198
199 sWorker.post(new Runnable() {
200 public void run() {
201 cr.update(uri, values, null, null);
202 }
203 });
204 }
205
206 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400207 * Returns true if the shortcuts already exists in the database.
208 * we identify a shortcut by its title and intent.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800209 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400210 static boolean shortcutExists(Context context, String title, Intent intent) {
211 final ContentResolver cr = context.getContentResolver();
212 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
213 new String[] { "title", "intent" }, "title=? and intent=?",
214 new String[] { title, intent.toUri(0) }, null);
215 boolean result = false;
216 try {
217 result = c.moveToFirst();
218 } finally {
219 c.close();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400221 return result;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700222 }
223
Joe Onorato9c1289c2009-08-17 11:03:03 -0400224 /**
Winson Chungaafa03c2010-06-11 17:34:16 -0700225 * Returns an ItemInfo array containing all the items in the LauncherModel.
226 * The ItemInfo.id is not set through this function.
227 */
228 static ArrayList<ItemInfo> getItemsInLocalCoordinates(Context context) {
229 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
230 final ContentResolver cr = context.getContentResolver();
231 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] {
232 LauncherSettings.Favorites.ITEM_TYPE, LauncherSettings.Favorites.CONTAINER,
233 LauncherSettings.Favorites.SCREEN, LauncherSettings.Favorites.CELLX, LauncherSettings.Favorites.CELLY,
234 LauncherSettings.Favorites.SPANX, LauncherSettings.Favorites.SPANY }, null, null, null);
235
236 final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
237 final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
238 final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
239 final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
240 final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
241 final int spanXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANX);
242 final int spanYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANY);
243
244 try {
245 while (c.moveToNext()) {
246 ItemInfo item = new ItemInfo();
247 item.cellX = c.getInt(cellXIndex);
248 item.cellY = c.getInt(cellYIndex);
249 item.spanX = c.getInt(spanXIndex);
250 item.spanY = c.getInt(spanYIndex);
251 item.container = c.getInt(containerIndex);
252 item.itemType = c.getInt(itemTypeIndex);
253 item.screen = c.getInt(screenIndex);
254
255 items.add(item);
256 }
257 } catch (Exception e) {
258 items.clear();
259 } finally {
260 c.close();
261 }
262
263 return items;
264 }
265
266 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400267 * Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList.
268 */
269 FolderInfo getFolderById(Context context, HashMap<Long,FolderInfo> folderList, long id) {
270 final ContentResolver cr = context.getContentResolver();
271 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null,
272 "_id=? and (itemType=? or itemType=?)",
273 new String[] { String.valueOf(id),
274 String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER),
275 String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER) }, null);
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700276
Joe Onorato9c1289c2009-08-17 11:03:03 -0400277 try {
278 if (c.moveToFirst()) {
279 final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
280 final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
281 final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
282 final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
283 final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
284 final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285
Joe Onorato9c1289c2009-08-17 11:03:03 -0400286 FolderInfo folderInfo = null;
287 switch (c.getInt(itemTypeIndex)) {
288 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
289 folderInfo = findOrMakeUserFolder(folderList, id);
290 break;
291 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
292 folderInfo = findOrMakeLiveFolder(folderList, id);
293 break;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700294 }
295
Joe Onorato9c1289c2009-08-17 11:03:03 -0400296 folderInfo.title = c.getString(titleIndex);
297 folderInfo.id = id;
298 folderInfo.container = c.getInt(containerIndex);
299 folderInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -0700300 folderInfo.cellX = c.getInt(cellXIndex);
301 folderInfo.cellY = c.getInt(cellYIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400302
303 return folderInfo;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700304 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400305 } finally {
306 c.close();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700307 }
308
309 return null;
310 }
311
Joe Onorato9c1289c2009-08-17 11:03:03 -0400312 /**
313 * Add an item to the database in a specified container. Sets the container, screen, cellX and
314 * cellY fields of the item. Also assigns an ID to the item.
315 */
316 static void addItemToDatabase(Context context, ItemInfo item, long container,
317 int screen, int cellX, int cellY, boolean notify) {
318 item.container = container;
319 item.screen = screen;
320 item.cellX = cellX;
321 item.cellY = cellY;
322
323 final ContentValues values = new ContentValues();
324 final ContentResolver cr = context.getContentResolver();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400325 item.onAddToDatabase(values);
326
Adam Cohend22015c2010-07-26 22:02:18 -0700327 item.updateValuesWithCoordinates(values, cellX, cellY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700328
Joe Onorato9c1289c2009-08-17 11:03:03 -0400329 Uri result = cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
330 LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
331
332 if (result != null) {
333 item.id = Integer.parseInt(result.getPathSegments().get(1));
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700334 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700335 }
336
Joe Onorato9c1289c2009-08-17 11:03:03 -0400337 /**
Winson Chungaafa03c2010-06-11 17:34:16 -0700338 * Creates a new unique child id, for a given cell span across all layouts.
339 */
Michael Jurka845ba3b2010-09-28 17:09:46 -0700340 static int getCellLayoutChildId(
341 int cellId, int screen, int localCellX, int localCellY, int spanX, int spanY) {
342 return ((cellId & 0xFF) << 24)
343 | (screen & 0xFF) << 16 | (localCellX & 0xFF) << 8 | (localCellY & 0xFF);
Winson Chungaafa03c2010-06-11 17:34:16 -0700344 }
345
Adam Cohend22015c2010-07-26 22:02:18 -0700346 static int getCellCountX() {
347 return mCellCountX;
Winson Chungaafa03c2010-06-11 17:34:16 -0700348 }
349
Adam Cohend22015c2010-07-26 22:02:18 -0700350 static int getCellCountY() {
351 return mCellCountY;
Winson Chungaafa03c2010-06-11 17:34:16 -0700352 }
353
354 /**
355 * Updates the model orientation helper to take into account the current layout dimensions
356 * when performing local/canonical coordinate transformations.
357 */
358 static void updateWorkspaceLayoutCells(int shortAxisCellCount, int longAxisCellCount) {
Adam Cohend22015c2010-07-26 22:02:18 -0700359 mCellCountX = shortAxisCellCount;
360 mCellCountY = longAxisCellCount;
Winson Chungaafa03c2010-06-11 17:34:16 -0700361 }
362
363 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400364 * Update an item to the database in a specified container.
365 */
366 static void updateItemInDatabase(Context context, ItemInfo item) {
367 final ContentValues values = new ContentValues();
368 final ContentResolver cr = context.getContentResolver();
369
370 item.onAddToDatabase(values);
Adam Cohend22015c2010-07-26 22:02:18 -0700371 item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700372
Joe Onorato9c1289c2009-08-17 11:03:03 -0400373 cr.update(LauncherSettings.Favorites.getContentUri(item.id, false), values, null, null);
374 }
375
376 /**
377 * Removes the specified item from the database
378 * @param context
379 * @param item
380 */
381 static void deleteItemFromDatabase(Context context, ItemInfo item) {
382 final ContentResolver cr = context.getContentResolver();
Brad Fitzpatrick73013bf2010-09-14 12:15:32 -0700383 final Uri uriToDelete = LauncherSettings.Favorites.getContentUri(item.id, false);
Brad Fitzpatrick700889f2010-10-11 09:40:44 -0700384 sWorker.post(new Runnable() {
385 public void run() {
386 cr.delete(uriToDelete, null, null);
387 }
388 });
Joe Onorato9c1289c2009-08-17 11:03:03 -0400389 }
390
391 /**
392 * Remove the contents of the specified folder from the database
393 */
394 static void deleteUserFolderContentsFromDatabase(Context context, UserFolderInfo info) {
395 final ContentResolver cr = context.getContentResolver();
396
397 cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
398 cr.delete(LauncherSettings.Favorites.CONTENT_URI,
399 LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
400 }
401
402 /**
403 * Set this as the current Launcher activity object for the loader.
404 */
405 public void initialize(Callbacks callbacks) {
406 synchronized (mLock) {
407 mCallbacks = new WeakReference<Callbacks>(callbacks);
408 }
409 }
410
Joe Onorato1d8e7bb2009-10-15 19:49:43 -0700411 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400412 * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
413 * ACTION_PACKAGE_CHANGED.
414 */
Joe Onoratof99f8c12009-10-31 17:27:36 -0400415 public void onReceive(Context context, Intent intent) {
Joe Onorato36115782010-06-17 13:28:48 -0400416 if (DEBUG_LOADERS) Log.d(TAG, "onReceive intent=" + intent);
Winson Chungaafa03c2010-06-11 17:34:16 -0700417
Joe Onorato36115782010-06-17 13:28:48 -0400418 final String action = intent.getAction();
Joe Onoratof99f8c12009-10-31 17:27:36 -0400419
Joe Onorato36115782010-06-17 13:28:48 -0400420 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
421 || Intent.ACTION_PACKAGE_REMOVED.equals(action)
422 || Intent.ACTION_PACKAGE_ADDED.equals(action)) {
423 final String packageName = intent.getData().getSchemeSpecificPart();
424 final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400425
Joe Onorato36115782010-06-17 13:28:48 -0400426 int op = PackageUpdatedTask.OP_NONE;
427
428 if (packageName == null || packageName.length() == 0) {
429 // they sent us a bad intent
430 return;
431 }
432
433 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
434 op = PackageUpdatedTask.OP_UPDATE;
435 } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
436 if (!replacing) {
437 op = PackageUpdatedTask.OP_REMOVE;
438 }
439 // else, we are replacing the package, so a PACKAGE_ADDED will be sent
440 // later, we will update the package at this time
441 } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
442 if (!replacing) {
443 op = PackageUpdatedTask.OP_ADD;
444 } else {
445 op = PackageUpdatedTask.OP_UPDATE;
446 }
447 }
448
449 if (op != PackageUpdatedTask.OP_NONE) {
450 enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packageName }));
451 }
452
453 } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
Joe Onoratocec58332010-10-07 14:37:40 -0400454 // First, schedule to add these apps back in.
455 String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
456 enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_ADD, packages));
457 // Then, rebind everything.
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700458 startLoaderFromBackground();
Joe Onorato36115782010-06-17 13:28:48 -0400459 } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
460 String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
461 enqueuePackageUpdated(new PackageUpdatedTask(
462 PackageUpdatedTask.OP_UNAVAILABLE, packages));
Joe Onoratoe9ad59e2010-10-29 17:35:36 -0700463 } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
464 // If we have changed locale we need to clear out the labels in all apps.
465 // Do this here because if the launcher activity is running it will be restarted.
466 // If it's not running startLoaderFromBackground will merely tell it that it needs
467 // to reload. Either way, mAllAppsLoaded will be cleared so it re-reads everything
468 // next time.
469 mAllAppsLoaded = false;
470 startLoaderFromBackground();
471 }
472 }
473
474 /**
475 * When the launcher is in the background, it's possible for it to miss paired
476 * configuration changes. So whenever we trigger the loader from the background
477 * tell the launcher that it needs to re-run the loader when it comes back instead
478 * of doing it now.
479 */
480 public void startLoaderFromBackground() {
481 boolean runLoader = false;
482 if (mCallbacks != null) {
483 Callbacks callbacks = mCallbacks.get();
484 if (callbacks != null) {
485 // Only actually run the loader if they're not paused.
486 if (!callbacks.setLoadOnResume()) {
487 runLoader = true;
488 }
489 }
490 }
491 if (runLoader) {
492 startLoader(mApp, false);
Joe Onorato790c2d92010-06-11 00:14:11 -0700493 }
Joe Onorato36115782010-06-17 13:28:48 -0400494 }
Joe Onoratof99f8c12009-10-31 17:27:36 -0400495
Joe Onorato36115782010-06-17 13:28:48 -0400496 public void startLoader(Context context, boolean isLaunching) {
497 synchronized (mLock) {
498 if (DEBUG_LOADERS) {
499 Log.d(TAG, "startLoader isLaunching=" + isLaunching);
500 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400501
Joe Onorato36115782010-06-17 13:28:48 -0400502 // Don't bother to start the thread if we know it's not going to do anything
503 if (mCallbacks != null && mCallbacks.get() != null) {
504 // If there is already one running, tell it to stop.
505 LoaderTask oldTask = mLoaderTask;
506 if (oldTask != null) {
507 if (oldTask.isLaunching()) {
508 // don't downgrade isLaunching if we're already running
509 isLaunching = true;
Joe Onorato64e6be72010-03-05 15:05:52 -0500510 }
Joe Onorato36115782010-06-17 13:28:48 -0400511 oldTask.stopLocked();
Joe Onorato64e6be72010-03-05 15:05:52 -0500512 }
Joe Onorato36115782010-06-17 13:28:48 -0400513 mLoaderTask = new LoaderTask(context, isLaunching);
Brad Fitzpatrick700889f2010-10-11 09:40:44 -0700514 sWorker.post(mLoaderTask);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400515 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400516 }
517 }
518
Joe Onorato36115782010-06-17 13:28:48 -0400519 public void stopLoader() {
520 synchronized (mLock) {
521 if (mLoaderTask != null) {
522 mLoaderTask.stopLocked();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400523 }
524 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -0800525 mItems.clear();
526 mAppWidgets.clear();
527 mFolders.clear();
Joe Onorato36115782010-06-17 13:28:48 -0400528 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400529
Joe Onorato36115782010-06-17 13:28:48 -0400530 /**
531 * Runnable for the thread that loads the contents of the launcher:
532 * - workspace icons
533 * - widgets
534 * - all apps icons
535 */
536 private class LoaderTask implements Runnable {
537 private Context mContext;
538 private Thread mWaitThread;
539 private boolean mIsLaunching;
540 private boolean mStopped;
541 private boolean mLoadAndBindStepFinished;
542
543 LoaderTask(Context context, boolean isLaunching) {
544 mContext = context;
545 mIsLaunching = isLaunching;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400546 }
547
Joe Onorato36115782010-06-17 13:28:48 -0400548 boolean isLaunching() {
549 return mIsLaunching;
550 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400551
Joe Onorato36115782010-06-17 13:28:48 -0400552 private void loadAndBindWorkspace() {
553 // Load the workspace
554
555 // For now, just always reload the workspace. It's ~100 ms vs. the
556 // binding which takes many hundreds of ms.
557 // We can reconsider.
558 if (DEBUG_LOADERS) {
559 Log.d(TAG, "loadAndBindWorkspace mWorkspaceLoaded=" + mWorkspaceLoaded);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400560 }
Joe Onorato36115782010-06-17 13:28:48 -0400561 if (true || !mWorkspaceLoaded) {
562 loadWorkspace();
563 if (mStopped) {
564 return;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400565 }
Joe Onorato36115782010-06-17 13:28:48 -0400566 mWorkspaceLoaded = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400567 }
568
Joe Onorato36115782010-06-17 13:28:48 -0400569 // Bind the workspace
570 bindWorkspace();
571 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400572
Joe Onorato36115782010-06-17 13:28:48 -0400573 private void waitForIdle() {
574 // Wait until the either we're stopped or the other threads are done.
575 // This way we don't start loading all apps until the workspace has settled
576 // down.
577 synchronized (LoaderTask.this) {
578 final long workspaceWaitTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
Joe Onoratocc67f472010-06-08 10:54:30 -0700579
Joe Onorato36115782010-06-17 13:28:48 -0400580 mHandler.postIdle(new Runnable() {
581 public void run() {
582 synchronized (LoaderTask.this) {
583 mLoadAndBindStepFinished = true;
584 if (DEBUG_LOADERS) {
585 Log.d(TAG, "done with previous binding step");
Daniel Sandler843e8602010-06-07 14:59:01 -0400586 }
Joe Onorato36115782010-06-17 13:28:48 -0400587 LoaderTask.this.notify();
Daniel Sandler843e8602010-06-07 14:59:01 -0400588 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400589 }
Joe Onorato36115782010-06-17 13:28:48 -0400590 });
591
592 while (!mStopped && !mLoadAndBindStepFinished) {
593 try {
594 this.wait();
595 } catch (InterruptedException ex) {
596 // Ignore
Daniel Sandler843e8602010-06-07 14:59:01 -0400597 }
598 }
Joe Onorato36115782010-06-17 13:28:48 -0400599 if (DEBUG_LOADERS) {
600 Log.d(TAG, "waited "
Winson Chungaafa03c2010-06-11 17:34:16 -0700601 + (SystemClock.uptimeMillis()-workspaceWaitTime)
Joe Onorato36115782010-06-17 13:28:48 -0400602 + "ms for previous step to finish binding");
603 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400604 }
Joe Onorato36115782010-06-17 13:28:48 -0400605 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400606
Joe Onorato36115782010-06-17 13:28:48 -0400607 public void run() {
608 // Optimize for end-user experience: if the Launcher is up and // running with the
609 // All Apps interface in the foreground, load All Apps first. Otherwise, load the
610 // workspace first (default).
611 final Callbacks cbk = mCallbacks.get();
612 final boolean loadWorkspaceFirst = cbk != null ? (!cbk.isAllAppsVisible()) : true;
Daniel Sandler843e8602010-06-07 14:59:01 -0400613
Joe Onorato36115782010-06-17 13:28:48 -0400614 keep_running: {
Daniel Sandler843e8602010-06-07 14:59:01 -0400615 // Elevate priority when Home launches for the first time to avoid
616 // starving at boot time. Staring at a blank home is not cool.
617 synchronized (mLock) {
618 android.os.Process.setThreadPriority(mIsLaunching
619 ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
620 }
Daniel Sandler843e8602010-06-07 14:59:01 -0400621 if (loadWorkspaceFirst) {
622 if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace");
623 loadAndBindWorkspace();
624 } else {
625 if (DEBUG_LOADERS) Log.d(TAG, "step 1: special: loading all apps");
Joe Onoratocc67f472010-06-08 10:54:30 -0700626 loadAndBindAllApps();
Daniel Sandler843e8602010-06-07 14:59:01 -0400627 }
628
Joe Onorato36115782010-06-17 13:28:48 -0400629 if (mStopped) {
630 break keep_running;
631 }
632
633 // Whew! Hard work done. Slow us down, and wait until the UI thread has
634 // settled down.
Daniel Sandler843e8602010-06-07 14:59:01 -0400635 synchronized (mLock) {
636 if (mIsLaunching) {
637 android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
638 }
639 }
Joe Onorato36115782010-06-17 13:28:48 -0400640 waitForIdle();
Daniel Sandler843e8602010-06-07 14:59:01 -0400641
642 // second step
643 if (loadWorkspaceFirst) {
644 if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps");
Joe Onoratocc67f472010-06-08 10:54:30 -0700645 loadAndBindAllApps();
Daniel Sandler843e8602010-06-07 14:59:01 -0400646 } else {
647 if (DEBUG_LOADERS) Log.d(TAG, "step 2: special: loading workspace");
648 loadAndBindWorkspace();
649 }
Joe Onorato36115782010-06-17 13:28:48 -0400650 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400651
Joe Onorato36115782010-06-17 13:28:48 -0400652 // Clear out this reference, otherwise we end up holding it until all of the
653 // callback runnables are done.
654 mContext = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400655
Joe Onorato36115782010-06-17 13:28:48 -0400656 synchronized (mLock) {
657 // If we are still the last one to be scheduled, remove ourselves.
658 if (mLoaderTask == this) {
659 mLoaderTask = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400660 }
Joe Onorato36115782010-06-17 13:28:48 -0400661 }
Joe Onoratof3d5ea92010-05-18 18:43:51 -0700662
Joe Onorato36115782010-06-17 13:28:48 -0400663 // Trigger a gc to try to clean up after the stuff is done, since the
664 // renderscript allocations aren't charged to the java heap.
665 if (mStopped) {
Joe Onoratof3d5ea92010-05-18 18:43:51 -0700666 mHandler.post(new Runnable() {
667 public void run() {
668 System.gc();
669 }
670 });
Joe Onorato36115782010-06-17 13:28:48 -0400671 } else {
672 mHandler.postIdle(new Runnable() {
673 public void run() {
674 System.gc();
Daniel Sandler8802e962010-05-26 16:28:16 -0400675 }
Joe Onorato36115782010-06-17 13:28:48 -0400676 });
677 }
678 }
679
680 public void stopLocked() {
681 synchronized (LoaderTask.this) {
682 mStopped = true;
683 this.notify();
684 }
685 }
686
687 /**
688 * Gets the callbacks object. If we've been stopped, or if the launcher object
689 * has somehow been garbage collected, return null instead. Pass in the Callbacks
690 * object that was around when the deferred message was scheduled, and if there's
691 * a new Callbacks object around then also return null. This will save us from
692 * calling onto it with data that will be ignored.
693 */
694 Callbacks tryGetCallbacks(Callbacks oldCallbacks) {
695 synchronized (mLock) {
696 if (mStopped) {
697 return null;
Daniel Sandler8802e962010-05-26 16:28:16 -0400698 }
Joe Onorato36115782010-06-17 13:28:48 -0400699
700 if (mCallbacks == null) {
701 return null;
Daniel Sandler8802e962010-05-26 16:28:16 -0400702 }
Joe Onorato36115782010-06-17 13:28:48 -0400703
704 final Callbacks callbacks = mCallbacks.get();
705 if (callbacks != oldCallbacks) {
706 return null;
707 }
708 if (callbacks == null) {
709 Log.w(TAG, "no mCallbacks");
710 return null;
711 }
712
713 return callbacks;
714 }
715 }
716
717 // check & update map of what's occupied; used to discard overlapping/invalid items
718 private boolean checkItemPlacement(ItemInfo occupied[][][], ItemInfo item) {
719 if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Daniel Sandler8802e962010-05-26 16:28:16 -0400720 return true;
721 }
Joe Onorato36115782010-06-17 13:28:48 -0400722 for (int x = item.cellX; x < (item.cellX+item.spanX); x++) {
723 for (int y = item.cellY; y < (item.cellY+item.spanY); y++) {
724 if (occupied[item.screen][x][y] != null) {
725 Log.e(TAG, "Error loading shortcut " + item
Winson Chungaafa03c2010-06-11 17:34:16 -0700726 + " into cell (" + item.screen + ":"
Joe Onorato36115782010-06-17 13:28:48 -0400727 + x + "," + y
Winson Chungaafa03c2010-06-11 17:34:16 -0700728 + ") occupied by "
Joe Onorato36115782010-06-17 13:28:48 -0400729 + occupied[item.screen][x][y]);
730 return false;
731 }
732 }
733 }
734 for (int x = item.cellX; x < (item.cellX+item.spanX); x++) {
735 for (int y = item.cellY; y < (item.cellY+item.spanY); y++) {
736 occupied[item.screen][x][y] = item;
737 }
738 }
739 return true;
740 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400741
Joe Onorato36115782010-06-17 13:28:48 -0400742 private void loadWorkspace() {
743 final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400744
Joe Onorato36115782010-06-17 13:28:48 -0400745 final Context context = mContext;
746 final ContentResolver contentResolver = context.getContentResolver();
747 final PackageManager manager = context.getPackageManager();
748 final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
749 final boolean isSafeMode = manager.isSafeMode();
Joe Onorato3c2f7e12009-10-31 19:17:31 -0400750
Joe Onorato36115782010-06-17 13:28:48 -0400751 mItems.clear();
752 mAppWidgets.clear();
753 mFolders.clear();
Romain Guy5c16f3e2010-01-12 17:24:58 -0800754
Joe Onorato36115782010-06-17 13:28:48 -0400755 final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400756
Joe Onorato36115782010-06-17 13:28:48 -0400757 final Cursor c = contentResolver.query(
758 LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
Daniel Sandler8802e962010-05-26 16:28:16 -0400759
Adam Cohend22015c2010-07-26 22:02:18 -0700760 final ItemInfo occupied[][][] =
761 new ItemInfo[Launcher.SCREEN_COUNT][mCellCountX][mCellCountY];
Joe Onorato9c1289c2009-08-17 11:03:03 -0400762
Joe Onorato36115782010-06-17 13:28:48 -0400763 try {
764 final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
765 final int intentIndex = c.getColumnIndexOrThrow
766 (LauncherSettings.Favorites.INTENT);
767 final int titleIndex = c.getColumnIndexOrThrow
768 (LauncherSettings.Favorites.TITLE);
769 final int iconTypeIndex = c.getColumnIndexOrThrow(
770 LauncherSettings.Favorites.ICON_TYPE);
771 final int iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
772 final int iconPackageIndex = c.getColumnIndexOrThrow(
773 LauncherSettings.Favorites.ICON_PACKAGE);
774 final int iconResourceIndex = c.getColumnIndexOrThrow(
775 LauncherSettings.Favorites.ICON_RESOURCE);
776 final int containerIndex = c.getColumnIndexOrThrow(
777 LauncherSettings.Favorites.CONTAINER);
778 final int itemTypeIndex = c.getColumnIndexOrThrow(
779 LauncherSettings.Favorites.ITEM_TYPE);
780 final int appWidgetIdIndex = c.getColumnIndexOrThrow(
781 LauncherSettings.Favorites.APPWIDGET_ID);
782 final int screenIndex = c.getColumnIndexOrThrow(
783 LauncherSettings.Favorites.SCREEN);
784 final int cellXIndex = c.getColumnIndexOrThrow
785 (LauncherSettings.Favorites.CELLX);
786 final int cellYIndex = c.getColumnIndexOrThrow
787 (LauncherSettings.Favorites.CELLY);
788 final int spanXIndex = c.getColumnIndexOrThrow
789 (LauncherSettings.Favorites.SPANX);
790 final int spanYIndex = c.getColumnIndexOrThrow(
791 LauncherSettings.Favorites.SPANY);
792 final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI);
793 final int displayModeIndex = c.getColumnIndexOrThrow(
794 LauncherSettings.Favorites.DISPLAY_MODE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400795
Joe Onorato36115782010-06-17 13:28:48 -0400796 ShortcutInfo info;
797 String intentDescription;
798 LauncherAppWidgetInfo appWidgetInfo;
799 int container;
800 long id;
801 Intent intent;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400802
Joe Onorato36115782010-06-17 13:28:48 -0400803 while (!mStopped && c.moveToNext()) {
804 try {
805 int itemType = c.getInt(itemTypeIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400806
Joe Onorato36115782010-06-17 13:28:48 -0400807 switch (itemType) {
808 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
809 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
810 intentDescription = c.getString(intentIndex);
811 try {
812 intent = Intent.parseUri(intentDescription, 0);
813 } catch (URISyntaxException e) {
814 continue;
815 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400816
Joe Onorato36115782010-06-17 13:28:48 -0400817 if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
818 info = getShortcutInfo(manager, intent, context, c, iconIndex,
819 titleIndex);
820 } else {
821 info = getShortcutInfo(c, context, iconTypeIndex,
822 iconPackageIndex, iconResourceIndex, iconIndex,
823 titleIndex);
824 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400825
Joe Onorato36115782010-06-17 13:28:48 -0400826 if (info != null) {
Joe Onorato36115782010-06-17 13:28:48 -0400827 info.intent = intent;
828 info.id = c.getLong(idIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400829 container = c.getInt(containerIndex);
Joe Onorato36115782010-06-17 13:28:48 -0400830 info.container = container;
831 info.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -0700832 info.cellX = c.getInt(cellXIndex);
833 info.cellY = c.getInt(cellYIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400834
Daniel Sandler8802e962010-05-26 16:28:16 -0400835 // check & update map of what's occupied
Joe Onorato36115782010-06-17 13:28:48 -0400836 if (!checkItemPlacement(occupied, info)) {
Daniel Sandler8802e962010-05-26 16:28:16 -0400837 break;
838 }
839
Joe Onorato9c1289c2009-08-17 11:03:03 -0400840 switch (container) {
Joe Onorato36115782010-06-17 13:28:48 -0400841 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
842 mItems.add(info);
843 break;
844 default:
845 // Item is in a user folder
846 UserFolderInfo folderInfo =
847 findOrMakeUserFolder(mFolders, container);
848 folderInfo.add(info);
849 break;
850 }
Joe Onorato17a89222011-02-08 17:26:11 -0800851
852 // now that we've loaded everthing re-save it with the
853 // icon in case it disappears somehow.
854 updateSavedIcon(context, info, c, iconIndex);
Joe Onorato36115782010-06-17 13:28:48 -0400855 } else {
856 // Failed to load the shortcut, probably because the
857 // activity manager couldn't resolve it (maybe the app
858 // was uninstalled), or the db row was somehow screwed up.
859 // Delete it.
860 id = c.getLong(idIndex);
861 Log.e(TAG, "Error loading shortcut " + id + ", removing it");
862 contentResolver.delete(LauncherSettings.Favorites.getContentUri(
863 id, false), null, null);
864 }
865 break;
866
867 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
868 id = c.getLong(idIndex);
869 UserFolderInfo folderInfo = findOrMakeUserFolder(mFolders, id);
870
Winson Chungaafa03c2010-06-11 17:34:16 -0700871 folderInfo.title = c.getString(titleIndex);
Joe Onorato36115782010-06-17 13:28:48 -0400872 folderInfo.id = id;
873 container = c.getInt(containerIndex);
874 folderInfo.container = container;
875 folderInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -0700876 folderInfo.cellX = c.getInt(cellXIndex);
877 folderInfo.cellY = c.getInt(cellYIndex);
Joe Onorato36115782010-06-17 13:28:48 -0400878
879 // check & update map of what's occupied
880 if (!checkItemPlacement(occupied, folderInfo)) {
881 break;
882 }
Joe Onorato36115782010-06-17 13:28:48 -0400883 switch (container) {
884 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
885 mItems.add(folderInfo);
886 break;
887 }
888
889 mFolders.put(folderInfo.id, folderInfo);
890 break;
891
892 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
893 id = c.getLong(idIndex);
894 Uri uri = Uri.parse(c.getString(uriIndex));
895
896 // Make sure the live folder exists
897 final ProviderInfo providerInfo =
898 context.getPackageManager().resolveContentProvider(
899 uri.getAuthority(), 0);
900
901 if (providerInfo == null && !isSafeMode) {
902 itemsToRemove.add(id);
903 } else {
904 LiveFolderInfo liveFolderInfo = findOrMakeLiveFolder(mFolders, id);
Joe Onorato36115782010-06-17 13:28:48 -0400905 intentDescription = c.getString(intentIndex);
906 intent = null;
907 if (intentDescription != null) {
908 try {
909 intent = Intent.parseUri(intentDescription, 0);
910 } catch (URISyntaxException e) {
911 // Ignore, a live folder might not have a base intent
912 }
913 }
914
915 liveFolderInfo.title = c.getString(titleIndex);
916 liveFolderInfo.id = id;
917 liveFolderInfo.uri = uri;
918 container = c.getInt(containerIndex);
919 liveFolderInfo.container = container;
920 liveFolderInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -0700921 liveFolderInfo.cellX = c.getInt(cellXIndex);
922 liveFolderInfo.cellY = c.getInt(cellYIndex);
Joe Onorato36115782010-06-17 13:28:48 -0400923 liveFolderInfo.baseIntent = intent;
924 liveFolderInfo.displayMode = c.getInt(displayModeIndex);
925
926 // check & update map of what's occupied
927 if (!checkItemPlacement(occupied, liveFolderInfo)) {
928 break;
929 }
930
931 loadLiveFolderIcon(context, c, iconTypeIndex, iconPackageIndex,
932 iconResourceIndex, liveFolderInfo);
933
934 switch (container) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400935 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
Joe Onorato36115782010-06-17 13:28:48 -0400936 mItems.add(liveFolderInfo);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400937 break;
938 }
Joe Onorato36115782010-06-17 13:28:48 -0400939 mFolders.put(liveFolderInfo.id, liveFolderInfo);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400940 }
Joe Onorato36115782010-06-17 13:28:48 -0400941 break;
Romain Guy5c16f3e2010-01-12 17:24:58 -0800942
Joe Onorato36115782010-06-17 13:28:48 -0400943 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
944 // Read all Launcher-specific widget details
945 int appWidgetId = c.getInt(appWidgetIdIndex);
946 id = c.getLong(idIndex);
947
948 final AppWidgetProviderInfo provider =
949 widgets.getAppWidgetInfo(appWidgetId);
Winson Chungaafa03c2010-06-11 17:34:16 -0700950
Joe Onorato36115782010-06-17 13:28:48 -0400951 if (!isSafeMode && (provider == null || provider.provider == null ||
952 provider.provider.getPackageName() == null)) {
953 Log.e(TAG, "Deleting widget that isn't installed anymore: id="
954 + id + " appWidgetId=" + appWidgetId);
955 itemsToRemove.add(id);
956 } else {
957 appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId);
958 appWidgetInfo.id = id;
959 appWidgetInfo.screen = c.getInt(screenIndex);
Adam Cohend22015c2010-07-26 22:02:18 -0700960 appWidgetInfo.cellX = c.getInt(cellXIndex);
961 appWidgetInfo.cellY = c.getInt(cellYIndex);
962 appWidgetInfo.spanX = c.getInt(spanXIndex);
963 appWidgetInfo.spanY = c.getInt(spanYIndex);
Joe Onorato36115782010-06-17 13:28:48 -0400964
965 container = c.getInt(containerIndex);
966 if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
967 Log.e(TAG, "Widget found where container "
968 + "!= CONTAINER_DESKTOP -- ignoring!");
969 continue;
970 }
971 appWidgetInfo.container = c.getInt(containerIndex);
972
973 // check & update map of what's occupied
974 if (!checkItemPlacement(occupied, appWidgetInfo)) {
975 break;
976 }
977
978 mAppWidgets.add(appWidgetInfo);
979 }
980 break;
Romain Guy5c16f3e2010-01-12 17:24:58 -0800981 }
Joe Onorato36115782010-06-17 13:28:48 -0400982 } catch (Exception e) {
983 Log.w(TAG, "Desktop items loading interrupted:", e);
Romain Guy5c16f3e2010-01-12 17:24:58 -0800984 }
985 }
Joe Onorato36115782010-06-17 13:28:48 -0400986 } finally {
987 c.close();
988 }
Romain Guy5c16f3e2010-01-12 17:24:58 -0800989
Joe Onorato36115782010-06-17 13:28:48 -0400990 if (itemsToRemove.size() > 0) {
991 ContentProviderClient client = contentResolver.acquireContentProviderClient(
992 LauncherSettings.Favorites.CONTENT_URI);
993 // Remove dead items
994 for (long id : itemsToRemove) {
995 if (DEBUG_LOADERS) {
996 Log.d(TAG, "Removed id = " + id);
997 }
998 // Don't notify content observers
999 try {
1000 client.delete(LauncherSettings.Favorites.getContentUri(id, false),
1001 null, null);
1002 } catch (RemoteException e) {
1003 Log.w(TAG, "Could not remove id = " + id);
Daniel Sandler8802e962010-05-26 16:28:16 -04001004 }
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001005 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001006 }
1007
Joe Onorato36115782010-06-17 13:28:48 -04001008 if (DEBUG_LOADERS) {
1009 Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms");
1010 Log.d(TAG, "workspace layout: ");
Adam Cohend22015c2010-07-26 22:02:18 -07001011 for (int y = 0; y < mCellCountY; y++) {
Joe Onorato36115782010-06-17 13:28:48 -04001012 String line = "";
1013 for (int s = 0; s < Launcher.SCREEN_COUNT; s++) {
1014 if (s > 0) {
1015 line += " | ";
1016 }
Adam Cohend22015c2010-07-26 22:02:18 -07001017 for (int x = 0; x < mCellCountX; x++) {
Joe Onorato36115782010-06-17 13:28:48 -04001018 line += ((occupied[s][x][y] != null) ? "#" : ".");
1019 }
1020 }
1021 Log.d(TAG, "[ " + line + " ]");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001022 }
Joe Onorato36115782010-06-17 13:28:48 -04001023 }
1024 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001025
Joe Onorato36115782010-06-17 13:28:48 -04001026 /**
1027 * Read everything out of our database.
1028 */
1029 private void bindWorkspace() {
1030 final long t = SystemClock.uptimeMillis();
1031
1032 // Don't use these two variables in any of the callback runnables.
1033 // Otherwise we hold a reference to them.
1034 final Callbacks oldCallbacks = mCallbacks.get();
1035 if (oldCallbacks == null) {
1036 // This launcher has exited and nobody bothered to tell us. Just bail.
1037 Log.w(TAG, "LoaderTask running with no launcher");
1038 return;
1039 }
1040
1041 int N;
1042 // Tell the workspace that we're about to start firing items at it
1043 mHandler.post(new Runnable() {
1044 public void run() {
1045 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1046 if (callbacks != null) {
1047 callbacks.startBinding();
1048 }
1049 }
1050 });
1051 // Add the items to the workspace.
1052 N = mItems.size();
1053 for (int i=0; i<N; i+=ITEMS_CHUNK) {
1054 final int start = i;
1055 final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001056 mHandler.post(new Runnable() {
1057 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -08001058 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001059 if (callbacks != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001060 callbacks.bindItems(mItems, start, start+chunkSize);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001061 }
1062 }
1063 });
Joe Onorato36115782010-06-17 13:28:48 -04001064 }
1065 mHandler.post(new Runnable() {
1066 public void run() {
1067 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1068 if (callbacks != null) {
1069 callbacks.bindFolders(mFolders);
1070 }
1071 }
1072 });
1073 // Wait until the queue goes empty.
1074 mHandler.post(new Runnable() {
1075 public void run() {
1076 if (DEBUG_LOADERS) {
1077 Log.d(TAG, "Going to start binding widgets soon.");
1078 }
1079 }
1080 });
1081 // Bind the widgets, one at a time.
1082 // WARNING: this is calling into the workspace from the background thread,
1083 // but since getCurrentScreen() just returns the int, we should be okay. This
1084 // is just a hint for the order, and if it's wrong, we'll be okay.
1085 // TODO: instead, we should have that push the current screen into here.
1086 final int currentScreen = oldCallbacks.getCurrentWorkspaceScreen();
1087 N = mAppWidgets.size();
1088 // once for the current screen
1089 for (int i=0; i<N; i++) {
1090 final LauncherAppWidgetInfo widget = mAppWidgets.get(i);
1091 if (widget.screen == currentScreen) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001092 mHandler.post(new Runnable() {
1093 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -08001094 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001095 if (callbacks != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001096 callbacks.bindAppWidget(widget);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001097 }
1098 }
1099 });
1100 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001101 }
Joe Onorato36115782010-06-17 13:28:48 -04001102 // once for the other screens
1103 for (int i=0; i<N; i++) {
1104 final LauncherAppWidgetInfo widget = mAppWidgets.get(i);
1105 if (widget.screen != currentScreen) {
1106 mHandler.post(new Runnable() {
1107 public void run() {
1108 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1109 if (callbacks != null) {
1110 callbacks.bindAppWidget(widget);
1111 }
1112 }
1113 });
Joe Onoratocc67f472010-06-08 10:54:30 -07001114 }
1115 }
Joe Onorato36115782010-06-17 13:28:48 -04001116 // Tell the workspace that we're done.
1117 mHandler.post(new Runnable() {
1118 public void run() {
1119 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1120 if (callbacks != null) {
1121 callbacks.finishBindingItems();
1122 }
1123 }
1124 });
1125 // If we're profiling, this is the last thing in the queue.
1126 mHandler.post(new Runnable() {
1127 public void run() {
1128 if (DEBUG_LOADERS) {
1129 Log.d(TAG, "bound workspace in "
1130 + (SystemClock.uptimeMillis()-t) + "ms");
1131 }
1132 }
1133 });
1134 }
Joe Onoratocc67f472010-06-08 10:54:30 -07001135
Joe Onorato36115782010-06-17 13:28:48 -04001136 private void loadAndBindAllApps() {
1137 if (DEBUG_LOADERS) {
1138 Log.d(TAG, "loadAndBindAllApps mAllAppsLoaded=" + mAllAppsLoaded);
1139 }
1140 if (!mAllAppsLoaded) {
1141 loadAllAppsByBatch();
1142 if (mStopped) {
Joe Onoratocc67f472010-06-08 10:54:30 -07001143 return;
1144 }
Joe Onorato36115782010-06-17 13:28:48 -04001145 mAllAppsLoaded = true;
1146 } else {
1147 onlyBindAllApps();
1148 }
1149 }
Joe Onoratocc67f472010-06-08 10:54:30 -07001150
Joe Onorato36115782010-06-17 13:28:48 -04001151 private void onlyBindAllApps() {
1152 final Callbacks oldCallbacks = mCallbacks.get();
1153 if (oldCallbacks == null) {
1154 // This launcher has exited and nobody bothered to tell us. Just bail.
1155 Log.w(TAG, "LoaderTask running with no launcher (onlyBindAllApps)");
1156 return;
1157 }
1158
1159 // shallow copy
1160 final ArrayList<ApplicationInfo> list
1161 = (ArrayList<ApplicationInfo>)mAllAppsList.data.clone();
1162 mHandler.post(new Runnable() {
1163 public void run() {
1164 final long t = SystemClock.uptimeMillis();
1165 final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1166 if (callbacks != null) {
1167 callbacks.bindAllApplications(list);
1168 }
1169 if (DEBUG_LOADERS) {
1170 Log.d(TAG, "bound all " + list.size() + " apps from cache in "
1171 + (SystemClock.uptimeMillis()-t) + "ms");
1172 }
1173 }
1174 });
1175
1176 }
1177
1178 private void loadAllAppsByBatch() {
1179 final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1180
1181 // Don't use these two variables in any of the callback runnables.
1182 // Otherwise we hold a reference to them.
1183 final Callbacks oldCallbacks = mCallbacks.get();
1184 if (oldCallbacks == null) {
1185 // This launcher has exited and nobody bothered to tell us. Just bail.
1186 Log.w(TAG, "LoaderTask running with no launcher (loadAllAppsByBatch)");
1187 return;
1188 }
1189
1190 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1191 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
1192
1193 final PackageManager packageManager = mContext.getPackageManager();
1194 List<ResolveInfo> apps = null;
1195
1196 int N = Integer.MAX_VALUE;
1197
1198 int startIndex;
1199 int i=0;
1200 int batchSize = -1;
1201 while (i < N && !mStopped) {
1202 if (i == 0) {
1203 mAllAppsList.clear();
1204 final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1205 apps = packageManager.queryIntentActivities(mainIntent, 0);
1206 if (DEBUG_LOADERS) {
1207 Log.d(TAG, "queryIntentActivities took "
1208 + (SystemClock.uptimeMillis()-qiaTime) + "ms");
1209 }
1210 if (apps == null) {
1211 return;
1212 }
1213 N = apps.size();
1214 if (DEBUG_LOADERS) {
1215 Log.d(TAG, "queryIntentActivities got " + N + " apps");
1216 }
1217 if (N == 0) {
1218 // There are no apps?!?
1219 return;
1220 }
1221 if (mBatchSize == 0) {
1222 batchSize = N;
1223 } else {
1224 batchSize = mBatchSize;
1225 }
1226
1227 final long sortTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1228 Collections.sort(apps,
1229 new ResolveInfo.DisplayNameComparator(packageManager));
1230 if (DEBUG_LOADERS) {
1231 Log.d(TAG, "sort took "
1232 + (SystemClock.uptimeMillis()-sortTime) + "ms");
1233 }
1234 }
1235
1236 final long t2 = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1237
1238 startIndex = i;
1239 for (int j=0; i<N && j<batchSize; j++) {
1240 // This builds the icon bitmaps.
Patrick Dubroy3d605d52010-07-29 13:59:29 -07001241 mAllAppsList.add(new ApplicationInfo(packageManager, apps.get(i), mIconCache));
Joe Onorato36115782010-06-17 13:28:48 -04001242 i++;
1243 }
1244
1245 final boolean first = i <= batchSize;
1246 final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
1247 final ArrayList<ApplicationInfo> added = mAllAppsList.added;
1248 mAllAppsList.added = new ArrayList<ApplicationInfo>();
1249
Joe Onoratocc67f472010-06-08 10:54:30 -07001250 mHandler.post(new Runnable() {
1251 public void run() {
1252 final long t = SystemClock.uptimeMillis();
Joe Onoratocc67f472010-06-08 10:54:30 -07001253 if (callbacks != null) {
Joe Onorato36115782010-06-17 13:28:48 -04001254 if (first) {
1255 callbacks.bindAllApplications(added);
1256 } else {
1257 callbacks.bindAppsAdded(added);
1258 }
1259 if (DEBUG_LOADERS) {
1260 Log.d(TAG, "bound " + added.size() + " apps in "
1261 + (SystemClock.uptimeMillis() - t) + "ms");
1262 }
1263 } else {
1264 Log.i(TAG, "not binding apps: no Launcher activity");
Joe Onoratocc67f472010-06-08 10:54:30 -07001265 }
1266 }
1267 });
1268
Daniel Sandlerdca66122010-04-13 16:23:58 -04001269 if (DEBUG_LOADERS) {
Joe Onorato36115782010-06-17 13:28:48 -04001270 Log.d(TAG, "batch of " + (i-startIndex) + " icons processed in "
1271 + (SystemClock.uptimeMillis()-t2) + "ms");
1272 }
1273
1274 if (mAllAppsLoadDelay > 0 && i < N) {
1275 try {
1276 if (DEBUG_LOADERS) {
1277 Log.d(TAG, "sleeping for " + mAllAppsLoadDelay + "ms");
1278 }
1279 Thread.sleep(mAllAppsLoadDelay);
1280 } catch (InterruptedException exc) { }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001281 }
1282 }
1283
Joe Onorato36115782010-06-17 13:28:48 -04001284 if (DEBUG_LOADERS) {
1285 Log.d(TAG, "cached all " + N + " apps in "
1286 + (SystemClock.uptimeMillis()-t) + "ms"
1287 + (mAllAppsLoadDelay > 0 ? " (including delay)" : ""));
Joe Onoratobe386092009-11-17 17:32:16 -08001288 }
1289 }
1290
1291 public void dumpState() {
Joe Onorato36115782010-06-17 13:28:48 -04001292 Log.d(TAG, "mLoaderTask.mContext=" + mContext);
1293 Log.d(TAG, "mLoaderTask.mWaitThread=" + mWaitThread);
1294 Log.d(TAG, "mLoaderTask.mIsLaunching=" + mIsLaunching);
1295 Log.d(TAG, "mLoaderTask.mStopped=" + mStopped);
1296 Log.d(TAG, "mLoaderTask.mLoadAndBindStepFinished=" + mLoadAndBindStepFinished);
1297 }
1298 }
1299
1300 void enqueuePackageUpdated(PackageUpdatedTask task) {
Brad Fitzpatrick700889f2010-10-11 09:40:44 -07001301 sWorker.post(task);
Joe Onorato36115782010-06-17 13:28:48 -04001302 }
1303
1304 private class PackageUpdatedTask implements Runnable {
1305 int mOp;
1306 String[] mPackages;
1307
1308 public static final int OP_NONE = 0;
1309 public static final int OP_ADD = 1;
1310 public static final int OP_UPDATE = 2;
1311 public static final int OP_REMOVE = 3; // uninstlled
1312 public static final int OP_UNAVAILABLE = 4; // external media unmounted
1313
1314
1315 public PackageUpdatedTask(int op, String[] packages) {
1316 mOp = op;
1317 mPackages = packages;
1318 }
1319
1320 public void run() {
1321 final Context context = mApp;
1322
1323 final String[] packages = mPackages;
1324 final int N = packages.length;
1325 switch (mOp) {
1326 case OP_ADD:
1327 for (int i=0; i<N; i++) {
1328 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
1329 mAllAppsList.addPackage(context, packages[i]);
1330 }
1331 break;
1332 case OP_UPDATE:
1333 for (int i=0; i<N; i++) {
1334 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
1335 mAllAppsList.updatePackage(context, packages[i]);
1336 }
1337 break;
1338 case OP_REMOVE:
1339 case OP_UNAVAILABLE:
1340 for (int i=0; i<N; i++) {
1341 if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
1342 mAllAppsList.removePackage(packages[i]);
1343 }
1344 break;
1345 }
1346
1347 ArrayList<ApplicationInfo> added = null;
1348 ArrayList<ApplicationInfo> removed = null;
1349 ArrayList<ApplicationInfo> modified = null;
1350
1351 if (mAllAppsList.added.size() > 0) {
1352 added = mAllAppsList.added;
1353 mAllAppsList.added = new ArrayList<ApplicationInfo>();
1354 }
1355 if (mAllAppsList.removed.size() > 0) {
1356 removed = mAllAppsList.removed;
1357 mAllAppsList.removed = new ArrayList<ApplicationInfo>();
1358 for (ApplicationInfo info: removed) {
1359 mIconCache.remove(info.intent.getComponent());
1360 }
1361 }
1362 if (mAllAppsList.modified.size() > 0) {
1363 modified = mAllAppsList.modified;
1364 mAllAppsList.modified = new ArrayList<ApplicationInfo>();
1365 }
1366
1367 final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
1368 if (callbacks == null) {
1369 Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading.");
1370 return;
1371 }
1372
1373 if (added != null) {
1374 final ArrayList<ApplicationInfo> addedFinal = added;
1375 mHandler.post(new Runnable() {
1376 public void run() {
1377 if (callbacks == mCallbacks.get()) {
1378 callbacks.bindAppsAdded(addedFinal);
1379 }
1380 }
1381 });
1382 }
1383 if (modified != null) {
1384 final ArrayList<ApplicationInfo> modifiedFinal = modified;
1385 mHandler.post(new Runnable() {
1386 public void run() {
1387 if (callbacks == mCallbacks.get()) {
1388 callbacks.bindAppsUpdated(modifiedFinal);
1389 }
1390 }
1391 });
1392 }
1393 if (removed != null) {
1394 final boolean permanent = mOp != OP_UNAVAILABLE;
1395 final ArrayList<ApplicationInfo> removedFinal = removed;
1396 mHandler.post(new Runnable() {
1397 public void run() {
1398 if (callbacks == mCallbacks.get()) {
1399 callbacks.bindAppsRemoved(removedFinal, permanent);
1400 }
1401 }
1402 });
Joe Onoratobe386092009-11-17 17:32:16 -08001403 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001404
1405 mHandler.post(new Runnable() {
1406 @Override
1407 public void run() {
1408 if (callbacks == mCallbacks.get()) {
1409 callbacks.bindPackagesUpdated();
1410 }
1411 }
1412 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04001413 }
1414 }
1415
1416 /**
Joe Onorato56d82912010-03-07 14:32:10 -05001417 * This is called from the code that adds shortcuts from the intent receiver. This
1418 * doesn't have a Cursor, but
Joe Onorato9c1289c2009-08-17 11:03:03 -04001419 */
Joe Onorato56d82912010-03-07 14:32:10 -05001420 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context) {
Joe Onoratoe74daed2010-03-11 12:32:24 -08001421 return getShortcutInfo(manager, intent, context, null, -1, -1);
Joe Onorato56d82912010-03-07 14:32:10 -05001422 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001423
Joe Onorato56d82912010-03-07 14:32:10 -05001424 /**
1425 * Make an ShortcutInfo object for a shortcut that is an application.
1426 *
1427 * If c is not null, then it will be used to fill in missing data like the title and icon.
1428 */
1429 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context,
1430 Cursor c, int iconIndex, int titleIndex) {
1431 Bitmap icon = null;
1432 final ShortcutInfo info = new ShortcutInfo();
1433
1434 ComponentName componentName = intent.getComponent();
1435 if (componentName == null) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001436 return null;
1437 }
1438
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001439 // TODO: See if the PackageManager knows about this case. If it doesn't
1440 // then return null & delete this.
1441
Joe Onorato56d82912010-03-07 14:32:10 -05001442 // the resource -- This may implicitly give us back the fallback icon,
1443 // but don't worry about that. All we're doing with usingFallbackIcon is
1444 // to avoid saving lots of copies of that in the database, and most apps
1445 // have icons anyway.
1446 final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);
1447 if (resolveInfo != null) {
1448 icon = mIconCache.getIcon(componentName, resolveInfo);
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001449 }
Joe Onorato56d82912010-03-07 14:32:10 -05001450 // the db
1451 if (icon == null) {
1452 if (c != null) {
1453 icon = getIconFromCursor(c, iconIndex);
1454 }
1455 }
1456 // the fallback icon
1457 if (icon == null) {
1458 icon = getFallbackIcon();
1459 info.usingFallbackIcon = true;
1460 }
1461 info.setIcon(icon);
1462
1463 // from the resource
1464 if (resolveInfo != null) {
1465 info.title = resolveInfo.activityInfo.loadLabel(manager);
1466 }
1467 // from the db
Joe Onorato9c1289c2009-08-17 11:03:03 -04001468 if (info.title == null) {
Joe Onorato56d82912010-03-07 14:32:10 -05001469 if (c != null) {
1470 info.title = c.getString(titleIndex);
1471 }
1472 }
1473 // fall back to the class name of the activity
1474 if (info.title == null) {
1475 info.title = componentName.getClassName();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001476 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001477 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
1478 return info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001479 }
The Android Open Source Projectbc219c32009-03-09 11:52:14 -07001480
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001481 /**
Joe Onorato0589f0f2010-02-08 13:44:00 -08001482 * Make an ShortcutInfo object for a shortcut that isn't an application.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001483 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001484 private ShortcutInfo getShortcutInfo(Cursor c, Context context,
Joe Onorato56d82912010-03-07 14:32:10 -05001485 int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex,
1486 int titleIndex) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001487
Joe Onorato56d82912010-03-07 14:32:10 -05001488 Bitmap icon = null;
Joe Onorato0589f0f2010-02-08 13:44:00 -08001489 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001490 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001491
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001492 // TODO: If there's an explicit component and we can't install that, delete it.
1493
Joe Onorato56d82912010-03-07 14:32:10 -05001494 info.title = c.getString(titleIndex);
1495
Joe Onorato9c1289c2009-08-17 11:03:03 -04001496 int iconType = c.getInt(iconTypeIndex);
1497 switch (iconType) {
1498 case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
1499 String packageName = c.getString(iconPackageIndex);
1500 String resourceName = c.getString(iconResourceIndex);
1501 PackageManager packageManager = context.getPackageManager();
Joe Onorato56d82912010-03-07 14:32:10 -05001502 info.customIcon = false;
1503 // the resource
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 try {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001505 Resources resources = packageManager.getResourcesForApplication(packageName);
Joe Onorato56d82912010-03-07 14:32:10 -05001506 if (resources != null) {
1507 final int id = resources.getIdentifier(resourceName, null, null);
Michael Jurkac9a96192010-11-01 11:52:08 -07001508 icon = Utilities.createIconBitmap(
1509 mIconCache.getFullResIcon(resources, id), context);
Joe Onorato56d82912010-03-07 14:32:10 -05001510 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001511 } catch (Exception e) {
Joe Onorato56d82912010-03-07 14:32:10 -05001512 // drop this. we have other places to look for icons
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001513 }
Joe Onorato56d82912010-03-07 14:32:10 -05001514 // the db
1515 if (icon == null) {
1516 icon = getIconFromCursor(c, iconIndex);
1517 }
1518 // the fallback icon
1519 if (icon == null) {
1520 icon = getFallbackIcon();
1521 info.usingFallbackIcon = true;
1522 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001523 break;
1524 case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
Joe Onorato56d82912010-03-07 14:32:10 -05001525 icon = getIconFromCursor(c, iconIndex);
1526 if (icon == null) {
1527 icon = getFallbackIcon();
1528 info.customIcon = false;
1529 info.usingFallbackIcon = true;
1530 } else {
1531 info.customIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001532 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001533 break;
1534 default:
Joe Onoratod8d22da2010-03-11 17:59:11 -08001535 icon = getFallbackIcon();
Joe Onorato56d82912010-03-07 14:32:10 -05001536 info.usingFallbackIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001537 info.customIcon = false;
1538 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001539 }
Joe Onoratod8d22da2010-03-11 17:59:11 -08001540 info.setIcon(icon);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001541 return info;
1542 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543
Joe Onorato56d82912010-03-07 14:32:10 -05001544 Bitmap getIconFromCursor(Cursor c, int iconIndex) {
1545 if (false) {
1546 Log.d(TAG, "getIconFromCursor app="
1547 + c.getString(c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE)));
1548 }
1549 byte[] data = c.getBlob(iconIndex);
1550 try {
1551 return BitmapFactory.decodeByteArray(data, 0, data.length);
1552 } catch (Exception e) {
1553 return null;
1554 }
1555 }
1556
Joe Onorato0589f0f2010-02-08 13:44:00 -08001557 ShortcutInfo addShortcut(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001558 int screen, int cellX, int cellY, boolean notify) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001559
Winson Chunga9abd0e2010-10-27 17:18:37 -07001560 final ShortcutInfo info = infoFromShortcutIntent(context, data, null);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001561 addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001562 screen, cellX, cellY, notify);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001563
1564 return info;
1565 }
1566
Winson Chunga9abd0e2010-10-27 17:18:37 -07001567 /**
Winson Chung55cef262010-10-28 14:14:18 -07001568 * Attempts to find an AppWidgetProviderInfo that matches the given component.
1569 */
1570 AppWidgetProviderInfo findAppWidgetProviderInfoWithComponent(Context context,
1571 ComponentName component) {
1572 List<AppWidgetProviderInfo> widgets =
1573 AppWidgetManager.getInstance(context).getInstalledProviders();
1574 for (AppWidgetProviderInfo info : widgets) {
1575 if (info.provider.equals(component)) {
1576 return info;
1577 }
1578 }
1579 return null;
Winson Chunga9abd0e2010-10-27 17:18:37 -07001580 }
1581
Winson Chung68846fd2010-10-29 11:00:27 -07001582 /**
1583 * Returns a list of all the widgets that can handle configuration with a particular mimeType.
1584 */
1585 List<WidgetMimeTypeHandlerData> resolveWidgetsForMimeType(Context context, String mimeType) {
1586 final PackageManager packageManager = context.getPackageManager();
1587 final List<WidgetMimeTypeHandlerData> supportedConfigurationActivities =
1588 new ArrayList<WidgetMimeTypeHandlerData>();
1589
1590 final Intent supportsIntent =
1591 new Intent(InstallWidgetReceiver.ACTION_SUPPORTS_CLIPDATA_MIMETYPE);
1592 supportsIntent.setType(mimeType);
1593
1594 // Create a set of widget configuration components that we can test against
1595 final List<AppWidgetProviderInfo> widgets =
1596 AppWidgetManager.getInstance(context).getInstalledProviders();
1597 final HashMap<ComponentName, AppWidgetProviderInfo> configurationComponentToWidget =
1598 new HashMap<ComponentName, AppWidgetProviderInfo>();
1599 for (AppWidgetProviderInfo info : widgets) {
1600 configurationComponentToWidget.put(info.configure, info);
1601 }
1602
1603 // Run through each of the intents that can handle this type of clip data, and cross
1604 // reference them with the components that are actual configuration components
1605 final List<ResolveInfo> activities = packageManager.queryIntentActivities(supportsIntent,
1606 PackageManager.MATCH_DEFAULT_ONLY);
1607 for (ResolveInfo info : activities) {
1608 final ActivityInfo activityInfo = info.activityInfo;
1609 final ComponentName infoComponent = new ComponentName(activityInfo.packageName,
1610 activityInfo.name);
1611 if (configurationComponentToWidget.containsKey(infoComponent)) {
1612 supportedConfigurationActivities.add(
1613 new InstallWidgetReceiver.WidgetMimeTypeHandlerData(info,
1614 configurationComponentToWidget.get(infoComponent)));
1615 }
1616 }
1617 return supportedConfigurationActivities;
1618 }
1619
Winson Chunga9abd0e2010-10-27 17:18:37 -07001620 ShortcutInfo infoFromShortcutIntent(Context context, Intent data, Bitmap fallbackIcon) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001621 Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
1622 String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
1623 Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
1624
1625 Bitmap icon = null;
1626 boolean filtered = false;
1627 boolean customIcon = false;
1628 ShortcutIconResource iconResource = null;
1629
1630 if (bitmap != null && bitmap instanceof Bitmap) {
1631 icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap)bitmap), context);
1632 filtered = true;
1633 customIcon = true;
1634 } else {
1635 Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
1636 if (extra != null && extra instanceof ShortcutIconResource) {
1637 try {
1638 iconResource = (ShortcutIconResource) extra;
1639 final PackageManager packageManager = context.getPackageManager();
1640 Resources resources = packageManager.getResourcesForApplication(
1641 iconResource.packageName);
1642 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
Michael Jurkac9a96192010-11-01 11:52:08 -07001643 icon = Utilities.createIconBitmap(
1644 mIconCache.getFullResIcon(resources, id), context);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001645 } catch (Exception e) {
1646 Log.w(TAG, "Could not load shortcut icon: " + extra);
1647 }
1648 }
1649 }
1650
Joe Onorato0589f0f2010-02-08 13:44:00 -08001651 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato56d82912010-03-07 14:32:10 -05001652
1653 if (icon == null) {
Winson Chunga9abd0e2010-10-27 17:18:37 -07001654 if (fallbackIcon != null) {
1655 icon = fallbackIcon;
1656 } else {
1657 icon = getFallbackIcon();
1658 info.usingFallbackIcon = true;
1659 }
Joe Onorato56d82912010-03-07 14:32:10 -05001660 }
Joe Onorato0589f0f2010-02-08 13:44:00 -08001661 info.setIcon(icon);
Joe Onorato56d82912010-03-07 14:32:10 -05001662
Joe Onorato0589f0f2010-02-08 13:44:00 -08001663 info.title = name;
1664 info.intent = intent;
1665 info.customIcon = customIcon;
1666 info.iconResource = iconResource;
1667
1668 return info;
1669 }
1670
Michael Jurkac9a96192010-11-01 11:52:08 -07001671 private void loadLiveFolderIcon(Context context, Cursor c, int iconTypeIndex,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001672 int iconPackageIndex, int iconResourceIndex, LiveFolderInfo liveFolderInfo) {
1673
1674 int iconType = c.getInt(iconTypeIndex);
1675 switch (iconType) {
1676 case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
1677 String packageName = c.getString(iconPackageIndex);
1678 String resourceName = c.getString(iconResourceIndex);
1679 PackageManager packageManager = context.getPackageManager();
1680 try {
Michael Jurkac9a96192010-11-01 11:52:08 -07001681 Resources appResources = packageManager.getResourcesForApplication(packageName);
1682 final int id = appResources.getIdentifier(resourceName, null, null);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001683 liveFolderInfo.icon = Utilities.createIconBitmap(
Michael Jurkac9a96192010-11-01 11:52:08 -07001684 mIconCache.getFullResIcon(appResources, id), context);
1685 } catch (Exception e) {
1686 Resources resources = context.getResources();
1687 liveFolderInfo.icon = Utilities.createIconBitmap(
1688 mIconCache.getFullResIcon(resources, R.drawable.ic_launcher_folder),
Joe Onorato0589f0f2010-02-08 13:44:00 -08001689 context);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001690 }
1691 liveFolderInfo.iconResource = new Intent.ShortcutIconResource();
1692 liveFolderInfo.iconResource.packageName = packageName;
1693 liveFolderInfo.iconResource.resourceName = resourceName;
1694 break;
1695 default:
Michael Jurkac9a96192010-11-01 11:52:08 -07001696 Resources resources = context.getResources();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001697 liveFolderInfo.icon = Utilities.createIconBitmap(
Michael Jurkac9a96192010-11-01 11:52:08 -07001698 mIconCache.getFullResIcon(resources, R.drawable.ic_launcher_folder),
Joe Onorato0589f0f2010-02-08 13:44:00 -08001699 context);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001700 }
1701 }
1702
Joe Onorato56d82912010-03-07 14:32:10 -05001703 void updateSavedIcon(Context context, ShortcutInfo info, Cursor c, int iconIndex) {
Joe Onorato17a89222011-02-08 17:26:11 -08001704 // If apps can't be on SD, don't even bother.
1705 if (!mAppsCanBeOnExternalStorage) {
1706 return;
1707 }
Joe Onorato56d82912010-03-07 14:32:10 -05001708 // If this icon doesn't have a custom icon, check to see
1709 // what's stored in the DB, and if it doesn't match what
1710 // we're going to show, store what we are going to show back
1711 // into the DB. We do this so when we're loading, if the
1712 // package manager can't find an icon (for example because
1713 // the app is on SD) then we can use that instead.
Joe Onoratoddc9c1f2010-08-30 18:30:15 -07001714 if (!info.customIcon && !info.usingFallbackIcon) {
Joe Onorato56d82912010-03-07 14:32:10 -05001715 boolean needSave;
1716 byte[] data = c.getBlob(iconIndex);
1717 try {
1718 if (data != null) {
1719 Bitmap saved = BitmapFactory.decodeByteArray(data, 0, data.length);
1720 Bitmap loaded = info.getIcon(mIconCache);
1721 needSave = !saved.sameAs(loaded);
1722 } else {
1723 needSave = true;
1724 }
1725 } catch (Exception e) {
1726 needSave = true;
1727 }
1728 if (needSave) {
1729 Log.d(TAG, "going to save icon bitmap for info=" + info);
Joe Onorato17a89222011-02-08 17:26:11 -08001730 // This is slower than is ideal, but this only happens once
1731 // or when the app is updated with a new icon.
Joe Onorato56d82912010-03-07 14:32:10 -05001732 updateItemInDatabase(context, info);
1733 }
1734 }
1735 }
1736
Joe Onorato9c1289c2009-08-17 11:03:03 -04001737 /**
1738 * Return an existing UserFolderInfo object if we have encountered this ID previously,
1739 * or make a new one.
1740 */
1741 private static UserFolderInfo findOrMakeUserFolder(HashMap<Long, FolderInfo> folders, long id) {
1742 // See if a placeholder was created for us already
1743 FolderInfo folderInfo = folders.get(id);
1744 if (folderInfo == null || !(folderInfo instanceof UserFolderInfo)) {
1745 // No placeholder -- create a new instance
1746 folderInfo = new UserFolderInfo();
1747 folders.put(id, folderInfo);
1748 }
1749 return (UserFolderInfo) folderInfo;
1750 }
1751
1752 /**
1753 * Return an existing UserFolderInfo object if we have encountered this ID previously, or make a
1754 * new one.
1755 */
1756 private static LiveFolderInfo findOrMakeLiveFolder(HashMap<Long, FolderInfo> folders, long id) {
1757 // See if a placeholder was created for us already
1758 FolderInfo folderInfo = folders.get(id);
1759 if (folderInfo == null || !(folderInfo instanceof LiveFolderInfo)) {
1760 // No placeholder -- create a new instance
1761 folderInfo = new LiveFolderInfo();
1762 folders.put(id, folderInfo);
1763 }
1764 return (LiveFolderInfo) folderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001765 }
1766
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001767 private static String getLabel(PackageManager manager, ActivityInfo activityInfo) {
1768 String label = activityInfo.loadLabel(manager).toString();
1769 if (label == null) {
1770 label = manager.getApplicationLabel(activityInfo.applicationInfo).toString();
1771 if (label == null) {
1772 label = activityInfo.name;
1773 }
1774 }
1775 return label;
1776 }
1777
Joe Onorato9c1289c2009-08-17 11:03:03 -04001778 private static final Collator sCollator = Collator.getInstance();
Joe Onoratob0c27f22009-12-01 16:19:38 -08001779 public static final Comparator<ApplicationInfo> APP_NAME_COMPARATOR
Joe Onorato9c1289c2009-08-17 11:03:03 -04001780 = new Comparator<ApplicationInfo>() {
1781 public final int compare(ApplicationInfo a, ApplicationInfo b) {
1782 return sCollator.compare(a.title.toString(), b.title.toString());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001783 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001784 };
Winson Chung78403fe2011-01-21 15:38:02 -08001785 public static final Comparator<ApplicationInfo> APP_INSTALL_TIME_COMPARATOR
1786 = new Comparator<ApplicationInfo>() {
1787 public final int compare(ApplicationInfo a, ApplicationInfo b) {
1788 if (a.firstInstallTime < b.firstInstallTime) return 1;
1789 if (a.firstInstallTime > b.firstInstallTime) return -1;
1790 return 0;
1791 }
1792 };
Joe Onoratobe386092009-11-17 17:32:16 -08001793
1794 public void dumpState() {
Joe Onoratobe386092009-11-17 17:32:16 -08001795 Log.d(TAG, "mCallbacks=" + mCallbacks);
1796 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mAllAppsList.data);
1797 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mAllAppsList.added);
1798 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mAllAppsList.removed);
1799 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mAllAppsList.modified);
Joe Onorato36115782010-06-17 13:28:48 -04001800 Log.d(TAG, "mItems size=" + mItems.size());
1801 if (mLoaderTask != null) {
1802 mLoaderTask.dumpState();
1803 } else {
1804 Log.d(TAG, "mLoaderTask=null");
1805 }
Joe Onoratobe386092009-11-17 17:32:16 -08001806 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807}