use of com.amaze.filemanager.database.CryptHandler in project AmazeFileManager by TeamAmaze.
the class EncryptDecryptUtils method findEncryptedEntry.
/**
* Queries database to find entry for the specific path
*
* @param path the path to match with
* @return the entry
*/
private static EncryptedEntry findEncryptedEntry(Context context, String path) throws GeneralSecurityException, IOException {
CryptHandler handler = new CryptHandler(context);
EncryptedEntry matchedEntry = null;
// find closest path which matches with database entry
for (EncryptedEntry encryptedEntry : handler.getAllEntries()) {
if (path.contains(encryptedEntry.getPath())) {
if (matchedEntry == null || matchedEntry.getPath().length() < encryptedEntry.getPath().length()) {
matchedEntry = encryptedEntry;
}
}
}
return matchedEntry;
}
use of com.amaze.filemanager.database.CryptHandler in project AmazeFileManager by TeamAmaze.
the class EncryptDecryptUtils method startEncryption.
/**
* Queries database to map path and password.
* Starts the encryption process after database query
*
* @param path the path of file to encrypt
* @param password the password in plaintext
*/
public static void startEncryption(Context c, final String path, final String password, Intent intent) throws Exception {
CryptHandler cryptHandler = new CryptHandler(c);
EncryptedEntry encryptedEntry = new EncryptedEntry(path.concat(CryptUtil.CRYPT_EXTENSION), password);
cryptHandler.addEntry(encryptedEntry);
// start the encryption process
ServiceWatcherUtil.runService(c, intent);
}
use of com.amaze.filemanager.database.CryptHandler in project AmazeFileManager by TeamAmaze.
the class MainActivity method onDestroy.
@Override
protected void onDestroy() {
super.onDestroy();
// TODO: 6/5/2017 Android may choose to not call this method before destruction
// TODO: https://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29
closeInteractiveShell();
tabHandler.close();
utilsHandler.close();
cloudHandler.close();
CryptHandler cryptHandler = new CryptHandler(this);
cryptHandler.close();
SshConnectionPool.getInstance().expungeAllConnections();
/*if (mainFragment!=null)
mainFragment = null;*/
}
use of com.amaze.filemanager.database.CryptHandler in project AmazeFileManager by TeamAmaze.
the class DeleteTask method doInBackground.
protected Boolean doInBackground(ArrayList<HybridFileParcelable>... p1) {
files = p1[0];
boolean wasDeleted = true;
if (files.size() == 0)
return true;
if (files.get(0).isOtgFile()) {
for (HybridFileParcelable file : files) {
DocumentFile documentFile = OTGUtil.getDocumentFile(file.getPath(), cd, false);
wasDeleted = documentFile.delete();
}
} else if (files.get(0).isDropBoxFile()) {
CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageDropbox.delete(CloudUtil.stripPath(OpenMode.DROPBOX, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isBoxFile()) {
CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageBox.delete(CloudUtil.stripPath(OpenMode.BOX, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isGoogleDriveFile()) {
CloudStorage cloudStorageGdrive = dataUtils.getAccount(OpenMode.GDRIVE);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageGdrive.delete(CloudUtil.stripPath(OpenMode.GDRIVE, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isOneDriveFile()) {
CloudStorage cloudStorageOnedrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageOnedrive.delete(CloudUtil.stripPath(OpenMode.ONEDRIVE, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else {
for (HybridFileParcelable file : files) {
try {
if (file.delete(cd, rootMode)) {
wasDeleted = true;
} else {
wasDeleted = false;
break;
}
} catch (ShellNotRunningException e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
}
// delete file from media database
if (!files.get(0).isSmb()) {
try {
for (HybridFileParcelable f : files) {
delete(cd, f.getPath());
}
} catch (Exception e) {
for (HybridFileParcelable f : files) {
FileUtils.scanFile(f.getPath(), cd);
}
}
}
// delete file entry from encrypted database
for (HybridFileParcelable file : files) {
if (file.getName().endsWith(CryptUtil.CRYPT_EXTENSION)) {
CryptHandler handler = new CryptHandler(cd);
handler.clear(file.getPath());
}
}
return wasDeleted;
}
use of com.amaze.filemanager.database.CryptHandler in project AmazeFileManager by TeamAmaze.
the class MoveFiles method onPostExecute.
@Override
public void onPostExecute(Boolean movedCorrectly) {
if (movedCorrectly) {
if (mainFrag != null && mainFrag.getCurrentPath().equals(paths.get(0))) {
// mainFrag.updateList();
Intent intent = new Intent(MainActivity.KEY_INTENT_LOAD_LIST);
intent.putExtra(MainActivity.KEY_INTENT_LOAD_LIST_FILE, paths.get(0));
context.sendBroadcast(intent);
}
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable f : files.get(i)) {
FileUtils.scanFile(f.getPath(), context);
FileUtils.scanFile(paths.get(i) + "/" + f.getName(), context);
}
}
// updating encrypted db entry if any encrypted file was moved
AppConfig.runInBackground(() -> {
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable file : files.get(i)) {
if (file.getName().endsWith(CryptUtil.CRYPT_EXTENSION)) {
try {
CryptHandler cryptHandler = new CryptHandler(context);
EncryptedEntry oldEntry = cryptHandler.findEntry(file.getPath());
EncryptedEntry newEntry = new EncryptedEntry();
newEntry.setId(oldEntry.getId());
newEntry.setPassword(oldEntry.getPassword());
newEntry.setPath(paths.get(i) + "/" + file.getName());
cryptHandler.updateEntry(oldEntry, newEntry);
} catch (Exception e) {
e.printStackTrace();
// couldn't change the entry, leave it alone
}
}
}
}
});
} else {
for (int i = 0; i < paths.size(); i++) {
Intent intent = new Intent(context, CopyService.class);
intent.putExtra(CopyService.TAG_COPY_SOURCES, files.get(i));
intent.putExtra(CopyService.TAG_COPY_TARGET, paths.get(i));
intent.putExtra(CopyService.TAG_COPY_MOVE, true);
intent.putExtra(CopyService.TAG_COPY_OPEN_MODE, mode.ordinal());
ServiceWatcherUtil.runService(context, intent);
}
}
}
Aggregations