本文整理汇总了Java中android.app.backup.BackupDataOutput类的典型用法代码示例。如果您正苦于以下问题:Java BackupDataOutput类的具体用法?Java BackupDataOutput怎么用?Java BackupDataOutput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BackupDataOutput类属于android.app.backup包,在下文中一共展示了BackupDataOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: backupScreens
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
/**
* Write all modified screens to the data stream.
*
* @param data output stream for key/value pairs
* @throws IOException
*/
private void backupScreens(BackupDataOutput data) throws IOException {
// persist things that have changed since the last backup
ContentResolver cr = mContext.getContentResolver();
Cursor cursor = cr.query(WorkspaceScreens.CONTENT_URI, SCREEN_PROJECTION,
null, null, null);
try {
cursor.moveToPosition(-1);
if (DEBUG) Log.d(TAG, "dumping screens after: " + mLastBackupRestoreTime);
while(cursor.moveToNext()) {
final long id = cursor.getLong(ID_INDEX);
final long updateTime = cursor.getLong(ID_MODIFIED);
Key key = getKey(Key.SCREEN, id);
mKeys.add(key);
final String backupKey = keyToBackupKey(key);
if (!mExistingKeys.contains(backupKey) || updateTime >= mLastBackupRestoreTime) {
writeRowToBackup(key, packScreen(cursor), data);
} else {
if (VERBOSE) Log.v(TAG, "screen already backup up " + id);
}
}
} finally {
cursor.close();
}
}
示例2: onBackup
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
public void onBackup(ParcelFileDescriptor paramParcelFileDescriptor1, BackupDataOutput paramBackupDataOutput, ParcelFileDescriptor paramParcelFileDescriptor2)
throws IOException
{
ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream localDataOutputStream = new DataOutputStream(localByteArrayOutputStream);
long l = ((Long)DfeApiConfig.androidId.get()).longValue();
Object[] arrayOfObject = new Object[1];
arrayOfObject[0] = FinskyLog.scrubPii(Long.toHexString(l));
FinskyLog.d("Backing up aid: %s", arrayOfObject);
localDataOutputStream.writeLong(l);
flushBufferData(paramBackupDataOutput, localByteArrayOutputStream, "vending");
writeData(paramBackupDataOutput, localByteArrayOutputStream, localDataOutputStream, "auto_update_enabled", ((Boolean)FinskyPreferences.autoUpdateEnabled.get()).booleanValue());
writeData(paramBackupDataOutput, localByteArrayOutputStream, localDataOutputStream, "update_over_wifi_only", ((Boolean)FinskyPreferences.autoUpdateWifiOnly.get()).booleanValue());
writeData(paramBackupDataOutput, localByteArrayOutputStream, localDataOutputStream, "auto_add_shortcuts", ((Boolean)VendingPreferences.AUTO_ADD_SHORTCUTS.get()).booleanValue());
writeData(paramBackupDataOutput, localByteArrayOutputStream, localDataOutputStream, "notify_updates", ((Boolean)VendingPreferences.NOTIFY_UPDATES.get()).booleanValue());
writeData(paramBackupDataOutput, localByteArrayOutputStream, localDataOutputStream, "notify_updates_completion", ((Boolean)VendingPreferences.NOTIFY_UPDATES_COMPLETION.get()).booleanValue());
localDataOutputStream.writeInt(((Integer)FinskyPreferences.contentFilterLevel.get()).intValue());
flushBufferData(paramBackupDataOutput, localByteArrayOutputStream, "content-filter-level");
VendingPreferences.BACKED_UP.put(Boolean.valueOf(true));
}
示例3: writeRowToBackup
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
private void writeRowToBackup(Key key, byte[] blob, Journal out,
BackupDataOutput data) throws IOException {
String backupKey = keyToBackupKey(key);
data.writeEntityHeader(backupKey, blob.length);
data.writeEntityData(blob, blob.length);
out.rows++;
out.bytes += blob.length;
if (VERBOSE) Log.v(TAG, "saving " + geKeyType(key) + " " + backupKey + ": " +
getKeyName(key) + "/" + blob.length);
if(DEBUG_PAYLOAD) {
String encoded = Base64.encodeToString(blob, 0, blob.length, Base64.NO_WRAP);
final int chunkSize = 1024;
for (int offset = 0; offset < encoded.length(); offset += chunkSize) {
int end = offset + chunkSize;
end = Math.min(end, encoded.length());
Log.w(TAG, "wrote " + encoded.substring(offset, end));
}
}
}
示例4: backupFavorites
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
/**
* Write all modified favorites to the data stream.
*
* @param data output stream for key/value pairs
* @throws IOException
*/
private void backupFavorites(BackupDataOutput data) throws IOException {
// persist things that have changed since the last backup
ContentResolver cr = mContext.getContentResolver();
// Don't backup apps in other profiles for now.
Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION,
getUserSelectionArg(), null, null);
try {
cursor.moveToPosition(-1);
while(cursor.moveToNext()) {
final long id = cursor.getLong(ID_INDEX);
final long updateTime = cursor.getLong(ID_MODIFIED);
Key key = getKey(Key.FAVORITE, id);
mKeys.add(key);
final String backupKey = keyToBackupKey(key);
if (!mExistingKeys.contains(backupKey) || updateTime >= mLastBackupRestoreTime) {
writeRowToBackup(key, packFavorite(cursor), data);
} else {
if (DEBUG) Log.d(TAG, "favorite already backup up: " + id);
}
}
} finally {
cursor.close();
}
}
示例5: onCreate
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
@Override
public void onCreate() {
// The name of the SharedPreferences file
final String prefs = getPackageName() + "_preferences"; // getPackageName() cannot be used in final
SharedPreferencesBackupHelper prefsHelper = new SharedPreferencesBackupHelper(this, prefs) {
@Override
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) {
if (new WorkTimeTrackerBackupManager(WorkTimeTrackerBackupAgentHelper.this).isEnabled()) {
super.performBackup(oldState, data, newState);
}
}
};
addHelper(PREFS_BACKUP_KEY, prefsHelper);
DbBackupHelper dbHelper = new DbBackupHelper(this);
addHelper(DB_BACKUP_KEY, dbHelper);
}
示例6: backupCursor
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
private void backupCursor(BackupDataOutput data,
ContentResolver contentResolver, Cursor cursor) {
StringBuilder backedUp = new StringBuilder();
int idColumn = cursor.getColumnIndex(ID_COLUMN);
while (cursor.moveToNext()) {
int id = cursor.getInt(idColumn);
byte[] serialized = mAdaptor.Serialize(cursor);
try {
data.writeEntityHeader("row_" + id, serialized.length);
data.writeEntityData(serialized, serialized.length);
if (backedUp.length() != 0) backedUp.append(',');
backedUp.append(id);
} catch (IOException e) {
Log.e("AltidroidBackup", "cannot backup: " + id);
e.printStackTrace();
}
}
// Mark all entries that were just backed up as such
if (backedUp.length() > 0) {
ContentValues values = new ContentValues();
values.put("backed_up", true);
contentResolver.update(mUri, values, "_id IN (" + backedUp.toString() + ")", null);
}
}
示例7: writeData
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
private void writeData(BackupDataOutput data, String value) throws IOException {
// Create buffer stream and data output stream for our data
ByteArrayOutputStream bufStream = new ByteArrayOutputStream();
DataOutputStream outWriter = new DataOutputStream(bufStream);
// Write structured data
outWriter.writeUTF(value);
// Send the data to the Backup Manager via the BackupDataOutput
byte[] buffer = bufStream.toByteArray();
int len = buffer.length;
data.writeEntityHeader(ACCOUNTS_BACKUP_KEY, len);
data.writeEntityData(buffer, len);
}
示例8: writeData
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
private void writeData(BackupDataOutput data, String value) throws IOException {
// Create buffer stream and data output stream for our data
ByteArrayOutputStream bufStream = new ByteArrayOutputStream();
DataOutputStream outWriter = new DataOutputStream(bufStream);
// Write structured data
outWriter.writeUTF(value);
// Send the data to the Backup Manager via the BackupDataOutput
byte[] buffer = bufStream.toByteArray();
int len = buffer.length;
data.writeEntityHeader(SETTINGS_BACKUP_KEY, len);
data.writeEntityData(buffer, len);
}
示例9: transferIncrementalRestoreData
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
private int transferIncrementalRestoreData(String packageName, ParcelFileDescriptor outputFileDescriptor)
throws IOException, InvalidAlgorithmParameterException, InvalidKeyException {
ParcelFileDescriptor inputFileDescriptor = buildInputFileDescriptor();
ZipInputStream inputStream = buildInputStream(inputFileDescriptor);
BackupDataOutput backupDataOutput = new BackupDataOutput(outputFileDescriptor.getFileDescriptor());
Optional<ZipEntry> zipEntryOptional = seekToEntry(inputStream,
configuration.getIncrementalBackupDirectory() + packageName);
while (zipEntryOptional.isPresent()) {
String fileName = new File(zipEntryOptional.get().getName()).getName();
String blobKey = new String(Base64.decode(fileName, Base64.DEFAULT));
byte[] backupData = Streams.readFullyNoClose(inputStream);
backupDataOutput.writeEntityHeader(blobKey, backupData.length);
backupDataOutput.writeEntityData(backupData, backupData.length);
inputStream.closeEntry();
zipEntryOptional = seekToEntry(inputStream, configuration.getIncrementalBackupDirectory() + packageName);
}
IoUtils.closeQuietly(inputFileDescriptor);
IoUtils.closeQuietly(outputFileDescriptor);
return TRANSPORT_OK;
}
示例10: onBackup
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
/**
* We want to ensure that the UI is not trying to rewrite the data file
* while we're reading it for backup, so we override this method to
* supply the necessary locking.
*/
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
// Hold the lock while the FileBackupHelper performs the backup operation
synchronized (BackupRestoreActivity.sDataLock) {
super.onBackup(oldState, data, newState);
}
}
示例11: backupFavorites
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
/**
* Write all modified favorites to the data stream.
*
* @param data output stream for key/value pairs
* @throws IOException
*/
private void backupFavorites(BackupDataOutput data) throws IOException {
// persist things that have changed since the last backup
ContentResolver cr = mContext.getContentResolver();
// Don't backup apps in other profiles for now.
Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION,
getUserSelectionArg(), null, null);
try {
cursor.moveToPosition(-1);
while(cursor.moveToNext()) {
final long id = cursor.getLong(ID_INDEX);
final long updateTime = cursor.getLong(ID_MODIFIED);
Key key = getKey(Key.FAVORITE, id);
mKeys.add(key);
final String backupKey = keyToBackupKey(key);
// Favorite proto changed in v4. Backup again if the version is old.
if (!mExistingKeys.contains(backupKey) || updateTime >= mLastBackupRestoreTime
|| restoredBackupVersion < 4) {
writeRowToBackup(key, packFavorite(cursor), data);
} else {
if (DEBUG) Log.d(TAG, "favorite already backup up: " + id);
}
}
} finally {
cursor.close();
}
}
示例12: writeRowToBackup
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
private void writeRowToBackup(String backupKey, MessageNano proto,
BackupDataOutput data) throws IOException {
byte[] blob = writeCheckedBytes(proto);
data.writeEntityHeader(backupKey, blob.length);
data.writeEntityData(blob, blob.length);
mBackupDataWasUpdated = true;
if (VERBOSE) Log.v(TAG, "Writing New entry " + backupKey);
}
示例13: onBackup
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
synchronized(FlavordexProvider.class) {
super.onBackup(oldState, data, newState);
}
}
示例14: onBackup
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
Log.i(TAG, "Performing backup");
SharedPreferences preferences = this.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
backupPreferences(data, preferences);
Log.i(TAG, "Backup complete");
}
示例15: backupPreferences
import android.app.backup.BackupDataOutput; //导入依赖的package包/类
private void backupPreferences(BackupDataOutput data,
SharedPreferences preferences) throws IOException {
PreferenceBackupHelper preferenceDumper = createPreferenceBackupHelper();
byte[] dumpedContents = preferenceDumper.exportPreferences(preferences);
data.writeEntityHeader(PREFERENCES_ENTITY, dumpedContents.length);
data.writeEntityData(dumpedContents, dumpedContents.length);
}