Mitigate 10 minutes delay in launcher restore for work apps.

1. Instead of debouncing launcher restore when new install session
(triggered by Play Service due to restore) is created, it is now
throttled at once every 30 seconds. (i.e. Launcher restore is triggered
immediately, but cannot be triggered again within 30 seconds)
2. Removes the backup table when all items are restored. (i.e. no item
were removed as a result of sanitize db due to user didn't sign in to
their work profile)

Bug: 153648870
Change-Id: I32df371f8b47c60a72515876217fd83ac1e56f0a
Test: manually verified with deferred restore
This commit is contained in:
Pinyao Ting
2020-04-28 13:58:45 -07:00
parent a29a69943a
commit 0807c946b6
3 changed files with 22 additions and 29 deletions

View File

@@ -56,8 +56,6 @@ public class InstallSessionHelper {
// Set<String> of session ids of promise icons that have been added to the home screen
// as FLAG_PROMISE_NEW_INSTALLS.
protected static final String PROMISE_ICON_IDS = "promise_icon_ids";
public static final String KEY_INSTALL_SESSION_CREATED_TIMESTAMP =
"key_install_session_created_timestamp";
private static final boolean DEBUG = false;
@@ -166,14 +164,13 @@ public class InstallSessionHelper {
}
/**
* Attempt to restore workspace layout if the session is triggered due to device restore and it
* has a newer timestamp.
* Attempt to restore workspace layout if the session is triggered due to device restore.
*/
public boolean restoreDbIfApplicable(@NonNull final SessionInfo info) {
if (!Utilities.ATLEAST_OREO || !FeatureFlags.ENABLE_DATABASE_RESTORE.get()) {
return false;
}
if (isRestore(info) && hasNewerTimestamp(mAppContext, info)) {
if (isRestore(info)) {
LauncherSettings.Settings.call(mAppContext.getContentResolver(),
LauncherSettings.Settings.METHOD_RESTORE_BACKUP_TABLE);
return true;
@@ -186,13 +183,6 @@ public class InstallSessionHelper {
return info.getInstallReason() == PackageManager.INSTALL_REASON_DEVICE_RESTORE;
}
private static boolean hasNewerTimestamp(
@NonNull final Context context, @NonNull final SessionInfo info) {
return PackageManagerHelper.getSessionCreatedTimeInMillis(info)
> Utilities.getDevicePrefs(context).getLong(
KEY_INSTALL_SESSION_CREATED_TIMESTAMP, 0);
}
public boolean promiseIconAddedForId(int sessionId) {
return mPromiseIconIds.contains(sessionId);
}