The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 19 | import java.lang.ref.WeakReference; |
| 20 | import java.net.URISyntaxException; |
| 21 | import java.text.Collator; |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.Collections; |
| 24 | import java.util.Comparator; |
| 25 | import java.util.HashMap; |
| 26 | import java.util.List; |
| 27 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 28 | import android.appwidget.AppWidgetManager; |
| 29 | import android.appwidget.AppWidgetProviderInfo; |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 30 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | import android.content.ComponentName; |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 32 | import android.content.ContentProviderClient; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 33 | import android.content.ContentResolver; |
| 34 | import android.content.ContentValues; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 35 | import android.content.Context; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.content.Intent; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 37 | import android.content.Intent.ShortcutIconResource; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | import android.content.pm.ActivityInfo; |
| 39 | import android.content.pm.PackageManager; |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 40 | import android.content.pm.ProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | import android.content.pm.ResolveInfo; |
| 42 | import android.content.res.Resources; |
| 43 | import android.database.Cursor; |
| 44 | import android.graphics.Bitmap; |
| 45 | import android.graphics.BitmapFactory; |
| 46 | import android.net.Uri; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 47 | import android.os.Handler; |
| 48 | import android.os.HandlerThread; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 49 | import android.os.Parcelable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | import android.os.Process; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 51 | import android.os.RemoteException; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 52 | import android.os.SystemClock; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 53 | import android.util.Log; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 55 | import java.lang.ref.WeakReference; |
| 56 | import java.net.URISyntaxException; |
| 57 | import java.text.Collator; |
| 58 | import java.util.ArrayList; |
| 59 | import java.util.Arrays; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 60 | import java.util.Collections; |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 61 | import java.util.Comparator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 62 | import java.util.HashMap; |
| 63 | import java.util.List; |
| 64 | |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 65 | import com.android.launcher.R; |
| 66 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 67 | /** |
| 68 | * Maintains in-memory state of the Launcher. It is expected that there should be only one |
| 69 | * LauncherModel object held in a static. Also provide APIs for updating the database state |
The Android Open Source Project | bc219c3 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 70 | * for the Launcher. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 71 | */ |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 72 | public class LauncherModel extends BroadcastReceiver { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 73 | static final boolean DEBUG_LOADERS = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 74 | static final String TAG = "Launcher.Model"; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 75 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 76 | private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons |
Joe Onorato | d65d08e | 2010-04-20 15:43:37 -0400 | [diff] [blame] | 77 | private int mBatchSize; // 0 is all apps at once |
Daniel Sandler | 2ff10b3 | 2010-04-16 15:06:06 -0400 | [diff] [blame] | 78 | private int mAllAppsLoadDelay; // milliseconds between batches |
Daniel Sandler | dca6612 | 2010-04-13 16:23:58 -0400 | [diff] [blame] | 79 | |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 80 | private final LauncherApplication mApp; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 81 | private final Object mLock = new Object(); |
| 82 | private DeferredHandler mHandler = new DeferredHandler(); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 83 | private LoaderTask mLoaderTask; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 84 | |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 85 | private static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader"); |
| 86 | static { |
| 87 | sWorkerThread.start(); |
| 88 | } |
| 89 | private static final Handler sWorker = new Handler(sWorkerThread.getLooper()); |
| 90 | |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 91 | // We start off with everything not loaded. After that, we assume that |
| 92 | // our monitoring of the package manager provides all updates and we never |
| 93 | // need to do a requery. These are only ever touched from the loader thread. |
| 94 | private boolean mWorkspaceLoaded; |
| 95 | private boolean mAllAppsLoaded; |
| 96 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 97 | private WeakReference<Callbacks> mCallbacks; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 98 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 99 | private AllAppsList mAllAppsList; // only access in worker thread |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 100 | private IconCache mIconCache; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 101 | final ArrayList<ItemInfo> mItems = new ArrayList<ItemInfo>(); |
| 102 | final ArrayList<LauncherAppWidgetInfo> mAppWidgets = new ArrayList<LauncherAppWidgetInfo>(); |
| 103 | final HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 104 | |
| 105 | private Bitmap mDefaultIcon; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 106 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 107 | private static int mCellCountX; |
| 108 | private static int mCellCountY; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 109 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 110 | public interface Callbacks { |
| 111 | public int getCurrentWorkspaceScreen(); |
| 112 | public void startBinding(); |
| 113 | public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end); |
Joe Onorato | ad72e17 | 2009-11-06 16:25:04 -0500 | [diff] [blame] | 114 | public void bindFolders(HashMap<Long,FolderInfo> folders); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 115 | public void finishBindingItems(); |
| 116 | public void bindAppWidget(LauncherAppWidgetInfo info); |
| 117 | public void bindAllApplications(ArrayList<ApplicationInfo> apps); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 118 | public void bindAppsAdded(ArrayList<ApplicationInfo> apps); |
| 119 | public void bindAppsUpdated(ArrayList<ApplicationInfo> apps); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 120 | public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 121 | public void bindPackagesUpdated(); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 122 | public boolean isAllAppsVisible(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 123 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 124 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 125 | LauncherModel(LauncherApplication app, IconCache iconCache) { |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 126 | mApp = app; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 127 | mAllAppsList = new AllAppsList(iconCache); |
| 128 | mIconCache = iconCache; |
| 129 | |
| 130 | mDefaultIcon = Utilities.createIconBitmap( |
| 131 | app.getPackageManager().getDefaultActivityIcon(), app); |
Daniel Sandler | 2ff10b3 | 2010-04-16 15:06:06 -0400 | [diff] [blame] | 132 | |
| 133 | mAllAppsLoadDelay = app.getResources().getInteger(R.integer.config_allAppsBatchLoadDelay); |
Joe Onorato | d65d08e | 2010-04-20 15:43:37 -0400 | [diff] [blame] | 134 | |
| 135 | mBatchSize = app.getResources().getInteger(R.integer.config_allAppsBatchSize); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 138 | public Bitmap getFallbackIcon() { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 139 | return Bitmap.createBitmap(mDefaultIcon); |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 140 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 141 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 142 | /** |
| 143 | * Adds an item to the DB if it was not created previously, or move it to a new |
| 144 | * <container, screen, cellX, cellY> |
| 145 | */ |
| 146 | static void addOrMoveItemInDatabase(Context context, ItemInfo item, long container, |
| 147 | int screen, int cellX, int cellY) { |
| 148 | if (item.container == ItemInfo.NO_ID) { |
| 149 | // From all apps |
| 150 | addItemToDatabase(context, item, container, screen, cellX, cellY, false); |
| 151 | } else { |
| 152 | // From somewhere else |
| 153 | moveItemInDatabase(context, item, container, screen, cellX, cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 158 | * Move an item in the DB to a new <container, screen, cellX, cellY> |
The Android Open Source Project | bc219c3 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 159 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 160 | static void moveItemInDatabase(Context context, ItemInfo item, long container, int screen, |
| 161 | int cellX, int cellY) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 162 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 163 | item.container = container; |
| 164 | item.screen = screen; |
| 165 | item.cellX = cellX; |
| 166 | item.cellY = cellY; |
| 167 | |
Brad Fitzpatrick | ade2f81 | 2010-10-10 15:42:06 -0700 | [diff] [blame] | 168 | final Uri uri = LauncherSettings.Favorites.getContentUri(item.id, false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 169 | final ContentValues values = new ContentValues(); |
| 170 | final ContentResolver cr = context.getContentResolver(); |
| 171 | |
| 172 | values.put(LauncherSettings.Favorites.CONTAINER, item.container); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 173 | values.put(LauncherSettings.Favorites.CELLX, cellX); |
| 174 | values.put(LauncherSettings.Favorites.CELLY, cellY); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 175 | values.put(LauncherSettings.Favorites.SCREEN, item.screen); |
| 176 | |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 177 | sWorker.post(new Runnable() { |
| 178 | public void run() { |
| 179 | cr.update(uri, values, null, null); |
| 180 | } |
| 181 | }); |
The Android Open Source Project | bc219c3 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 185 | * Returns true if the shortcuts already exists in the database. |
| 186 | * we identify a shortcut by its title and intent. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 187 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 188 | static boolean shortcutExists(Context context, String title, Intent intent) { |
| 189 | final ContentResolver cr = context.getContentResolver(); |
| 190 | Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, |
| 191 | new String[] { "title", "intent" }, "title=? and intent=?", |
| 192 | new String[] { title, intent.toUri(0) }, null); |
| 193 | boolean result = false; |
| 194 | try { |
| 195 | result = c.moveToFirst(); |
| 196 | } finally { |
| 197 | c.close(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 198 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 199 | return result; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 202 | /** |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 203 | * Returns an ItemInfo array containing all the items in the LauncherModel. |
| 204 | * The ItemInfo.id is not set through this function. |
| 205 | */ |
| 206 | static ArrayList<ItemInfo> getItemsInLocalCoordinates(Context context) { |
| 207 | ArrayList<ItemInfo> items = new ArrayList<ItemInfo>(); |
| 208 | final ContentResolver cr = context.getContentResolver(); |
| 209 | Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] { |
| 210 | LauncherSettings.Favorites.ITEM_TYPE, LauncherSettings.Favorites.CONTAINER, |
| 211 | LauncherSettings.Favorites.SCREEN, LauncherSettings.Favorites.CELLX, LauncherSettings.Favorites.CELLY, |
| 212 | LauncherSettings.Favorites.SPANX, LauncherSettings.Favorites.SPANY }, null, null, null); |
| 213 | |
| 214 | final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE); |
| 215 | final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER); |
| 216 | final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN); |
| 217 | final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX); |
| 218 | final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY); |
| 219 | final int spanXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANX); |
| 220 | final int spanYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANY); |
| 221 | |
| 222 | try { |
| 223 | while (c.moveToNext()) { |
| 224 | ItemInfo item = new ItemInfo(); |
| 225 | item.cellX = c.getInt(cellXIndex); |
| 226 | item.cellY = c.getInt(cellYIndex); |
| 227 | item.spanX = c.getInt(spanXIndex); |
| 228 | item.spanY = c.getInt(spanYIndex); |
| 229 | item.container = c.getInt(containerIndex); |
| 230 | item.itemType = c.getInt(itemTypeIndex); |
| 231 | item.screen = c.getInt(screenIndex); |
| 232 | |
| 233 | items.add(item); |
| 234 | } |
| 235 | } catch (Exception e) { |
| 236 | items.clear(); |
| 237 | } finally { |
| 238 | c.close(); |
| 239 | } |
| 240 | |
| 241 | return items; |
| 242 | } |
| 243 | |
| 244 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 245 | * Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList. |
| 246 | */ |
| 247 | FolderInfo getFolderById(Context context, HashMap<Long,FolderInfo> folderList, long id) { |
| 248 | final ContentResolver cr = context.getContentResolver(); |
| 249 | Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null, |
| 250 | "_id=? and (itemType=? or itemType=?)", |
| 251 | new String[] { String.valueOf(id), |
| 252 | String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER), |
| 253 | String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER) }, null); |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 254 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 255 | try { |
| 256 | if (c.moveToFirst()) { |
| 257 | final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE); |
| 258 | final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE); |
| 259 | final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER); |
| 260 | final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN); |
| 261 | final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX); |
| 262 | final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 263 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 264 | FolderInfo folderInfo = null; |
| 265 | switch (c.getInt(itemTypeIndex)) { |
| 266 | case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: |
| 267 | folderInfo = findOrMakeUserFolder(folderList, id); |
| 268 | break; |
| 269 | case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: |
| 270 | folderInfo = findOrMakeLiveFolder(folderList, id); |
| 271 | break; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 274 | folderInfo.title = c.getString(titleIndex); |
| 275 | folderInfo.id = id; |
| 276 | folderInfo.container = c.getInt(containerIndex); |
| 277 | folderInfo.screen = c.getInt(screenIndex); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 278 | folderInfo.cellX = c.getInt(cellXIndex); |
| 279 | folderInfo.cellY = c.getInt(cellYIndex); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 280 | |
| 281 | return folderInfo; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 282 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 283 | } finally { |
| 284 | c.close(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | return null; |
| 288 | } |
| 289 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 290 | /** |
| 291 | * Add an item to the database in a specified container. Sets the container, screen, cellX and |
| 292 | * cellY fields of the item. Also assigns an ID to the item. |
| 293 | */ |
| 294 | static void addItemToDatabase(Context context, ItemInfo item, long container, |
| 295 | int screen, int cellX, int cellY, boolean notify) { |
| 296 | item.container = container; |
| 297 | item.screen = screen; |
| 298 | item.cellX = cellX; |
| 299 | item.cellY = cellY; |
| 300 | |
| 301 | final ContentValues values = new ContentValues(); |
| 302 | final ContentResolver cr = context.getContentResolver(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 303 | item.onAddToDatabase(values); |
| 304 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 305 | item.updateValuesWithCoordinates(values, cellX, cellY); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 306 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 307 | Uri result = cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI : |
| 308 | LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values); |
| 309 | |
| 310 | if (result != null) { |
| 311 | item.id = Integer.parseInt(result.getPathSegments().get(1)); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 312 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 315 | /** |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 316 | * Creates a new unique child id, for a given cell span across all layouts. |
| 317 | */ |
Michael Jurka | 845ba3b | 2010-09-28 17:09:46 -0700 | [diff] [blame] | 318 | static int getCellLayoutChildId( |
| 319 | int cellId, int screen, int localCellX, int localCellY, int spanX, int spanY) { |
| 320 | return ((cellId & 0xFF) << 24) |
| 321 | | (screen & 0xFF) << 16 | (localCellX & 0xFF) << 8 | (localCellY & 0xFF); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 324 | static int getCellCountX() { |
| 325 | return mCellCountX; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 328 | static int getCellCountY() { |
| 329 | return mCellCountY; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Updates the model orientation helper to take into account the current layout dimensions |
| 334 | * when performing local/canonical coordinate transformations. |
| 335 | */ |
| 336 | static void updateWorkspaceLayoutCells(int shortAxisCellCount, int longAxisCellCount) { |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 337 | mCellCountX = shortAxisCellCount; |
| 338 | mCellCountY = longAxisCellCount; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 342 | * Update an item to the database in a specified container. |
| 343 | */ |
| 344 | static void updateItemInDatabase(Context context, ItemInfo item) { |
| 345 | final ContentValues values = new ContentValues(); |
| 346 | final ContentResolver cr = context.getContentResolver(); |
| 347 | |
| 348 | item.onAddToDatabase(values); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 349 | item.updateValuesWithCoordinates(values, item.cellX, item.cellY); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 350 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 351 | cr.update(LauncherSettings.Favorites.getContentUri(item.id, false), values, null, null); |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Removes the specified item from the database |
| 356 | * @param context |
| 357 | * @param item |
| 358 | */ |
| 359 | static void deleteItemFromDatabase(Context context, ItemInfo item) { |
| 360 | final ContentResolver cr = context.getContentResolver(); |
Brad Fitzpatrick | 73013bf | 2010-09-14 12:15:32 -0700 | [diff] [blame] | 361 | final Uri uriToDelete = LauncherSettings.Favorites.getContentUri(item.id, false); |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 362 | sWorker.post(new Runnable() { |
| 363 | public void run() { |
| 364 | cr.delete(uriToDelete, null, null); |
| 365 | } |
| 366 | }); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Remove the contents of the specified folder from the database |
| 371 | */ |
| 372 | static void deleteUserFolderContentsFromDatabase(Context context, UserFolderInfo info) { |
| 373 | final ContentResolver cr = context.getContentResolver(); |
| 374 | |
| 375 | cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null); |
| 376 | cr.delete(LauncherSettings.Favorites.CONTENT_URI, |
| 377 | LauncherSettings.Favorites.CONTAINER + "=" + info.id, null); |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Set this as the current Launcher activity object for the loader. |
| 382 | */ |
| 383 | public void initialize(Callbacks callbacks) { |
| 384 | synchronized (mLock) { |
| 385 | mCallbacks = new WeakReference<Callbacks>(callbacks); |
| 386 | } |
| 387 | } |
| 388 | |
Joe Onorato | 1d8e7bb | 2009-10-15 19:49:43 -0700 | [diff] [blame] | 389 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 390 | * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and |
| 391 | * ACTION_PACKAGE_CHANGED. |
| 392 | */ |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 393 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 394 | if (DEBUG_LOADERS) Log.d(TAG, "onReceive intent=" + intent); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 395 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 396 | final String action = intent.getAction(); |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 397 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 398 | if (Intent.ACTION_PACKAGE_CHANGED.equals(action) |
| 399 | || Intent.ACTION_PACKAGE_REMOVED.equals(action) |
| 400 | || Intent.ACTION_PACKAGE_ADDED.equals(action)) { |
| 401 | final String packageName = intent.getData().getSchemeSpecificPart(); |
| 402 | final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 403 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 404 | int op = PackageUpdatedTask.OP_NONE; |
| 405 | |
| 406 | if (packageName == null || packageName.length() == 0) { |
| 407 | // they sent us a bad intent |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) { |
| 412 | op = PackageUpdatedTask.OP_UPDATE; |
| 413 | } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) { |
| 414 | if (!replacing) { |
| 415 | op = PackageUpdatedTask.OP_REMOVE; |
| 416 | } |
| 417 | // else, we are replacing the package, so a PACKAGE_ADDED will be sent |
| 418 | // later, we will update the package at this time |
| 419 | } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) { |
| 420 | if (!replacing) { |
| 421 | op = PackageUpdatedTask.OP_ADD; |
| 422 | } else { |
| 423 | op = PackageUpdatedTask.OP_UPDATE; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | if (op != PackageUpdatedTask.OP_NONE) { |
| 428 | enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packageName })); |
| 429 | } |
| 430 | |
| 431 | } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) { |
Joe Onorato | cec5833 | 2010-10-07 14:37:40 -0400 | [diff] [blame] | 432 | // First, schedule to add these apps back in. |
| 433 | String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); |
| 434 | enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_ADD, packages)); |
| 435 | // Then, rebind everything. |
Joe Onorato | 789065d | 2010-09-30 16:29:59 -0700 | [diff] [blame] | 436 | startLoader(mApp, false); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 437 | |
| 438 | } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) { |
| 439 | String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); |
| 440 | enqueuePackageUpdated(new PackageUpdatedTask( |
| 441 | PackageUpdatedTask.OP_UNAVAILABLE, packages)); |
Joe Onorato | 790c2d9 | 2010-06-11 00:14:11 -0700 | [diff] [blame] | 442 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 443 | } |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 444 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 445 | public void startLoader(Context context, boolean isLaunching) { |
| 446 | synchronized (mLock) { |
| 447 | if (DEBUG_LOADERS) { |
| 448 | Log.d(TAG, "startLoader isLaunching=" + isLaunching); |
| 449 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 450 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 451 | // Don't bother to start the thread if we know it's not going to do anything |
| 452 | if (mCallbacks != null && mCallbacks.get() != null) { |
| 453 | // If there is already one running, tell it to stop. |
| 454 | LoaderTask oldTask = mLoaderTask; |
| 455 | if (oldTask != null) { |
| 456 | if (oldTask.isLaunching()) { |
| 457 | // don't downgrade isLaunching if we're already running |
| 458 | isLaunching = true; |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 459 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 460 | oldTask.stopLocked(); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 461 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 462 | mLoaderTask = new LoaderTask(context, isLaunching); |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 463 | sWorker.post(mLoaderTask); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 464 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 468 | public void stopLoader() { |
| 469 | synchronized (mLock) { |
| 470 | if (mLoaderTask != null) { |
| 471 | mLoaderTask.stopLocked(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 472 | } |
| 473 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 474 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 475 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 476 | /** |
| 477 | * Runnable for the thread that loads the contents of the launcher: |
| 478 | * - workspace icons |
| 479 | * - widgets |
| 480 | * - all apps icons |
| 481 | */ |
| 482 | private class LoaderTask implements Runnable { |
| 483 | private Context mContext; |
| 484 | private Thread mWaitThread; |
| 485 | private boolean mIsLaunching; |
| 486 | private boolean mStopped; |
| 487 | private boolean mLoadAndBindStepFinished; |
| 488 | |
| 489 | LoaderTask(Context context, boolean isLaunching) { |
| 490 | mContext = context; |
| 491 | mIsLaunching = isLaunching; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 492 | } |
| 493 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 494 | boolean isLaunching() { |
| 495 | return mIsLaunching; |
| 496 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 497 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 498 | private void loadAndBindWorkspace() { |
| 499 | // Load the workspace |
| 500 | |
| 501 | // For now, just always reload the workspace. It's ~100 ms vs. the |
| 502 | // binding which takes many hundreds of ms. |
| 503 | // We can reconsider. |
| 504 | if (DEBUG_LOADERS) { |
| 505 | Log.d(TAG, "loadAndBindWorkspace mWorkspaceLoaded=" + mWorkspaceLoaded); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 506 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 507 | if (true || !mWorkspaceLoaded) { |
| 508 | loadWorkspace(); |
| 509 | if (mStopped) { |
| 510 | return; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 511 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 512 | mWorkspaceLoaded = true; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 513 | } |
| 514 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 515 | // Bind the workspace |
| 516 | bindWorkspace(); |
| 517 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 518 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 519 | private void waitForIdle() { |
| 520 | // Wait until the either we're stopped or the other threads are done. |
| 521 | // This way we don't start loading all apps until the workspace has settled |
| 522 | // down. |
| 523 | synchronized (LoaderTask.this) { |
| 524 | final long workspaceWaitTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 525 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 526 | mHandler.postIdle(new Runnable() { |
| 527 | public void run() { |
| 528 | synchronized (LoaderTask.this) { |
| 529 | mLoadAndBindStepFinished = true; |
| 530 | if (DEBUG_LOADERS) { |
| 531 | Log.d(TAG, "done with previous binding step"); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 532 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 533 | LoaderTask.this.notify(); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 534 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 535 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 536 | }); |
| 537 | |
| 538 | while (!mStopped && !mLoadAndBindStepFinished) { |
| 539 | try { |
| 540 | this.wait(); |
| 541 | } catch (InterruptedException ex) { |
| 542 | // Ignore |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 543 | } |
| 544 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 545 | if (DEBUG_LOADERS) { |
| 546 | Log.d(TAG, "waited " |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 547 | + (SystemClock.uptimeMillis()-workspaceWaitTime) |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 548 | + "ms for previous step to finish binding"); |
| 549 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 550 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 551 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 552 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 553 | public void run() { |
| 554 | // Optimize for end-user experience: if the Launcher is up and // running with the |
| 555 | // All Apps interface in the foreground, load All Apps first. Otherwise, load the |
| 556 | // workspace first (default). |
| 557 | final Callbacks cbk = mCallbacks.get(); |
| 558 | final boolean loadWorkspaceFirst = cbk != null ? (!cbk.isAllAppsVisible()) : true; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 559 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 560 | keep_running: { |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 561 | // Elevate priority when Home launches for the first time to avoid |
| 562 | // starving at boot time. Staring at a blank home is not cool. |
| 563 | synchronized (mLock) { |
| 564 | android.os.Process.setThreadPriority(mIsLaunching |
| 565 | ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND); |
| 566 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 567 | if (loadWorkspaceFirst) { |
| 568 | if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace"); |
| 569 | loadAndBindWorkspace(); |
| 570 | } else { |
| 571 | if (DEBUG_LOADERS) Log.d(TAG, "step 1: special: loading all apps"); |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 572 | loadAndBindAllApps(); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 575 | if (mStopped) { |
| 576 | break keep_running; |
| 577 | } |
| 578 | |
| 579 | // Whew! Hard work done. Slow us down, and wait until the UI thread has |
| 580 | // settled down. |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 581 | synchronized (mLock) { |
| 582 | if (mIsLaunching) { |
| 583 | android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 584 | } |
| 585 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 586 | waitForIdle(); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 587 | |
| 588 | // second step |
| 589 | if (loadWorkspaceFirst) { |
| 590 | if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps"); |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 591 | loadAndBindAllApps(); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 592 | } else { |
| 593 | if (DEBUG_LOADERS) Log.d(TAG, "step 2: special: loading workspace"); |
| 594 | loadAndBindWorkspace(); |
| 595 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 596 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 597 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 598 | // Clear out this reference, otherwise we end up holding it until all of the |
| 599 | // callback runnables are done. |
| 600 | mContext = null; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 601 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 602 | synchronized (mLock) { |
| 603 | // If we are still the last one to be scheduled, remove ourselves. |
| 604 | if (mLoaderTask == this) { |
| 605 | mLoaderTask = null; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 606 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 607 | } |
Joe Onorato | f3d5ea9 | 2010-05-18 18:43:51 -0700 | [diff] [blame] | 608 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 609 | // Trigger a gc to try to clean up after the stuff is done, since the |
| 610 | // renderscript allocations aren't charged to the java heap. |
| 611 | if (mStopped) { |
Joe Onorato | f3d5ea9 | 2010-05-18 18:43:51 -0700 | [diff] [blame] | 612 | mHandler.post(new Runnable() { |
| 613 | public void run() { |
| 614 | System.gc(); |
| 615 | } |
| 616 | }); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 617 | } else { |
| 618 | mHandler.postIdle(new Runnable() { |
| 619 | public void run() { |
| 620 | System.gc(); |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 621 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 622 | }); |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | public void stopLocked() { |
| 627 | synchronized (LoaderTask.this) { |
| 628 | mStopped = true; |
| 629 | this.notify(); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Gets the callbacks object. If we've been stopped, or if the launcher object |
| 635 | * has somehow been garbage collected, return null instead. Pass in the Callbacks |
| 636 | * object that was around when the deferred message was scheduled, and if there's |
| 637 | * a new Callbacks object around then also return null. This will save us from |
| 638 | * calling onto it with data that will be ignored. |
| 639 | */ |
| 640 | Callbacks tryGetCallbacks(Callbacks oldCallbacks) { |
| 641 | synchronized (mLock) { |
| 642 | if (mStopped) { |
| 643 | return null; |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 644 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 645 | |
| 646 | if (mCallbacks == null) { |
| 647 | return null; |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 648 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 649 | |
| 650 | final Callbacks callbacks = mCallbacks.get(); |
| 651 | if (callbacks != oldCallbacks) { |
| 652 | return null; |
| 653 | } |
| 654 | if (callbacks == null) { |
| 655 | Log.w(TAG, "no mCallbacks"); |
| 656 | return null; |
| 657 | } |
| 658 | |
| 659 | return callbacks; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | // check & update map of what's occupied; used to discard overlapping/invalid items |
| 664 | private boolean checkItemPlacement(ItemInfo occupied[][][], ItemInfo item) { |
| 665 | if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 666 | return true; |
| 667 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 668 | for (int x = item.cellX; x < (item.cellX+item.spanX); x++) { |
| 669 | for (int y = item.cellY; y < (item.cellY+item.spanY); y++) { |
| 670 | if (occupied[item.screen][x][y] != null) { |
| 671 | Log.e(TAG, "Error loading shortcut " + item |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 672 | + " into cell (" + item.screen + ":" |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 673 | + x + "," + y |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 674 | + ") occupied by " |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 675 | + occupied[item.screen][x][y]); |
| 676 | return false; |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | for (int x = item.cellX; x < (item.cellX+item.spanX); x++) { |
| 681 | for (int y = item.cellY; y < (item.cellY+item.spanY); y++) { |
| 682 | occupied[item.screen][x][y] = item; |
| 683 | } |
| 684 | } |
| 685 | return true; |
| 686 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 687 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 688 | private void loadWorkspace() { |
| 689 | final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 690 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 691 | final Context context = mContext; |
| 692 | final ContentResolver contentResolver = context.getContentResolver(); |
| 693 | final PackageManager manager = context.getPackageManager(); |
| 694 | final AppWidgetManager widgets = AppWidgetManager.getInstance(context); |
| 695 | final boolean isSafeMode = manager.isSafeMode(); |
Joe Onorato | 3c2f7e1 | 2009-10-31 19:17:31 -0400 | [diff] [blame] | 696 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 697 | mItems.clear(); |
| 698 | mAppWidgets.clear(); |
| 699 | mFolders.clear(); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 700 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 701 | final ArrayList<Long> itemsToRemove = new ArrayList<Long>(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 702 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 703 | final Cursor c = contentResolver.query( |
| 704 | LauncherSettings.Favorites.CONTENT_URI, null, null, null, null); |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 705 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 706 | final ItemInfo occupied[][][] = |
| 707 | new ItemInfo[Launcher.SCREEN_COUNT][mCellCountX][mCellCountY]; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 708 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 709 | try { |
| 710 | final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID); |
| 711 | final int intentIndex = c.getColumnIndexOrThrow |
| 712 | (LauncherSettings.Favorites.INTENT); |
| 713 | final int titleIndex = c.getColumnIndexOrThrow |
| 714 | (LauncherSettings.Favorites.TITLE); |
| 715 | final int iconTypeIndex = c.getColumnIndexOrThrow( |
| 716 | LauncherSettings.Favorites.ICON_TYPE); |
| 717 | final int iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON); |
| 718 | final int iconPackageIndex = c.getColumnIndexOrThrow( |
| 719 | LauncherSettings.Favorites.ICON_PACKAGE); |
| 720 | final int iconResourceIndex = c.getColumnIndexOrThrow( |
| 721 | LauncherSettings.Favorites.ICON_RESOURCE); |
| 722 | final int containerIndex = c.getColumnIndexOrThrow( |
| 723 | LauncherSettings.Favorites.CONTAINER); |
| 724 | final int itemTypeIndex = c.getColumnIndexOrThrow( |
| 725 | LauncherSettings.Favorites.ITEM_TYPE); |
| 726 | final int appWidgetIdIndex = c.getColumnIndexOrThrow( |
| 727 | LauncherSettings.Favorites.APPWIDGET_ID); |
| 728 | final int screenIndex = c.getColumnIndexOrThrow( |
| 729 | LauncherSettings.Favorites.SCREEN); |
| 730 | final int cellXIndex = c.getColumnIndexOrThrow |
| 731 | (LauncherSettings.Favorites.CELLX); |
| 732 | final int cellYIndex = c.getColumnIndexOrThrow |
| 733 | (LauncherSettings.Favorites.CELLY); |
| 734 | final int spanXIndex = c.getColumnIndexOrThrow |
| 735 | (LauncherSettings.Favorites.SPANX); |
| 736 | final int spanYIndex = c.getColumnIndexOrThrow( |
| 737 | LauncherSettings.Favorites.SPANY); |
| 738 | final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI); |
| 739 | final int displayModeIndex = c.getColumnIndexOrThrow( |
| 740 | LauncherSettings.Favorites.DISPLAY_MODE); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 741 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 742 | ShortcutInfo info; |
| 743 | String intentDescription; |
| 744 | LauncherAppWidgetInfo appWidgetInfo; |
| 745 | int container; |
| 746 | long id; |
| 747 | Intent intent; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 748 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 749 | while (!mStopped && c.moveToNext()) { |
| 750 | try { |
| 751 | int itemType = c.getInt(itemTypeIndex); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 752 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 753 | switch (itemType) { |
| 754 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 755 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 756 | intentDescription = c.getString(intentIndex); |
| 757 | try { |
| 758 | intent = Intent.parseUri(intentDescription, 0); |
| 759 | } catch (URISyntaxException e) { |
| 760 | continue; |
| 761 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 762 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 763 | if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { |
| 764 | info = getShortcutInfo(manager, intent, context, c, iconIndex, |
| 765 | titleIndex); |
| 766 | } else { |
| 767 | info = getShortcutInfo(c, context, iconTypeIndex, |
| 768 | iconPackageIndex, iconResourceIndex, iconIndex, |
| 769 | titleIndex); |
| 770 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 771 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 772 | if (info != null) { |
| 773 | updateSavedIcon(context, info, c, iconIndex); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 774 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 775 | info.intent = intent; |
| 776 | info.id = c.getLong(idIndex); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 777 | container = c.getInt(containerIndex); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 778 | info.container = container; |
| 779 | info.screen = c.getInt(screenIndex); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 780 | info.cellX = c.getInt(cellXIndex); |
| 781 | info.cellY = c.getInt(cellYIndex); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 782 | |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 783 | // check & update map of what's occupied |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 784 | if (!checkItemPlacement(occupied, info)) { |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 785 | break; |
| 786 | } |
| 787 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 788 | switch (container) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 789 | case LauncherSettings.Favorites.CONTAINER_DESKTOP: |
| 790 | mItems.add(info); |
| 791 | break; |
| 792 | default: |
| 793 | // Item is in a user folder |
| 794 | UserFolderInfo folderInfo = |
| 795 | findOrMakeUserFolder(mFolders, container); |
| 796 | folderInfo.add(info); |
| 797 | break; |
| 798 | } |
| 799 | } else { |
| 800 | // Failed to load the shortcut, probably because the |
| 801 | // activity manager couldn't resolve it (maybe the app |
| 802 | // was uninstalled), or the db row was somehow screwed up. |
| 803 | // Delete it. |
| 804 | id = c.getLong(idIndex); |
| 805 | Log.e(TAG, "Error loading shortcut " + id + ", removing it"); |
| 806 | contentResolver.delete(LauncherSettings.Favorites.getContentUri( |
| 807 | id, false), null, null); |
| 808 | } |
| 809 | break; |
| 810 | |
| 811 | case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: |
| 812 | id = c.getLong(idIndex); |
| 813 | UserFolderInfo folderInfo = findOrMakeUserFolder(mFolders, id); |
| 814 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 815 | folderInfo.title = c.getString(titleIndex); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 816 | folderInfo.id = id; |
| 817 | container = c.getInt(containerIndex); |
| 818 | folderInfo.container = container; |
| 819 | folderInfo.screen = c.getInt(screenIndex); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 820 | folderInfo.cellX = c.getInt(cellXIndex); |
| 821 | folderInfo.cellY = c.getInt(cellYIndex); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 822 | |
| 823 | // check & update map of what's occupied |
| 824 | if (!checkItemPlacement(occupied, folderInfo)) { |
| 825 | break; |
| 826 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 827 | switch (container) { |
| 828 | case LauncherSettings.Favorites.CONTAINER_DESKTOP: |
| 829 | mItems.add(folderInfo); |
| 830 | break; |
| 831 | } |
| 832 | |
| 833 | mFolders.put(folderInfo.id, folderInfo); |
| 834 | break; |
| 835 | |
| 836 | case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: |
| 837 | id = c.getLong(idIndex); |
| 838 | Uri uri = Uri.parse(c.getString(uriIndex)); |
| 839 | |
| 840 | // Make sure the live folder exists |
| 841 | final ProviderInfo providerInfo = |
| 842 | context.getPackageManager().resolveContentProvider( |
| 843 | uri.getAuthority(), 0); |
| 844 | |
| 845 | if (providerInfo == null && !isSafeMode) { |
| 846 | itemsToRemove.add(id); |
| 847 | } else { |
| 848 | LiveFolderInfo liveFolderInfo = findOrMakeLiveFolder(mFolders, id); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 849 | intentDescription = c.getString(intentIndex); |
| 850 | intent = null; |
| 851 | if (intentDescription != null) { |
| 852 | try { |
| 853 | intent = Intent.parseUri(intentDescription, 0); |
| 854 | } catch (URISyntaxException e) { |
| 855 | // Ignore, a live folder might not have a base intent |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | liveFolderInfo.title = c.getString(titleIndex); |
| 860 | liveFolderInfo.id = id; |
| 861 | liveFolderInfo.uri = uri; |
| 862 | container = c.getInt(containerIndex); |
| 863 | liveFolderInfo.container = container; |
| 864 | liveFolderInfo.screen = c.getInt(screenIndex); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 865 | liveFolderInfo.cellX = c.getInt(cellXIndex); |
| 866 | liveFolderInfo.cellY = c.getInt(cellYIndex); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 867 | liveFolderInfo.baseIntent = intent; |
| 868 | liveFolderInfo.displayMode = c.getInt(displayModeIndex); |
| 869 | |
| 870 | // check & update map of what's occupied |
| 871 | if (!checkItemPlacement(occupied, liveFolderInfo)) { |
| 872 | break; |
| 873 | } |
| 874 | |
| 875 | loadLiveFolderIcon(context, c, iconTypeIndex, iconPackageIndex, |
| 876 | iconResourceIndex, liveFolderInfo); |
| 877 | |
| 878 | switch (container) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 879 | case LauncherSettings.Favorites.CONTAINER_DESKTOP: |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 880 | mItems.add(liveFolderInfo); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 881 | break; |
| 882 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 883 | mFolders.put(liveFolderInfo.id, liveFolderInfo); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 884 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 885 | break; |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 886 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 887 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
| 888 | // Read all Launcher-specific widget details |
| 889 | int appWidgetId = c.getInt(appWidgetIdIndex); |
| 890 | id = c.getLong(idIndex); |
| 891 | |
| 892 | final AppWidgetProviderInfo provider = |
| 893 | widgets.getAppWidgetInfo(appWidgetId); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 894 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 895 | if (!isSafeMode && (provider == null || provider.provider == null || |
| 896 | provider.provider.getPackageName() == null)) { |
| 897 | Log.e(TAG, "Deleting widget that isn't installed anymore: id=" |
| 898 | + id + " appWidgetId=" + appWidgetId); |
| 899 | itemsToRemove.add(id); |
| 900 | } else { |
| 901 | appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId); |
| 902 | appWidgetInfo.id = id; |
| 903 | appWidgetInfo.screen = c.getInt(screenIndex); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 904 | appWidgetInfo.cellX = c.getInt(cellXIndex); |
| 905 | appWidgetInfo.cellY = c.getInt(cellYIndex); |
| 906 | appWidgetInfo.spanX = c.getInt(spanXIndex); |
| 907 | appWidgetInfo.spanY = c.getInt(spanYIndex); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 908 | |
| 909 | container = c.getInt(containerIndex); |
| 910 | if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 911 | Log.e(TAG, "Widget found where container " |
| 912 | + "!= CONTAINER_DESKTOP -- ignoring!"); |
| 913 | continue; |
| 914 | } |
| 915 | appWidgetInfo.container = c.getInt(containerIndex); |
| 916 | |
| 917 | // check & update map of what's occupied |
| 918 | if (!checkItemPlacement(occupied, appWidgetInfo)) { |
| 919 | break; |
| 920 | } |
| 921 | |
| 922 | mAppWidgets.add(appWidgetInfo); |
| 923 | } |
| 924 | break; |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 925 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 926 | } catch (Exception e) { |
| 927 | Log.w(TAG, "Desktop items loading interrupted:", e); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 928 | } |
| 929 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 930 | } finally { |
| 931 | c.close(); |
| 932 | } |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 933 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 934 | if (itemsToRemove.size() > 0) { |
| 935 | ContentProviderClient client = contentResolver.acquireContentProviderClient( |
| 936 | LauncherSettings.Favorites.CONTENT_URI); |
| 937 | // Remove dead items |
| 938 | for (long id : itemsToRemove) { |
| 939 | if (DEBUG_LOADERS) { |
| 940 | Log.d(TAG, "Removed id = " + id); |
| 941 | } |
| 942 | // Don't notify content observers |
| 943 | try { |
| 944 | client.delete(LauncherSettings.Favorites.getContentUri(id, false), |
| 945 | null, null); |
| 946 | } catch (RemoteException e) { |
| 947 | Log.w(TAG, "Could not remove id = " + id); |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 948 | } |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 949 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 950 | } |
| 951 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 952 | if (DEBUG_LOADERS) { |
| 953 | Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms"); |
| 954 | Log.d(TAG, "workspace layout: "); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 955 | for (int y = 0; y < mCellCountY; y++) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 956 | String line = ""; |
| 957 | for (int s = 0; s < Launcher.SCREEN_COUNT; s++) { |
| 958 | if (s > 0) { |
| 959 | line += " | "; |
| 960 | } |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 961 | for (int x = 0; x < mCellCountX; x++) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 962 | line += ((occupied[s][x][y] != null) ? "#" : "."); |
| 963 | } |
| 964 | } |
| 965 | Log.d(TAG, "[ " + line + " ]"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 966 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 967 | } |
| 968 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 969 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 970 | /** |
| 971 | * Read everything out of our database. |
| 972 | */ |
| 973 | private void bindWorkspace() { |
| 974 | final long t = SystemClock.uptimeMillis(); |
| 975 | |
| 976 | // Don't use these two variables in any of the callback runnables. |
| 977 | // Otherwise we hold a reference to them. |
| 978 | final Callbacks oldCallbacks = mCallbacks.get(); |
| 979 | if (oldCallbacks == null) { |
| 980 | // This launcher has exited and nobody bothered to tell us. Just bail. |
| 981 | Log.w(TAG, "LoaderTask running with no launcher"); |
| 982 | return; |
| 983 | } |
| 984 | |
| 985 | int N; |
| 986 | // Tell the workspace that we're about to start firing items at it |
| 987 | mHandler.post(new Runnable() { |
| 988 | public void run() { |
| 989 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 990 | if (callbacks != null) { |
| 991 | callbacks.startBinding(); |
| 992 | } |
| 993 | } |
| 994 | }); |
| 995 | // Add the items to the workspace. |
| 996 | N = mItems.size(); |
| 997 | for (int i=0; i<N; i+=ITEMS_CHUNK) { |
| 998 | final int start = i; |
| 999 | final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1000 | mHandler.post(new Runnable() { |
| 1001 | public void run() { |
Joe Onorato | c131b74 | 2010-03-11 15:45:05 -0800 | [diff] [blame] | 1002 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1003 | if (callbacks != null) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1004 | callbacks.bindItems(mItems, start, start+chunkSize); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | }); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1008 | } |
| 1009 | mHandler.post(new Runnable() { |
| 1010 | public void run() { |
| 1011 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 1012 | if (callbacks != null) { |
| 1013 | callbacks.bindFolders(mFolders); |
| 1014 | } |
| 1015 | } |
| 1016 | }); |
| 1017 | // Wait until the queue goes empty. |
| 1018 | mHandler.post(new Runnable() { |
| 1019 | public void run() { |
| 1020 | if (DEBUG_LOADERS) { |
| 1021 | Log.d(TAG, "Going to start binding widgets soon."); |
| 1022 | } |
| 1023 | } |
| 1024 | }); |
| 1025 | // Bind the widgets, one at a time. |
| 1026 | // WARNING: this is calling into the workspace from the background thread, |
| 1027 | // but since getCurrentScreen() just returns the int, we should be okay. This |
| 1028 | // is just a hint for the order, and if it's wrong, we'll be okay. |
| 1029 | // TODO: instead, we should have that push the current screen into here. |
| 1030 | final int currentScreen = oldCallbacks.getCurrentWorkspaceScreen(); |
| 1031 | N = mAppWidgets.size(); |
| 1032 | // once for the current screen |
| 1033 | for (int i=0; i<N; i++) { |
| 1034 | final LauncherAppWidgetInfo widget = mAppWidgets.get(i); |
| 1035 | if (widget.screen == currentScreen) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1036 | mHandler.post(new Runnable() { |
| 1037 | public void run() { |
Joe Onorato | c131b74 | 2010-03-11 15:45:05 -0800 | [diff] [blame] | 1038 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1039 | if (callbacks != null) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1040 | callbacks.bindAppWidget(widget); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | }); |
| 1044 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1045 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1046 | // once for the other screens |
| 1047 | for (int i=0; i<N; i++) { |
| 1048 | final LauncherAppWidgetInfo widget = mAppWidgets.get(i); |
| 1049 | if (widget.screen != currentScreen) { |
| 1050 | mHandler.post(new Runnable() { |
| 1051 | public void run() { |
| 1052 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 1053 | if (callbacks != null) { |
| 1054 | callbacks.bindAppWidget(widget); |
| 1055 | } |
| 1056 | } |
| 1057 | }); |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 1058 | } |
| 1059 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1060 | // Tell the workspace that we're done. |
| 1061 | mHandler.post(new Runnable() { |
| 1062 | public void run() { |
| 1063 | Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 1064 | if (callbacks != null) { |
| 1065 | callbacks.finishBindingItems(); |
| 1066 | } |
| 1067 | } |
| 1068 | }); |
| 1069 | // If we're profiling, this is the last thing in the queue. |
| 1070 | mHandler.post(new Runnable() { |
| 1071 | public void run() { |
| 1072 | if (DEBUG_LOADERS) { |
| 1073 | Log.d(TAG, "bound workspace in " |
| 1074 | + (SystemClock.uptimeMillis()-t) + "ms"); |
| 1075 | } |
| 1076 | } |
| 1077 | }); |
| 1078 | } |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 1079 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1080 | private void loadAndBindAllApps() { |
| 1081 | if (DEBUG_LOADERS) { |
| 1082 | Log.d(TAG, "loadAndBindAllApps mAllAppsLoaded=" + mAllAppsLoaded); |
| 1083 | } |
| 1084 | if (!mAllAppsLoaded) { |
| 1085 | loadAllAppsByBatch(); |
| 1086 | if (mStopped) { |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 1087 | return; |
| 1088 | } |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1089 | mAllAppsLoaded = true; |
| 1090 | } else { |
| 1091 | onlyBindAllApps(); |
| 1092 | } |
| 1093 | } |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 1094 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1095 | private void onlyBindAllApps() { |
| 1096 | final Callbacks oldCallbacks = mCallbacks.get(); |
| 1097 | if (oldCallbacks == null) { |
| 1098 | // This launcher has exited and nobody bothered to tell us. Just bail. |
| 1099 | Log.w(TAG, "LoaderTask running with no launcher (onlyBindAllApps)"); |
| 1100 | return; |
| 1101 | } |
| 1102 | |
| 1103 | // shallow copy |
| 1104 | final ArrayList<ApplicationInfo> list |
| 1105 | = (ArrayList<ApplicationInfo>)mAllAppsList.data.clone(); |
| 1106 | mHandler.post(new Runnable() { |
| 1107 | public void run() { |
| 1108 | final long t = SystemClock.uptimeMillis(); |
| 1109 | final Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 1110 | if (callbacks != null) { |
| 1111 | callbacks.bindAllApplications(list); |
| 1112 | } |
| 1113 | if (DEBUG_LOADERS) { |
| 1114 | Log.d(TAG, "bound all " + list.size() + " apps from cache in " |
| 1115 | + (SystemClock.uptimeMillis()-t) + "ms"); |
| 1116 | } |
| 1117 | } |
| 1118 | }); |
| 1119 | |
| 1120 | } |
| 1121 | |
| 1122 | private void loadAllAppsByBatch() { |
| 1123 | final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
| 1124 | |
| 1125 | // Don't use these two variables in any of the callback runnables. |
| 1126 | // Otherwise we hold a reference to them. |
| 1127 | final Callbacks oldCallbacks = mCallbacks.get(); |
| 1128 | if (oldCallbacks == null) { |
| 1129 | // This launcher has exited and nobody bothered to tell us. Just bail. |
| 1130 | Log.w(TAG, "LoaderTask running with no launcher (loadAllAppsByBatch)"); |
| 1131 | return; |
| 1132 | } |
| 1133 | |
| 1134 | final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1135 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 1136 | |
| 1137 | final PackageManager packageManager = mContext.getPackageManager(); |
| 1138 | List<ResolveInfo> apps = null; |
| 1139 | |
| 1140 | int N = Integer.MAX_VALUE; |
| 1141 | |
| 1142 | int startIndex; |
| 1143 | int i=0; |
| 1144 | int batchSize = -1; |
| 1145 | while (i < N && !mStopped) { |
| 1146 | if (i == 0) { |
| 1147 | mAllAppsList.clear(); |
| 1148 | final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
| 1149 | apps = packageManager.queryIntentActivities(mainIntent, 0); |
| 1150 | if (DEBUG_LOADERS) { |
| 1151 | Log.d(TAG, "queryIntentActivities took " |
| 1152 | + (SystemClock.uptimeMillis()-qiaTime) + "ms"); |
| 1153 | } |
| 1154 | if (apps == null) { |
| 1155 | return; |
| 1156 | } |
| 1157 | N = apps.size(); |
| 1158 | if (DEBUG_LOADERS) { |
| 1159 | Log.d(TAG, "queryIntentActivities got " + N + " apps"); |
| 1160 | } |
| 1161 | if (N == 0) { |
| 1162 | // There are no apps?!? |
| 1163 | return; |
| 1164 | } |
| 1165 | if (mBatchSize == 0) { |
| 1166 | batchSize = N; |
| 1167 | } else { |
| 1168 | batchSize = mBatchSize; |
| 1169 | } |
| 1170 | |
| 1171 | final long sortTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
| 1172 | Collections.sort(apps, |
| 1173 | new ResolveInfo.DisplayNameComparator(packageManager)); |
| 1174 | if (DEBUG_LOADERS) { |
| 1175 | Log.d(TAG, "sort took " |
| 1176 | + (SystemClock.uptimeMillis()-sortTime) + "ms"); |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | final long t2 = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; |
| 1181 | |
| 1182 | startIndex = i; |
| 1183 | for (int j=0; i<N && j<batchSize; j++) { |
| 1184 | // This builds the icon bitmaps. |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 1185 | mAllAppsList.add(new ApplicationInfo(packageManager, apps.get(i), mIconCache)); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1186 | i++; |
| 1187 | } |
| 1188 | |
| 1189 | final boolean first = i <= batchSize; |
| 1190 | final Callbacks callbacks = tryGetCallbacks(oldCallbacks); |
| 1191 | final ArrayList<ApplicationInfo> added = mAllAppsList.added; |
| 1192 | mAllAppsList.added = new ArrayList<ApplicationInfo>(); |
| 1193 | |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 1194 | mHandler.post(new Runnable() { |
| 1195 | public void run() { |
| 1196 | final long t = SystemClock.uptimeMillis(); |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 1197 | if (callbacks != null) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1198 | if (first) { |
| 1199 | callbacks.bindAllApplications(added); |
| 1200 | } else { |
| 1201 | callbacks.bindAppsAdded(added); |
| 1202 | } |
| 1203 | if (DEBUG_LOADERS) { |
| 1204 | Log.d(TAG, "bound " + added.size() + " apps in " |
| 1205 | + (SystemClock.uptimeMillis() - t) + "ms"); |
| 1206 | } |
| 1207 | } else { |
| 1208 | Log.i(TAG, "not binding apps: no Launcher activity"); |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | }); |
| 1212 | |
Daniel Sandler | dca6612 | 2010-04-13 16:23:58 -0400 | [diff] [blame] | 1213 | if (DEBUG_LOADERS) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1214 | Log.d(TAG, "batch of " + (i-startIndex) + " icons processed in " |
| 1215 | + (SystemClock.uptimeMillis()-t2) + "ms"); |
| 1216 | } |
| 1217 | |
| 1218 | if (mAllAppsLoadDelay > 0 && i < N) { |
| 1219 | try { |
| 1220 | if (DEBUG_LOADERS) { |
| 1221 | Log.d(TAG, "sleeping for " + mAllAppsLoadDelay + "ms"); |
| 1222 | } |
| 1223 | Thread.sleep(mAllAppsLoadDelay); |
| 1224 | } catch (InterruptedException exc) { } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1228 | if (DEBUG_LOADERS) { |
| 1229 | Log.d(TAG, "cached all " + N + " apps in " |
| 1230 | + (SystemClock.uptimeMillis()-t) + "ms" |
| 1231 | + (mAllAppsLoadDelay > 0 ? " (including delay)" : "")); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | public void dumpState() { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1236 | Log.d(TAG, "mLoaderTask.mContext=" + mContext); |
| 1237 | Log.d(TAG, "mLoaderTask.mWaitThread=" + mWaitThread); |
| 1238 | Log.d(TAG, "mLoaderTask.mIsLaunching=" + mIsLaunching); |
| 1239 | Log.d(TAG, "mLoaderTask.mStopped=" + mStopped); |
| 1240 | Log.d(TAG, "mLoaderTask.mLoadAndBindStepFinished=" + mLoadAndBindStepFinished); |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | void enqueuePackageUpdated(PackageUpdatedTask task) { |
Brad Fitzpatrick | 700889f | 2010-10-11 09:40:44 -0700 | [diff] [blame] | 1245 | sWorker.post(task); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | private class PackageUpdatedTask implements Runnable { |
| 1249 | int mOp; |
| 1250 | String[] mPackages; |
| 1251 | |
| 1252 | public static final int OP_NONE = 0; |
| 1253 | public static final int OP_ADD = 1; |
| 1254 | public static final int OP_UPDATE = 2; |
| 1255 | public static final int OP_REMOVE = 3; // uninstlled |
| 1256 | public static final int OP_UNAVAILABLE = 4; // external media unmounted |
| 1257 | |
| 1258 | |
| 1259 | public PackageUpdatedTask(int op, String[] packages) { |
| 1260 | mOp = op; |
| 1261 | mPackages = packages; |
| 1262 | } |
| 1263 | |
| 1264 | public void run() { |
| 1265 | final Context context = mApp; |
| 1266 | |
| 1267 | final String[] packages = mPackages; |
| 1268 | final int N = packages.length; |
| 1269 | switch (mOp) { |
| 1270 | case OP_ADD: |
| 1271 | for (int i=0; i<N; i++) { |
| 1272 | if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.addPackage " + packages[i]); |
| 1273 | mAllAppsList.addPackage(context, packages[i]); |
| 1274 | } |
| 1275 | break; |
| 1276 | case OP_UPDATE: |
| 1277 | for (int i=0; i<N; i++) { |
| 1278 | if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]); |
| 1279 | mAllAppsList.updatePackage(context, packages[i]); |
| 1280 | } |
| 1281 | break; |
| 1282 | case OP_REMOVE: |
| 1283 | case OP_UNAVAILABLE: |
| 1284 | for (int i=0; i<N; i++) { |
| 1285 | if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]); |
| 1286 | mAllAppsList.removePackage(packages[i]); |
| 1287 | } |
| 1288 | break; |
| 1289 | } |
| 1290 | |
| 1291 | ArrayList<ApplicationInfo> added = null; |
| 1292 | ArrayList<ApplicationInfo> removed = null; |
| 1293 | ArrayList<ApplicationInfo> modified = null; |
| 1294 | |
| 1295 | if (mAllAppsList.added.size() > 0) { |
| 1296 | added = mAllAppsList.added; |
| 1297 | mAllAppsList.added = new ArrayList<ApplicationInfo>(); |
| 1298 | } |
| 1299 | if (mAllAppsList.removed.size() > 0) { |
| 1300 | removed = mAllAppsList.removed; |
| 1301 | mAllAppsList.removed = new ArrayList<ApplicationInfo>(); |
| 1302 | for (ApplicationInfo info: removed) { |
| 1303 | mIconCache.remove(info.intent.getComponent()); |
| 1304 | } |
| 1305 | } |
| 1306 | if (mAllAppsList.modified.size() > 0) { |
| 1307 | modified = mAllAppsList.modified; |
| 1308 | mAllAppsList.modified = new ArrayList<ApplicationInfo>(); |
| 1309 | } |
| 1310 | |
| 1311 | final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null; |
| 1312 | if (callbacks == null) { |
| 1313 | Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading."); |
| 1314 | return; |
| 1315 | } |
| 1316 | |
| 1317 | if (added != null) { |
| 1318 | final ArrayList<ApplicationInfo> addedFinal = added; |
| 1319 | mHandler.post(new Runnable() { |
| 1320 | public void run() { |
| 1321 | if (callbacks == mCallbacks.get()) { |
| 1322 | callbacks.bindAppsAdded(addedFinal); |
| 1323 | } |
| 1324 | } |
| 1325 | }); |
| 1326 | } |
| 1327 | if (modified != null) { |
| 1328 | final ArrayList<ApplicationInfo> modifiedFinal = modified; |
| 1329 | mHandler.post(new Runnable() { |
| 1330 | public void run() { |
| 1331 | if (callbacks == mCallbacks.get()) { |
| 1332 | callbacks.bindAppsUpdated(modifiedFinal); |
| 1333 | } |
| 1334 | } |
| 1335 | }); |
| 1336 | } |
| 1337 | if (removed != null) { |
| 1338 | final boolean permanent = mOp != OP_UNAVAILABLE; |
| 1339 | final ArrayList<ApplicationInfo> removedFinal = removed; |
| 1340 | mHandler.post(new Runnable() { |
| 1341 | public void run() { |
| 1342 | if (callbacks == mCallbacks.get()) { |
| 1343 | callbacks.bindAppsRemoved(removedFinal, permanent); |
| 1344 | } |
| 1345 | } |
| 1346 | }); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1347 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1348 | |
| 1349 | mHandler.post(new Runnable() { |
| 1350 | @Override |
| 1351 | public void run() { |
| 1352 | if (callbacks == mCallbacks.get()) { |
| 1353 | callbacks.bindPackagesUpdated(); |
| 1354 | } |
| 1355 | } |
| 1356 | }); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | /** |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1361 | * This is called from the code that adds shortcuts from the intent receiver. This |
| 1362 | * doesn't have a Cursor, but |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1363 | */ |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1364 | public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context) { |
Joe Onorato | e74daed | 2010-03-11 12:32:24 -0800 | [diff] [blame] | 1365 | return getShortcutInfo(manager, intent, context, null, -1, -1); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1366 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1367 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1368 | /** |
| 1369 | * Make an ShortcutInfo object for a shortcut that is an application. |
| 1370 | * |
| 1371 | * If c is not null, then it will be used to fill in missing data like the title and icon. |
| 1372 | */ |
| 1373 | public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context, |
| 1374 | Cursor c, int iconIndex, int titleIndex) { |
| 1375 | Bitmap icon = null; |
| 1376 | final ShortcutInfo info = new ShortcutInfo(); |
| 1377 | |
| 1378 | ComponentName componentName = intent.getComponent(); |
| 1379 | if (componentName == null) { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1380 | return null; |
| 1381 | } |
| 1382 | |
Joe Onorato | 8ddc4fd | 2010-03-17 09:14:50 -0700 | [diff] [blame] | 1383 | // TODO: See if the PackageManager knows about this case. If it doesn't |
| 1384 | // then return null & delete this. |
| 1385 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1386 | // the resource -- This may implicitly give us back the fallback icon, |
| 1387 | // but don't worry about that. All we're doing with usingFallbackIcon is |
| 1388 | // to avoid saving lots of copies of that in the database, and most apps |
| 1389 | // have icons anyway. |
| 1390 | final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0); |
| 1391 | if (resolveInfo != null) { |
| 1392 | icon = mIconCache.getIcon(componentName, resolveInfo); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1393 | } |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1394 | // the db |
| 1395 | if (icon == null) { |
| 1396 | if (c != null) { |
| 1397 | icon = getIconFromCursor(c, iconIndex); |
| 1398 | } |
| 1399 | } |
| 1400 | // the fallback icon |
| 1401 | if (icon == null) { |
| 1402 | icon = getFallbackIcon(); |
| 1403 | info.usingFallbackIcon = true; |
| 1404 | } |
| 1405 | info.setIcon(icon); |
| 1406 | |
| 1407 | // from the resource |
| 1408 | if (resolveInfo != null) { |
| 1409 | info.title = resolveInfo.activityInfo.loadLabel(manager); |
| 1410 | } |
| 1411 | // from the db |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1412 | if (info.title == null) { |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1413 | if (c != null) { |
| 1414 | info.title = c.getString(titleIndex); |
| 1415 | } |
| 1416 | } |
| 1417 | // fall back to the class name of the activity |
| 1418 | if (info.title == null) { |
| 1419 | info.title = componentName.getClassName(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1420 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1421 | info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; |
| 1422 | return info; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1423 | } |
The Android Open Source Project | bc219c3 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 1424 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1425 | /** |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1426 | * Make an ShortcutInfo object for a shortcut that isn't an application. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1427 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1428 | private ShortcutInfo getShortcutInfo(Cursor c, Context context, |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1429 | int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex, |
| 1430 | int titleIndex) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1431 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1432 | Bitmap icon = null; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1433 | final ShortcutInfo info = new ShortcutInfo(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1434 | info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1435 | |
Joe Onorato | 8ddc4fd | 2010-03-17 09:14:50 -0700 | [diff] [blame] | 1436 | // TODO: If there's an explicit component and we can't install that, delete it. |
| 1437 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1438 | info.title = c.getString(titleIndex); |
| 1439 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1440 | int iconType = c.getInt(iconTypeIndex); |
| 1441 | switch (iconType) { |
| 1442 | case LauncherSettings.Favorites.ICON_TYPE_RESOURCE: |
| 1443 | String packageName = c.getString(iconPackageIndex); |
| 1444 | String resourceName = c.getString(iconResourceIndex); |
| 1445 | PackageManager packageManager = context.getPackageManager(); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1446 | info.customIcon = false; |
| 1447 | // the resource |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1448 | try { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1449 | Resources resources = packageManager.getResourcesForApplication(packageName); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1450 | if (resources != null) { |
| 1451 | final int id = resources.getIdentifier(resourceName, null, null); |
| 1452 | icon = Utilities.createIconBitmap(resources.getDrawable(id), context); |
| 1453 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1454 | } catch (Exception e) { |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1455 | // drop this. we have other places to look for icons |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1456 | } |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1457 | // the db |
| 1458 | if (icon == null) { |
| 1459 | icon = getIconFromCursor(c, iconIndex); |
| 1460 | } |
| 1461 | // the fallback icon |
| 1462 | if (icon == null) { |
| 1463 | icon = getFallbackIcon(); |
| 1464 | info.usingFallbackIcon = true; |
| 1465 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1466 | break; |
| 1467 | case LauncherSettings.Favorites.ICON_TYPE_BITMAP: |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1468 | icon = getIconFromCursor(c, iconIndex); |
| 1469 | if (icon == null) { |
| 1470 | icon = getFallbackIcon(); |
| 1471 | info.customIcon = false; |
| 1472 | info.usingFallbackIcon = true; |
| 1473 | } else { |
| 1474 | info.customIcon = true; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1475 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1476 | break; |
| 1477 | default: |
Joe Onorato | d8d22da | 2010-03-11 17:59:11 -0800 | [diff] [blame] | 1478 | icon = getFallbackIcon(); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1479 | info.usingFallbackIcon = true; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1480 | info.customIcon = false; |
| 1481 | break; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1482 | } |
Joe Onorato | d8d22da | 2010-03-11 17:59:11 -0800 | [diff] [blame] | 1483 | info.setIcon(icon); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1484 | return info; |
| 1485 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1486 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1487 | Bitmap getIconFromCursor(Cursor c, int iconIndex) { |
| 1488 | if (false) { |
| 1489 | Log.d(TAG, "getIconFromCursor app=" |
| 1490 | + c.getString(c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE))); |
| 1491 | } |
| 1492 | byte[] data = c.getBlob(iconIndex); |
| 1493 | try { |
| 1494 | return BitmapFactory.decodeByteArray(data, 0, data.length); |
| 1495 | } catch (Exception e) { |
| 1496 | return null; |
| 1497 | } |
| 1498 | } |
| 1499 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1500 | ShortcutInfo addShortcut(Context context, Intent data, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1501 | int screen, int cellX, int cellY, boolean notify) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1502 | |
| 1503 | final ShortcutInfo info = infoFromShortcutIntent(context, data); |
| 1504 | addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1505 | screen, cellX, cellY, notify); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1506 | |
| 1507 | return info; |
| 1508 | } |
| 1509 | |
| 1510 | private ShortcutInfo infoFromShortcutIntent(Context context, Intent data) { |
| 1511 | Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); |
| 1512 | String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
| 1513 | Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); |
| 1514 | |
| 1515 | Bitmap icon = null; |
| 1516 | boolean filtered = false; |
| 1517 | boolean customIcon = false; |
| 1518 | ShortcutIconResource iconResource = null; |
| 1519 | |
| 1520 | if (bitmap != null && bitmap instanceof Bitmap) { |
| 1521 | icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap)bitmap), context); |
| 1522 | filtered = true; |
| 1523 | customIcon = true; |
| 1524 | } else { |
| 1525 | Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); |
| 1526 | if (extra != null && extra instanceof ShortcutIconResource) { |
| 1527 | try { |
| 1528 | iconResource = (ShortcutIconResource) extra; |
| 1529 | final PackageManager packageManager = context.getPackageManager(); |
| 1530 | Resources resources = packageManager.getResourcesForApplication( |
| 1531 | iconResource.packageName); |
| 1532 | final int id = resources.getIdentifier(iconResource.resourceName, null, null); |
| 1533 | icon = Utilities.createIconBitmap(resources.getDrawable(id), context); |
| 1534 | } catch (Exception e) { |
| 1535 | Log.w(TAG, "Could not load shortcut icon: " + extra); |
| 1536 | } |
| 1537 | } |
| 1538 | } |
| 1539 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1540 | final ShortcutInfo info = new ShortcutInfo(); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1541 | |
| 1542 | if (icon == null) { |
| 1543 | icon = getFallbackIcon(); |
| 1544 | info.usingFallbackIcon = true; |
| 1545 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1546 | info.setIcon(icon); |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1547 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1548 | info.title = name; |
| 1549 | info.intent = intent; |
| 1550 | info.customIcon = customIcon; |
| 1551 | info.iconResource = iconResource; |
| 1552 | |
| 1553 | return info; |
| 1554 | } |
| 1555 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1556 | private static void loadLiveFolderIcon(Context context, Cursor c, int iconTypeIndex, |
| 1557 | int iconPackageIndex, int iconResourceIndex, LiveFolderInfo liveFolderInfo) { |
| 1558 | |
| 1559 | int iconType = c.getInt(iconTypeIndex); |
| 1560 | switch (iconType) { |
| 1561 | case LauncherSettings.Favorites.ICON_TYPE_RESOURCE: |
| 1562 | String packageName = c.getString(iconPackageIndex); |
| 1563 | String resourceName = c.getString(iconResourceIndex); |
| 1564 | PackageManager packageManager = context.getPackageManager(); |
| 1565 | try { |
| 1566 | Resources resources = packageManager.getResourcesForApplication(packageName); |
| 1567 | final int id = resources.getIdentifier(resourceName, null, null); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1568 | liveFolderInfo.icon = Utilities.createIconBitmap(resources.getDrawable(id), |
| 1569 | context); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1570 | } catch (Exception e) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1571 | liveFolderInfo.icon = Utilities.createIconBitmap( |
| 1572 | context.getResources().getDrawable(R.drawable.ic_launcher_folder), |
| 1573 | context); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1574 | } |
| 1575 | liveFolderInfo.iconResource = new Intent.ShortcutIconResource(); |
| 1576 | liveFolderInfo.iconResource.packageName = packageName; |
| 1577 | liveFolderInfo.iconResource.resourceName = resourceName; |
| 1578 | break; |
| 1579 | default: |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1580 | liveFolderInfo.icon = Utilities.createIconBitmap( |
| 1581 | context.getResources().getDrawable(R.drawable.ic_launcher_folder), |
| 1582 | context); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1583 | } |
| 1584 | } |
| 1585 | |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1586 | void updateSavedIcon(Context context, ShortcutInfo info, Cursor c, int iconIndex) { |
| 1587 | // If this icon doesn't have a custom icon, check to see |
| 1588 | // what's stored in the DB, and if it doesn't match what |
| 1589 | // we're going to show, store what we are going to show back |
| 1590 | // into the DB. We do this so when we're loading, if the |
| 1591 | // package manager can't find an icon (for example because |
| 1592 | // the app is on SD) then we can use that instead. |
Joe Onorato | ddc9c1f | 2010-08-30 18:30:15 -0700 | [diff] [blame] | 1593 | if (!info.customIcon && !info.usingFallbackIcon) { |
Joe Onorato | 56d8291 | 2010-03-07 14:32:10 -0500 | [diff] [blame] | 1594 | boolean needSave; |
| 1595 | byte[] data = c.getBlob(iconIndex); |
| 1596 | try { |
| 1597 | if (data != null) { |
| 1598 | Bitmap saved = BitmapFactory.decodeByteArray(data, 0, data.length); |
| 1599 | Bitmap loaded = info.getIcon(mIconCache); |
| 1600 | needSave = !saved.sameAs(loaded); |
| 1601 | } else { |
| 1602 | needSave = true; |
| 1603 | } |
| 1604 | } catch (Exception e) { |
| 1605 | needSave = true; |
| 1606 | } |
| 1607 | if (needSave) { |
| 1608 | Log.d(TAG, "going to save icon bitmap for info=" + info); |
| 1609 | // This is slower than is ideal, but this only happens either |
| 1610 | // after the froyo OTA or when the app is updated with a new |
| 1611 | // icon. |
| 1612 | updateItemInDatabase(context, info); |
| 1613 | } |
| 1614 | } |
| 1615 | } |
| 1616 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1617 | /** |
| 1618 | * Return an existing UserFolderInfo object if we have encountered this ID previously, |
| 1619 | * or make a new one. |
| 1620 | */ |
| 1621 | private static UserFolderInfo findOrMakeUserFolder(HashMap<Long, FolderInfo> folders, long id) { |
| 1622 | // See if a placeholder was created for us already |
| 1623 | FolderInfo folderInfo = folders.get(id); |
| 1624 | if (folderInfo == null || !(folderInfo instanceof UserFolderInfo)) { |
| 1625 | // No placeholder -- create a new instance |
| 1626 | folderInfo = new UserFolderInfo(); |
| 1627 | folders.put(id, folderInfo); |
| 1628 | } |
| 1629 | return (UserFolderInfo) folderInfo; |
| 1630 | } |
| 1631 | |
| 1632 | /** |
| 1633 | * Return an existing UserFolderInfo object if we have encountered this ID previously, or make a |
| 1634 | * new one. |
| 1635 | */ |
| 1636 | private static LiveFolderInfo findOrMakeLiveFolder(HashMap<Long, FolderInfo> folders, long id) { |
| 1637 | // See if a placeholder was created for us already |
| 1638 | FolderInfo folderInfo = folders.get(id); |
| 1639 | if (folderInfo == null || !(folderInfo instanceof LiveFolderInfo)) { |
| 1640 | // No placeholder -- create a new instance |
| 1641 | folderInfo = new LiveFolderInfo(); |
| 1642 | folders.put(id, folderInfo); |
| 1643 | } |
| 1644 | return (LiveFolderInfo) folderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1645 | } |
| 1646 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1647 | private static String getLabel(PackageManager manager, ActivityInfo activityInfo) { |
| 1648 | String label = activityInfo.loadLabel(manager).toString(); |
| 1649 | if (label == null) { |
| 1650 | label = manager.getApplicationLabel(activityInfo.applicationInfo).toString(); |
| 1651 | if (label == null) { |
| 1652 | label = activityInfo.name; |
| 1653 | } |
| 1654 | } |
| 1655 | return label; |
| 1656 | } |
| 1657 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1658 | private static final Collator sCollator = Collator.getInstance(); |
Joe Onorato | b0c27f2 | 2009-12-01 16:19:38 -0800 | [diff] [blame] | 1659 | public static final Comparator<ApplicationInfo> APP_NAME_COMPARATOR |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1660 | = new Comparator<ApplicationInfo>() { |
| 1661 | public final int compare(ApplicationInfo a, ApplicationInfo b) { |
| 1662 | return sCollator.compare(a.title.toString(), b.title.toString()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1663 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1664 | }; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1665 | |
| 1666 | public void dumpState() { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1667 | Log.d(TAG, "mCallbacks=" + mCallbacks); |
| 1668 | ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mAllAppsList.data); |
| 1669 | ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mAllAppsList.added); |
| 1670 | ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mAllAppsList.removed); |
| 1671 | ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mAllAppsList.modified); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 1672 | Log.d(TAG, "mItems size=" + mItems.size()); |
| 1673 | if (mLoaderTask != null) { |
| 1674 | mLoaderTask.dumpState(); |
| 1675 | } else { |
| 1676 | Log.d(TAG, "mLoaderTask=null"); |
| 1677 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1678 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1679 | } |