Merge "Only marking items not already restored as restore" into ub-launcher3-master
This commit is contained in:
commit
a3db1fc674
|
@ -1105,10 +1105,6 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
final boolean isSdCardReady = Utilities.isBootCompleted();
|
final boolean isSdCardReady = Utilities.isBootCompleted();
|
||||||
final MultiHashMap<UserHandle, String> pendingPackages = new MultiHashMap<>();
|
final MultiHashMap<UserHandle, String> pendingPackages = new MultiHashMap<>();
|
||||||
|
|
||||||
InvariantDeviceProfile profile = mApp.getInvariantDeviceProfile();
|
|
||||||
int countX = profile.numColumns;
|
|
||||||
int countY = profile.numRows;
|
|
||||||
|
|
||||||
boolean clearDb = false;
|
boolean clearDb = false;
|
||||||
try {
|
try {
|
||||||
ImportDataTask.performImportIfPossible(context);
|
ImportDataTask.performImportIfPossible(context);
|
||||||
|
@ -1159,8 +1155,6 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
LauncherSettings.Favorites.SPANY);
|
LauncherSettings.Favorites.SPANY);
|
||||||
final int rankIndex = c.getColumnIndexOrThrow(
|
final int rankIndex = c.getColumnIndexOrThrow(
|
||||||
LauncherSettings.Favorites.RANK);
|
LauncherSettings.Favorites.RANK);
|
||||||
final int restoredIndex = c.getColumnIndexOrThrow(
|
|
||||||
LauncherSettings.Favorites.RESTORED);
|
|
||||||
final int optionsIndex = c.getColumnIndexOrThrow(
|
final int optionsIndex = c.getColumnIndexOrThrow(
|
||||||
LauncherSettings.Favorites.OPTIONS);
|
LauncherSettings.Favorites.OPTIONS);
|
||||||
|
|
||||||
|
@ -1207,7 +1201,6 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean restored = 0 != c.getInt(restoredIndex);
|
|
||||||
boolean allowMissingTarget = false;
|
boolean allowMissingTarget = false;
|
||||||
switch (c.itemType) {
|
switch (c.itemType) {
|
||||||
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: {
|
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: {
|
||||||
|
@ -1220,7 +1213,6 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
|
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
|
||||||
case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
|
case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
|
||||||
intentDescription = c.getString(intentIndex);
|
intentDescription = c.getString(intentIndex);
|
||||||
int promiseType = c.getInt(restoredIndex);
|
|
||||||
int disabledState = 0;
|
int disabledState = 0;
|
||||||
targetPackage = null;
|
targetPackage = null;
|
||||||
|
|
||||||
|
@ -1237,17 +1229,14 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validComponent) {
|
if (validComponent) {
|
||||||
if (restored) {
|
// no special handling necessary for this item
|
||||||
// no special handling necessary for this item
|
c.markRestored();
|
||||||
c.markRestored();
|
|
||||||
restored = false;
|
|
||||||
}
|
|
||||||
if (quietMode.get(c.serialNumber)) {
|
if (quietMode.get(c.serialNumber)) {
|
||||||
disabledState = ShortcutInfo.FLAG_DISABLED_QUIET_USER;
|
disabledState = ShortcutInfo.FLAG_DISABLED_QUIET_USER;
|
||||||
}
|
}
|
||||||
} else if (validPkg) {
|
} else if (validPkg) {
|
||||||
intent = null;
|
intent = null;
|
||||||
if ((promiseType & ShortcutInfo.FLAG_AUTOINTALL_ICON) != 0) {
|
if (c.hasRestoreFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
|
||||||
// We allow auto install apps to have their intent
|
// We allow auto install apps to have their intent
|
||||||
// updated after an install.
|
// updated after an install.
|
||||||
intent = manager.getLaunchIntentForPackage(
|
intent = manager.getLaunchIntentForPackage(
|
||||||
|
@ -1267,21 +1256,20 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
} else {
|
} else {
|
||||||
// no special handling necessary for this item
|
// no special handling necessary for this item
|
||||||
c.markRestored();
|
c.markRestored();
|
||||||
restored = false;
|
|
||||||
}
|
}
|
||||||
} else if (restored) {
|
} else if (c.restoreFlag != 0) {
|
||||||
// Package is not yet available but might be
|
// Package is not yet available but might be
|
||||||
// installed later.
|
// installed later.
|
||||||
FileLog.d(TAG, "package not yet restored: " + cn);
|
FileLog.d(TAG, "package not yet restored: " + cn);
|
||||||
|
|
||||||
if ((promiseType & ShortcutInfo.FLAG_RESTORE_STARTED) != 0) {
|
if (c.hasRestoreFlag(ShortcutInfo.FLAG_RESTORE_STARTED)) {
|
||||||
// Restore has started once.
|
// Restore has started once.
|
||||||
} else if (installingPkgs.containsKey(cn.getPackageName())) {
|
} else if (installingPkgs.containsKey(cn.getPackageName())) {
|
||||||
// App restore has started. Update the flag
|
// App restore has started. Update the flag
|
||||||
promiseType |= ShortcutInfo.FLAG_RESTORE_STARTED;
|
c.restoreFlag |= ShortcutInfo.FLAG_RESTORE_STARTED;
|
||||||
c.updater().put(
|
c.updater().put(
|
||||||
LauncherSettings.Favorites.RESTORED,
|
LauncherSettings.Favorites.RESTORED,
|
||||||
promiseType).commit();
|
c.restoreFlag).commit();
|
||||||
} else {
|
} else {
|
||||||
c.markDeleted("Unrestored package removed: " + cn);
|
c.markDeleted("Unrestored package removed: " + cn);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1308,7 +1296,6 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
} else if (cn == null) {
|
} else if (cn == null) {
|
||||||
// For shortcuts with no component, keep them as they are
|
// For shortcuts with no component, keep them as they are
|
||||||
c.markRestored();
|
c.markRestored();
|
||||||
restored = false;
|
|
||||||
}
|
}
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
c.markDeleted("Invalid uri: " + intentDescription);
|
c.markDeleted("Invalid uri: " + intentDescription);
|
||||||
|
@ -1318,9 +1305,9 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
boolean useLowResIcon = !c.isOnWorkspaceOrHotseat() &&
|
boolean useLowResIcon = !c.isOnWorkspaceOrHotseat() &&
|
||||||
c.getInt(rankIndex) >= FolderIcon.NUM_ITEMS_IN_PREVIEW;
|
c.getInt(rankIndex) >= FolderIcon.NUM_ITEMS_IN_PREVIEW;
|
||||||
|
|
||||||
if (restored) {
|
if (c.restoreFlag != 0) {
|
||||||
if (c.user.equals(Process.myUserHandle())) {
|
if (c.user.equals(Process.myUserHandle())) {
|
||||||
info = c.getRestoredItemInfo(intent, promiseType);
|
info = c.getRestoredItemInfo(intent);
|
||||||
} else {
|
} else {
|
||||||
// Don't restore items for other profiles.
|
// Don't restore items for other profiles.
|
||||||
c.markDeleted("Restore from managed profile not supported");
|
c.markDeleted("Restore from managed profile not supported");
|
||||||
|
@ -1385,7 +1372,7 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
info.isDisabled |= ShortcutInfo.FLAG_DISABLED_SAFEMODE;
|
info.isDisabled |= ShortcutInfo.FLAG_DISABLED_SAFEMODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restored) {
|
if (c.restoreFlag != 0) {
|
||||||
ComponentName cn = info.getTargetComponent();
|
ComponentName cn = info.getTargetComponent();
|
||||||
if (cn != null) {
|
if (cn != null) {
|
||||||
Integer progress = installingPkgs.get(cn.getPackageName());
|
Integer progress = installingPkgs.get(cn.getPackageName());
|
||||||
|
@ -1413,10 +1400,8 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
folderInfo.spanY = 1;
|
folderInfo.spanY = 1;
|
||||||
folderInfo.options = c.getInt(optionsIndex);
|
folderInfo.options = c.getInt(optionsIndex);
|
||||||
|
|
||||||
if (restored) {
|
// no special handling required for restored folders
|
||||||
// no special handling required for restored folders
|
c.markRestored();
|
||||||
c.markRestored();
|
|
||||||
}
|
|
||||||
|
|
||||||
c.checkAndAddItem(folderInfo, sBgDataModel);
|
c.checkAndAddItem(folderInfo, sBgDataModel);
|
||||||
break;
|
break;
|
||||||
|
@ -1433,11 +1418,10 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
final ComponentName component =
|
final ComponentName component =
|
||||||
ComponentName.unflattenFromString(savedProvider);
|
ComponentName.unflattenFromString(savedProvider);
|
||||||
|
|
||||||
final int restoreStatus = c.getInt(restoredIndex);
|
final boolean isIdValid = !c.hasRestoreFlag(
|
||||||
final boolean isIdValid = (restoreStatus &
|
LauncherAppWidgetInfo.FLAG_ID_NOT_VALID);
|
||||||
LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) == 0;
|
final boolean wasProviderReady = !c.hasRestoreFlag(
|
||||||
final boolean wasProviderReady = (restoreStatus &
|
LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY);
|
||||||
LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0;
|
|
||||||
|
|
||||||
if (widgetProvidersMap == null) {
|
if (widgetProvidersMap == null) {
|
||||||
widgetProvidersMap = AppWidgetManagerCompat
|
widgetProvidersMap = AppWidgetManagerCompat
|
||||||
|
@ -1462,7 +1446,7 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
// The provider is available. So the widget is either
|
// The provider is available. So the widget is either
|
||||||
// available or not available. We do not need to track
|
// available or not available. We do not need to track
|
||||||
// any future restore updates.
|
// any future restore updates.
|
||||||
int status = restoreStatus &
|
int status = c.restoreFlag &
|
||||||
~LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
|
~LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
|
||||||
if (!wasProviderReady) {
|
if (!wasProviderReady) {
|
||||||
// If provider was not previously ready, update the
|
// If provider was not previously ready, update the
|
||||||
|
@ -1480,13 +1464,13 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
} else {
|
} else {
|
||||||
Log.v(TAG, "Widget restore pending id=" + c.id
|
Log.v(TAG, "Widget restore pending id=" + c.id
|
||||||
+ " appWidgetId=" + appWidgetId
|
+ " appWidgetId=" + appWidgetId
|
||||||
+ " status =" + restoreStatus);
|
+ " status =" + c.restoreFlag);
|
||||||
appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId,
|
appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId,
|
||||||
component);
|
component);
|
||||||
appWidgetInfo.restoreStatus = restoreStatus;
|
appWidgetInfo.restoreStatus = c.restoreFlag;
|
||||||
Integer installProgress = installingPkgs.get(component.getPackageName());
|
Integer installProgress = installingPkgs.get(component.getPackageName());
|
||||||
|
|
||||||
if ((restoreStatus & LauncherAppWidgetInfo.FLAG_RESTORE_STARTED) != 0) {
|
if (c.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_RESTORE_STARTED)) {
|
||||||
// Restore has started once.
|
// Restore has started once.
|
||||||
} else if (installProgress != null) {
|
} else if (installProgress != null) {
|
||||||
// App restore has started. Update the flag
|
// App restore has started. Update the flag
|
||||||
|
@ -1524,7 +1508,7 @@ public class LauncherModel extends BroadcastReceiver
|
||||||
String providerName =
|
String providerName =
|
||||||
appWidgetInfo.providerName.flattenToString();
|
appWidgetInfo.providerName.flattenToString();
|
||||||
if (!providerName.equals(savedProvider) ||
|
if (!providerName.equals(savedProvider) ||
|
||||||
(appWidgetInfo.restoreStatus != restoreStatus)) {
|
(appWidgetInfo.restoreStatus != c.restoreFlag)) {
|
||||||
c.updater()
|
c.updater()
|
||||||
.put(LauncherSettings.Favorites.APPWIDGET_PROVIDER,
|
.put(LauncherSettings.Favorites.APPWIDGET_PROVIDER,
|
||||||
providerName)
|
providerName)
|
||||||
|
|
|
@ -83,6 +83,7 @@ public class LoaderCursor extends CursorWrapper {
|
||||||
private final int cellXIndex;
|
private final int cellXIndex;
|
||||||
private final int cellYIndex;
|
private final int cellYIndex;
|
||||||
private final int profileIdIndex;
|
private final int profileIdIndex;
|
||||||
|
private final int restoredIndex;
|
||||||
|
|
||||||
// Properties loaded per iteration
|
// Properties loaded per iteration
|
||||||
public long serialNumber;
|
public long serialNumber;
|
||||||
|
@ -90,6 +91,7 @@ public class LoaderCursor extends CursorWrapper {
|
||||||
public long id;
|
public long id;
|
||||||
public long container;
|
public long container;
|
||||||
public int itemType;
|
public int itemType;
|
||||||
|
public int restoreFlag;
|
||||||
|
|
||||||
public LoaderCursor(Cursor c, LauncherAppState app) {
|
public LoaderCursor(Cursor c, LauncherAppState app) {
|
||||||
super(c);
|
super(c);
|
||||||
|
@ -111,6 +113,7 @@ public class LoaderCursor extends CursorWrapper {
|
||||||
cellXIndex = getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
|
cellXIndex = getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
|
||||||
cellYIndex = getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
|
cellYIndex = getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
|
||||||
profileIdIndex = getColumnIndexOrThrow(LauncherSettings.Favorites.PROFILE_ID);
|
profileIdIndex = getColumnIndexOrThrow(LauncherSettings.Favorites.PROFILE_ID);
|
||||||
|
restoredIndex = getColumnIndexOrThrow(LauncherSettings.Favorites.RESTORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,6 +126,7 @@ public class LoaderCursor extends CursorWrapper {
|
||||||
id = getLong(idIndex);
|
id = getLong(idIndex);
|
||||||
serialNumber = getInt(profileIdIndex);
|
serialNumber = getInt(profileIdIndex);
|
||||||
user = allUsers.get(serialNumber);
|
user = allUsers.get(serialNumber);
|
||||||
|
restoreFlag = getInt(restoredIndex);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -185,7 +189,7 @@ public class LoaderCursor extends CursorWrapper {
|
||||||
* Make an ShortcutInfo object for a restored application or shortcut item that points
|
* Make an ShortcutInfo object for a restored application or shortcut item that points
|
||||||
* to a package that is not yet installed on the system.
|
* to a package that is not yet installed on the system.
|
||||||
*/
|
*/
|
||||||
public ShortcutInfo getRestoredItemInfo(Intent intent, int promiseType) {
|
public ShortcutInfo getRestoredItemInfo(Intent intent) {
|
||||||
final ShortcutInfo info = new ShortcutInfo();
|
final ShortcutInfo info = new ShortcutInfo();
|
||||||
info.user = user;
|
info.user = user;
|
||||||
info.intent = intent;
|
info.intent = intent;
|
||||||
|
@ -196,22 +200,22 @@ public class LoaderCursor extends CursorWrapper {
|
||||||
mIconCache.getTitleAndIcon(info, false /* useLowResIcon */);
|
mIconCache.getTitleAndIcon(info, false /* useLowResIcon */);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((promiseType & ShortcutInfo.FLAG_RESTORED_ICON) != 0) {
|
if (hasRestoreFlag(ShortcutInfo.FLAG_RESTORED_ICON)) {
|
||||||
String title = getTitle();
|
String title = getTitle();
|
||||||
if (!TextUtils.isEmpty(title)) {
|
if (!TextUtils.isEmpty(title)) {
|
||||||
info.title = Utilities.trim(title);
|
info.title = Utilities.trim(title);
|
||||||
}
|
}
|
||||||
} else if ((promiseType & ShortcutInfo.FLAG_AUTOINTALL_ICON) != 0) {
|
} else if (hasRestoreFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
|
||||||
if (TextUtils.isEmpty(info.title)) {
|
if (TextUtils.isEmpty(info.title)) {
|
||||||
info.title = getTitle();
|
info.title = getTitle();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidParameterException("Invalid restoreType " + promiseType);
|
throw new InvalidParameterException("Invalid restoreType " + restoreFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
|
info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
|
||||||
info.itemType = itemType;
|
info.itemType = itemType;
|
||||||
info.status = promiseType;
|
info.status = restoreFlag;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +309,14 @@ public class LoaderCursor extends CursorWrapper {
|
||||||
* Marks the current item as restored
|
* Marks the current item as restored
|
||||||
*/
|
*/
|
||||||
public void markRestored() {
|
public void markRestored() {
|
||||||
restoredRows.add(id);
|
if (restoreFlag != 0) {
|
||||||
|
restoredRows.add(id);
|
||||||
|
restoreFlag = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRestoreFlag(int flagMask) {
|
||||||
|
return (restoreFlag & flagMask) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void commitRestoredItems() {
|
public void commitRestoredItems() {
|
||||||
|
|
|
@ -37,6 +37,7 @@ import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE;
|
||||||
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
|
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
|
||||||
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
|
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
|
||||||
import static com.android.launcher3.LauncherSettings.Favorites.PROFILE_ID;
|
import static com.android.launcher3.LauncherSettings.Favorites.PROFILE_ID;
|
||||||
|
import static com.android.launcher3.LauncherSettings.Favorites.RESTORED;
|
||||||
import static com.android.launcher3.LauncherSettings.Favorites.SCREEN;
|
import static com.android.launcher3.LauncherSettings.Favorites.SCREEN;
|
||||||
import static com.android.launcher3.LauncherSettings.Favorites.TITLE;
|
import static com.android.launcher3.LauncherSettings.Favorites.TITLE;
|
||||||
import static com.android.launcher3.LauncherSettings.Favorites._ID;
|
import static com.android.launcher3.LauncherSettings.Favorites._ID;
|
||||||
|
@ -72,7 +73,7 @@ public class LoaderCursorTest {
|
||||||
mCursor = new MatrixCursor(new String[] {
|
mCursor = new MatrixCursor(new String[] {
|
||||||
ICON, ICON_PACKAGE, ICON_RESOURCE, TITLE,
|
ICON, ICON_PACKAGE, ICON_RESOURCE, TITLE,
|
||||||
_ID, CONTAINER, ITEM_TYPE, PROFILE_ID,
|
_ID, CONTAINER, ITEM_TYPE, PROFILE_ID,
|
||||||
SCREEN, CELLX, CELLY,
|
SCREEN, CELLX, CELLY, RESTORED
|
||||||
});
|
});
|
||||||
mContext = InstrumentationRegistry.getTargetContext();
|
mContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue