blob: 9766831bb16cb5c02706b43f6ef5efd8c918bed2 [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
Romain Guy629de3e2010-01-13 12:20:59 -080019import android.appwidget.AppWidgetManager;
20import android.appwidget.AppWidgetProviderInfo;
Joe Onoratof99f8c12009-10-31 17:27:36 -040021import android.content.BroadcastReceiver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080022import android.content.ComponentName;
Romain Guy5c16f3e2010-01-12 17:24:58 -080023import android.content.ContentProviderClient;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024import android.content.ContentResolver;
25import android.content.ContentValues;
26import android.content.Intent;
Joe Onorato0589f0f2010-02-08 13:44:00 -080027import android.content.Intent.ShortcutIconResource;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.content.Context;
29import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
Romain Guy5c16f3e2010-01-12 17:24:58 -080031import android.content.pm.ProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.content.pm.ResolveInfo;
33import android.content.res.Resources;
34import android.database.Cursor;
35import android.graphics.Bitmap;
36import android.graphics.BitmapFactory;
37import android.net.Uri;
Joe Onorato0589f0f2010-02-08 13:44:00 -080038import android.os.Parcelable;
Romain Guy5c16f3e2010-01-12 17:24:58 -080039import android.os.RemoteException;
Joe Onorato9c1289c2009-08-17 11:03:03 -040040import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.os.Process;
Joe Onorato9c1289c2009-08-17 11:03:03 -040042import android.os.SystemClock;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043
Joe Onorato9c1289c2009-08-17 11:03:03 -040044import java.lang.ref.WeakReference;
45import java.net.URISyntaxException;
46import java.text.Collator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import java.util.ArrayList;
Joe Onorato56d82912010-03-07 14:32:10 -050048import java.util.Arrays;
Joe Onorato9c1289c2009-08-17 11:03:03 -040049import java.util.Comparator;
50import java.util.Collections;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051import java.util.HashMap;
52import java.util.List;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053
Romain Guyedcce092010-03-04 13:03:17 -080054import com.android.launcher.R;
55
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056/**
57 * Maintains in-memory state of the Launcher. It is expected that there should be only one
58 * LauncherModel object held in a static. Also provide APIs for updating the database state
The Android Open Source Projectbc219c32009-03-09 11:52:14 -070059 * for the Launcher.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060 */
Joe Onoratof99f8c12009-10-31 17:27:36 -040061public class LauncherModel extends BroadcastReceiver {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080062 static final boolean DEBUG_LOADERS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -040063 static final String TAG = "Launcher.Model";
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070064
Daniel Sandlerdca66122010-04-13 16:23:58 -040065 final int ALL_APPS_LOAD_DELAY = 150; // ms
66
Joe Onoratof99f8c12009-10-31 17:27:36 -040067 private final LauncherApplication mApp;
Joe Onorato9c1289c2009-08-17 11:03:03 -040068 private final Object mLock = new Object();
69 private DeferredHandler mHandler = new DeferredHandler();
70 private Loader mLoader = new Loader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071
Joe Onoratof99f8c12009-10-31 17:27:36 -040072 private boolean mBeforeFirstLoad = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -040073 private WeakReference<Callbacks> mCallbacks;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074
Joe Onorato0589f0f2010-02-08 13:44:00 -080075 private AllAppsList mAllAppsList;
76 private IconCache mIconCache;
77
78 private Bitmap mDefaultIcon;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080079
Joe Onorato9c1289c2009-08-17 11:03:03 -040080 public interface Callbacks {
81 public int getCurrentWorkspaceScreen();
82 public void startBinding();
83 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end);
Joe Onoratoad72e172009-11-06 16:25:04 -050084 public void bindFolders(HashMap<Long,FolderInfo> folders);
Joe Onorato9c1289c2009-08-17 11:03:03 -040085 public void finishBindingItems();
86 public void bindAppWidget(LauncherAppWidgetInfo info);
87 public void bindAllApplications(ArrayList<ApplicationInfo> apps);
Joe Onorato64e6be72010-03-05 15:05:52 -050088 public void bindAppsAdded(ArrayList<ApplicationInfo> apps);
89 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps);
90 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps);
Daniel Sandlerdca66122010-04-13 16:23:58 -040091 public int getAppBatchSize();
Joe Onorato9c1289c2009-08-17 11:03:03 -040092 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093
Joe Onorato0589f0f2010-02-08 13:44:00 -080094 LauncherModel(LauncherApplication app, IconCache iconCache) {
Joe Onoratof99f8c12009-10-31 17:27:36 -040095 mApp = app;
Joe Onorato0589f0f2010-02-08 13:44:00 -080096 mAllAppsList = new AllAppsList(iconCache);
97 mIconCache = iconCache;
98
99 mDefaultIcon = Utilities.createIconBitmap(
100 app.getPackageManager().getDefaultActivityIcon(), app);
101 }
102
Joe Onorato56d82912010-03-07 14:32:10 -0500103 public Bitmap getFallbackIcon() {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800104 return Bitmap.createBitmap(mDefaultIcon);
Joe Onoratof99f8c12009-10-31 17:27:36 -0400105 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800106
Joe Onorato9c1289c2009-08-17 11:03:03 -0400107 /**
108 * Adds an item to the DB if it was not created previously, or move it to a new
109 * <container, screen, cellX, cellY>
110 */
111 static void addOrMoveItemInDatabase(Context context, ItemInfo item, long container,
112 int screen, int cellX, int cellY) {
113 if (item.container == ItemInfo.NO_ID) {
114 // From all apps
115 addItemToDatabase(context, item, container, screen, cellX, cellY, false);
116 } else {
117 // From somewhere else
118 moveItemInDatabase(context, item, container, screen, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119 }
120 }
121
122 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400123 * Move an item in the DB to a new <container, screen, cellX, cellY>
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700124 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400125 static void moveItemInDatabase(Context context, ItemInfo item, long container, int screen,
126 int cellX, int cellY) {
127 item.container = container;
128 item.screen = screen;
129 item.cellX = cellX;
130 item.cellY = cellY;
131
132 final ContentValues values = new ContentValues();
133 final ContentResolver cr = context.getContentResolver();
134
135 values.put(LauncherSettings.Favorites.CONTAINER, item.container);
136 values.put(LauncherSettings.Favorites.CELLX, item.cellX);
137 values.put(LauncherSettings.Favorites.CELLY, item.cellY);
138 values.put(LauncherSettings.Favorites.SCREEN, item.screen);
139
140 cr.update(LauncherSettings.Favorites.getContentUri(item.id, false), values, null, null);
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700141 }
142
143 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -0400144 * Returns true if the shortcuts already exists in the database.
145 * we identify a shortcut by its title and intent.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400147 static boolean shortcutExists(Context context, String title, Intent intent) {
148 final ContentResolver cr = context.getContentResolver();
149 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
150 new String[] { "title", "intent" }, "title=? and intent=?",
151 new String[] { title, intent.toUri(0) }, null);
152 boolean result = false;
153 try {
154 result = c.moveToFirst();
155 } finally {
156 c.close();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400158 return result;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700159 }
160
Joe Onorato9c1289c2009-08-17 11:03:03 -0400161 /**
162 * Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList.
163 */
164 FolderInfo getFolderById(Context context, HashMap<Long,FolderInfo> folderList, long id) {
165 final ContentResolver cr = context.getContentResolver();
166 Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null,
167 "_id=? and (itemType=? or itemType=?)",
168 new String[] { String.valueOf(id),
169 String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER),
170 String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER) }, null);
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700171
Joe Onorato9c1289c2009-08-17 11:03:03 -0400172 try {
173 if (c.moveToFirst()) {
174 final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
175 final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
176 final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
177 final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
178 final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
179 final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180
Joe Onorato9c1289c2009-08-17 11:03:03 -0400181 FolderInfo folderInfo = null;
182 switch (c.getInt(itemTypeIndex)) {
183 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
184 folderInfo = findOrMakeUserFolder(folderList, id);
185 break;
186 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
187 folderInfo = findOrMakeLiveFolder(folderList, id);
188 break;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700189 }
190
Joe Onorato9c1289c2009-08-17 11:03:03 -0400191 folderInfo.title = c.getString(titleIndex);
192 folderInfo.id = id;
193 folderInfo.container = c.getInt(containerIndex);
194 folderInfo.screen = c.getInt(screenIndex);
195 folderInfo.cellX = c.getInt(cellXIndex);
196 folderInfo.cellY = c.getInt(cellYIndex);
197
198 return folderInfo;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700199 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400200 } finally {
201 c.close();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700202 }
203
204 return null;
205 }
206
Joe Onorato9c1289c2009-08-17 11:03:03 -0400207 /**
208 * Add an item to the database in a specified container. Sets the container, screen, cellX and
209 * cellY fields of the item. Also assigns an ID to the item.
210 */
211 static void addItemToDatabase(Context context, ItemInfo item, long container,
212 int screen, int cellX, int cellY, boolean notify) {
213 item.container = container;
214 item.screen = screen;
215 item.cellX = cellX;
216 item.cellY = cellY;
217
218 final ContentValues values = new ContentValues();
219 final ContentResolver cr = context.getContentResolver();
220
221 item.onAddToDatabase(values);
222
223 Uri result = cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
224 LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
225
226 if (result != null) {
227 item.id = Integer.parseInt(result.getPathSegments().get(1));
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700228 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700229 }
230
Joe Onorato9c1289c2009-08-17 11:03:03 -0400231 /**
232 * Update an item to the database in a specified container.
233 */
234 static void updateItemInDatabase(Context context, ItemInfo item) {
235 final ContentValues values = new ContentValues();
236 final ContentResolver cr = context.getContentResolver();
237
238 item.onAddToDatabase(values);
239
240 cr.update(LauncherSettings.Favorites.getContentUri(item.id, false), values, null, null);
241 }
242
243 /**
244 * Removes the specified item from the database
245 * @param context
246 * @param item
247 */
248 static void deleteItemFromDatabase(Context context, ItemInfo item) {
249 final ContentResolver cr = context.getContentResolver();
250
251 cr.delete(LauncherSettings.Favorites.getContentUri(item.id, false), null, null);
252 }
253
254 /**
255 * Remove the contents of the specified folder from the database
256 */
257 static void deleteUserFolderContentsFromDatabase(Context context, UserFolderInfo info) {
258 final ContentResolver cr = context.getContentResolver();
259
260 cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
261 cr.delete(LauncherSettings.Favorites.CONTENT_URI,
262 LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
263 }
264
265 /**
266 * Set this as the current Launcher activity object for the loader.
267 */
268 public void initialize(Callbacks callbacks) {
269 synchronized (mLock) {
270 mCallbacks = new WeakReference<Callbacks>(callbacks);
271 }
272 }
273
274 public void startLoader(Context context, boolean isLaunching) {
275 mLoader.startLoader(context, isLaunching);
276 }
277
278 public void stopLoader() {
279 mLoader.stopLoader();
280 }
281
Joe Onorato1d8e7bb2009-10-15 19:49:43 -0700282 /**
283 * We pick up most of the changes to all apps.
284 */
285 public void setAllAppsDirty() {
286 mLoader.setAllAppsDirty();
287 }
288
Joe Onorato9c1289c2009-08-17 11:03:03 -0400289 public void setWorkspaceDirty() {
290 mLoader.setWorkspaceDirty();
291 }
292
293 /**
294 * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
295 * ACTION_PACKAGE_CHANGED.
296 */
Joe Onoratof99f8c12009-10-31 17:27:36 -0400297 public void onReceive(Context context, Intent intent) {
298 // Use the app as the context.
299 context = mApp;
300
Joe Onorato9c1289c2009-08-17 11:03:03 -0400301 ArrayList<ApplicationInfo> added = null;
302 ArrayList<ApplicationInfo> removed = null;
303 ArrayList<ApplicationInfo> modified = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400304
305 synchronized (mLock) {
Joe Onoratof99f8c12009-10-31 17:27:36 -0400306 if (mBeforeFirstLoad) {
307 // If we haven't even loaded yet, don't bother, since we'll just pick
308 // up the changes.
309 return;
310 }
311
Joe Onorato9c1289c2009-08-17 11:03:03 -0400312 final String action = intent.getAction();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400313
Joe Onorato64e6be72010-03-05 15:05:52 -0500314 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
315 || Intent.ACTION_PACKAGE_REMOVED.equals(action)
316 || Intent.ACTION_PACKAGE_ADDED.equals(action)) {
317 final String packageName = intent.getData().getSchemeSpecificPart();
318 final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400319
Joe Onorato64e6be72010-03-05 15:05:52 -0500320 if (packageName == null || packageName.length() == 0) {
321 // they sent us a bad intent
322 return;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400323 }
Joe Onorato64e6be72010-03-05 15:05:52 -0500324
325 if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400326 mAllAppsList.updatePackage(context, packageName);
Joe Onorato64e6be72010-03-05 15:05:52 -0500327 } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
328 if (!replacing) {
329 mAllAppsList.removePackage(packageName);
330 }
331 // else, we are replacing the package, so a PACKAGE_ADDED will be sent
332 // later, we will update the package at this time
333 } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
334 if (!replacing) {
335 mAllAppsList.addPackage(context, packageName);
336 } else {
337 mAllAppsList.updatePackage(context, packageName);
338 }
339 }
Joe Onorato56d82912010-03-07 14:32:10 -0500340
341 if (mAllAppsList.added.size() > 0) {
342 added = mAllAppsList.added;
343 mAllAppsList.added = new ArrayList<ApplicationInfo>();
344 }
345 if (mAllAppsList.removed.size() > 0) {
346 removed = mAllAppsList.removed;
347 mAllAppsList.removed = new ArrayList<ApplicationInfo>();
348 for (ApplicationInfo info: removed) {
349 mIconCache.remove(info.intent.getComponent());
350 }
351 }
352 if (mAllAppsList.modified.size() > 0) {
353 modified = mAllAppsList.modified;
354 mAllAppsList.modified = new ArrayList<ApplicationInfo>();
355 }
356
357 final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
358 if (callbacks == null) {
359 Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading.");
360 return;
361 }
362
363 if (added != null) {
364 final ArrayList<ApplicationInfo> addedFinal = added;
365 mHandler.post(new Runnable() {
366 public void run() {
367 callbacks.bindAppsAdded(addedFinal);
368 }
369 });
370 }
371 if (modified != null) {
372 final ArrayList<ApplicationInfo> modifiedFinal = modified;
373 mHandler.post(new Runnable() {
374 public void run() {
375 callbacks.bindAppsUpdated(modifiedFinal);
376 }
377 });
378 }
379 if (removed != null) {
380 final ArrayList<ApplicationInfo> removedFinal = removed;
381 mHandler.post(new Runnable() {
382 public void run() {
383 callbacks.bindAppsRemoved(removedFinal);
384 }
385 });
386 }
Joe Onorato64e6be72010-03-05 15:05:52 -0500387 } else {
388 if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
389 String packages[] = intent.getStringArrayExtra(
390 Intent.EXTRA_CHANGED_PACKAGE_LIST);
391 if (packages == null || packages.length == 0) {
392 return;
393 }
Joe Onorato56d82912010-03-07 14:32:10 -0500394 setAllAppsDirty();
395 setWorkspaceDirty();
396 startLoader(context, false);
Joe Onorato64e6be72010-03-05 15:05:52 -0500397 } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
398 String packages[] = intent.getStringArrayExtra(
399 Intent.EXTRA_CHANGED_PACKAGE_LIST);
400 if (packages == null || packages.length == 0) {
401 return;
402 }
Joe Onorato56d82912010-03-07 14:32:10 -0500403 setAllAppsDirty();
404 setWorkspaceDirty();
405 startLoader(context, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400406 }
407 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400408 }
409 }
410
411 public class Loader {
412 private static final int ITEMS_CHUNK = 6;
413
414 private LoaderThread mLoaderThread;
415
416 private int mLastWorkspaceSeq = 0;
417 private int mWorkspaceSeq = 1;
418
419 private int mLastAllAppsSeq = 0;
420 private int mAllAppsSeq = 1;
421
Romain Guy84f296c2009-11-04 15:00:44 -0800422 final ArrayList<ItemInfo> mItems = new ArrayList<ItemInfo>();
423 final ArrayList<LauncherAppWidgetInfo> mAppWidgets = new ArrayList<LauncherAppWidgetInfo>();
Joe Onoratoad72e172009-11-06 16:25:04 -0500424 final HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400425
426 /**
427 * Call this from the ui thread so the handler is initialized on the correct thread.
428 */
429 public Loader() {
430 }
431
432 public void startLoader(Context context, boolean isLaunching) {
433 synchronized (mLock) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800434 if (DEBUG_LOADERS) {
435 Log.d(TAG, "startLoader isLaunching=" + isLaunching);
436 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400437 // Don't bother to start the thread if we know it's not going to do anything
Joe Onoratoac033302010-04-13 17:19:18 -0700438 if (mCallbacks != null && mCallbacks.get() != null) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400439 LoaderThread oldThread = mLoaderThread;
440 if (oldThread != null) {
441 if (oldThread.isLaunching()) {
442 // don't downgrade isLaunching if we're already running
443 isLaunching = true;
444 }
445 oldThread.stopLocked();
446 }
447 mLoaderThread = new LoaderThread(context, oldThread, isLaunching);
448 mLoaderThread.start();
449 }
450 }
451 }
452
453 public void stopLoader() {
454 synchronized (mLock) {
455 if (mLoaderThread != null) {
456 mLoaderThread.stopLocked();
457 }
458 }
459 }
460
461 public void setWorkspaceDirty() {
462 synchronized (mLock) {
463 mWorkspaceSeq++;
464 }
465 }
466
467 public void setAllAppsDirty() {
468 synchronized (mLock) {
469 mAllAppsSeq++;
470 }
471 }
472
473 /**
474 * Runnable for the thread that loads the contents of the launcher:
475 * - workspace icons
476 * - widgets
477 * - all apps icons
478 */
479 private class LoaderThread extends Thread {
480 private Context mContext;
481 private Thread mWaitThread;
482 private boolean mIsLaunching;
483 private boolean mStopped;
484 private boolean mWorkspaceDoneBinding;
485
486 LoaderThread(Context context, Thread waitThread, boolean isLaunching) {
487 mContext = context;
488 mWaitThread = waitThread;
489 mIsLaunching = isLaunching;
490 }
491
492 boolean isLaunching() {
493 return mIsLaunching;
494 }
495
496 /**
497 * If another LoaderThread was supplied, we need to wait for that to finish before
498 * we start our processing. This keeps the ordering of the setting and clearing
499 * of the dirty flags correct by making sure we don't start processing stuff until
500 * they've had a chance to re-set them. We do this waiting the worker thread, not
501 * the ui thread to avoid ANRs.
502 */
503 private void waitForOtherThread() {
504 if (mWaitThread != null) {
505 boolean done = false;
506 while (!done) {
507 try {
508 mWaitThread.join();
Joe Onoratoefabe002009-08-28 09:38:18 -0700509 done = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400510 } catch (InterruptedException ex) {
Romain Guy84f296c2009-11-04 15:00:44 -0800511 // Ignore
Joe Onorato9c1289c2009-08-17 11:03:03 -0400512 }
513 }
514 mWaitThread = null;
515 }
516 }
517
518 public void run() {
519 waitForOtherThread();
520
521 // Elevate priority when Home launches for the first time to avoid
522 // starving at boot time. Staring at a blank home is not cool.
523 synchronized (mLock) {
524 android.os.Process.setThreadPriority(mIsLaunching
525 ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
526 }
527
528 // Load the workspace only if it's dirty.
529 int workspaceSeq;
530 boolean workspaceDirty;
531 synchronized (mLock) {
532 workspaceSeq = mWorkspaceSeq;
533 workspaceDirty = mWorkspaceSeq != mLastWorkspaceSeq;
534 }
535 if (workspaceDirty) {
536 loadWorkspace();
537 }
538 synchronized (mLock) {
539 // If we're not stopped, and nobody has incremented mWorkspaceSeq.
540 if (mStopped) {
541 return;
542 }
543 if (workspaceSeq == mWorkspaceSeq) {
544 mLastWorkspaceSeq = mWorkspaceSeq;
545 }
546 }
547
548 // Bind the workspace
549 bindWorkspace();
550
551 // Wait until the either we're stopped or the other threads are done.
552 // This way we don't start loading all apps until the workspace has settled
553 // down.
554 synchronized (LoaderThread.this) {
Joe Onorato080d9b62009-11-02 12:01:11 -0500555 mHandler.postIdle(new Runnable() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400556 public void run() {
557 synchronized (LoaderThread.this) {
558 mWorkspaceDoneBinding = true;
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800559 if (DEBUG_LOADERS) {
560 Log.d(TAG, "done with workspace");
561 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400562 LoaderThread.this.notify();
563 }
564 }
565 });
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800566 if (DEBUG_LOADERS) {
567 Log.d(TAG, "waiting to be done with workspace");
568 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400569 while (!mStopped && !mWorkspaceDoneBinding) {
570 try {
571 this.wait();
572 } catch (InterruptedException ex) {
Romain Guy84f296c2009-11-04 15:00:44 -0800573 // Ignore
Joe Onorato9c1289c2009-08-17 11:03:03 -0400574 }
575 }
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800576 if (DEBUG_LOADERS) {
577 Log.d(TAG, "done waiting to be done with workspace");
578 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400579 }
580
Daniel Sandlerdca66122010-04-13 16:23:58 -0400581 // Whew! Hard work done.
582 synchronized (mLock) {
583 if (mIsLaunching) {
584 android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
585 }
586 }
587
Joe Onorato9c1289c2009-08-17 11:03:03 -0400588 // Load all apps if they're dirty
589 int allAppsSeq;
590 boolean allAppsDirty;
591 synchronized (mLock) {
592 allAppsSeq = mAllAppsSeq;
593 allAppsDirty = mAllAppsSeq != mLastAllAppsSeq;
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800594 if (DEBUG_LOADERS) {
595 Log.d(TAG, "mAllAppsSeq=" + mAllAppsSeq
596 + " mLastAllAppsSeq=" + mLastAllAppsSeq + " allAppsDirty");
597 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400598 }
599 if (allAppsDirty) {
Daniel Sandlerdca66122010-04-13 16:23:58 -0400600 loadAndBindAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400601 }
602 synchronized (mLock) {
603 // If we're not stopped, and nobody has incremented mAllAppsSeq.
604 if (mStopped) {
605 return;
606 }
607 if (allAppsSeq == mAllAppsSeq) {
608 mLastAllAppsSeq = mAllAppsSeq;
609 }
610 }
611
Joe Onorato9c1289c2009-08-17 11:03:03 -0400612 // Clear out this reference, otherwise we end up holding it until all of the
613 // callback runnables are done.
614 mContext = null;
615
616 synchronized (mLock) {
617 // Setting the reference is atomic, but we can't do it inside the other critical
618 // sections.
619 mLoaderThread = null;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400620 }
621 }
622
623 public void stopLocked() {
624 synchronized (LoaderThread.this) {
625 mStopped = true;
626 this.notify();
627 }
628 }
629
630 /**
631 * Gets the callbacks object. If we've been stopped, or if the launcher object
Joe Onoratoc131b742010-03-11 15:45:05 -0800632 * has somehow been garbage collected, return null instead. Pass in the Callbacks
633 * object that was around when the deferred message was scheduled, and if there's
634 * a new Callbacks object around then also return null. This will save us from
635 * calling onto it with data that will be ignored.
Joe Onorato9c1289c2009-08-17 11:03:03 -0400636 */
Joe Onoratoc131b742010-03-11 15:45:05 -0800637 Callbacks tryGetCallbacks(Callbacks oldCallbacks) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400638 synchronized (mLock) {
639 if (mStopped) {
640 return null;
641 }
642
Joe Onoratoac033302010-04-13 17:19:18 -0700643 if (mCallbacks == null) {
644 return null;
645 }
646
Joe Onorato9c1289c2009-08-17 11:03:03 -0400647 final Callbacks callbacks = mCallbacks.get();
Joe Onoratoc131b742010-03-11 15:45:05 -0800648 if (callbacks != oldCallbacks) {
649 return null;
650 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400651 if (callbacks == null) {
652 Log.w(TAG, "no mCallbacks");
653 return null;
654 }
655
656 return callbacks;
657 }
658 }
659
660 private void loadWorkspace() {
661 long t = SystemClock.uptimeMillis();
662
663 final Context context = mContext;
664 final ContentResolver contentResolver = context.getContentResolver();
665 final PackageManager manager = context.getPackageManager();
Romain Guy629de3e2010-01-13 12:20:59 -0800666 final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
Romain Guy5c16f3e2010-01-12 17:24:58 -0800667 final boolean isSafeMode = manager.isSafeMode();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400668
Joe Onorato3c2f7e12009-10-31 19:17:31 -0400669 mItems.clear();
Joe Onorato511ab642009-11-08 14:14:07 -0500670 mAppWidgets.clear();
Joe Onorato1db7a972009-11-16 18:32:22 -0800671 mFolders.clear();
Joe Onorato3c2f7e12009-10-31 19:17:31 -0400672
Romain Guy5c16f3e2010-01-12 17:24:58 -0800673 final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
674
Joe Onorato9c1289c2009-08-17 11:03:03 -0400675 final Cursor c = contentResolver.query(
676 LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
677
678 try {
679 final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
680 final int intentIndex = c.getColumnIndexOrThrow
681 (LauncherSettings.Favorites.INTENT);
682 final int titleIndex = c.getColumnIndexOrThrow
683 (LauncherSettings.Favorites.TITLE);
684 final int iconTypeIndex = c.getColumnIndexOrThrow(
685 LauncherSettings.Favorites.ICON_TYPE);
686 final int iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
687 final int iconPackageIndex = c.getColumnIndexOrThrow(
688 LauncherSettings.Favorites.ICON_PACKAGE);
689 final int iconResourceIndex = c.getColumnIndexOrThrow(
690 LauncherSettings.Favorites.ICON_RESOURCE);
691 final int containerIndex = c.getColumnIndexOrThrow(
692 LauncherSettings.Favorites.CONTAINER);
693 final int itemTypeIndex = c.getColumnIndexOrThrow(
694 LauncherSettings.Favorites.ITEM_TYPE);
695 final int appWidgetIdIndex = c.getColumnIndexOrThrow(
696 LauncherSettings.Favorites.APPWIDGET_ID);
697 final int screenIndex = c.getColumnIndexOrThrow(
698 LauncherSettings.Favorites.SCREEN);
699 final int cellXIndex = c.getColumnIndexOrThrow
700 (LauncherSettings.Favorites.CELLX);
701 final int cellYIndex = c.getColumnIndexOrThrow
702 (LauncherSettings.Favorites.CELLY);
703 final int spanXIndex = c.getColumnIndexOrThrow
704 (LauncherSettings.Favorites.SPANX);
705 final int spanYIndex = c.getColumnIndexOrThrow(
706 LauncherSettings.Favorites.SPANY);
707 final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI);
708 final int displayModeIndex = c.getColumnIndexOrThrow(
709 LauncherSettings.Favorites.DISPLAY_MODE);
710
Joe Onorato0589f0f2010-02-08 13:44:00 -0800711 ShortcutInfo info;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400712 String intentDescription;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400713 LauncherAppWidgetInfo appWidgetInfo;
714 int container;
715 long id;
716 Intent intent;
717
718 while (!mStopped && c.moveToNext()) {
719 try {
720 int itemType = c.getInt(itemTypeIndex);
721
722 switch (itemType) {
723 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
724 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
725 intentDescription = c.getString(intentIndex);
726 try {
727 intent = Intent.parseUri(intentDescription, 0);
728 } catch (URISyntaxException e) {
729 continue;
730 }
731
732 if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
Joe Onorato56d82912010-03-07 14:32:10 -0500733 info = getShortcutInfo(manager, intent, context, c, iconIndex,
734 titleIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400735 } else {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800736 info = getShortcutInfo(c, context, iconTypeIndex,
Joe Onorato56d82912010-03-07 14:32:10 -0500737 iconPackageIndex, iconResourceIndex, iconIndex,
738 titleIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400739 }
740
741 if (info != null) {
Joe Onorato56d82912010-03-07 14:32:10 -0500742 updateSavedIcon(context, info, c, iconIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400743
Joe Onorato56d82912010-03-07 14:32:10 -0500744 info.intent = intent;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400745 info.id = c.getLong(idIndex);
746 container = c.getInt(containerIndex);
747 info.container = container;
748 info.screen = c.getInt(screenIndex);
749 info.cellX = c.getInt(cellXIndex);
750 info.cellY = c.getInt(cellYIndex);
751
752 switch (container) {
753 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
754 mItems.add(info);
755 break;
756 default:
757 // Item is in a user folder
758 UserFolderInfo folderInfo =
Joe Onoratoad72e172009-11-06 16:25:04 -0500759 findOrMakeUserFolder(mFolders, container);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400760 folderInfo.add(info);
761 break;
762 }
Joe Onorato56d82912010-03-07 14:32:10 -0500763 } else {
764 // Failed to load the shortcut, probably because the
765 // activity manager couldn't resolve it (maybe the app
766 // was uninstalled), or the db row was somehow screwed up.
767 // Delete it.
768 id = c.getLong(idIndex);
769 Log.e(TAG, "Error loading shortcut " + id + ", removing it");
770 contentResolver.delete(LauncherSettings.Favorites.getContentUri(
771 id, false), null, null);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400772 }
773 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400774
Joe Onoratoad72e172009-11-06 16:25:04 -0500775 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400776 id = c.getLong(idIndex);
Joe Onoratoad72e172009-11-06 16:25:04 -0500777 UserFolderInfo folderInfo = findOrMakeUserFolder(mFolders, id);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400778
779 folderInfo.title = c.getString(titleIndex);
780
781 folderInfo.id = id;
782 container = c.getInt(containerIndex);
783 folderInfo.container = container;
784 folderInfo.screen = c.getInt(screenIndex);
785 folderInfo.cellX = c.getInt(cellXIndex);
786 folderInfo.cellY = c.getInt(cellYIndex);
787
788 switch (container) {
789 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
790 mItems.add(folderInfo);
791 break;
792 }
Joe Onoratoad72e172009-11-06 16:25:04 -0500793
794 mFolders.put(folderInfo.id, folderInfo);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400795 break;
Joe Onoratoad72e172009-11-06 16:25:04 -0500796
Joe Onorato9c1289c2009-08-17 11:03:03 -0400797 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400798 id = c.getLong(idIndex);
Romain Guy5c16f3e2010-01-12 17:24:58 -0800799 Uri uri = Uri.parse(c.getString(uriIndex));
Joe Onorato9c1289c2009-08-17 11:03:03 -0400800
Romain Guy5c16f3e2010-01-12 17:24:58 -0800801 // Make sure the live folder exists
802 final ProviderInfo providerInfo =
803 context.getPackageManager().resolveContentProvider(
804 uri.getAuthority(), 0);
805
806 if (providerInfo == null && !isSafeMode) {
807 itemsToRemove.add(id);
808 } else {
809 LiveFolderInfo liveFolderInfo = findOrMakeLiveFolder(mFolders, id);
810
811 intentDescription = c.getString(intentIndex);
812 intent = null;
813 if (intentDescription != null) {
814 try {
815 intent = Intent.parseUri(intentDescription, 0);
816 } catch (URISyntaxException e) {
817 // Ignore, a live folder might not have a base intent
818 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400819 }
Romain Guy5c16f3e2010-01-12 17:24:58 -0800820
821 liveFolderInfo.title = c.getString(titleIndex);
822 liveFolderInfo.id = id;
823 liveFolderInfo.uri = uri;
824 container = c.getInt(containerIndex);
825 liveFolderInfo.container = container;
826 liveFolderInfo.screen = c.getInt(screenIndex);
827 liveFolderInfo.cellX = c.getInt(cellXIndex);
828 liveFolderInfo.cellY = c.getInt(cellYIndex);
829 liveFolderInfo.baseIntent = intent;
830 liveFolderInfo.displayMode = c.getInt(displayModeIndex);
831
832 loadLiveFolderIcon(context, c, iconTypeIndex, iconPackageIndex,
833 iconResourceIndex, liveFolderInfo);
834
835 switch (container) {
836 case LauncherSettings.Favorites.CONTAINER_DESKTOP:
837 mItems.add(liveFolderInfo);
838 break;
839 }
840 mFolders.put(liveFolderInfo.id, liveFolderInfo);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400841 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400842 break;
Joe Onoratoad72e172009-11-06 16:25:04 -0500843
Joe Onorato9c1289c2009-08-17 11:03:03 -0400844 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
845 // Read all Launcher-specific widget details
846 int appWidgetId = c.getInt(appWidgetIdIndex);
Romain Guy629de3e2010-01-13 12:20:59 -0800847 id = c.getLong(idIndex);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400848
Romain Guy629de3e2010-01-13 12:20:59 -0800849 final AppWidgetProviderInfo provider =
850 widgets.getAppWidgetInfo(appWidgetId);
851
852 if (!isSafeMode && (provider == null || provider.provider == null ||
853 provider.provider.getPackageName() == null)) {
Joe Onorato8ddc4fd2010-03-17 09:14:50 -0700854 Log.e(TAG, "Deleting widget that isn't installed anymore: id="
855 + id + " appWidgetId=" + appWidgetId);
Romain Guy629de3e2010-01-13 12:20:59 -0800856 itemsToRemove.add(id);
857 } else {
858 appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId);
859 appWidgetInfo.id = id;
860 appWidgetInfo.screen = c.getInt(screenIndex);
861 appWidgetInfo.cellX = c.getInt(cellXIndex);
862 appWidgetInfo.cellY = c.getInt(cellYIndex);
863 appWidgetInfo.spanX = c.getInt(spanXIndex);
864 appWidgetInfo.spanY = c.getInt(spanYIndex);
865
866 container = c.getInt(containerIndex);
867 if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
868 Log.e(TAG, "Widget found where container "
869 + "!= CONTAINER_DESKTOP -- ignoring!");
870 continue;
871 }
872 appWidgetInfo.container = c.getInt(containerIndex);
873
874 mAppWidgets.add(appWidgetInfo);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400875 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400876 break;
877 }
878 } catch (Exception e) {
879 Log.w(TAG, "Desktop items loading interrupted:", e);
880 }
881 }
882 } finally {
883 c.close();
884 }
Romain Guy5c16f3e2010-01-12 17:24:58 -0800885
886 if (itemsToRemove.size() > 0) {
887 ContentProviderClient client = contentResolver.acquireContentProviderClient(
888 LauncherSettings.Favorites.CONTENT_URI);
889 // Remove dead items
890 for (long id : itemsToRemove) {
891 if (DEBUG_LOADERS) {
892 Log.d(TAG, "Removed id = " + id);
893 }
894 // Don't notify content observers
895 try {
896 client.delete(LauncherSettings.Favorites.getContentUri(id, false),
897 null, null);
898 } catch (RemoteException e) {
899 Log.w(TAG, "Could not remove id = " + id);
900 }
901 }
902 }
903
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800904 if (DEBUG_LOADERS) {
905 Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms");
906 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400907 }
908
909 /**
910 * Read everything out of our database.
911 */
912 private void bindWorkspace() {
913 final long t = SystemClock.uptimeMillis();
914
915 // Don't use these two variables in any of the callback runnables.
916 // Otherwise we hold a reference to them.
Joe Onoratoc131b742010-03-11 15:45:05 -0800917 final Callbacks oldCallbacks = mCallbacks.get();
918 if (oldCallbacks == null) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400919 // This launcher has exited and nobody bothered to tell us. Just bail.
920 Log.w(TAG, "LoaderThread running with no launcher");
921 return;
922 }
923
924 int N;
925 // Tell the workspace that we're about to start firing items at it
926 mHandler.post(new Runnable() {
927 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -0800928 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400929 if (callbacks != null) {
930 callbacks.startBinding();
931 }
932 }
933 });
934 // Add the items to the workspace.
935 N = mItems.size();
936 for (int i=0; i<N; i+=ITEMS_CHUNK) {
937 final int start = i;
938 final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i);
939 mHandler.post(new Runnable() {
940 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -0800941 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400942 if (callbacks != null) {
943 callbacks.bindItems(mItems, start, start+chunkSize);
944 }
945 }
946 });
947 }
Joe Onoratoad72e172009-11-06 16:25:04 -0500948 mHandler.post(new Runnable() {
949 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -0800950 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onoratoad72e172009-11-06 16:25:04 -0500951 if (callbacks != null) {
952 callbacks.bindFolders(mFolders);
953 }
954 }
955 });
Joe Onorato9c1289c2009-08-17 11:03:03 -0400956 // Wait until the queue goes empty.
957 mHandler.postIdle(new Runnable() {
958 public void run() {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800959 if (DEBUG_LOADERS) {
960 Log.d(TAG, "Going to start binding widgets soon.");
961 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400962 }
963 });
964 // Bind the widgets, one at a time.
965 // WARNING: this is calling into the workspace from the background thread,
966 // but since getCurrentScreen() just returns the int, we should be okay. This
967 // is just a hint for the order, and if it's wrong, we'll be okay.
968 // TODO: instead, we should have that push the current screen into here.
Joe Onoratoc131b742010-03-11 15:45:05 -0800969 final int currentScreen = oldCallbacks.getCurrentWorkspaceScreen();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400970 N = mAppWidgets.size();
971 // once for the current screen
972 for (int i=0; i<N; i++) {
973 final LauncherAppWidgetInfo widget = mAppWidgets.get(i);
974 if (widget.screen == currentScreen) {
975 mHandler.post(new Runnable() {
976 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -0800977 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400978 if (callbacks != null) {
979 callbacks.bindAppWidget(widget);
980 }
981 }
982 });
983 }
984 }
985 // once for the other screens
986 for (int i=0; i<N; i++) {
987 final LauncherAppWidgetInfo widget = mAppWidgets.get(i);
988 if (widget.screen != currentScreen) {
989 mHandler.post(new Runnable() {
990 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -0800991 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400992 if (callbacks != null) {
993 callbacks.bindAppWidget(widget);
994 }
995 }
996 });
997 }
998 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400999 // Tell the workspace that we're done.
1000 mHandler.post(new Runnable() {
1001 public void run() {
Joe Onoratoc131b742010-03-11 15:45:05 -08001002 Callbacks callbacks = tryGetCallbacks(oldCallbacks);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001003 if (callbacks != null) {
1004 callbacks.finishBindingItems();
1005 }
1006 }
1007 });
1008 // If we're profiling, this is the last thing in the queue.
1009 mHandler.post(new Runnable() {
1010 public void run() {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001011 if (DEBUG_LOADERS) {
1012 Log.d(TAG, "bound workspace in "
1013 + (SystemClock.uptimeMillis()-t) + "ms");
1014 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001015 if (Launcher.PROFILE_ROTATE) {
1016 android.os.Debug.stopMethodTracing();
1017 }
1018 }
1019 });
1020 }
1021
Daniel Sandlerdca66122010-04-13 16:23:58 -04001022 private void loadAndBindAllApps() {
1023 final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1024
Joe Onorato9c1289c2009-08-17 11:03:03 -04001025 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1026 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
1027
Joe Onoratoc131b742010-03-11 15:45:05 -08001028 final Callbacks callbacks = mCallbacks.get();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001029 if (callbacks == null) {
1030 return;
1031 }
1032
Joe Onorato0589f0f2010-02-08 13:44:00 -08001033 final PackageManager packageManager = mContext.getPackageManager();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001034 final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0);
1035
Daniel Sandlerdca66122010-04-13 16:23:58 -04001036 int N;
1037 int batchSize = callbacks.getAppBatchSize();
1038
Joe Onorato9c1289c2009-08-17 11:03:03 -04001039 synchronized (mLock) {
Joe Onoratof99f8c12009-10-31 17:27:36 -04001040 mBeforeFirstLoad = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001041 mAllAppsList.clear();
Daniel Sandlerdca66122010-04-13 16:23:58 -04001042 if (apps == null) return;
1043 N = apps.size();
1044 if (batchSize <= 0)
1045 batchSize = N;
1046 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001047
Daniel Sandlerdca66122010-04-13 16:23:58 -04001048 int i=0;
1049 while (i < N && !mStopped) {
1050 synchronized (mLock) {
1051 final long t2 = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
1052
1053 for (int j=0; i<N && j<batchSize; j++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001054 // This builds the icon bitmaps.
Joe Onorato0589f0f2010-02-08 13:44:00 -08001055 mAllAppsList.add(new ApplicationInfo(apps.get(i), mIconCache));
Daniel Sandlerdca66122010-04-13 16:23:58 -04001056 i++;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001057 }
Daniel Sandlerdca66122010-04-13 16:23:58 -04001058 // re-sort before binding this batch to the grid
Joe Onoratob0c27f22009-12-01 16:19:38 -08001059 Collections.sort(mAllAppsList.data, APP_NAME_COMPARATOR);
1060 Collections.sort(mAllAppsList.added, APP_NAME_COMPARATOR);
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001061 if (DEBUG_LOADERS) {
Daniel Sandlerdca66122010-04-13 16:23:58 -04001062 Log.d(TAG, "batch of " + batchSize + " icons processed in "
1063 + (SystemClock.uptimeMillis()-t2) + "ms");
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001064 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001065 }
Daniel Sandlerdca66122010-04-13 16:23:58 -04001066
1067 mHandler.post(bindAllAppsTask);
1068
1069 if (ALL_APPS_LOAD_DELAY > 0) {
1070 try {
1071 Thread.sleep(ALL_APPS_LOAD_DELAY);
1072 } catch (InterruptedException exc) { }
1073 }
1074 }
1075
1076 if (DEBUG_LOADERS) {
1077 Log.d(TAG, "cached all " + N + " apps in "
1078 + (SystemClock.uptimeMillis()-t) + "ms");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001079 }
1080 }
1081
Daniel Sandlerdca66122010-04-13 16:23:58 -04001082 final Runnable bindAllAppsTask = new Runnable() {
1083 public void run() {
1084 final long t = SystemClock.uptimeMillis();
1085 int count = 0;
1086 Callbacks callbacks = null;
1087 ArrayList<ApplicationInfo> results = null;
1088 synchronized (mLock) {
1089 mHandler.cancelRunnable(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001090
Daniel Sandlerdca66122010-04-13 16:23:58 -04001091 results = (ArrayList<ApplicationInfo>) mAllAppsList.data.clone();
1092 // We're adding this now, so clear out this so we don't re-send them.
1093 mAllAppsList.added = new ArrayList<ApplicationInfo>();
1094 count = results.size();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001095
Daniel Sandlerdca66122010-04-13 16:23:58 -04001096 callbacks = tryGetCallbacks(mCallbacks.get());
1097 }
1098
1099 if (callbacks != null && count > 0) {
1100 callbacks.bindAllApplications(results);
1101 }
1102
1103 if (DEBUG_LOADERS) {
1104 Log.d(TAG, "bound " + count + " apps in "
1105 + (SystemClock.uptimeMillis() - t) + "ms");
1106 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001107 }
Daniel Sandlerdca66122010-04-13 16:23:58 -04001108 };
Joe Onoratobe386092009-11-17 17:32:16 -08001109
1110 public void dumpState() {
1111 Log.d(TAG, "mLoader.mLoaderThread.mContext=" + mContext);
1112 Log.d(TAG, "mLoader.mLoaderThread.mWaitThread=" + mWaitThread);
1113 Log.d(TAG, "mLoader.mLoaderThread.mIsLaunching=" + mIsLaunching);
1114 Log.d(TAG, "mLoader.mLoaderThread.mStopped=" + mStopped);
1115 Log.d(TAG, "mLoader.mLoaderThread.mWorkspaceDoneBinding=" + mWorkspaceDoneBinding);
1116 }
1117 }
1118
1119 public void dumpState() {
1120 Log.d(TAG, "mLoader.mLastWorkspaceSeq=" + mLoader.mLastWorkspaceSeq);
1121 Log.d(TAG, "mLoader.mWorkspaceSeq=" + mLoader.mWorkspaceSeq);
1122 Log.d(TAG, "mLoader.mLastAllAppsSeq=" + mLoader.mLastAllAppsSeq);
1123 Log.d(TAG, "mLoader.mAllAppsSeq=" + mLoader.mAllAppsSeq);
1124 Log.d(TAG, "mLoader.mItems size=" + mLoader.mItems.size());
1125 if (mLoaderThread != null) {
1126 mLoaderThread.dumpState();
1127 } else {
1128 Log.d(TAG, "mLoader.mLoaderThread=null");
1129 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001130 }
1131 }
1132
1133 /**
Joe Onorato56d82912010-03-07 14:32:10 -05001134 * This is called from the code that adds shortcuts from the intent receiver. This
1135 * doesn't have a Cursor, but
Joe Onorato9c1289c2009-08-17 11:03:03 -04001136 */
Joe Onorato56d82912010-03-07 14:32:10 -05001137 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context) {
Joe Onoratoe74daed2010-03-11 12:32:24 -08001138 return getShortcutInfo(manager, intent, context, null, -1, -1);
Joe Onorato56d82912010-03-07 14:32:10 -05001139 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001140
Joe Onorato56d82912010-03-07 14:32:10 -05001141 /**
1142 * Make an ShortcutInfo object for a shortcut that is an application.
1143 *
1144 * If c is not null, then it will be used to fill in missing data like the title and icon.
1145 */
1146 public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context,
1147 Cursor c, int iconIndex, int titleIndex) {
1148 Bitmap icon = null;
1149 final ShortcutInfo info = new ShortcutInfo();
1150
1151 ComponentName componentName = intent.getComponent();
1152 if (componentName == null) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001153 return null;
1154 }
1155
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001156 // TODO: See if the PackageManager knows about this case. If it doesn't
1157 // then return null & delete this.
1158
Joe Onorato56d82912010-03-07 14:32:10 -05001159 // the resource -- This may implicitly give us back the fallback icon,
1160 // but don't worry about that. All we're doing with usingFallbackIcon is
1161 // to avoid saving lots of copies of that in the database, and most apps
1162 // have icons anyway.
1163 final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);
1164 if (resolveInfo != null) {
1165 icon = mIconCache.getIcon(componentName, resolveInfo);
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001166 }
Joe Onorato56d82912010-03-07 14:32:10 -05001167 // the db
1168 if (icon == null) {
1169 if (c != null) {
1170 icon = getIconFromCursor(c, iconIndex);
1171 }
1172 }
1173 // the fallback icon
1174 if (icon == null) {
1175 icon = getFallbackIcon();
1176 info.usingFallbackIcon = true;
1177 }
1178 info.setIcon(icon);
1179
1180 // from the resource
1181 if (resolveInfo != null) {
1182 info.title = resolveInfo.activityInfo.loadLabel(manager);
1183 }
1184 // from the db
Joe Onorato9c1289c2009-08-17 11:03:03 -04001185 if (info.title == null) {
Joe Onorato56d82912010-03-07 14:32:10 -05001186 if (c != null) {
1187 info.title = c.getString(titleIndex);
1188 }
1189 }
1190 // fall back to the class name of the activity
1191 if (info.title == null) {
1192 info.title = componentName.getClassName();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001193 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001194 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
1195 return info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001196 }
The Android Open Source Projectbc219c32009-03-09 11:52:14 -07001197
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001198 /**
Joe Onorato0589f0f2010-02-08 13:44:00 -08001199 * Make an ShortcutInfo object for a shortcut that isn't an application.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001201 private ShortcutInfo getShortcutInfo(Cursor c, Context context,
Joe Onorato56d82912010-03-07 14:32:10 -05001202 int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex,
1203 int titleIndex) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001204
Joe Onorato56d82912010-03-07 14:32:10 -05001205 Bitmap icon = null;
Joe Onorato0589f0f2010-02-08 13:44:00 -08001206 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001207 info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001208
Joe Onorato8ddc4fd2010-03-17 09:14:50 -07001209 // TODO: If there's an explicit component and we can't install that, delete it.
1210
Joe Onorato56d82912010-03-07 14:32:10 -05001211 info.title = c.getString(titleIndex);
1212
Joe Onorato9c1289c2009-08-17 11:03:03 -04001213 int iconType = c.getInt(iconTypeIndex);
1214 switch (iconType) {
1215 case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
1216 String packageName = c.getString(iconPackageIndex);
1217 String resourceName = c.getString(iconResourceIndex);
1218 PackageManager packageManager = context.getPackageManager();
Joe Onorato56d82912010-03-07 14:32:10 -05001219 info.customIcon = false;
1220 // the resource
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001221 try {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001222 Resources resources = packageManager.getResourcesForApplication(packageName);
Joe Onorato56d82912010-03-07 14:32:10 -05001223 if (resources != null) {
1224 final int id = resources.getIdentifier(resourceName, null, null);
1225 icon = Utilities.createIconBitmap(resources.getDrawable(id), context);
1226 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001227 } catch (Exception e) {
Joe Onorato56d82912010-03-07 14:32:10 -05001228 // drop this. we have other places to look for icons
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 }
Joe Onorato56d82912010-03-07 14:32:10 -05001230 // the db
1231 if (icon == null) {
1232 icon = getIconFromCursor(c, iconIndex);
1233 }
1234 // the fallback icon
1235 if (icon == null) {
1236 icon = getFallbackIcon();
1237 info.usingFallbackIcon = true;
1238 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001239 break;
1240 case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
Joe Onorato56d82912010-03-07 14:32:10 -05001241 icon = getIconFromCursor(c, iconIndex);
1242 if (icon == null) {
1243 icon = getFallbackIcon();
1244 info.customIcon = false;
1245 info.usingFallbackIcon = true;
1246 } else {
1247 info.customIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001248 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001249 break;
1250 default:
Joe Onoratod8d22da2010-03-11 17:59:11 -08001251 icon = getFallbackIcon();
Joe Onorato56d82912010-03-07 14:32:10 -05001252 info.usingFallbackIcon = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001253 info.customIcon = false;
1254 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001255 }
Joe Onoratod8d22da2010-03-11 17:59:11 -08001256 info.setIcon(icon);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001257 return info;
1258 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259
Joe Onorato56d82912010-03-07 14:32:10 -05001260 Bitmap getIconFromCursor(Cursor c, int iconIndex) {
1261 if (false) {
1262 Log.d(TAG, "getIconFromCursor app="
1263 + c.getString(c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE)));
1264 }
1265 byte[] data = c.getBlob(iconIndex);
1266 try {
1267 return BitmapFactory.decodeByteArray(data, 0, data.length);
1268 } catch (Exception e) {
1269 return null;
1270 }
1271 }
1272
Joe Onorato0589f0f2010-02-08 13:44:00 -08001273 ShortcutInfo addShortcut(Context context, Intent data,
1274 CellLayout.CellInfo cellInfo, boolean notify) {
1275
1276 final ShortcutInfo info = infoFromShortcutIntent(context, data);
1277 addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1278 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
1279
1280 return info;
1281 }
1282
1283 private ShortcutInfo infoFromShortcutIntent(Context context, Intent data) {
1284 Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
1285 String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
1286 Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
1287
1288 Bitmap icon = null;
1289 boolean filtered = false;
1290 boolean customIcon = false;
1291 ShortcutIconResource iconResource = null;
1292
1293 if (bitmap != null && bitmap instanceof Bitmap) {
1294 icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap)bitmap), context);
1295 filtered = true;
1296 customIcon = true;
1297 } else {
1298 Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
1299 if (extra != null && extra instanceof ShortcutIconResource) {
1300 try {
1301 iconResource = (ShortcutIconResource) extra;
1302 final PackageManager packageManager = context.getPackageManager();
1303 Resources resources = packageManager.getResourcesForApplication(
1304 iconResource.packageName);
1305 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1306 icon = Utilities.createIconBitmap(resources.getDrawable(id), context);
1307 } catch (Exception e) {
1308 Log.w(TAG, "Could not load shortcut icon: " + extra);
1309 }
1310 }
1311 }
1312
Joe Onorato0589f0f2010-02-08 13:44:00 -08001313 final ShortcutInfo info = new ShortcutInfo();
Joe Onorato56d82912010-03-07 14:32:10 -05001314
1315 if (icon == null) {
1316 icon = getFallbackIcon();
1317 info.usingFallbackIcon = true;
1318 }
Joe Onorato0589f0f2010-02-08 13:44:00 -08001319 info.setIcon(icon);
Joe Onorato56d82912010-03-07 14:32:10 -05001320
Joe Onorato0589f0f2010-02-08 13:44:00 -08001321 info.title = name;
1322 info.intent = intent;
1323 info.customIcon = customIcon;
1324 info.iconResource = iconResource;
1325
1326 return info;
1327 }
1328
Joe Onorato9c1289c2009-08-17 11:03:03 -04001329 private static void loadLiveFolderIcon(Context context, Cursor c, int iconTypeIndex,
1330 int iconPackageIndex, int iconResourceIndex, LiveFolderInfo liveFolderInfo) {
1331
1332 int iconType = c.getInt(iconTypeIndex);
1333 switch (iconType) {
1334 case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
1335 String packageName = c.getString(iconPackageIndex);
1336 String resourceName = c.getString(iconResourceIndex);
1337 PackageManager packageManager = context.getPackageManager();
1338 try {
1339 Resources resources = packageManager.getResourcesForApplication(packageName);
1340 final int id = resources.getIdentifier(resourceName, null, null);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001341 liveFolderInfo.icon = Utilities.createIconBitmap(resources.getDrawable(id),
1342 context);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001343 } catch (Exception e) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001344 liveFolderInfo.icon = Utilities.createIconBitmap(
1345 context.getResources().getDrawable(R.drawable.ic_launcher_folder),
1346 context);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001347 }
1348 liveFolderInfo.iconResource = new Intent.ShortcutIconResource();
1349 liveFolderInfo.iconResource.packageName = packageName;
1350 liveFolderInfo.iconResource.resourceName = resourceName;
1351 break;
1352 default:
Joe Onorato0589f0f2010-02-08 13:44:00 -08001353 liveFolderInfo.icon = Utilities.createIconBitmap(
1354 context.getResources().getDrawable(R.drawable.ic_launcher_folder),
1355 context);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001356 }
1357 }
1358
Joe Onorato56d82912010-03-07 14:32:10 -05001359 void updateSavedIcon(Context context, ShortcutInfo info, Cursor c, int iconIndex) {
1360 // If this icon doesn't have a custom icon, check to see
1361 // what's stored in the DB, and if it doesn't match what
1362 // we're going to show, store what we are going to show back
1363 // into the DB. We do this so when we're loading, if the
1364 // package manager can't find an icon (for example because
1365 // the app is on SD) then we can use that instead.
1366 if (info.onExternalStorage && !info.customIcon && !info.usingFallbackIcon) {
1367 boolean needSave;
1368 byte[] data = c.getBlob(iconIndex);
1369 try {
1370 if (data != null) {
1371 Bitmap saved = BitmapFactory.decodeByteArray(data, 0, data.length);
1372 Bitmap loaded = info.getIcon(mIconCache);
1373 needSave = !saved.sameAs(loaded);
1374 } else {
1375 needSave = true;
1376 }
1377 } catch (Exception e) {
1378 needSave = true;
1379 }
1380 if (needSave) {
1381 Log.d(TAG, "going to save icon bitmap for info=" + info);
1382 // This is slower than is ideal, but this only happens either
1383 // after the froyo OTA or when the app is updated with a new
1384 // icon.
1385 updateItemInDatabase(context, info);
1386 }
1387 }
1388 }
1389
Joe Onorato9c1289c2009-08-17 11:03:03 -04001390 /**
1391 * Return an existing UserFolderInfo object if we have encountered this ID previously,
1392 * or make a new one.
1393 */
1394 private static UserFolderInfo findOrMakeUserFolder(HashMap<Long, FolderInfo> folders, long id) {
1395 // See if a placeholder was created for us already
1396 FolderInfo folderInfo = folders.get(id);
1397 if (folderInfo == null || !(folderInfo instanceof UserFolderInfo)) {
1398 // No placeholder -- create a new instance
1399 folderInfo = new UserFolderInfo();
1400 folders.put(id, folderInfo);
1401 }
1402 return (UserFolderInfo) folderInfo;
1403 }
1404
1405 /**
1406 * Return an existing UserFolderInfo object if we have encountered this ID previously, or make a
1407 * new one.
1408 */
1409 private static LiveFolderInfo findOrMakeLiveFolder(HashMap<Long, FolderInfo> folders, long id) {
1410 // See if a placeholder was created for us already
1411 FolderInfo folderInfo = folders.get(id);
1412 if (folderInfo == null || !(folderInfo instanceof LiveFolderInfo)) {
1413 // No placeholder -- create a new instance
1414 folderInfo = new LiveFolderInfo();
1415 folders.put(id, folderInfo);
1416 }
1417 return (LiveFolderInfo) folderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001418 }
1419
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 private static String getLabel(PackageManager manager, ActivityInfo activityInfo) {
1421 String label = activityInfo.loadLabel(manager).toString();
1422 if (label == null) {
1423 label = manager.getApplicationLabel(activityInfo.applicationInfo).toString();
1424 if (label == null) {
1425 label = activityInfo.name;
1426 }
1427 }
1428 return label;
1429 }
1430
Joe Onorato9c1289c2009-08-17 11:03:03 -04001431 private static final Collator sCollator = Collator.getInstance();
Joe Onoratob0c27f22009-12-01 16:19:38 -08001432 public static final Comparator<ApplicationInfo> APP_NAME_COMPARATOR
Joe Onorato9c1289c2009-08-17 11:03:03 -04001433 = new Comparator<ApplicationInfo>() {
1434 public final int compare(ApplicationInfo a, ApplicationInfo b) {
1435 return sCollator.compare(a.title.toString(), b.title.toString());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001437 };
Joe Onoratobe386092009-11-17 17:32:16 -08001438
1439 public void dumpState() {
1440 Log.d(TAG, "mBeforeFirstLoad=" + mBeforeFirstLoad);
1441 Log.d(TAG, "mCallbacks=" + mCallbacks);
1442 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mAllAppsList.data);
1443 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mAllAppsList.added);
1444 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mAllAppsList.removed);
1445 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mAllAppsList.modified);
1446 mLoader.dumpState();
1447 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001448}