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