Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix - GPlay Variant E2E Dialog #14348

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;

import javax.inject.Inject;

Expand Down Expand Up @@ -1892,38 +1891,45 @@ protected RemoteOperation getSearchRemoteOperation(final User currentUser, final
ocCapability);
}

@Subscribe(threadMode = ThreadMode.BACKGROUND)
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(EncryptionEvent event) {
final User user = accountManager.getUser();
new Thread(() -> {{
final User user = accountManager.getUser();

// check if keys are stored
String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
// check if keys are stored
String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);

FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
OCFile file = storageManager.getFileByRemoteId(event.getRemoteId());
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
OCFile file = storageManager.getFileByRemoteId(event.getRemoteId());

if (publicKey.isEmpty() || privateKey.isEmpty()) {
Log_OC.d(TAG, "no public key for " + user.getAccountName());
if (publicKey.isEmpty() || privateKey.isEmpty()) {
Log_OC.d(TAG, "no public key for " + user.getAccountName());

int position = -1;
if (file != null) {
position = mAdapter.getItemPosition(file);
int position;
if (file != null) {
position = mAdapter.getItemPosition(file);
} else {
position = -1;
}

requireActivity().runOnUiThread(() -> {
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
dialog.setTargetFragment(OCFileListFragment.this, SETUP_ENCRYPTION_REQUEST_CODE);
dialog.show(getParentFragmentManager(), SETUP_ENCRYPTION_DIALOG_TAG);
});
} else {
// TODO E2E: if encryption fails, to not set it as encrypted!
encryptFolder(file,
event.getLocalId(),
event.getRemoteId(),
event.getRemotePath(),
event.getShouldBeEncrypted(),
publicKey,
privateKey,
storageManager);
}
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
dialog.setTargetFragment(this, SETUP_ENCRYPTION_REQUEST_CODE);
dialog.show(getParentFragmentManager(), SETUP_ENCRYPTION_DIALOG_TAG);
} else {
// TODO E2E: if encryption fails, to not set it as encrypted!
encryptFolder(file,
event.getLocalId(),
event.getRemoteId(),
event.getRemotePath(),
event.getShouldBeEncrypted(),
publicKey,
privateKey,
storageManager);
}
}}).start();
}

private void encryptFolder(OCFile folder,
Expand Down Expand Up @@ -1985,15 +1991,15 @@ private void encryptFolder(OCFile folder,
throw new IllegalArgumentException("Unknown E2E version");
}

mAdapter.setEncryptionAttributeForItemID(remoteId, shouldBeEncrypted);
requireActivity().runOnUiThread(() -> mAdapter.setEncryptionAttributeForItemID(remoteId, shouldBeEncrypted));
} else if (remoteOperationResult.getHttpCode() == HttpStatus.SC_FORBIDDEN) {
Snackbar.make(getRecyclerView(),
R.string.end_to_end_encryption_folder_not_empty,
Snackbar.LENGTH_LONG).show();
requireActivity().runOnUiThread(() -> Snackbar.make(getRecyclerView(),
R.string.end_to_end_encryption_folder_not_empty,
Snackbar.LENGTH_LONG).show());
} else {
Snackbar.make(getRecyclerView(),
R.string.common_error_unknown,
Snackbar.LENGTH_LONG).show();
requireActivity().runOnUiThread(() -> Snackbar.make(getRecyclerView(),
R.string.common_error_unknown,
Snackbar.LENGTH_LONG).show());
}

} catch (Throwable e) {
Expand Down
Loading