summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherProvider.java
diff options
context:
space:
mode:
authorDan Sandler <dsandler@android.com>2014-01-09 15:01:33 -0500
committerDan Sandler <dsandler@android.com>2014-01-10 15:49:51 -0500
commitd502404a44fb7c4ea739622d7f8bdd2a764d97a1 (patch)
tree2d14d3da3c805d6dcb61b9573ffdbc8cb4e85dc9 /src/com/android/launcher3/LauncherProvider.java
parent0bae5b220a24541dbc69fb2cb755f303776d0a59 (diff)
downloadandroid_packages_apps_Trebuchet-d502404a44fb7c4ea739622d7f8bdd2a764d97a1.tar.gz
android_packages_apps_Trebuchet-d502404a44fb7c4ea739622d7f8bdd2a764d97a1.tar.bz2
android_packages_apps_Trebuchet-d502404a44fb7c4ea739622d7f8bdd2a764d97a1.zip
New launcher2 icon migration algorithm.
The user will be able to request "icon migration", which is not a direct mapping of the old workspace, but rather follows this heuristic for bringing the user's favorite icons (by dint of their existence on the workspace) into Launcher3: Workspace shortcuts are placed in lexicographic order on the workspace starting at screen 0 (leaving the bottom row of screen 0 empty to make sure there's room to move things around). Folders are preserved and their contents sorted. Duplicate icons (that is, shortcuts with the same intent, pursuant to some cleanups) are removed. Hotseat icons are migrated in their original place, unless their new location is not accommodated by the hotseat (i.e. the L3 hotseat is too small on this device), in which case they're treated like any other shortcut and tossed into the workspace. To test, turn on Launcher.ENABLE_DEBUG_INTENTS and then: $ adb shell am broadcast -a com.android.launcher3.action.DELETE_DATABASE $ adb shell am broadcast -a com.android.launcher3.action.MIGRATE_DATABASE Bug: 12416411 Change-Id: Ia5c56f36c11455867ea20a39f70210f595020a87
Diffstat (limited to 'src/com/android/launcher3/LauncherProvider.java')
-rw-r--r--src/com/android/launcher3/LauncherProvider.java224
1 files changed, 223 insertions, 1 deletions
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 28efd0148..3cacd6c70 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -55,9 +55,11 @@ import com.android.launcher3.config.ProviderConfig;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
public class LauncherProvider extends ContentProvider {
@@ -72,7 +74,7 @@ public class LauncherProvider extends ContentProvider {
static final String AUTHORITY = ProviderConfig.AUTHORITY;
// Should we attempt to load anything from the com.android.launcher2 provider?
- static final boolean IMPORT_LAUNCHER2_DATABASE = true;
+ static final boolean IMPORT_LAUNCHER2_DATABASE = false;
static final String TABLE_FAVORITES = "favorites";
static final String TABLE_WORKSPACE_SCREENS = "workspaceScreens";
@@ -133,6 +135,9 @@ public class LauncherProvider extends ContentProvider {
private static long dbInsertAndCheck(DatabaseHelper helper,
SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) {
+ if (values == null) {
+ throw new RuntimeException("Error: attempting to insert null values");
+ }
if (!values.containsKey(LauncherSettings.Favorites._ID)) {
throw new RuntimeException("Error: attempting to add item without specifying an id");
}
@@ -287,6 +292,11 @@ public class LauncherProvider extends ContentProvider {
}
}
+ public void migrateLauncher2Shortcuts() {
+ mOpenHelper.migrateLauncher2Shortcuts(mOpenHelper.getWritableDatabase(),
+ LauncherSettings.Favorites.OLD_CONTENT_URI);
+ }
+
private static int getDefaultWorkspaceResourceId() {
if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
return R.xml.default_workspace_no_all_apps;
@@ -306,6 +316,15 @@ public class LauncherProvider extends ContentProvider {
return !isTablet && IMPORT_LAUNCHER2_DATABASE;
}
+ public void deleteDatabase() {
+ // Are you sure? (y/n)
+ final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ final String dbFile = db.getPath();
+ mOpenHelper.close();
+ SQLiteDatabase.deleteDatabase(new File(dbFile));
+ mOpenHelper = new DatabaseHelper(getContext());
+ }
+
private static class DatabaseHelper extends SQLiteOpenHelper {
private static final String TAG_FAVORITES = "favorites";
private static final String TAG_FAVORITE = "favorite";
@@ -1431,6 +1450,209 @@ public class LauncherProvider extends ContentProvider {
}
return id;
}
+
+ public void migrateLauncher2Shortcuts(SQLiteDatabase db, Uri uri) {
+ final ContentResolver resolver = mContext.getContentResolver();
+ Cursor c = null;
+ int count = 0;
+ int curScreen = 0;
+
+ try {
+ c = resolver.query(uri, null, null, null, "title ASC");
+ } catch (Exception e) {
+ // Ignore
+ }
+
+
+ // We already have a favorites database in the old provider
+ if (c != null) {
+ try {
+ if (c.getCount() > 0) {
+ final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
+ final int intentIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
+ final int titleIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
+ final int iconTypeIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_TYPE);
+ final int iconIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
+ final int iconPackageIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_PACKAGE);
+ final int iconResourceIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_RESOURCE);
+ final int containerIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
+ final int itemTypeIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
+ final int screenIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
+ final int cellXIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
+ final int cellYIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
+ final int uriIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI);
+ final int displayModeIndex
+ = c.getColumnIndexOrThrow(LauncherSettings.Favorites.DISPLAY_MODE);
+
+ int i = 0;
+ int curX = 0;
+ int curY = 0;
+
+ final LauncherAppState app = LauncherAppState.getInstance();
+ final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
+ final int width = (int) grid.numColumns;
+ final int height = (int) grid.numRows;
+ final int hotseatWidth = (int) grid.numHotseatIcons;
+
+ final HashSet<String> seenIntents = new HashSet<String>(c.getCount());
+
+ final ContentValues[] rows = new ContentValues[c.getCount()];
+
+ while (c.moveToNext()) {
+ final int itemType = c.getInt(itemTypeIndex);
+ if (itemType != Favorites.ITEM_TYPE_APPLICATION
+ && itemType != Favorites.ITEM_TYPE_SHORTCUT
+ && itemType != Favorites.ITEM_TYPE_FOLDER) {
+ continue;
+ }
+
+ final int cellX = c.getInt(cellXIndex);
+ final int cellY = c.getInt(cellYIndex);
+ final int screen = c.getInt(screenIndex);
+ int container = c.getInt(containerIndex);
+ final String intentStr = c.getString(intentIndex);
+ Launcher.addDumpLog(TAG, "migrating \""
+ + c.getString(titleIndex) + "\": " + intentStr, true);
+
+ if (itemType != Favorites.ITEM_TYPE_FOLDER) {
+ if (TextUtils.isEmpty(intentStr)) {
+ // no intent? no icon
+ Launcher.addDumpLog(TAG, "skipping empty intent", true);
+ continue;
+ } else {
+ try {
+ // Canonicalize
+ final Intent intent = Intent.parseUri(intentStr, 0);
+ // the Play Store sets the package parameter, but Launcher
+ // does not, so we clear that out to keep them the same
+ intent.setPackage(null);
+ final String key = intent.toUri(0);
+ if (seenIntents.contains(key)) {
+ Launcher.addDumpLog(TAG, "skipping duplicate", true);
+ continue;
+ } else {
+ seenIntents.add(key);
+ }
+ } catch (URISyntaxException e) {
+ // bogus intent?
+ Launcher.addDumpLog(TAG,
+ "skipping invalid intent uri", true);
+ continue;
+ }
+ }
+ }
+
+ ContentValues values = new ContentValues(c.getColumnCount());
+ values.put(LauncherSettings.Favorites._ID, c.getInt(idIndex));
+ values.put(LauncherSettings.Favorites.INTENT, intentStr);
+ values.put(LauncherSettings.Favorites.TITLE, c.getString(titleIndex));
+ values.put(LauncherSettings.Favorites.ICON_TYPE,
+ c.getInt(iconTypeIndex));
+ values.put(LauncherSettings.Favorites.ICON, c.getBlob(iconIndex));
+ values.put(LauncherSettings.Favorites.ICON_PACKAGE,
+ c.getString(iconPackageIndex));
+ values.put(LauncherSettings.Favorites.ICON_RESOURCE,
+ c.getString(iconResourceIndex));
+ values.put(LauncherSettings.Favorites.ITEM_TYPE, itemType);
+ values.put(LauncherSettings.Favorites.APPWIDGET_ID, -1);
+ values.put(LauncherSettings.Favorites.URI, c.getString(uriIndex));
+ values.put(LauncherSettings.Favorites.DISPLAY_MODE,
+ c.getInt(displayModeIndex));
+
+ if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT
+ && screen >= hotseatWidth) {
+ // no room for you in the hotseat? it's off to the desktop with you
+ container = Favorites.CONTAINER_DESKTOP;
+ }
+
+ if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
+ // In a folder or in the hotseat, preserve position
+ values.put(LauncherSettings.Favorites.SCREEN, screen);
+ values.put(LauncherSettings.Favorites.CELLX, cellX);
+ values.put(LauncherSettings.Favorites.CELLY, cellY);
+ } else {
+ values.put(LauncherSettings.Favorites.SCREEN, curScreen);
+ values.put(LauncherSettings.Favorites.CELLX, curX);
+ values.put(LauncherSettings.Favorites.CELLY, curY);
+ curX = (curX + 1) % width;
+ if (curX == 0) {
+ curY = (curY + 1);
+ }
+ // Leave the last row of icons blank on screen 0
+ if (curScreen == 0 && curY == height - 1 || curY == height) {
+ curScreen = (int) generateNewScreenId();
+ curY = 0;
+ }
+ }
+
+ values.put(LauncherSettings.Favorites.CONTAINER, container);
+
+ rows[i++] = values;
+ }
+
+ if (i > 0) {
+ db.beginTransaction();
+ try {
+ final int N = rows.length;
+ for (i = 0; i < N; i++) {
+ if (rows[i] == null) continue;
+ if (dbInsertAndCheck(this, db, TABLE_FAVORITES, null, rows[i])
+ < 0) {
+ return;
+ } else {
+ count++;
+ }
+ }
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ }
+
+ db.beginTransaction();
+ try {
+ for (i=0; i<=curScreen; i++) {
+ final ContentValues values = new ContentValues();
+ values.put(LauncherSettings.WorkspaceScreens._ID, i);
+ values.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
+ if (dbInsertAndCheck(this, db, TABLE_WORKSPACE_SCREENS, null, values)
+ < 0) {
+ return;
+ }
+ }
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ }
+ } finally {
+ c.close();
+ }
+ }
+
+ Launcher.addDumpLog(TAG, "migrated " + count + " icons from Launcher2 into "
+ + (curScreen+1) + " screens", true);
+
+ // ensure that new screens are created to hold these icons
+ setFlagJustLoadedOldDb();
+
+ // Update max IDs; very important since we just grabbed IDs from another database
+ mMaxItemId = initializeMaxItemId(db);
+ mMaxScreenId = initializeMaxScreenId(db);
+ if (LOGD) Log.d(TAG, "mMaxItemId: " + mMaxItemId + " mMaxScreenId: " + mMaxScreenId);
+ }
}
/**