summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/provider/ImportDataTask.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/provider/ImportDataTask.java')
-rw-r--r--src/com/android/launcher3/provider/ImportDataTask.java62
1 files changed, 19 insertions, 43 deletions
diff --git a/src/com/android/launcher3/provider/ImportDataTask.java b/src/com/android/launcher3/provider/ImportDataTask.java
index b389b145d..86fcc0680 100644
--- a/src/com/android/launcher3/provider/ImportDataTask.java
+++ b/src/com/android/launcher3/provider/ImportDataTask.java
@@ -33,7 +33,6 @@ import android.os.Process;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.SparseBooleanArray;
-import android.util.SparseIntArray;
import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
import com.android.launcher3.DefaultLayoutParser;
@@ -43,7 +42,6 @@ import com.android.launcher3.LauncherProvider;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherSettings.Settings;
-import com.android.launcher3.LauncherSettings.WorkspaceScreens;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.compat.UserManagerCompat;
@@ -72,7 +70,6 @@ public class ImportDataTask {
private final Context mContext;
- private final Uri mOtherScreensUri;
private final Uri mOtherFavoritesUri;
private int mHotseatSize;
@@ -81,41 +78,14 @@ public class ImportDataTask {
private ImportDataTask(Context context, String sourceAuthority) {
mContext = context;
- mOtherScreensUri = Uri.parse("content://" +
- sourceAuthority + "/" + WorkspaceScreens.TABLE_NAME);
mOtherFavoritesUri = Uri.parse("content://" + sourceAuthority + "/" + Favorites.TABLE_NAME);
}
public boolean importWorkspace() throws Exception {
- IntArray allScreens = LauncherDbUtils.getScreenIdsFromCursor(
- mContext.getContentResolver().query(mOtherScreensUri, null, null, null,
- LauncherSettings.WorkspaceScreens.SCREEN_RANK));
FileLog.d(TAG, "Importing DB from " + mOtherFavoritesUri);
- // During import we reset the screen IDs to 0-indexed values.
- if (allScreens.isEmpty()) {
- // No thing to migrate
- FileLog.e(TAG, "No data found to import");
- return false;
- }
-
mHotseatSize = mMaxGridSizeX = mMaxGridSizeY = 0;
-
- // Build screen update
- ArrayList<ContentProviderOperation> screenOps = new ArrayList<>();
- int count = allScreens.size();
- SparseIntArray screenIdMap = new SparseIntArray(count);
- for (int i = 0; i < count; i++) {
- ContentValues v = new ContentValues();
- v.put(LauncherSettings.WorkspaceScreens._ID, i);
- v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
- screenIdMap.put(allScreens.get(i), i);
- screenOps.add(ContentProviderOperation.newInsert(
- LauncherSettings.WorkspaceScreens.CONTENT_URI).withValues(v).build());
- }
- mContext.getContentResolver().applyBatch(LauncherProvider.AUTHORITY, screenOps);
- importWorkspaceItems(allScreens.get(0), screenIdMap);
-
+ importWorkspaceItems();
GridSizeMigrationTask.markForMigration(mContext, mMaxGridSizeX, mMaxGridSizeY, mHotseatSize);
// Create empty DB flag.
@@ -129,17 +99,17 @@ public class ImportDataTask {
* 2) For home screen entries, maps the screen id based on {@param screenIdMap}
* 3) In the end fills any holes in hotseat with items from default hotseat layout.
*/
- private void importWorkspaceItems(
- int firstScreenId, SparseIntArray screenIdMap) throws Exception {
+ private void importWorkspaceItems() throws Exception {
String profileId = Long.toString(UserManagerCompat.getInstance(mContext)
.getSerialNumberForUser(Process.myUserHandle()));
boolean createEmptyRowOnFirstScreen;
if (FeatureFlags.QSB_ON_FIRST_SCREEN.get()) {
try (Cursor c = mContext.getContentResolver().query(mOtherFavoritesUri, null,
- // get items on the first row of the first screen
- "profileId = ? AND container = -100 AND screen = ? AND cellY = 0",
- new String[]{profileId, Integer.toString(firstScreenId)},
+ // get items on the first row of the first screen (min screen id)
+ "profileId = ? AND container = -100 AND cellY = 0 AND screen = " +
+ "(SELECT MIN(screen) FROM favorites WHERE container = -100)",
+ new String[]{profileId},
null)) {
// First row of first screen is not empty
createEmptyRowOnFirstScreen = c.moveToNext();
@@ -163,7 +133,7 @@ public class ImportDataTask {
Favorites.PROFILE_ID + " = ?", new String[]{profileId},
// Get the items sorted by container, so that the folders are loaded
// before the corresponding items.
- Favorites.CONTAINER)) {
+ Favorites.CONTAINER + " , " + Favorites.SCREEN)) {
// various columns we expect to exist.
final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
@@ -185,6 +155,7 @@ public class ImportDataTask {
SparseBooleanArray mValidFolders = new SparseBooleanArray();
ContentValues values = new ContentValues();
+ Integer firstScreenId = null;
while (c.moveToNext()) {
values.clear();
int id = c.getInt(idIndex);
@@ -201,16 +172,21 @@ public class ImportDataTask {
switch (container) {
case Favorites.CONTAINER_DESKTOP: {
- Integer newScreenId = screenIdMap.get(screen);
- if (newScreenId == null) {
- FileLog.d(TAG, String.format("Skipping item %d, type %d not on a valid screen %d", id, type, screen));
+ if (screen < Workspace.FIRST_SCREEN_ID) {
+ FileLog.d(TAG, String.format(
+ "Skipping item %d, type %d not on a valid screen %d",
+ id, type, screen));
continue;
}
+ if (firstScreenId == null) {
+ firstScreenId = screen;
+ }
// Reset the screen to 0-index value
- screen = newScreenId;
- if (createEmptyRowOnFirstScreen && screen == Workspace.FIRST_SCREEN_ID) {
+ if (createEmptyRowOnFirstScreen && firstScreenId.equals(screen)) {
// Shift items by 1.
cellY++;
+ // Change the screen id to first screen
+ screen = Workspace.FIRST_SCREEN_ID;
}
mMaxGridSizeX = Math.max(mMaxGridSizeX, cellX + spanX);
@@ -218,7 +194,7 @@ public class ImportDataTask {
break;
}
case Favorites.CONTAINER_HOTSEAT: {
- mHotseatSize = Math.max(mHotseatSize, (int) screen + 1);
+ mHotseatSize = Math.max(mHotseatSize, screen + 1);
break;
}
default: