info.guardianproject.iocipher.File Java Examples

The following examples show how to use info.guardianproject.iocipher.File. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AudioRecorderActivity.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
private void startRecording ()
{
	String fileName = "audio" + new java.util.Date().getTime();
	info.guardianproject.iocipher.File fileOut = new info.guardianproject.iocipher.File(mFileBasePath,fileName);
	
	try {
		mIsRecording = true;
		
		if (useAAC)
			initAudio(fileOut.getAbsolutePath()+".aac");
		else
			initAudio(fileOut.getAbsolutePath()+".pcm");
		
		
		startAudioRecording();
		

	} catch (Exception e) {
		Log.d("Video","error starting video",e);
		Toast.makeText(this, "Error init'ing video: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
		finish();
	}
}
 
Example #2
Source File: OtrDataHandler.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
public String closeFile() throws IOException {
    //Log.e(TAG, "closeFile") ;
    raf.close();
    File file = new File(localFilename);
    String newPath = file.getCanonicalPath();
    if(true) return newPath;

    newPath = newPath.substring(0,newPath.length()-4); // remove the .tmp
    //Log.e(TAG, "vfsCloseFile: rename " + newPath) ;
    File newPathFile = new File(newPath);
    boolean success = file.renameTo(newPathFile);
    if (!success) {
        throw new IOException("Rename error " + newPath );
    }
    return newPath;
}
 
Example #3
Source File: DropboxSyncManager.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
private void saveCredentials () throws IOException
{
	
	if (mSession != null && mSession.isLinked()
			&& mSession.getOAuth2AccessToken() != null)
	{
		
        mStoredAccessToken = mSession.getOAuth2AccessToken();
        
        Properties props = new Properties();
        props.setProperty("dbtoken", mStoredAccessToken);
        
        info.guardianproject.iocipher.File fileProps = new info.guardianproject.iocipher.File("/dropbox.properties");
        info.guardianproject.iocipher.FileOutputStream fos = new info.guardianproject.iocipher.FileOutputStream(fileProps);
        props.storeToXML(fos,"");
        fos.close();
        
	}
	else
	{
		Log.d("Dropbox","no valid dropbox session / not linked");
        
	}
}
 
Example #4
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
@Override
public HashMap<Integer, T_PreKey> loadOmemoPreKeys(OmemoManager omemoManager) {
    File preKeyDirectory = hierarchy.getPreKeysDirectory(omemoManager);
    HashMap<Integer, T_PreKey> preKeys = new HashMap<>();

    if (preKeyDirectory == null) {
        return preKeys;
    }

    File[] keys = preKeyDirectory.listFiles();
    for (File f : keys != null ? keys : new File[0]) {

        try {
            byte[] bytes = readBytes(f);
            if (bytes == null) {
                continue;
            }
            T_PreKey p = keyUtil().preKeyFromBytes(bytes);
            preKeys.put(Integer.parseInt(f.getName()), p);

        } catch (IOException e) {
            //Do nothing
        }
    }
    return preKeys;
}
 
Example #5
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean isFreshInstallation(OmemoManager omemoManager) {
    File userDirectory = hierarchy.getUserDeviceDirectory(omemoManager);
    File[] files = userDirectory.listFiles();
    if (files == null || files.length == 0)
        return true;
    else
    {
        try {
            Object key = loadOmemoIdentityKeyPair(omemoManager);
            if (key == null)
                return true;
        } catch (CorruptedOmemoKeyException e) {
            e.printStackTrace();
            return true;
        }

    }

    return false;
}
 
Example #6
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
@Override
public HashMap<Integer, T_SigPreKey> loadOmemoSignedPreKeys(OmemoManager omemoManager) {
    File signedPreKeysDirectory = hierarchy.getSignedPreKeysDirectory(omemoManager);
    HashMap<Integer, T_SigPreKey> signedPreKeys = new HashMap<>();

    if (signedPreKeysDirectory == null) {
        return signedPreKeys;
    }

    File[] keys = signedPreKeysDirectory.listFiles();
    for (File f : keys != null ? keys : new File[0]) {

        try {
            byte[] bytes = readBytes(f);
            if (bytes == null) {
                continue;
            }
            T_SigPreKey p = keyUtil().signedPreKeyFromBytes(bytes);
            signedPreKeys.put(Integer.parseInt(f.getName()), p);

        } catch (IOException e) {
            //Do nothing
        }
    }
    return signedPreKeys;
}
 
Example #7
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void removeAllRawSessionsOf(OmemoManager omemoManager, BareJid contact) {
    File contactsDirectory = hierarchy.getContactsDir(omemoManager, contact);
    String[] devices = contactsDirectory.list();

    for (String deviceId : devices != null ? devices : new String[0]) {
        int id;
        try {
            id = Integer.parseInt(deviceId);
        } catch (NumberFormatException e) {
            continue;
        }
        OmemoDevice device = new OmemoDevice(contact, id);
        File session = hierarchy.getContactsSessionPath(omemoManager, device);
        session.delete();
    }
}
 
Example #8
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
public static void deleteDirectory(File root) {
    File[] currList;
    Stack<File> stack = new Stack<>();
    stack.push(root);
    while (!stack.isEmpty()) {
        if (stack.lastElement().isDirectory()) {
            currList = stack.lastElement().listFiles();
            if (currList != null && currList.length > 0) {
                for (File curr : currList) {
                    stack.push(curr);
                }
            } else {
                stack.pop().delete();
            }
        } else {
            stack.pop().delete();
        }
    }
}
 
Example #9
Source File: StillCameraActivity.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected File doInBackground(byte[]... data) {

	try {

		long mTime = System.currentTimeMillis();
		File fileSecurePicture = new File(mFileBasePath, "camerav_image_" + mTime + ".jpg");
		mResultList.add(fileSecurePicture.getAbsolutePath());

		FileOutputStream out = new FileOutputStream(fileSecurePicture);
		out.write(data[0]);
		out.flush();
		out.close();

		return fileSecurePicture;

	} catch (IOException ioe) {
		Log.e(StillCameraActivity.class.getName(), "error saving picture", ioe);
	}

	return null;
}
 
Example #10
Source File: GalleryActivity.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
private void shareExternalFile (java.io.File fileExtern)
{
    Uri uri = Uri.fromFile(fileExtern);

    Intent intent = new Intent(Intent.ACTION_SEND);

    String fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
    if (fileExtension.equals("mp4") || fileExtension.equals("mkv") || fileExtension.equals("mov"))
        mimeType = "video/*";
    if (mimeType == null)
        mimeType = "application/octet-stream";

    intent.setDataAndType(uri, mimeType);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    intent.putExtra(Intent.EXTRA_SUBJECT, fileExtern.getName());
    intent.putExtra(Intent.EXTRA_TITLE, fileExtern.getName());

    try {
        startActivity(Intent.createChooser(intent, "Share this!"));
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "No relevant Activity found", e);
    }
}
 
Example #11
Source File: DropboxSyncManager.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
private boolean loadCredentials ()
{
	try
	{
		Properties props = new Properties();
		info.guardianproject.iocipher.File fileProps = new info.guardianproject.iocipher.File("/dropbox.properties");
		
		if (fileProps.exists())
		{
	        info.guardianproject.iocipher.FileInputStream fis = new info.guardianproject.iocipher.FileInputStream(fileProps);        
	        props.loadFromXML(fis);
	        
	        mStoredAccessToken = props.getProperty("dbtoken");
	        
	        return true;
		}
        
        
	}
	catch (IOException ioe)
	{
		Log.e("DbAuthLog", "Error I/O", ioe);
	}
	
	return false;
}
 
Example #12
Source File: MessageListItem.java    From zom-android-matrix with Apache License 2.0 6 votes vote down vote up
/**
 * @param contentResolver
 * @param id
 * @param aHolder
 * @param mediaUri
 */
private void setVideoThumbnail(final ContentResolver contentResolver, final int id, final MessageViewHolder aHolder, final Uri mediaUri) {

    //if the same URI, we don't need to reload
    if (aHolder.mMediaUri != null
            && aHolder.mMediaUri.getPath() != null
            && aHolder.mMediaUri.getPath().equals(mediaUri.getPath()))
        return;

    // pair this holder to the uri. if the holder is recycled, the pairing is broken
    aHolder.mMediaUri = mediaUri;
    // if a content uri - already scanned

    File fileThumb = new File(mediaUri.getPath()+".thumb.jpg");
    if (fileThumb.exists()) {
        //GlideUtils.loadVideoFromUri(context, mediaUri, aHolder.mMediaThumbnail);
        GlideUtils.loadImageFromUri(context, Uri.parse("vfs://"+fileThumb.getAbsolutePath()), aHolder.mMediaThumbnail);
    }
    else {
        aHolder.mMediaThumbnail.setImageResource(R.drawable.video256); // generic file icon
        aHolder.mMediaThumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER);
    }
}
 
Example #13
Source File: MessageListItem.java    From zom-android-matrix with Apache License 2.0 6 votes vote down vote up
public void exportMediaFile ()
{
    

    if (mimeType != null && mediaUri != null) {
        java.io.File exportPath = SecureMediaStore.exportPath(mimeType, mediaUri);
        exportMediaFile(mimeType, mediaUri, exportPath, true);
    }
    else
    {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_TEXT,lastMessage);
        shareIntent.setType("text/plain");
        context.startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.export_media)));
    }

}
 
Example #14
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private static void mkdirs(String targetPath) throws IOException {
    File targetFile = new File(targetPath);
    if (!targetFile.exists()) {
        File dirFile = targetFile.getParentFile();
        if (!dirFile.exists()) {
            boolean created = dirFile.mkdirs();
            if (!created) {
                throw new IOException("Error creating " + targetPath);
            }
        }
    }
}
 
Example #15
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void storeOmemoSignedPreKey(OmemoManager omemoManager, int signedPreKeyId, T_SigPreKey signedPreKey) {
    File signedPreKeyPath = new File(hierarchy.getSignedPreKeysDirectory(omemoManager), Integer.toString(signedPreKeyId));
    try {
        writeBytes(signedPreKeyPath, keyUtil().signedPreKeyToBytes(signedPreKey));
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Could not write signedPreKey " + signedPreKey
                + " for " + omemoManager.getOwnDevice() + ": " + e, e);
    }
}
 
Example #16
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T_SigPreKey loadOmemoSignedPreKey(OmemoManager omemoManager, int signedPreKeyId) {
    File signedPreKeyPath = new File(hierarchy.getSignedPreKeysDirectory(omemoManager), Integer.toString(signedPreKeyId));
    try {
        byte[] bytes = readBytes(signedPreKeyPath);
        return bytes != null ? keyUtil().signedPreKeyFromBytes(bytes) : null;
    } catch (IOException e) {
        return null;
    }
}
 
Example #17
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example #18
Source File: VideoCameraActivity.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
private void initAudio(final String audioPath) throws Exception {

			fileAudio  = new File(audioPath); 
			
			   outputStreamAudio = new BufferedOutputStream(new info.guardianproject.iocipher.FileOutputStream(fileAudio),8192*8);
				
			   if (useAAC)
			   {
				   aac = new AACHelper();
				   aac.setEncoder(MediaConstants.sAudioSampleRate, MediaConstants.sAudioChannels, MediaConstants.sAudioBitRate);
			   }
			   else
			   {
			   
				   int minBufferSize = AudioRecord.getMinBufferSize(MediaConstants.sAudioSampleRate, 
					MediaConstants.sChannelConfigIn, 
				     AudioFormat.ENCODING_PCM_16BIT)*8;
				   
				   audioData = new byte[minBufferSize];
	
				   int audioSource = MediaRecorder.AudioSource.CAMCORDER;
				   
				   if (this.getCameraDirection() == CameraInfo.CAMERA_FACING_FRONT)
				   {
					   audioSource = MediaRecorder.AudioSource.MIC;
					   
				   }
				   
				   audioRecord = new AudioRecord(audioSource,
						   MediaConstants.sAudioSampleRate,
						   MediaConstants.sChannelConfigIn,
				     AudioFormat.ENCODING_PCM_16BIT,
				     minBufferSize);
			   }
	 }
 
Example #19
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private static File createFile(File f) throws IOException {
    File p = f.getParentFile();
    createDirectory(p);
    f.createNewFile();
    return f;

}
 
Example #20
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void trustOmemoIdentity(OmemoManager omemoManager, OmemoDevice device, OmemoFingerprint fingerprint) {
    File trustPath = hierarchy.getContactsTrustPath(omemoManager, device);
    try {
        writeBytes(trustPath, ("1 " + fingerprint.toString()).getBytes(StringUtils.UTF8));
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Could not trust " + device + ": " + e, e);
    }
}
 
Example #21
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int loadCurrentSignedPreKeyId(OmemoManager omemoManager) {
    File currentSignedPreKeyIdPath = hierarchy.getCurrentSignedPreKeyIdPath(omemoManager);
    try {
        int i = readInt(currentSignedPreKeyIdPath);
        return i == -1 ? 0 : i;
    } catch (IOException e) {
        return 0;
    }
}
 
Example #22
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void storeRawSession(OmemoManager omemoManager, OmemoDevice device, T_Sess session) {
    File sessionPath = hierarchy.getContactsSessionPath(omemoManager, device);
    try {
        writeBytes(sessionPath, keyUtil().rawSessionToBytes(session));
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Could not write session between our device " + omemoManager.getOwnDevice()
                + " and their device " + device + ": " + e.getMessage());
    }
}
 
Example #23
Source File: WebShareService.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
	
	if (intent != null && intent.getAction() != null)
	{

		if (intent.getAction().equals(ACTION_SERVER_START))
		{

			if (intent.hasExtra("medialist"))
				mMediaList = intent.getStringArrayExtra("medialist");
			
			if (intent.hasExtra("host"))
				mHost = intent.getExtras().getString("host");
			
			if (intent.hasExtra("port"))
				mPort = intent.getExtras().getInt("port");
			
			if (intent.hasExtra("root"))
				mRoot = new File(intent.getExtras().getString("root"));
			
			startServer();
			
		}
		else if (intent.getAction().equals(ACTION_SERVER_STOP))
		{
			stopServer();
		}
	}
	
	 return START_STICKY;
}
 
Example #24
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T_PreKey loadOmemoPreKey(OmemoManager omemoManager, int preKeyId) {
    File preKeyPath = hierarchy.getPreKeyPath(omemoManager, preKeyId);
    try {
        byte[] bytes = readBytes(preKeyPath);
        return bytes != null ? keyUtil().preKeyFromBytes(bytes) : null;
    } catch (IOException e) {
        return null;
    }
}
 
Example #25
Source File: SimpleWebServer.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
private String findIndexFileInDirectory(java.io.File directory) {
    for (String fileName : INDEX_FILE_NAMES) {
        File indexFile = new File(directory, fileName);
        if (indexFile.exists()) {
            return fileName;
        }
    }
    return null;
}
 
Example #26
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setDateOfLastSignedPreKeyRenewal(OmemoManager omemoManager, Date date) {
    File lastSignedPreKeyRenewal = hierarchy.getLastSignedPreKeyRenewal(omemoManager);
    try {
        writeLong(lastSignedPreKeyRenewal, date.getTime());
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Could not write date of last singedPreKey renewal for "
                + omemoManager.getOwnDevice() + ": " + e, e);
    }
}
 
Example #27
Source File: GalleryActivity.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
private void handleSendUri(Uri dataUri) {
	try {
		ContentResolver cr = getContentResolver();
		InputStream in = cr.openInputStream(dataUri);
		Log.i(TAG, "incoming URI: " + dataUri.toString());
		String fileName = dataUri.getLastPathSegment();
		File f = new File("/" + fileName);
		BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
		readBytesAndClose(in, out);
		Log.v(TAG, f.getAbsolutePath() + " size: " + String.valueOf(f.length()));
	} catch (Exception e) {
		Log.e(TAG, e.getMessage(), e);
	}
}
 
Example #28
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setDateOfLastReceivedMessage(OmemoManager omemoManager, OmemoDevice from, Date date) {
    File lastMessageReceived = hierarchy.getLastMessageReceivedDatePath(omemoManager, from);
    try {
        writeLong(lastMessageReceived, date.getTime());
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Could not write date of last received message from " + from + ": " + e, e);
    }
}
 
Example #29
Source File: IOCipherOmemoStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void distrustOmemoIdentity(OmemoManager omemoManager, OmemoDevice device, OmemoFingerprint fingerprint) {
    File trustPath = hierarchy.getContactsTrustPath(omemoManager, device);
    try {
        writeBytes(trustPath, ("2 " + fingerprint.toString()).getBytes(StringUtils.UTF8));
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Could not distrust " + device + ": " + e, e);
    }
}
 
Example #30
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public static void copyToExternal(String sourcePath, java.io.File targetPath) throws IOException {
    // copy
    FileInputStream fis = new FileInputStream(new File(sourcePath));
    java.io.FileOutputStream fos = new java.io.FileOutputStream(targetPath, false);

    IOUtils.copyLarge(fis, fos);

    fos.close();
    fis.close();
}