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.
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index b589560..b0ab35c 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -18,6 +18,7 @@
 
 import static com.android.launcher3.provider.LauncherDbUtils.dropTable;
 import static com.android.launcher3.provider.LauncherDbUtils.tableExists;
+import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
 
 import android.annotation.TargetApi;
 import android.app.backup.BackupManager;
@@ -45,6 +46,7 @@
 import android.os.Binder;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.Process;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -87,6 +89,8 @@
     private static final boolean LOGD = false;
 
     private static final String DOWNGRADE_SCHEMA_FILE = "downgrade_schema.json";
+    private static final String TOKEN_RESTORE_BACKUP_TABLE = "restore_backup_table";
+    private static final long RESTORE_BACKUP_TABLE_DELAY = 60000;
 
     /**
      * Represents the schema of the database. Changes in scheme need not be backwards compatible.
@@ -388,8 +392,11 @@
                 return null;
             }
             case LauncherSettings.Settings.METHOD_RESTORE_BACKUP_TABLE: {
-                RestoreDbTask.restoreIfPossible(
-                        getContext(), mOpenHelper, new BackupManager(getContext()));
+                final Handler handler = MODEL_EXECUTOR.getHandler();
+                handler.removeCallbacksAndMessages(TOKEN_RESTORE_BACKUP_TABLE);
+                handler.postDelayed(() -> RestoreDbTask.restoreIfPossible(
+                        getContext(), mOpenHelper, new BackupManager(getContext())),
+                        TOKEN_RESTORE_BACKUP_TABLE, RESTORE_BACKUP_TABLE_DELAY);
                 return null;
             }
         }