Search in sources :

Example 1 with BackupFrame

use of org.thoughtcrime.securesms.backup.BackupProtos.BackupFrame in project Signal-Android by WhisperSystems.

the class FullBackupImporter method importFile.

public static void importFile(@NonNull Context context, @NonNull AttachmentSecret attachmentSecret, @NonNull SQLiteDatabase db, @NonNull InputStream is, @NonNull String passphrase) throws IOException {
    int count = 0;
    SQLiteDatabase keyValueDatabase = KeyValueDatabase.getInstance(ApplicationDependencies.getApplication()).getSqlCipherDatabase();
    try {
        BackupRecordInputStream inputStream = new BackupRecordInputStream(is, passphrase);
        db.beginTransaction();
        keyValueDatabase.beginTransaction();
        dropAllTables(db);
        BackupFrame frame;
        while (!(frame = inputStream.readFrame()).getEnd()) {
            if (count % 100 == 0)
                EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.PROGRESS, count, 0));
            count++;
            if (frame.hasVersion())
                processVersion(db, frame.getVersion());
            else if (frame.hasStatement())
                processStatement(db, frame.getStatement());
            else if (frame.hasPreference())
                processPreference(context, frame.getPreference());
            else if (frame.hasAttachment())
                processAttachment(context, attachmentSecret, db, frame.getAttachment(), inputStream);
            else if (frame.hasSticker())
                processSticker(context, attachmentSecret, db, frame.getSticker(), inputStream);
            else if (frame.hasAvatar())
                processAvatar(context, db, frame.getAvatar(), inputStream);
            else if (frame.hasKeyValue())
                processKeyValue(frame.getKeyValue());
            else
                count--;
        }
        db.setTransactionSuccessful();
        keyValueDatabase.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        keyValueDatabase.endTransaction();
    }
    EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.FINISHED, count, 0));
}
Also used : SQLiteDatabase(net.zetetic.database.sqlcipher.SQLiteDatabase) BackupFrame(org.thoughtcrime.securesms.backup.BackupProtos.BackupFrame) SuppressLint(android.annotation.SuppressLint)

Example 2 with BackupFrame

use of org.thoughtcrime.securesms.backup.BackupProtos.BackupFrame in project Signal-Android by signalapp.

the class FullBackupImporter method importFile.

public static void importFile(@NonNull Context context, @NonNull AttachmentSecret attachmentSecret, @NonNull SQLiteDatabase db, @NonNull File file, @NonNull String passphrase) throws IOException {
    BackupRecordInputStream inputStream = new BackupRecordInputStream(file, passphrase);
    int count = 0;
    try {
        db.beginTransaction();
        BackupFrame frame;
        while (!(frame = inputStream.readFrame()).getEnd()) {
            if (count++ % 100 == 0)
                EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.PROGRESS, count));
            if (frame.hasVersion())
                processVersion(db, frame.getVersion());
            else if (frame.hasStatement())
                processStatement(db, frame.getStatement());
            else if (frame.hasPreference())
                processPreference(context, frame.getPreference());
            else if (frame.hasAttachment())
                processAttachment(context, attachmentSecret, db, frame.getAttachment(), inputStream);
            else if (frame.hasAvatar())
                processAvatar(context, frame.getAvatar(), inputStream);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.FINISHED, count));
}
Also used : BackupFrame(org.thoughtcrime.securesms.backup.BackupProtos.BackupFrame) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 BackupFrame (org.thoughtcrime.securesms.backup.BackupProtos.BackupFrame)2 SQLiteDatabase (net.zetetic.database.sqlcipher.SQLiteDatabase)1