@Override public int performIncrementalBackup(PackageInfo packageInfo, ParcelFileDescriptor data) { BackupDataInput backupDataInput = new BackupDataInput(data.getFileDescriptor()); try { initializeBackupState(); backupState.setPackageIndex(backupState.getPackageIndex() + 1); backupState.setPackageName(packageInfo.packageName); return transferIncrementalBackupData(backupDataInput); } catch (Exception ex) { Log.e(TAG, "Error reading backup input: ", ex); return TRANSPORT_ERROR; } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { Log.i(TAG, "Restoring from backup"); while (data.readNextHeader()) { String key = data.getKey(); Log.d(TAG, "Restoring entity " + key); if (key.equals(PREFERENCES_ENTITY)) { restorePreferences(data); } else { Log.e(TAG, "Found unknown backup entity: " + key); data.skipEntityData(); } } Log.i(TAG, "Done restoring from backup"); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { Analytics.event(EventType.BACKUP_RESTORE, "onRestore -> current", appVersionCode + "/" + BuildConfig.VERSION_CODE); lock.lock(); try { Timber.d("onRestore in-lock"); super.onRestore(data, appVersionCode, newState); if (appVersionCode < 22) { // migrate db to db.ver=3 Database.restart(this.getApplicationContext()); } } finally { lock.unlock(); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { synchronized (GeoPingBackupAgent.sDataLock) { Log.i(TAG, "----- ----- ----- ----- ----- ----- ----- ----- ----- "); Log.i(TAG, "----- ----- ----- ----- ----- ----- ----- ----- ----- "); Log.i(TAG, "----- onRestore GeoPing Backup : Version = " + appVersionCode); Log.i(TAG, "----- onRestore GeoPing Backup --- Begin"); super.onRestore(data, appVersionCode, newState); // Apply Prefs Config try { applyPrefsConfig(); } catch (Throwable e) { Log.e(TAG, "Error Prefs Config Apply to Service : " + e.getMessage(), e); } Log.i(TAG, "----- onRestore GeoPing End --- End"); Log.i(TAG, "----- ----- ----- ----- ----- ----- ----- ----- ----- "); Log.i(TAG, "----- ----- ----- ----- ----- ----- ----- ----- ----- "); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { Log.d(THIS_FILE, "App version code : " + appVersionCode); super.onRestore(data, appVersionCode, newState); }
private int transferIncrementalBackupData(BackupDataInput backupDataInput) throws IOException, InvalidAlgorithmParameterException, InvalidKeyException { ZipOutputStream outputStream = backupState.getOutputStream(); int bufferSize = INITIAL_BUFFER_SIZE; byte[] buffer = new byte[bufferSize]; while (backupDataInput.readNextHeader()) { String chunkFileName = Base64.encodeToString(backupDataInput.getKey().getBytes(), Base64.DEFAULT); int dataSize = backupDataInput.getDataSize(); if (dataSize >= 0) { ZipEntry zipEntry = new ZipEntry(configuration.getIncrementalBackupDirectory() + backupState.getPackageName() + "/" + chunkFileName); outputStream.putNextEntry(zipEntry); if (dataSize > bufferSize) { bufferSize = dataSize; buffer = new byte[bufferSize]; } backupDataInput.readEntityData(buffer, 0, dataSize); try { outputStream.write(buffer, 0, dataSize); } catch (Exception ex) { Log.e(TAG, "Error performing incremental backup for " + backupState.getPackageName() + ": ", ex); clearBackupState(true); return TRANSPORT_ERROR; } } } return TRANSPORT_OK; }
/** * Adding locking around the file rewrite that happens during restore is * similarly straightforward. */ @Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { // Hold the lock while the FileBackupHelper restores the file from // the data provided here. synchronized (BackupRestoreActivity.sDataLock) { super.onRestore(data, appVersionCode, newState); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { // Let the restore operation go through super.onRestore(data, appVersionCode, newState); // Remove the preferences that we don't want restored. final SharedPreferences.Editor prefEditor = getSharedPreferences( getPackageName() + PREF_SUFFIX, MODE_PRIVATE).edit(); for (final String key : LocalSettingsConstants.PREFS_TO_SKIP_RESTORING) { prefEditor.remove(key); } // Flush the changes to disk. prefEditor.commit(); }
/** * Restores all preferences from the backup. * * @param data the backup data to read from * @throws IOException if there are any errors while reading */ private void restorePreferences(BackupDataInput data) throws IOException { int dataSize = data.getDataSize(); byte[] dataBuffer = new byte[dataSize]; int read = data.readEntityData(dataBuffer, 0, dataSize); if (read != dataSize) { throw new IOException("Failed to read all the preferences data"); } SharedPreferences preferences = this.getSharedPreferences( Constants.SETTINGS_NAME, Context.MODE_PRIVATE); PreferenceBackupHelper importer = createPreferenceBackupHelper(); importer.importPreferences(dataBuffer, preferences); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { Log.d("ConnectBot.BackupAgent", "onRestore called"); synchronized (HostDatabase.dbLock) { Log.d("ConnectBot.BackupAgent", "onRestore in-lock"); super.onRestore(data, appVersionCode, newState); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { Log.d(LOG_TAG, "onRestore called"); synchronized (DbHelper.dbLock) { Log.d(LOG_TAG, "onRestore in-lock"); super.onRestore(data, appVersionCode, newState); ContactsUtils.restoreRawContacts(this.getApplicationContext()); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { super.onRestore(data, appVersionCode, newState); SharedPreferences.Editor editor = Util.getPreferences(this).edit(); editor.remove(Constants.PREFERENCES_KEY_CACHE_LOCATION); editor.remove(Constants.CACHE_AUDIO_SESSION_ID); editor.apply(); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { Log.v(TAG, "onRestore called"); // Hold the lock while the FileBackupHelper restores the file synchronized (StreamDatabase.dbLock) { super.onRestore(data, appVersionCode, newState); } }
@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_NO_NOTIFICATION, 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); } else { if (VERBOSE) Log.v(TAG, "Nothing was restored, clearing DB"); LauncherAppState.getLauncherProvider().createEmptyDB(); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { // Hold the lock while the BackupHelper restores synchronized (SafeSlinger.sDataLock) { super.onRestore(data, appVersionCode, newState); } // store restoration time and cancel pending notifications... SafeSlingerPrefs.setRestoreCompleteDate(new Date().getTime()); String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) getSystemService(ns); nm.cancel(HomeActivity.NOTIFY_BACKUP_DELAY_ID); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { Log.d(LOG_TAG, "on restore"); Log.d(LOG_TAG, data.toString()); super.onRestore(data, appVersionCode, newState); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { Log.i(TAG, "Restore from backup started"); super.onRestore(data, appVersionCode, newState); PreferencesUtils.patchAfterRestore(this); Log.i(TAG, "Restore from backup finished"); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { // Hold the lock while the FileBackupHelper restores the file synchronized (UserData.sFileBackupLock) { super.onRestore(data, appVersionCode, newState); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { // Hold the lock while the FileBackupHelper restores the file synchronized (DBHelper.sDataLock) { super.onRestore(data, appVersionCode, newState); } }
@Override public void onRestore( BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) { // Doesn't do incremental backup/restore }
/** * On restore, we pull the various bits of data out of the restore stream, * then reconstruct the application's data file inside the shared lock. A * restore data set will always be the full set of records supplied by the * application's backup operations. */ @Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { // Consume the restore data set, remembering each bit of application state // that we see along the way while (data.readNextHeader()) { String key = data.getKey(); int dataSize = data.getDataSize(); // In this implementation, we trust that we won't see any record keys // that we don't understand. Since we expect to handle them all, we // go ahead and extract the data for each record before deciding how // it will be handled. byte[] dataBuf = new byte[dataSize]; data.readEntityData(dataBuf, 0, dataSize); ByteArrayInputStream instream = new ByteArrayInputStream(dataBuf); DataInputStream in = new DataInputStream(instream); if (FILLING_KEY.equals(key)) { mFilling = in.readInt(); } else if (MAYO_KEY.equals(key)) { mAddMayo = in.readBoolean(); } else if (TOMATO_KEY.equals(key)) { mAddTomato = in.readBoolean(); } } // Now we're ready to write out a full new dataset for the application. Note that // the restore process is intended to *replace* any existing or default data, so // we can just go ahead and overwrite it all. synchronized (BackupRestoreActivity.sDataLock) { RandomAccessFile file = new RandomAccessFile(mDataFile, "rw"); file.setLength(0L); file.writeInt(mFilling); file.writeBoolean(mAddMayo); file.writeBoolean(mAddTomato); } // Finally, write the state file that describes our data as of this restore pass. writeStateFile(newState); }
/** * This application does not do any "live" restores of its own data, * so the only time a restore will happen is when the application is * installed. This means that the activity itself is not going to * be running while we change its data out from under it. That, in * turn, means that there is no need to send out any sort of notification * of the new data: we only need to read the data from the stream * provided here, build the application's new data file, and then * write our new backup state blob that will be consulted at the next * backup operation. * * <p>We don't bother checking the versionCode of the app who originated * the data because we have never revised the backup data format. If * we had, the 'appVersionCode' parameter would tell us how we should * interpret the data we're about to read. */ @Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { // We should only see one entity in the data stream, but the safest // way to consume it is using a while() loop while (data.readNextHeader()) { String key = data.getKey(); int dataSize = data.getDataSize(); if (APP_DATA_KEY.equals(key)) { // It's our saved data, a flattened chunk of data all in // one buffer. Use some handy structured I/O classes to // extract it. byte[] dataBuf = new byte[dataSize]; data.readEntityData(dataBuf, 0, dataSize); ByteArrayInputStream baStream = new ByteArrayInputStream(dataBuf); DataInputStream in = new DataInputStream(baStream); mFilling = in.readInt(); mAddMayo = in.readBoolean(); mAddTomato = in.readBoolean(); // Now we are ready to construct the app's data file based // on the data we are restoring from. synchronized (BackupRestoreActivity.sDataLock) { RandomAccessFile file = new RandomAccessFile(mDataFile, "rw"); file.setLength(0L); file.writeInt(mFilling); file.writeBoolean(mAddMayo); file.writeBoolean(mAddTomato); } } else { // Curious! This entity is data under a key we do not // understand how to process. Just skip it. data.skipEntityData(); } } // The last thing to do is write the state blob that describes the // app's data as restored from backup. writeStateFile(newState); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { super.onRestore(data, appVersionCode, newState); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { synchronized (DbHelper.sLock) { super.onRestore(data, appVersionCode, newState); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { if (!Utilities.ATLEAST_LOLLIPOP) { // 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); // Rank was added in v4. if (mHelper.restoredBackupVersion <= 3) { LauncherAppState.getLauncherProvider().updateFolderItemsRank(); } if (MigrateFromRestoreTask.ENABLED && mHelper.shouldAttemptWorkspaceMigration()) { MigrateFromRestoreTask.markForMigration(getApplicationContext(), (int) mHelper.migrationCompatibleProfileData.desktopCols, (int) mHelper.migrationCompatibleProfileData.desktopRows, mHelper.widgetSizes); } LauncherAppState.getLauncherProvider().convertShortcutsToLauncherActivities(); } else { if (VERBOSE) Log.v(TAG, "Nothing was restored, clearing DB"); LauncherAppState.getLauncherProvider().createEmptyDB(); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException{ super.onRestore(data, appVersionCode, newState); Util.getPreferences(this).edit().remove(Constants.PREFERENCES_KEY_CACHE_LOCATION).apply(); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { if (!Utilities.ATLEAST_LOLLIPOP) { // 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.markFirstRunClingDismissed(this); // Rank was added in v4. if (mHelper.restoredBackupVersion <= 3) { LauncherAppState.getLauncherProvider().updateFolderItemsRank(); } if (GridSizeMigrationTask.ENABLED && mHelper.shouldAttemptWorkspaceMigration()) { GridSizeMigrationTask.markForMigration(getApplicationContext(), mHelper.widgetSizes, mHelper.migrationCompatibleProfileData); } LauncherAppState.getLauncherProvider().convertShortcutsToLauncherActivities(); } else { if (VERBOSE) Log.v(TAG, "Nothing was restored, clearing DB"); LauncherAppState.getLauncherProvider().createEmptyDB(); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { super.onRestore(data, appVersionCode, newState); Log.i(Constants.LOG_TAG, "REstoring " + data + " " + appVersionCode); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { // TODO Auto-generated method stub super.onRestore(data, appVersionCode, newState); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { if (isAvailable) { instance.onRestore(data, appVersionCode, newState); } }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { super.onRestore(data, appVersionCode, newState); Timber.d(String.format("Restoring from backup (was saved using version %d)", appVersionCode)); App.getInstance().getTracker().sendEvent("backup","restore","",(long)0); }
@Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { if (LOCAL_LOGV) Log.v(TAG, "onRestore()"); super.onRestore(data, appVersionCode, newState); }