瀏覽代碼

enable subfolder
check if in subfolder of encrypted folder

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

tobiasKaminsky 7 年之前
父節點
當前提交
fc7b4f789c

+ 5 - 3
src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java

@@ -371,7 +371,8 @@ public class RefreshFolderOperation extends RemoteOperation {
 
 
         // if local folder is encrypted, download fresh metadata
         // if local folder is encrypted, download fresh metadata
         DecryptedFolderMetadata metadata;
         DecryptedFolderMetadata metadata;
-        if (mLocalFolder.isEncrypted() && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
+        boolean encryptedAncestor = FileStorageUtils.checkIfInEncryptedFolder(mLocalFolder, mStorageManager);
+        if (encryptedAncestor && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
             metadata = EncryptionUtils.downloadFolderMetadata(mLocalFolder, getClient(), mContext, mAccount);
             metadata = EncryptionUtils.downloadFolderMetadata(mLocalFolder, getClient(), mContext, mAccount);
         } else {
         } else {
             metadata = null;
             metadata = null;
@@ -383,7 +384,7 @@ public class RefreshFolderOperation extends RemoteOperation {
         for (OCFile file : localFiles) {
         for (OCFile file : localFiles) {
             String remotePath = file.getRemotePath();
             String remotePath = file.getRemotePath();
 
 
-            if (metadata != null) {
+            if (metadata != null && !file.isFolder()) {
                 remotePath = file.getParentRemotePath() + file.getEncryptedFileName();
                 remotePath = file.getParentRemotePath() + file.getEncryptedFileName();
             }
             }
             localFilesMap.put(remotePath, file);
             localFilesMap.put(remotePath, file);
@@ -467,9 +468,10 @@ public class RefreshFolderOperation extends RemoteOperation {
                 } catch (NullPointerException e) {
                 } catch (NullPointerException e) {
                     Log_OC.e(TAG, "Metadata for file " + updatedFile.getFileId() + " not found!");
                     Log_OC.e(TAG, "Metadata for file " + updatedFile.getFileId() + " not found!");
                 }
                 }
-                updatedFile.setEncrypted(true);
             }
             }
 
 
+            updatedFile.setEncrypted(encryptedAncestor);
+            
             updatedFiles.add(updatedFile);
             updatedFiles.add(updatedFile);
         }
         }
 
 

+ 16 - 13
src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -144,6 +144,8 @@ public class UploadFileOperation extends SyncOperation {
     private OCUpload mUpload;
     private OCUpload mUpload;
     private UploadsStorageManager uploadsStorageManager;
     private UploadsStorageManager uploadsStorageManager;
 
 
+    private boolean encryptedAncestor;
+
     public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType) {
     public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType) {
 
 
         // MIME type
         // MIME type
@@ -354,8 +356,7 @@ public class UploadFileOperation extends SyncOperation {
         mCancellationRequested.set(false);
         mCancellationRequested.set(false);
         mUploadStarted.set(true);
         mUploadStarted.set(true);
 
 
-        uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(),
-                mContext);
+        uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), mContext);
 
 
         for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) {
         for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) {
             if (ocUpload.getUploadId() == getOCUploadId()) {
             if (ocUpload.getUploadId() == getOCUploadId()) {
@@ -370,12 +371,21 @@ public class UploadFileOperation extends SyncOperation {
         remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ?
         remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ?
                 remoteParentPath : remoteParentPath + OCFile.PATH_SEPARATOR;
                 remoteParentPath : remoteParentPath + OCFile.PATH_SEPARATOR;
 
 
+        RemoteOperationResult result = grantFolderExistence(remoteParentPath, client);
+
+        if (!result.isSuccess()) {
+            return result;
+        }
+
         OCFile parent = getStorageManager().getFileByPath(remoteParentPath);
         OCFile parent = getStorageManager().getFileByPath(remoteParentPath);
         mFile.setParentId(parent.getFileId());
         mFile.setParentId(parent.getFileId());
-        mFile.setEncrypted(parent.isEncrypted());
+
+        // check if any parent is encrypted
+        encryptedAncestor = FileStorageUtils.checkIfInEncryptedFolder(parent, getStorageManager());
+        mFile.setEncrypted(encryptedAncestor);
 
 
         // try to unlock folder with stored token, e.g. when upload needs to be resumed or app crashed
         // try to unlock folder with stored token, e.g. when upload needs to be resumed or app crashed
-        if (parent.isEncrypted() && !mFolderUnlockToken.isEmpty()) {
+        if (encryptedAncestor && !mFolderUnlockToken.isEmpty()) {
             UnlockFileOperation unlockFileOperation = new UnlockFileOperation(parent.getLocalId(), mFolderUnlockToken);
             UnlockFileOperation unlockFileOperation = new UnlockFileOperation(parent.getLocalId(), mFolderUnlockToken);
             RemoteOperationResult unlockFileOperationResult = unlockFileOperation.execute(client, true);
             RemoteOperationResult unlockFileOperationResult = unlockFileOperation.execute(client, true);
 
 
@@ -384,13 +394,7 @@ public class UploadFileOperation extends SyncOperation {
             }
             }
         }
         }
 
 
-        RemoteOperationResult result = grantFolderExistence(remoteParentPath, client);
-
-        if (!result.isSuccess()) {
-            return result;
-        }
-
-        if (parent.isEncrypted()) {
+        if (encryptedAncestor) {
             Log_OC.d(TAG, "encrypted upload");
             Log_OC.d(TAG, "encrypted upload");
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                 return encryptedUpload(client, parent);
                 return encryptedUpload(client, parent);
@@ -1332,8 +1336,7 @@ public class UploadFileOperation extends SyncOperation {
         // TODO from the appropriate OC server version, get data from last PUT response headers, instead
         // TODO from the appropriate OC server version, get data from last PUT response headers, instead
         // TODO     of a new PROPFIND; the latter may fail, specially for chunked uploads
         // TODO     of a new PROPFIND; the latter may fail, specially for chunked uploads
         String path;
         String path;
-        OCFile parent = getStorageManager().getFileByPath(file.getParentRemotePath());
-        if (parent.isEncrypted()) {
+        if (encryptedAncestor) {
             path = file.getParentRemotePath() + mFile.getEncryptedFileName();
             path = file.getParentRemotePath() + mFile.getEncryptedFileName();
         } else {
         } else {
             path = getRemotePath();
             path = getRemotePath();

+ 0 - 13
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -1180,20 +1180,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
                 }
                 }
                 mFile = directory;
                 mFile = directory;
 
 
-                // hide create new folder within encrypted folders for now
-                if (mFile.isEncrypted()) {
-                    getFabMkdir().setVisibility(View.GONE);
-                } else {
-                    getFabMkdir().setVisibility(View.VISIBLE);
-
-                    if (miniFabClicked) {
-                        ((TextView) getFabMkdir().getTag(com.getbase.floatingactionbutton.R.id.fab_label))
-                                .setVisibility(View.GONE);
-                    }
-                }
-
                 updateLayout();
                 updateLayout();
-
             }
             }
         }
         }
     }
     }

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

@@ -382,4 +382,14 @@ public class FileStorageUtils {
 
 
         return true;
         return true;
     }
     }
+
+    public static boolean checkIfInEncryptedFolder(OCFile file, FileDataStorageManager storageManager) {
+        while (!OCFile.ROOT_PATH.equals(file.getRemotePath())) {
+            if (file.isEncrypted()) {
+                return true;
+            }
+            file = storageManager.getFileById(file.getParentId());
+        }
+        return false;
+    }
 }
 }