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

@@ -16,6 +16,7 @@
package com.android.launcher3.util;
import static android.content.pm.PackageInstaller.SessionInfo;
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
import android.app.AppOpsManager;
@@ -44,6 +45,8 @@ import android.util.Log;
import android.util.Pair;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.android.launcher3.AppInfo;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppWidgetInfo;
@@ -345,4 +348,15 @@ public class PackageManagerHelper {
}
return false;
}
/**
* Returns the created time in millis of given session info. Returns 0 if not available.
*/
public static long getSessionCreatedTimeInMillis(@NonNull final SessionInfo info) {
try {
return (long) SessionInfo.class.getDeclaredMethod("getCreatedMillis").invoke(info);
} catch (Exception e) {
return 0;
}
}
}