Search in sources :

Example 21 with File

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());
    }
}
Also used : VirtualFileSystem(info.guardianproject.iocipher.VirtualFileSystem) File(info.guardianproject.iocipher.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 22 with File

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();
}
Also used : FileOutputStream(info.guardianproject.iocipher.FileOutputStream) File(info.guardianproject.iocipher.File)

Example 23 with File

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);
}
Also used : Bitmap(android.graphics.Bitmap) FileOutputStream(info.guardianproject.iocipher.FileOutputStream) File(info.guardianproject.iocipher.File)

Example 24 with File

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()));
        }
    }
}
Also used : File(info.guardianproject.iocipher.File) Date(java.util.Date)

Example 25 with File

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();
}
Also used : OnPreparedListener(android.media.MediaPlayer.OnPreparedListener) HttpMediaStreamer(org.awesomeapp.messenger.util.HttpMediaStreamer) IOException(java.io.IOException) Uri(android.net.Uri) RandomAccessFile(info.guardianproject.iocipher.RandomAccessFile) OnCompletionListener(android.media.MediaPlayer.OnCompletionListener) MediaDataSource(android.media.MediaDataSource) File(info.guardianproject.iocipher.File) RandomAccessFile(info.guardianproject.iocipher.RandomAccessFile) MediaPlayer(android.media.MediaPlayer)

Aggregations

File (info.guardianproject.iocipher.File)32 IOException (java.io.IOException)14 FileOutputStream (info.guardianproject.iocipher.FileOutputStream)6 FileInputStream (info.guardianproject.iocipher.FileInputStream)5 FileNotFoundException (java.io.FileNotFoundException)5 Bitmap (android.graphics.Bitmap)4 Uri (android.net.Uri)4 HashMap (java.util.HashMap)4 RemoteException (android.os.RemoteException)3 RandomAccessFile (info.guardianproject.iocipher.RandomAccessFile)3 BitmapFactory (android.graphics.BitmapFactory)2 MediaDataSource (android.media.MediaDataSource)2 MediaPlayer (android.media.MediaPlayer)2 HttpRequest (cz.msebera.android.httpclient.HttpRequest)2 BasicHttpRequest (cz.msebera.android.httpclient.message.BasicHttpRequest)2 InputStream (java.io.InputStream)2 HttpMediaStreamer (org.awesomeapp.messenger.util.HttpMediaStreamer)2 OmemoFingerprint (org.jivesoftware.smackx.omemo.OmemoFingerprint)2 OmemoDevice (org.jivesoftware.smackx.omemo.internal.OmemoDevice)2 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)2