Java 类android.app.backup.BackupDataOutput 实例源码

项目:SimplOS    文件:LauncherBackupHelper.java   
/**
 * 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();
    }
}
项目:Trebuchet    文件:LauncherBackupHelper.java   
/**
 * 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();
    }
}
项目:FMTech    文件:VendingBackupAgent.java   
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));
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
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));
        }
    }
}
项目:FLauncher    文件:LauncherBackupHelper.java   
/**
 * 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();
    }
}
项目:LB-Launcher    文件:LauncherBackupHelper.java   
/**
 * 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();
    }
}
项目:LB-Launcher    文件:LauncherBackupHelper.java   
/**
 * 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();
    }
}
项目:trackworktime    文件:WorkTimeTrackerBackupAgentHelper.java   
@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);
}
项目:altidroid    文件:DatabaseBackupHelper.java   
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);
    }
}
项目:CSipSimple    文件:SipProfilesHelper.java   
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);
}
项目:CSipSimple    文件:SipSharedPreferencesHelper.java   
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);
}
项目:backup    文件:ContentProviderRestoreComponent.java   
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;
}
项目:buildAPKsSamples    文件:FileHelperExampleAgent.java   
/**
 * 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);
    }
}
项目:SimplOS    文件:LauncherBackupHelper.java   
/**
 * 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();
    }
}
项目:SimplOS    文件:LauncherBackupHelper.java   
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);
}
项目:flavordex    文件:FlavordexBackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
                     ParcelFileDescriptor newState) throws IOException {
    synchronized(FlavordexProvider.class) {
        super.onBackup(oldState, data, newState);
    }
}
项目:mytracks    文件:MyTracksBackupAgent.java   
@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");
}
项目:mytracks    文件:MyTracksBackupAgent.java   
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);
}
项目:connectbot    文件:BackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState) throws IOException {
    synchronized (HostDatabase.dbLock) {
        super.onBackup(oldState, data, newState);
    }
}
项目:Trebuchet    文件:LauncherBackupHelper.java   
/**
 * 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();
    }
}
项目:Trebuchet    文件:LauncherBackupHelper.java   
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);
}
项目:android-giftwise    文件:BackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException {
    Log.d(LOG_TAG, "onBackup called");

    synchronized (DbHelper.dbLock) {
        super.onBackup(oldState, data, newState);
    }
}
项目:FMTech    文件:VendingBackupAgent.java   
private static void flushBufferData(BackupDataOutput paramBackupDataOutput, ByteArrayOutputStream paramByteArrayOutputStream, String paramString)
  throws IOException
{
  byte[] arrayOfByte = paramByteArrayOutputStream.toByteArray();
  paramBackupDataOutput.writeEntityHeader(paramString, arrayOfByte.length);
  paramBackupDataOutput.writeEntityData(arrayOfByte, arrayOfByte.length);
  paramByteArrayOutputStream.reset();
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
/**
 * Back up launcher data so we can restore the user's state on a new device.
 *
 * <P>The journal is a timestamp and a list of keys that were saved as of that time.
 *
 * <P>Keys may come back in any order, so each key/value is one complete row of the database.
 *
 * @param oldState notes from the last backup
 * @param data incremental key/value pairs to persist off-device
 * @param newState notes for the next backup
 * @throws IOException
 */
@Override
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
        ParcelFileDescriptor newState) {
    if (VERBOSE) Log.v(TAG, "onBackup");

    Journal in = readJournal(oldState);
    Journal out = new Journal();

    long lastBackupTime = in.t;
    out.t = System.currentTimeMillis();
    out.rows = 0;
    out.bytes = 0;

    Log.v(TAG, "lastBackupTime = " + lastBackupTime);

    ArrayList<Key> keys = new ArrayList<Key>();
    if (launcherIsReady()) {
        try {
            backupFavorites(in, data, out, keys);
            backupScreens(in, data, out, keys);
            backupIcons(in, data, out, keys);
            backupWidgets(in, data, out, keys);
        } catch (IOException e) {
            Log.e(TAG, "launcher backup has failed", e);
        }
        out.key = keys.toArray(new BackupProtos.Key[keys.size()]);
    } else {
        out = in;
    }

    writeJournal(newState, out);
    Log.v(TAG, "onBackup: wrote " + out.bytes + "b in " + out.rows + " rows.");
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
/**
 * Write all modified favorites to the data stream.
 *
 *
 * @param in notes from last backup
 * @param data output stream for key/value pairs
 * @param out notes about this backup
 * @param keys keys to mark as clean in the notes for next backup
 * @throws IOException
 */
private void backupFavorites(Journal in, BackupDataOutput data, Journal out,
        ArrayList<Key> keys)
        throws IOException {
    // read the old ID set
    Set<String> savedIds = getSavedIdsByType(Key.FAVORITE, in);
    if (DEBUG) Log.d(TAG, "favorite savedIds.size()=" + savedIds.size());

    // persist things that have changed since the last backup
    ContentResolver cr = mContext.getContentResolver();
    Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION,
            null, null, null);
    Set<String> currentIds = new HashSet<String>(cursor.getCount());
    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);
            keys.add(key);
            final String backupKey = keyToBackupKey(key);
            currentIds.add(backupKey);
            if (!savedIds.contains(backupKey) || updateTime >= in.t) {
                byte[] blob = packFavorite(cursor);
                writeRowToBackup(key, blob, out, data);
            } else {
                if (VERBOSE) Log.v(TAG, "favorite " + id + " was too old: " + updateTime);
            }
        }
    } finally {
        cursor.close();
    }
    if (DEBUG) Log.d(TAG, "favorite currentIds.size()=" + currentIds.size());

    // these IDs must have been deleted
    savedIds.removeAll(currentIds);
    out.rows += removeDeletedKeysFromBackup(savedIds, data);
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
/**
 * Write all modified screens to the data stream.
 *
 *
 * @param in notes from last backup
 * @param data output stream for key/value pairs
 * @param out notes about this backup
 * @param keys keys to mark as clean in the notes for next backup
 * @throws IOException
 */
private void backupScreens(Journal in, BackupDataOutput data, Journal out,
        ArrayList<Key> keys)
        throws IOException {
    // read the old ID set
    Set<String> savedIds = getSavedIdsByType(Key.SCREEN, in);
    if (DEBUG) Log.d(TAG, "screen savedIds.size()=" + savedIds.size());

    // 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);
    Set<String> currentIds = new HashSet<String>(cursor.getCount());
    try {
        cursor.moveToPosition(-1);
        if (DEBUG) Log.d(TAG, "dumping screens after: " + in.t);
        while(cursor.moveToNext()) {
            final long id = cursor.getLong(ID_INDEX);
            final long updateTime = cursor.getLong(ID_MODIFIED);
            Key key = getKey(Key.SCREEN, id);
            keys.add(key);
            final String backupKey = keyToBackupKey(key);
            currentIds.add(backupKey);
            if (!savedIds.contains(backupKey) || updateTime >= in.t) {
                byte[] blob = packScreen(cursor);
                writeRowToBackup(key, blob, out, data);
            } else {
                if (VERBOSE) Log.v(TAG, "screen " + id + " was too old: " + updateTime);
            }
        }
    } finally {
        cursor.close();
    }
    if (DEBUG) Log.d(TAG, "screen currentIds.size()=" + currentIds.size());

    // these IDs must have been deleted
    savedIds.removeAll(currentIds);
    out.rows += removeDeletedKeysFromBackup(savedIds, data);
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
private int removeDeletedKeysFromBackup(Set<String> deletedIds, BackupDataOutput data)
        throws IOException {
    int rows = 0;
    for(String deleted: deletedIds) {
        if (VERBOSE) Log.v(TAG, "dropping deleted item " + deleted);
        data.writeEntityHeader(deleted, -1);
        rows++;
    }
    return rows;
}
项目:FLauncher    文件:LauncherBackupHelper.java   
/**
 * 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();
    }
}
项目:FLauncher    文件:LauncherBackupHelper.java   
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);
}
项目:BgLogger    文件:MyBackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
        ParcelFileDescriptor newState) throws IOException {
    // TODO Auto-generated method stub

/*  synchronized (HostDatabase.dbLock) {
           super.onBackup(oldState, data, newState);
   }*/

    super.onBackup(oldState, data, newState);
}
项目:ServeStream    文件:BackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
          ParcelFileDescriptor newState) throws IOException {

    Log.v(TAG, "onBackup called");

    // Hold the lock while the FileBackupHelper performs backup
    synchronized (StreamDatabase.dbLock) {
        super.onBackup(oldState, data, newState);
    }
}
项目:LB-Launcher    文件:LauncherBackupHelper.java   
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);
    if (VERBOSE) Log.v(TAG, "Writing New entry " + backupKey);
}
项目:Bill-Calculator    文件:PrefsAndDbBackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
                     ParcelFileDescriptor newState) throws IOException {
    Timber.i("onBackup");
    lock.lock();
    try {
        super.onBackup(oldState, data, newState);
    } finally {
        lock.unlock();
    }
}
项目:androidwisprclient    文件:BackupAgentHelperWrapper.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState)
        throws IOException {
    if (isAvailable) {
        instance.onBackup(oldState, data, newState);
    }
}
项目:SafeSlinger-Android    文件:KeyBackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
        ParcelFileDescriptor newState) throws IOException {
    // Hold the lock while the BackupHelper performs backup
    synchronized (SafeSlinger.sDataLock) {
        super.onBackup(oldState, data, newState);
    }

    // store backup time and cancel pending notifications...
    SafeSlingerPrefs.setBackupCompleteDate(new Date().getTime());
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) getSystemService(ns);
    nm.cancel(HomeActivity.NOTIFY_BACKUP_DELAY_ID);
}
项目:2048-Battles    文件:TheBackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
        ParcelFileDescriptor newState) throws IOException {

    Log.d(LOG_TAG, "on backup");

    super.onBackup(oldState, data, newState);
}
项目:geoPingProject    文件:GeoPingBackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException {
    synchronized (GeoPingBackupAgent.sDataLock) {
        Log.i(TAG, "----- ----- ----- ----- ----- ----- ----- ----- ----- ");
        Log.i(TAG, "----- ----- ----- ----- ----- ----- ----- ----- ----- ");
        Log.i(TAG, "----- onBackup GeoPing Backup --- Begin");
        super.onBackup(oldState, data, newState);
        Log.i(TAG, "----- onBackup GeoPing   Backup --- End");
        Log.i(TAG, "----- ----- ----- ----- ----- ----- ----- ----- ----- ");
        Log.i(TAG, "----- ----- ----- ----- ----- ----- ----- ----- ----- ");
    }
}
项目:geoPingProject    文件:TestSharedPreferencesBackupHelper.java   
/**
 * Backs up the configured {@link android.content.SharedPreferences} groups.
 */
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) {
    String backupKey = GeoPingBackupAgent.BACKUP_KEY_PREFS;
    Log.i(TAG, "-------------------------------------------------");
    Log.i(TAG, "--- performBackup : key =  " + backupKey);

    super.performBackup(oldState, data, newState);

    Log.i(TAG, "----- performBackup End : key =  " + backupKey);
    Log.i(TAG, "-------------------------------------------------");

}
项目:ministocks    文件:BackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
                     ParcelFileDescriptor newState) throws IOException {
    // Hold the lock while the FileBackupHelper performs backup
    synchronized (UserData.sFileBackupLock) {
        super.onBackup(oldState, data, newState);
    }
}
项目:servestream    文件:BackupAgent.java   
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
          ParcelFileDescriptor newState) throws IOException {

    Log.v(TAG, "onBackup called");

    // Hold the lock while the FileBackupHelper performs backup
    synchronized (StreamDatabase.dbLock) {
        super.onBackup(oldState, data, newState);
    }
}