Selaa lähdekoodia

Use path for each user

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 vuosi sitten
vanhempi
commit
80e581bcd3

+ 1 - 1
app/src/androidTest/java/com/owncloud/android/util/EncryptionTestIT.java

@@ -836,7 +836,7 @@ public class EncryptionTestIT extends AbstractIT {
 
         // Encryption
         Cipher encryptorCipher = EncryptionUtils.getCipher(Cipher.ENCRYPT_MODE, key, iv);
-        EncryptionUtils.encryptFile(targetContext, file, encryptorCipher);
+        EncryptionUtils.encryptFile(user.getAccountName(), file, encryptorCipher);
         String encryptorCipherAuthTag = EncryptionUtils.getAuthenticationTag(encryptorCipher);
 
         // Decryption

+ 4 - 11
app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -341,10 +341,8 @@ public class FileDataStorageManager {
         return ocFile;
     }
 
-    private static final String tempEncryptedFolderPath = "temp_encrypted_folder";
-
-    public static void clearTempEncryptedFolder(Context context) {
-        File tempEncryptedFolder = getTempEncryptedFolder(context);
+    public static void clearTempEncryptedFolder(String accountName) {
+        File tempEncryptedFolder =  new File(FileStorageUtils.getTemporalEncryptedFolderPath(accountName));
 
         if (!tempEncryptedFolder.exists()) {
             Log_OC.d(TAG,"tempEncryptedFolder not exists");
@@ -360,13 +358,8 @@ public class FileDataStorageManager {
         }
     }
 
-    public static File getTempEncryptedFolder(Context context) {
-        String dirPath = context.getFilesDir().getAbsolutePath() + File.separator + tempEncryptedFolderPath;
-        return new File(dirPath);
-    }
-
-    public static File createTempEncryptedFolder(Context context) {
-        File tempEncryptedFolder = getTempEncryptedFolder(context);
+    public static File createTempEncryptedFolder(String accountName) {
+        File tempEncryptedFolder = new File(FileStorageUtils.getTemporalEncryptedFolderPath(accountName));
 
         if (!tempEncryptedFolder.exists()) {
             boolean isTempEncryptedFolderCreated = tempEncryptedFolder.mkdirs();

+ 1 - 1
app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -553,7 +553,7 @@ public class UploadFileOperation extends SyncOperation {
             byte[] iv = EncryptionUtils.randomBytes(EncryptionUtils.ivLength);
             Cipher cipher = EncryptionUtils.getCipher(Cipher.ENCRYPT_MODE, key, iv);
             File file = new File(mFile.getStoragePath());
-            EncryptedFile encryptedFile = EncryptionUtils.encryptFile(getContext(), file, cipher);
+            EncryptedFile encryptedFile = EncryptionUtils.encryptFile(user.getAccountName(), file, cipher);
 
             // new random file name, check if it exists in metadata
             String encryptedFileName = EncryptionUtils.generateUid();

+ 7 - 5
app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java

@@ -54,8 +54,6 @@ import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.theme.ViewThemeUtils;
 
-import org.apache.commons.io.FileUtils;
-
 import java.io.File;
 import java.util.Arrays;
 import java.util.Optional;
@@ -143,7 +141,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
 
             if (itemId == R.id.action_upload_list_failed_clear) {
                 uploadsStorageManager.clearFailedButNotDelayedUploads();
-                FileDataStorageManager.clearTempEncryptedFolder(MainApp.getAppContext());
+                clearTempEncryptedFolder();
                 loadUploadItemsFromDb();
             } else if (itemId == R.id.action_upload_list_failed_retry) {
 
@@ -174,8 +172,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
             if (itemId == R.id.action_upload_list_cancelled_clear) {
                 uploadsStorageManager.clearCancelledUploadsForCurrentAccount();
                 loadUploadItemsFromDb();
-
-                FileDataStorageManager.clearTempEncryptedFolder(parentActivity);
+                clearTempEncryptedFolder();
             } else if (itemId == R.id.action_upload_list_cancelled_resume) {
                 retryCancelledUploads();
             }
@@ -186,6 +183,11 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
         popup.show();
     }
 
+    private void clearTempEncryptedFolder() {
+        Optional<User> user = parentActivity.getUser();
+        user.ifPresent(value -> FileDataStorageManager.clearTempEncryptedFolder(value.getAccountName()));
+    }
+
     // FIXME For e2e resume is not working
     private void retryCancelledUploads() {
         new Thread(() -> {

+ 2 - 2
app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java

@@ -547,8 +547,8 @@ public final class EncryptionUtils {
         return Base64.decode(string, Base64.NO_WRAP);
     }
 
-    public static EncryptedFile encryptFile(Context context, File file, Cipher cipher) throws InvalidParameterSpecException, IOException {
-        File tempEncryptedFolder = FileDataStorageManager.createTempEncryptedFolder(context);
+    public static EncryptedFile encryptFile(String accountName, File file, Cipher cipher) throws InvalidParameterSpecException, IOException {
+        File tempEncryptedFolder = FileDataStorageManager.createTempEncryptedFolder(accountName);
         File tempEncryptedFile = File.createTempFile(file.getName(), null, tempEncryptedFolder);
         encryptFileWithGivenCipher(file, tempEncryptedFile, cipher);
         String authenticationTagString = getAuthenticationTag(cipher);

+ 11 - 0
app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java

@@ -106,6 +106,17 @@ public final class FileStorageUtils {
         // that can be in the accountName since 0.1.190B
     }
 
+    public static String getTemporalEncryptedFolderPath(String accountName) {
+        return MainApp
+            .getAppContext()
+            .getFilesDir()
+            .getAbsolutePath()
+            + File.separator
+            + accountName
+            + File.separator
+            + "temp_encrypted_folder";
+    }
+
     /**
      * Get absolute path to tmp folder inside app folder for given accountName.
      */