use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class SecureMediaStore method init.
/**
* Careful! All of the {@code File}s in this method are {@link java.io.File}
* not {@link info.guardianproject.iocipher.File}s
*
* @param context
* @param key
* @throws IllegalArgumentException
*/
public static void init(Context context, byte[] key) throws IllegalArgumentException {
// there is only one VFS, so if its already mounted, nothing to do
VirtualFileSystem vfs = VirtualFileSystem.get();
if (vfs.isMounted()) {
Log.w(TAG, "VFS " + vfs.getContainerPath() + " is already mounted, so unmount()");
try {
vfs.unmount();
} catch (Exception e) {
Log.w(TAG, "VFS " + vfs.getContainerPath() + " issues with unmounting: " + e.getMessage());
}
}
Log.w(TAG, "Mounting VFS: " + vfs.getContainerPath());
dbFilePath = getInternalDbFilePath(context);
if (!new java.io.File(dbFilePath).exists()) {
vfs.createNewContainer(dbFilePath, key);
}
try {
vfs.mount(dbFilePath, key);
// list("/");
} catch (Exception e) {
Log.w(TAG, "VFS " + vfs.getContainerPath() + " issues with mounting: " + e.getMessage());
}
}
use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class SecureMediaStore method copyToVfs.
public static void copyToVfs(InputStream sourceIS, String targetPath) throws IOException {
// create the target directories tree
mkdirs(targetPath);
// copy
FileOutputStream fos = new FileOutputStream(new File(targetPath), false);
IOUtils.copyLarge(sourceIS, fos);
fos.close();
sourceIS.close();
}
use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class SecureMediaStore method resizeAndImportImage.
/**
* Resize an image to an efficient size for sending via OTRDATA, then copy
* that resized version into vfs. All imported content is stored under
* /SESSION_NAME/ The original full path is retained to facilitate browsing
* The session content can be deleted when the session is over
*
* @param sessionId
* @return vfs uri
* @throws IOException
*/
public static Uri resizeAndImportImage(Context context, String sessionId, Uri uri, String mimeType) throws IOException {
String originalImagePath = uri.getPath();
String targetPath = "/" + sessionId + "/upload/" + UUID.randomUUID().toString() + "/image";
boolean savePNG = false;
if (originalImagePath.endsWith(".png") || (mimeType != null && mimeType.contains("png")) || originalImagePath.endsWith(".gif") || (mimeType != null && mimeType.contains("gif"))) {
savePNG = true;
targetPath += ".png";
} else {
targetPath += ".jpg";
}
// load lower-res bitmap
Bitmap bmp = getThumbnailFile(context, uri, DEFAULT_IMAGE_WIDTH);
File file = new File(targetPath);
file.getParentFile().mkdirs();
FileOutputStream out = new info.guardianproject.iocipher.FileOutputStream(file);
if (savePNG)
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
else
bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
bmp.recycle();
return vfsUri(targetPath);
}
use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class SecureMediaStore method list.
public static void list(String parent) {
File file = new File(parent);
String[] list = file.list();
Log.d(TAG, "Dir=" + file.isDirectory() + ";" + file.getAbsolutePath() + ";last=" + new Date(file.lastModified()));
for (int i = 0; i < list.length; i++) {
File fileChild = new File(parent, list[i]);
if (fileChild.isDirectory()) {
list(fileChild.getAbsolutePath());
} else {
Log.d(TAG, "Dir=" + fileChild.isDirectory() + ";" + fileChild.getAbsolutePath() + ";last=" + new Date(fileChild.lastModified()));
}
}
}
use of info.guardianproject.iocipher.File in project Zom-Android by zom.
the class AudioPlayer method initPlayer.
public void initPlayer() throws Exception {
final File fileStream = new File(mFileName);
if (mediaPlayer != null) {
if (mediaPlayer.isPlaying())
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
if (fileStream.exists()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mediaPlayer.setDataSource(new MediaDataSource() {
info.guardianproject.iocipher.RandomAccessFile fis;
@Override
public int readAt(long position, byte[] buffer, int offset, int size) throws IOException {
if (fis == null)
fis = new info.guardianproject.iocipher.RandomAccessFile(fileStream, "r");
if (position > getSize())
return -1;
fis.seek(position);
byte[] outBuffer = new byte[size];
int readSize = fis.read(outBuffer, 0, size);
System.arraycopy(outBuffer, 0, buffer, offset, size);
return readSize;
}
@Override
public long getSize() throws IOException {
return fileStream.length();
}
@Override
public void close() throws IOException {
if (fis != null)
fis.close();
}
});
} else {
streamer = new HttpMediaStreamer(fileStream, mMimeType);
Uri uri = streamer.getUri();
mediaPlayer.setDataSource(mContext, uri);
}
} else {
mediaPlayer.setDataSource(mFileName);
}
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
Log.d("AudioPlayer", "there was an error loading music: " + i + " " + i1);
return true;
}
});
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mPrepared = true;
mDuration = mediaPlayer.getDuration();
mInfoView.setText((getDuration() / 1000) + "secs");
if (mPlayOnPrepare)
play();
}
});
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (mVisualizer != null)
mVisualizer.setEnabled(false);
}
});
// mediaPlayer.prepareAsync();
}
Aggregations