Esempio n. 1
0
 @Override
 public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
     throws IOException {
   super.onRestore(data, appVersionCode, newState);
   copyPrefs(RESTORE_PREFS, CacheVar.DEFAULT_PREFS);
   CacheVar.reinit();
 }
  @Override
  public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
      throws IOException {
    if (!Utilities.isLmpOrAbove()) {
      // No restore for old devices.
      Log.i(TAG, "You shall not pass!!!");
      Log.d(TAG, "Restore is only supported on devices running Lollipop and above.");
      return;
    }

    // Clear dB before restore
    LauncherAppState.getLauncherProvider().createEmptyDB();

    boolean hasData;
    try {
      super.onRestore(data, appVersionCode, newState);
      // If no favorite was migrated, clear the data and start fresh.
      final Cursor c =
          getContentResolver()
              .query(LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
      hasData = c.moveToNext();
      c.close();
    } catch (Exception e) {
      // If the restore fails, we should do a fresh start.
      Log.e(TAG, "Restore failed", e);
      hasData = false;
    }

    if (hasData && mHelper.restoreSuccessful) {
      LauncherAppState.getLauncherProvider().clearFlagEmptyDbCreated();
      LauncherClings.synchonouslyMarkFirstRunClingDismissed(this);

      // TODO: Update the backup set to include rank.
      if (mHelper.restoredBackupVersion <= 3) {
        LauncherAppState.getLauncherProvider().updateFolderItemsRank();
        LauncherAppState.getLauncherProvider().convertShortcutsToLauncherActivities();
      }
    } else {
      if (VERBOSE) Log.v(TAG, "Nothing was restored, clearing DB");
      LauncherAppState.getLauncherProvider().createEmptyDB();
    }
  }