hook database restore with restore session

1. Create feature flag for new backup & restore flow.
2. For each restore session (install reason is restore),
   if its creation time is newer than the one we have in
   SharedPreference, we update the entry and restores
   favorite table from backup.
3. The restore operation is debounced so that when
   multiple restore session is created within a small
   amount of time, only the last invocation will get
   executed.

Bug: 141472083
Change-Id: I7b5b63ec28741ba2b02ccfd13f591c961362ba36
Test:
1. apply on master, build & flash on physical device.
2. factory reset the device.
3. go through SuW, perform restore, exit without
   adding work profile.
4. settings -> account -> add work profile account.
5. finish work profile setup, verify work profiles
   is restored as well.
This commit is contained in:
Pinyao Ting
2019-12-10 14:56:34 -08:00
parent 9be1cfde79
commit ad5f24072c
6 changed files with 65 additions and 2 deletions

View File

@@ -29,6 +29,10 @@ import android.os.Process;
import android.os.UserHandle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.SessionCommitReceiver;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
@@ -52,6 +56,8 @@ 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;
@@ -159,6 +165,34 @@ public class InstallSessionHelper {
return list;
}
/**
* Attempt to restore workspace layout if the session is triggered due to device restore and it
* has a newer timestamp.
*/
public boolean restoreDbIfApplicable(@NonNull final SessionInfo info) {
if (!Utilities.ATLEAST_OREO || !FeatureFlags.ENABLE_DATABASE_RESTORE.get()) {
return false;
}
if (isRestore(info) && hasNewerTimestamp(mAppContext, info)) {
LauncherSettings.Settings.call(mAppContext.getContentResolver(),
LauncherSettings.Settings.METHOD_RESTORE_BACKUP_TABLE);
return true;
}
return false;
}
@RequiresApi(26)
private static boolean isRestore(@NonNull final SessionInfo info) {
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);
}