本文整理汇总了Java中android.app.backup.BackupDataInput类的典型用法代码示例。如果您正苦于以下问题:Java BackupDataInput类的具体用法?Java BackupDataInput怎么用?Java BackupDataInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BackupDataInput类属于android.app.backup包,在下文中一共展示了BackupDataInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performIncrementalBackup
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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;
}
}
示例2: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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");
}
示例3: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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();
}
}
示例4: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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, "----- ----- ----- ----- ----- ----- ----- ----- ----- ");
}
}
示例5: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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);
}
示例6: transferIncrementalBackupData
import android.app.backup.BackupDataInput; //导入依赖的package包/类
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;
}
示例7: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
/**
* 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);
}
}
示例8: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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();
}
示例9: restorePreferences
import android.app.backup.BackupDataInput; //导入依赖的package包/类
/**
* 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);
}
示例10: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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);
}
}
示例11: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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());
}
}
示例12: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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();
}
示例13: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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);
}
}
示例14: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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();
}
}
示例15: onRestore
import android.app.backup.BackupDataInput; //导入依赖的package包/类
@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);
}