Compare commits

...
Author SHA1 Message Date
tobiasKaminsky 3a1a58df24 Only allow creation of encrypted folder in root
Signed-off-by: tobiasKaminsky <[email protected]>
2022-12-13 14:53:24 +01:00
tobiasKaminsky efddccf1e3 allow to create encrypted folder directly via bottom sheet dialog
Signed-off-by: tobiasKaminsky <[email protected]>
2022-12-13 14:43:36 +01:00
10 changed files with 136 additions and 23 deletions

No files matched your search

@@ -65,16 +65,31 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
private RemoteFile createdRemoteFolder;
private User user;
private Context context;
private boolean encrypted;
/**
* Constructor
*/
public CreateFolderOperation(String remotePath, User user, Context context, FileDataStorageManager storageManager) {
public CreateFolderOperation(String remotePath,
User user,
Context context,
FileDataStorageManager storageManager
) {
this(remotePath, false, user, context, storageManager);
}
public CreateFolderOperation(String remotePath,
boolean encrypted,
User user,
Context context,
FileDataStorageManager storageManager
) {
super(storageManager);
this.remotePath = remotePath;
this.user = user;
this.context = context;
this.encrypted = encrypted;
}
@Override
@@ -102,7 +117,7 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
if (encryptedAncestor) {
return encryptedCreate(parent, client);
} else {
return normalCreate(client);
return normalCreate(client, encrypted);
}
}
@@ -283,7 +298,7 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
return encryptedFileName;
}
private RemoteOperationResult normalCreate(OwnCloudClient client) {
private RemoteOperationResult normalCreate(OwnCloudClient client, boolean encrypted) {
RemoteOperationResult result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
if (result.isSuccess()) {
@@ -292,6 +307,20 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
createdRemoteFolder = (RemoteFile) remoteFolderOperationResult.getData().get(0);
saveFolderInDB();
OCFile folder = getStorageManager().getFileByDecryptedRemotePath(remotePath);
if (encrypted) {
RemoteOperationResult remoteOperationResult = new ToggleEncryptionRemoteOperation(folder.getLocalId(),
remotePath,
true)
.execute(client);
if (remoteOperationResult.isSuccess()) {
folder.setEncrypted(true);
getStorageManager().saveFile(folder);
}
}
} else {
Log_OC.e(TAG, remotePath + " hasn't been created");
}
@@ -92,6 +92,7 @@ public class OperationsService extends Service {
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public static final String EXTRA_SERVER_URL = "SERVER_URL";
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
public static final String EXTRA_ENCRYPTED = "ENCRYPTED";
public static final String EXTRA_NEWNAME = "NEWNAME";
public static final String EXTRA_REMOVE_ONLY_LOCAL = "REMOVE_LOCAL_COPY";
public static final String EXTRA_SYNC_FILE_CONTENTS = "SYNC_FILE_CONTENTS";
@@ -676,7 +677,9 @@ public class OperationsService extends Service {
case ACTION_CREATE_FOLDER:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean encrypted = operationIntent.getBooleanExtra(EXTRA_ENCRYPTED, false);
operation = new CreateFolderOperation(remotePath,
encrypted,
user,
getApplicationContext(),
fileDataStorageManager);
@@ -532,6 +532,10 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
public @Nullable
OCFile getItem(int position) {
if (position == -1) {
return null;
}
int newPosition = position;
if (shouldShowHeader() && position > 0) {
@@ -62,6 +62,7 @@ public class CreateFolderDialogFragment
extends DialogFragment implements DialogInterface.OnClickListener, Injectable {
private static final String ARG_PARENT_FOLDER = "PARENT_FOLDER";
private static final String ARG_ENCRYPTED = "ENCRYPTED";
public static final String CREATE_FOLDER_FRAGMENT = "CREATE_FOLDER_FRAGMENT";
@@ -70,8 +71,9 @@ public class CreateFolderDialogFragment
@Inject KeyboardUtils keyboardUtils;
private OCFile mParentFolder;
private OCFile parentFolder;
private Button positiveButton;
private boolean encrypted;
private EditBoxDialogBinding binding;
@@ -83,12 +85,16 @@ public class CreateFolderDialogFragment
* @return Dialog ready to show.
*/
public static CreateFolderDialogFragment newInstance(OCFile parentFolder) {
return newInstance(parentFolder, false);
}
public static CreateFolderDialogFragment newInstance(OCFile parentFolder, boolean encrypted) {
CreateFolderDialogFragment frag = new CreateFolderDialogFragment();
Bundle args = new Bundle();
args.putParcelable(ARG_PARENT_FOLDER, parentFolder);
args.putBoolean(ARG_ENCRYPTED, encrypted);
frag.setArguments(args);
return frag;
}
@Override
@@ -114,7 +120,8 @@ public class CreateFolderDialogFragment
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
mParentFolder = getArguments().getParcelable(ARG_PARENT_FOLDER);
parentFolder = getArguments().getParcelable(ARG_PARENT_FOLDER);
encrypted = getArguments().getBoolean(ARG_ENCRYPTED);
// Inflate the layout for the dialog
LayoutInflater inflater = requireActivity().getLayoutInflater();
@@ -204,9 +211,9 @@ public class CreateFolderDialogFragment
return;
}
String path = mParentFolder.getDecryptedRemotePath() + newFolderName + OCFile.PATH_SEPARATOR;
String path = parentFolder.getDecryptedRemotePath() + newFolderName + OCFile.PATH_SEPARATOR;
((ComponentsGetter) getActivity()).getFileOperationsHelper().createFolder(path);
((ComponentsGetter) getActivity()).getFileOperationsHelper().createFolder(path, encrypted);
}
}
}
@@ -23,8 +23,7 @@ package com.owncloud.android.ui.fragment;
import com.owncloud.android.lib.common.Creator;
/**
* Actions interface to be implemented by any class that makes use of
* {@link com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog}.
* Actions interface to be implemented by any class that makes use of {@link com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog}.
*/
public interface OCFileListBottomSheetActions {
/**
@@ -32,6 +31,11 @@ public interface OCFileListBottomSheetActions {
*/
void createFolder();
/**
* creates an encrypted folder within the actual folder
*/
void createEncryptedFolder();
/**
* offers a file upload with the Android OS file picker to the current folder.
*/
@@ -90,14 +90,14 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog implements In
viewThemeUtils.platform.colorImageView(binding.menuIconDirectCameraUpload);
viewThemeUtils.platform.colorImageView(binding.menuIconScanDocUpload);
viewThemeUtils.platform.colorImageView(binding.menuIconMkdir);
viewThemeUtils.platform.colorImageView(binding.menuIconEncryptedMkdir);
viewThemeUtils.platform.colorImageView(binding.menuIconAddFolderInfo);
binding.addToCloud.setText(getContext().getResources().getString(R.string.add_to_cloud,
themeUtils.getDefaultDisplayNameForRootFolder(getContext())));
OCCapability capability = fileActivity.getCapabilities();
if (capability != null &&
capability.getRichDocuments().isTrue() &&
OCCapability capability = fileActivity.getStorageManager().getCapability(user.getAccountName());
if (capability.getRichDocuments().isTrue() &&
capability.getRichDocumentsDirectEditing().isTrue() &&
capability.getRichDocumentsTemplatesAvailable().isTrue() &&
!file.isEncrypted()) {
@@ -145,6 +145,12 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog implements In
binding.menuDirectCameraUpload.setVisibility(View.GONE);
}
if (capability.getEndToEndEncryption().isTrue() && OCFile.ROOT_PATH.equals(file.getRemotePath())) {
binding.menuEncryptedMkdir.setVisibility(View.VISIBLE);
} else {
binding.menuEncryptedMkdir.setVisibility(View.GONE);
}
// create rich workspace
if (editorUtils.isEditorAvailable(user,
MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN) &&
@@ -179,6 +185,11 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog implements In
dismiss();
});
binding.menuEncryptedMkdir.setOnClickListener(v -> {
actions.createEncryptedFolder();
dismiss();
});
binding.menuUploadFromApp.setOnClickListener(v -> {
actions.uploadFromApp();
dismiss();
@@ -485,7 +485,15 @@ public class OCFileListFragment extends ExtendedListFragment implements
@Override
public void createFolder() {
CreateFolderDialogFragment.newInstance(mFile)
.show(getActivity().getSupportFragmentManager(), DIALOG_CREATE_FOLDER);
}
@Override
public void createEncryptedFolder() {
if (checkEncryptionIsSetup(null)) {
CreateFolderDialogFragment.newInstance(mFile, true)
.show(getActivity().getSupportFragmentManager(), DIALOG_CREATE_FOLDER);
}
}
@Override
@@ -495,8 +503,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
getActivity().startActivityForResult(
Intent.createChooser(action, getString(R.string.upload_chooser_title)),
FileDisplayActivity.REQUEST_CODE__SELECT_CONTENT_FROM_APPS
Intent.createChooser(action, getString(R.string.upload_chooser_title)),
FileDisplayActivity.REQUEST_CODE__SELECT_CONTENT_FROM_APPS
);
}
@@ -1079,9 +1087,11 @@ public class OCFileListFragment extends ExtendedListFragment implements
int position = data.getIntExtra(SetupEncryptionDialogFragment.ARG_POSITION, -1);
OCFile file = mAdapter.getItem(position);
if (file != null) {
mContainerActivity.getFileOperationsHelper().toggleEncryption(file, true);
if (file == null) {
return;
}
encryptFolder(file.getLocalId(), file.getRemoteId(), file.getRemotePath(), true);
// update state and view of this fragment
searchFragment = false;
@@ -1649,6 +1659,12 @@ public class OCFileListFragment extends ExtendedListFragment implements
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(EncryptionEvent event) {
if (checkEncryptionIsSetup(event.remoteId)) {
encryptFolder(event.localId, event.remoteId, event.remotePath, event.shouldBeEncrypted);
}
}
private boolean checkEncryptionIsSetup(@Nullable String remoteId) {
final User user = accountManager.getUser();
// check if keys are stored
@@ -1659,16 +1675,20 @@ public class OCFileListFragment extends ExtendedListFragment implements
Log_OC.d(TAG, "no public key for " + user.getAccountName());
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
OCFile file = storageManager.getFileByRemoteId(event.remoteId);
int position = -1;
if (file != null) {
position = mAdapter.getItemPosition(file);
if (remoteId != null) {
OCFile file = storageManager.getFileByRemoteId(remoteId);
if (file != null) {
position = mAdapter.getItemPosition(file);
}
}
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
dialog.setTargetFragment(this, SETUP_ENCRYPTION_REQUEST_CODE);
dialog.show(getParentFragmentManager(), SETUP_ENCRYPTION_DIALOG_TAG);
return false;
} else {
encryptFolder(event.localId, event.remoteId, event.remotePath, event.shouldBeEncrypted);
return true;
}
}
@@ -966,13 +966,17 @@ public class FileOperationsHelper {
}
}
public void createFolder(String remotePath) {
createFolder(remotePath, false);
}
public void createFolder(String remotePath, boolean encrypted) {
// Create Folder
Intent service = new Intent(fileActivity, OperationsService.class);
service.setAction(OperationsService.ACTION_CREATE_FOLDER);
service.putExtra(OperationsService.EXTRA_ACCOUNT, fileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);
service.putExtra(OperationsService.EXTRA_ENCRYPTED, encrypted);
mWaitingForOpId = fileActivity.getOperationsServiceBinder().queueNewOperation(service);
fileActivity.showLoadingDialog(fileActivity.getString(R.string.wait_a_moment));
@@ -183,7 +183,7 @@
android:layout_height="wrap_content"
android:contentDescription="@null"
android:src="@drawable/ic_action_create_dir"
app:tint="@color/primary"/>
app:tint="@color/primary" />
<TextView
android:layout_width="wrap_content"
@@ -193,7 +193,37 @@
android:text="@string/create_new_folder"
android:textColor="@color/text_color"
android:textSize="@dimen/bottom_sheet_text_size" />
</LinearLayout>
<LinearLayout
android:id="@+id/menu_encrypted_mkdir"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_item_height"
android:orientation="horizontal"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:paddingLeft="@dimen/standard_padding"
android:paddingTop="@dimen/standard_half_padding"
android:paddingRight="@dimen/standard_padding"
android:paddingBottom="@dimen/standard_half_padding"
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@+id/menu_icon_encrypted_mkdir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:src="@drawable/folder_encrypted"
app:tint="@color/primary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/bottom_sheet_text_start_margin"
android:text="@string/create_new_encrypted_folder"
android:textColor="@color/text_color"
android:textSize="@dimen/bottom_sheet_text_size" />
</LinearLayout>
<LinearLayout
+1
View File
@@ -743,6 +743,7 @@
<string name="upload_scan_doc_upload">Scan document from camera</string>
<string name="upload_content_from_other_apps">Upload content from other apps</string>
<string name="create_new_folder">Create new folder</string>
<string name="create_new_encrypted_folder">Create new encrypted folder</string>
<string name="uploads_view_upload_status_virus_detected">Virus detected. Upload cannot be completed!</string>
<string name="tags">Tags</string>
<string name="sharee_add_failed">Adding sharee failed</string>