Allow 2x2 and 3x3 to be migrated after restore am: 238aaee059
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15992138 Change-Id: I8cf6ed0cdfc12678259a31194eb94992822a61cd
This commit is contained in:
@@ -46,6 +46,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.launcher3.model.DeviceGridState;
|
import com.android.launcher3.model.DeviceGridState;
|
||||||
|
import com.android.launcher3.provider.RestoreDbTask;
|
||||||
import com.android.launcher3.util.DisplayController;
|
import com.android.launcher3.util.DisplayController;
|
||||||
import com.android.launcher3.util.DisplayController.Info;
|
import com.android.launcher3.util.DisplayController.Info;
|
||||||
import com.android.launcher3.util.IntArray;
|
import com.android.launcher3.util.IntArray;
|
||||||
@@ -204,11 +205,11 @@ public class InvariantDeviceProfile {
|
|||||||
// Get the display info based on default display and interpolate it to existing display
|
// Get the display info based on default display and interpolate it to existing display
|
||||||
DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
|
DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
|
||||||
DisplayController.INSTANCE.get(context).getInfo(),
|
DisplayController.INSTANCE.get(context).getInfo(),
|
||||||
getPredefinedDeviceProfiles(context, gridName, false), false);
|
getPredefinedDeviceProfiles(context, gridName, false, false), false);
|
||||||
|
|
||||||
Info myInfo = new Info(context, display);
|
Info myInfo = new Info(context, display);
|
||||||
DisplayOption myDisplayOption = invDistWeightedInterpolate(
|
DisplayOption myDisplayOption = invDistWeightedInterpolate(
|
||||||
myInfo, getPredefinedDeviceProfiles(context, gridName, false), false);
|
myInfo, getPredefinedDeviceProfiles(context, gridName, false, false), false);
|
||||||
|
|
||||||
DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
|
DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
|
||||||
.add(myDisplayOption);
|
.add(myDisplayOption);
|
||||||
@@ -227,6 +228,29 @@ public class InvariantDeviceProfile {
|
|||||||
initGrid(context, myInfo, result, false);
|
initGrid(context, myInfo, result, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reinitialize the current grid after a restore, where some grids might now be disabled.
|
||||||
|
*/
|
||||||
|
public void reinitializeAfterRestore(Context context) {
|
||||||
|
String currentDbFile = dbFile;
|
||||||
|
String gridName = getCurrentGridName(context);
|
||||||
|
String newGridName = initGrid(context, gridName);
|
||||||
|
if (!newGridName.equals(gridName)) {
|
||||||
|
Log.d(TAG, "Restored grid is disabled : " + gridName
|
||||||
|
+ ", migrating to: " + newGridName
|
||||||
|
+ ", removing all other grid db files");
|
||||||
|
for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
|
||||||
|
if (gridDbFile.equals(currentDbFile)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (context.getDatabasePath(gridDbFile).delete()) {
|
||||||
|
Log.d(TAG, "Removed old grid db file: " + gridDbFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setCurrentGrid(context, gridName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getCurrentGridName(Context context) {
|
public static String getCurrentGridName(Context context) {
|
||||||
return Utilities.isGridOptionsEnabled(context)
|
return Utilities.isGridOptionsEnabled(context)
|
||||||
? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
|
? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
|
||||||
@@ -240,7 +264,8 @@ public class InvariantDeviceProfile {
|
|||||||
displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get();
|
displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get();
|
||||||
|
|
||||||
ArrayList<DisplayOption> allOptions =
|
ArrayList<DisplayOption> allOptions =
|
||||||
getPredefinedDeviceProfiles(context, gridName, isSplitDisplay);
|
getPredefinedDeviceProfiles(context, gridName, isSplitDisplay,
|
||||||
|
RestoreDbTask.isPending(context));
|
||||||
DisplayOption displayOption =
|
DisplayOption displayOption =
|
||||||
invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay);
|
invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay);
|
||||||
initGrid(context, displayInfo, displayOption, isSplitDisplay);
|
initGrid(context, displayInfo, displayOption, isSplitDisplay);
|
||||||
@@ -366,7 +391,7 @@ public class InvariantDeviceProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(
|
private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(
|
||||||
Context context, String gridName, boolean isSplitDisplay) {
|
Context context, String gridName, boolean isSplitDisplay, boolean allowDisabledGrid) {
|
||||||
ArrayList<DisplayOption> profiles = new ArrayList<>();
|
ArrayList<DisplayOption> profiles = new ArrayList<>();
|
||||||
try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
|
try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
|
||||||
final int depth = parser.getDepth();
|
final int depth = parser.getDepth();
|
||||||
@@ -378,7 +403,7 @@ public class InvariantDeviceProfile {
|
|||||||
|
|
||||||
GridOption gridOption =
|
GridOption gridOption =
|
||||||
new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay);
|
new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay);
|
||||||
if (gridOption.isEnabled) {
|
if (gridOption.isEnabled || allowDisabledGrid) {
|
||||||
final int displayDepth = parser.getDepth();
|
final int displayDepth = parser.getDepth();
|
||||||
while (((type = parser.next()) != XmlPullParser.END_TAG
|
while (((type = parser.next()) != XmlPullParser.END_TAG
|
||||||
|| parser.getDepth() > displayDepth)
|
|| parser.getDepth() > displayDepth)
|
||||||
@@ -400,7 +425,8 @@ public class InvariantDeviceProfile {
|
|||||||
ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
|
ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
|
||||||
if (!TextUtils.isEmpty(gridName)) {
|
if (!TextUtils.isEmpty(gridName)) {
|
||||||
for (DisplayOption option : profiles) {
|
for (DisplayOption option : profiles) {
|
||||||
if (gridName.equals(option.grid.name) && option.grid.isEnabled) {
|
if (gridName.equals(option.grid.name)
|
||||||
|
&& (option.grid.isEnabled || allowDisabledGrid)) {
|
||||||
filteredProfiles.add(option);
|
filteredProfiles.add(option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.android.launcher3;
|
package com.android.launcher3;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -29,16 +30,24 @@ public class LauncherFiles {
|
|||||||
public static final String WIDGET_PREVIEWS_DB = "widgetpreviews.db";
|
public static final String WIDGET_PREVIEWS_DB = "widgetpreviews.db";
|
||||||
public static final String APP_ICONS_DB = "app_icons.db";
|
public static final String APP_ICONS_DB = "app_icons.db";
|
||||||
|
|
||||||
public static final List<String> ALL_FILES = Collections.unmodifiableList(Arrays.asList(
|
public static final List<String> GRID_DB_FILES = Collections.unmodifiableList(Arrays.asList(
|
||||||
LAUNCHER_DB,
|
LAUNCHER_DB,
|
||||||
LAUNCHER_4_BY_5_DB,
|
LAUNCHER_4_BY_5_DB,
|
||||||
LAUNCHER_4_BY_4_DB,
|
LAUNCHER_4_BY_4_DB,
|
||||||
LAUNCHER_3_BY_3_DB,
|
LAUNCHER_3_BY_3_DB,
|
||||||
LAUNCHER_2_BY_2_DB,
|
LAUNCHER_2_BY_2_DB));
|
||||||
|
|
||||||
|
public static final List<String> OTHER_FILES = Collections.unmodifiableList(Arrays.asList(
|
||||||
BACKUP_DB,
|
BACKUP_DB,
|
||||||
SHARED_PREFERENCES_KEY + XML,
|
SHARED_PREFERENCES_KEY + XML,
|
||||||
WIDGET_PREVIEWS_DB,
|
WIDGET_PREVIEWS_DB,
|
||||||
MANAGED_USER_PREFERENCES_KEY + XML,
|
MANAGED_USER_PREFERENCES_KEY + XML,
|
||||||
DEVICE_PREFERENCES_KEY + XML,
|
DEVICE_PREFERENCES_KEY + XML,
|
||||||
APP_ICONS_DB));
|
APP_ICONS_DB));
|
||||||
|
|
||||||
|
public static final List<String> ALL_FILES = Collections.unmodifiableList(
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
addAll(GRID_DB_FILES);
|
||||||
|
addAll(OTHER_FILES);
|
||||||
|
}});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ public class RestoreDbTask {
|
|||||||
// Set is pending to false irrespective of the result, so that it doesn't get
|
// Set is pending to false irrespective of the result, so that it doesn't get
|
||||||
// executed again.
|
// executed again.
|
||||||
Utilities.getPrefs(context).edit().remove(RESTORED_DEVICE_TYPE).commit();
|
Utilities.getPrefs(context).edit().remove(RESTORED_DEVICE_TYPE).commit();
|
||||||
|
|
||||||
|
InvariantDeviceProfile.INSTANCE.get(context).reinitializeAfterRestore(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean performRestore(Context context, DatabaseHelper helper) {
|
private static boolean performRestore(Context context, DatabaseHelper helper) {
|
||||||
|
|||||||
Reference in New Issue
Block a user