use of net.sqlcipher.database.SQLiteDatabase in project cw-omnibus by commonsguy.
the class DatabaseHelper method encrypt.
static void encrypt(Context ctxt) {
SQLiteDatabase.loadLibs(ctxt);
File dbFile = ctxt.getDatabasePath(DATABASE_NAME);
File legacyFile = ctxt.getDatabasePath(LEGACY_DATABASE_NAME);
if (!dbFile.exists() && legacyFile.exists()) {
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(legacyFile, "", null);
db.rawExecSQL(String.format("ATTACH DATABASE '%s' AS encrypted KEY '%s';", dbFile.getAbsolutePath(), PASSPHRASE));
db.rawExecSQL("SELECT sqlcipher_export('encrypted')");
db.rawExecSQL("DETACH DATABASE encrypted;");
int version = db.getVersion();
db.close();
db = SQLiteDatabase.openOrCreateDatabase(dbFile, PASSPHRASE, null);
db.setVersion(version);
db.close();
legacyFile.delete();
}
}
use of net.sqlcipher.database.SQLiteDatabase in project requery by requery.
the class SqlCipherMetaData method queryMemory.
@Override
protected <R> R queryMemory(Function<Cursor, R> function, String query) throws SQLException {
try {
final SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(":memory:", "", null);
Cursor cursor = database.rawQuery(query, null);
return function.apply(closeWithCursor(new Closeable() {
@Override
public void close() throws IOException {
database.close();
}
}, cursor));
} catch (SQLiteException e) {
throw new SQLException(e);
}
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class AttachmentDatabase method getPendingAttachments.
@NonNull
public List<DatabaseAttachment> getPendingAttachments() {
final SQLiteDatabase database = databaseHelper.getReadableDatabase();
final List<DatabaseAttachment> attachments = new LinkedList<>();
Cursor cursor = null;
try {
cursor = database.query(TABLE_NAME, PROJECTION, TRANSFER_STATE + " = ?", new String[] { String.valueOf(TRANSFER_PROGRESS_STARTED) }, null, null, null);
while (cursor != null && cursor.moveToNext()) {
attachments.add(getAttachment(cursor));
}
} finally {
if (cursor != null)
cursor.close();
}
return attachments;
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class AttachmentDatabase method getAttachment.
@Nullable
public DatabaseAttachment getAttachment(@NonNull AttachmentId attachmentId) {
SQLiteDatabase database = databaseHelper.getReadableDatabase();
Cursor cursor = null;
try {
cursor = database.query(TABLE_NAME, PROJECTION, PART_ID_WHERE, attachmentId.toStrings(), null, null, null);
if (cursor != null && cursor.moveToFirst())
return getAttachment(cursor);
else
return null;
} finally {
if (cursor != null)
cursor.close();
}
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class AttachmentDatabase method insertAttachment.
private AttachmentId insertAttachment(long mmsId, Attachment attachment) throws MmsException {
Log.w(TAG, "Inserting attachment for mms id: " + mmsId);
SQLiteDatabase database = databaseHelper.getWritableDatabase();
DataInfo dataInfo = null;
long uniqueId = System.currentTimeMillis();
if (attachment.getDataUri() != null) {
dataInfo = setAttachmentData(attachment.getDataUri());
Log.w(TAG, "Wrote part to file: " + dataInfo.file.getAbsolutePath());
}
ContentValues contentValues = new ContentValues();
contentValues.put(MMS_ID, mmsId);
contentValues.put(CONTENT_TYPE, attachment.getContentType());
contentValues.put(TRANSFER_STATE, attachment.getTransferState());
contentValues.put(UNIQUE_ID, uniqueId);
contentValues.put(CONTENT_LOCATION, attachment.getLocation());
contentValues.put(DIGEST, attachment.getDigest());
contentValues.put(CONTENT_DISPOSITION, attachment.getKey());
contentValues.put(NAME, attachment.getRelay());
contentValues.put(FILE_NAME, StorageUtil.getCleanFileName(attachment.getFileName()));
contentValues.put(SIZE, attachment.getSize());
contentValues.put(FAST_PREFLIGHT_ID, attachment.getFastPreflightId());
contentValues.put(VOICE_NOTE, attachment.isVoiceNote() ? 1 : 0);
if (dataInfo != null) {
contentValues.put(DATA, dataInfo.file.getAbsolutePath());
contentValues.put(SIZE, dataInfo.length);
contentValues.put(DATA_RANDOM, dataInfo.random);
}
long rowId = database.insert(TABLE_NAME, null, contentValues);
AttachmentId attachmentId = new AttachmentId(rowId, uniqueId);
if (dataInfo != null) {
if (MediaUtil.hasVideoThumbnail(attachment.getDataUri())) {
Bitmap bitmap = MediaUtil.getVideoThumbnail(context, attachment.getDataUri());
if (bitmap != null) {
ThumbnailData thumbnailData = new ThumbnailData(bitmap);
updateAttachmentThumbnail(attachmentId, thumbnailData.toDataStream(), thumbnailData.getAspectRatio());
} else {
Log.w(TAG, "Retrieving video thumbnail failed, submitting thumbnail generation job...");
thumbnailExecutor.submit(new ThumbnailFetchCallable(attachmentId));
}
} else {
Log.w(TAG, "Submitting thumbnail generation job...");
thumbnailExecutor.submit(new ThumbnailFetchCallable(attachmentId));
}
}
return attachmentId;
}
Aggregations