use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class SecureCameraActivity method onPictureTaken.
@Override
public void onPictureTaken(final byte[] data, Camera camera) {
try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filename)));
out.write(data);
out.flush();
out.close();
if (thumbnail != null) {
Bitmap thumbnailBitmap = getThumbnail(getContentResolver(), filename);
FileOutputStream fos = new FileOutputStream(thumbnail);
thumbnailBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
}
Intent intent = new Intent();
intent.putExtra(FILENAME, filename);
intent.putExtra(THUMBNAIL, thumbnail);
intent.putExtra(MIMETYPE, "image/*");
setResult(Activity.RESULT_OK, intent);
finish();
} catch (Exception e) {
e.printStackTrace();
setResult(Activity.RESULT_CANCELED);
finish();
}
finish();
}
use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class ChatSessionAdapter method downloadMedia.
public String downloadMedia(String mediaLink, String msgId, String nickname) {
String result = null;
try {
Downloader dl = new Downloader();
File fileDownload = dl.openSecureStorageFile(mContactId + "", mediaLink);
OutputStream storageStream = new info.guardianproject.iocipher.FileOutputStream(fileDownload);
boolean downloaded = dl.get(mediaLink, storageStream);
if (downloaded) {
String mimeType = dl.getMimeType();
try {
// boolean isVerified = getDefaultOtrChatSession().isKeyVerified(bareUsername);
// int type = isVerified ? Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED : Imps.MessageType.INCOMING_ENCRYPTED;
int type = Imps.MessageType.INCOMING;
if (mediaLink.startsWith("aesgcm"))
type = Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED;
result = SecureMediaStore.vfsUri(fileDownload.getAbsolutePath()).toString();
insertOrUpdateChat(result);
// Imps.deleteMessageInDb(service.getContentResolver(),msgId);
Uri messageUri = Imps.insertMessageInDb(service.getContentResolver(), mIsGroupChat, getId(), true, nickname, result, System.currentTimeMillis(), type, 0, msgId, mimeType);
if (// error writing to database
messageUri == null) {
Log.e(TAG, "error saving message to the db: " + msgId);
return null;
}
String sanitizedPath = Uri.parse(mediaLink).getLastPathSegment();
try {
int N = mRemoteListeners.beginBroadcast();
for (int i = 0; i < N; i++) {
IChatListener listener = mRemoteListeners.getBroadcastItem(i);
try {
listener.onIncomingFileTransferProgress(sanitizedPath, 100);
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing the
// dead listeners.
}
}
mRemoteListeners.finishBroadcast();
} catch (Exception e) {
Log.e(TAG, "error notifying of new messages", e);
}
} catch (Exception e) {
Log.e(ImApp.LOG_TAG, "Error updating file transfer progress", e);
}
}
} catch (Exception e) {
Log.e(ImApp.LOG_TAG, "error downloading incoming media", e);
}
return result;
}
use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class ChatSessionAdapter method offerData.
@Override
public boolean offerData(String offerId, final String mediaPath, final String mimeType) {
if (TextUtils.isEmpty(mimeType))
return false;
Uri mediaUri = Uri.parse(mediaPath);
if (mediaUri == null || mediaUri.getPath() == null)
return false;
String fileName = mediaUri.getLastPathSegment();
java.io.InputStream fis = null;
long fileLength = -1;
if (mediaUri.getScheme() != null && mediaUri.getScheme().equals("vfs")) {
info.guardianproject.iocipher.File fileLocal = new info.guardianproject.iocipher.File(mediaUri.getPath());
if (fileLocal.exists()) {
try {
fis = new info.guardianproject.iocipher.FileInputStream(fileLocal);
fileName = fileLocal.getName();
fileLength = fileLocal.length();
} catch (FileNotFoundException fe) {
Log.w(TAG, "encrypted file not found on import: " + mediaUri);
return false;
}
} else {
Log.w(TAG, "encrypted file not found on import: " + mediaUri);
return false;
}
} else if (mediaUri.getScheme() != null && mediaUri.getScheme().equals("content")) {
ContentResolver cr = service.getContentResolver();
Cursor returnCursor = cr.query(mediaUri, null, null, null, null);
if (returnCursor != null && returnCursor.moveToFirst()) {
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
fileName = returnCursor.getString(nameIndex);
fileLength = returnCursor.getLong(sizeIndex);
returnCursor.close();
try {
fis = cr.openInputStream(mediaUri);
} catch (Exception e) {
return false;
}
} else {
return false;
}
} else {
java.io.File fileLocal = new java.io.File(mediaUri.getPath());
if (fileLocal.exists()) {
try {
fis = new java.io.FileInputStream(fileLocal);
fileLength = fileLocal.length();
} catch (FileNotFoundException fe) {
Log.w(TAG, "file system file not found on import: " + mediaUri);
return false;
}
} else {
Log.w(TAG, "file system file not found on import: " + mediaUri);
return false;
}
}
sendMediaMessageAsync(mediaPath, mimeType, fileName, fis, fileLength);
return true;
}
use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class SecureCameraActivity method getThumbnail.
public Bitmap getThumbnail(ContentResolver cr, String filename) throws IOException {
File file = new File(filename);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inInputShareable = true;
options.inPurgeable = true;
FileInputStream fis = new FileInputStream(file);
BitmapFactory.decodeStream(fis, null, options);
fis.close();
if ((options.outWidth == -1) || (options.outHeight == -1))
throw new IOException("Bad image " + file);
int originalSize = (options.outHeight > options.outWidth) ? options.outHeight : options.outWidth;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = originalSize / THUMBNAIL_SIZE;
fis = new FileInputStream(file);
Bitmap scaledBitmap = BitmapFactory.decodeStream(fis, null, opts);
return scaledBitmap;
}
use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class SecureMediaStore method copyToVfs.
public static void copyToVfs(byte[] buf, String targetPath) throws IOException {
File file = new File(targetPath);
FileOutputStream out = new FileOutputStream(file);
out.write(buf);
out.close();
}
Aggregations