Skip to content

Commit 426a625

Browse files
Merge pull request #14391 from nextcloud/backport/14348/stable-3.30
[stable-3.30] BugFix - GPlay Variant E2E Dialog
2 parents 16cdc3f + 6c0ae43 commit 426a625

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,38 +1774,45 @@ protected RemoteOperation getSearchRemoteOperation(final User currentUser, final
17741774
ocCapability);
17751775
}
17761776

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

1781-
// check if keys are stored
1782-
String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
1783-
String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
1782+
// check if keys are stored
1783+
String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
1784+
String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
17841785

1785-
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
1786-
OCFile file = storageManager.getFileByRemoteId(event.getRemoteId());
1786+
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
1787+
OCFile file = storageManager.getFileByRemoteId(event.getRemoteId());
17871788

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

1791-
int position = -1;
1792-
if (file != null) {
1793-
position = mAdapter.getItemPosition(file);
1792+
int position;
1793+
if (file != null) {
1794+
position = mAdapter.getItemPosition(file);
1795+
} else {
1796+
position = -1;
1797+
}
1798+
1799+
requireActivity().runOnUiThread(() -> {
1800+
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
1801+
dialog.setTargetFragment(OCFileListFragment.this, SETUP_ENCRYPTION_REQUEST_CODE);
1802+
dialog.show(getParentFragmentManager(), SETUP_ENCRYPTION_DIALOG_TAG);
1803+
});
1804+
} else {
1805+
// TODO E2E: if encryption fails, to not set it as encrypted!
1806+
encryptFolder(file,
1807+
event.getLocalId(),
1808+
event.getRemoteId(),
1809+
event.getRemotePath(),
1810+
event.getShouldBeEncrypted(),
1811+
publicKey,
1812+
privateKey,
1813+
storageManager);
17941814
}
1795-
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
1796-
dialog.setTargetFragment(this, SETUP_ENCRYPTION_REQUEST_CODE);
1797-
dialog.show(getParentFragmentManager(), SETUP_ENCRYPTION_DIALOG_TAG);
1798-
} else {
1799-
// TODO E2E: if encryption fails, to not set it as encrypted!
1800-
encryptFolder(file,
1801-
event.getLocalId(),
1802-
event.getRemoteId(),
1803-
event.getRemotePath(),
1804-
event.getShouldBeEncrypted(),
1805-
publicKey,
1806-
privateKey,
1807-
storageManager);
1808-
}
1815+
}}).start();
18091816
}
18101817

18111818
private void encryptFolder(OCFile folder,
@@ -1867,15 +1874,15 @@ private void encryptFolder(OCFile folder,
18671874
throw new IllegalArgumentException("Unknown E2E version");
18681875
}
18691876

1870-
mAdapter.setEncryptionAttributeForItemID(remoteId, shouldBeEncrypted);
1877+
requireActivity().runOnUiThread(() -> mAdapter.setEncryptionAttributeForItemID(remoteId, shouldBeEncrypted));
18711878
} else if (remoteOperationResult.getHttpCode() == HttpStatus.SC_FORBIDDEN) {
1872-
Snackbar.make(getRecyclerView(),
1873-
R.string.end_to_end_encryption_folder_not_empty,
1874-
Snackbar.LENGTH_LONG).show();
1879+
requireActivity().runOnUiThread(() -> Snackbar.make(getRecyclerView(),
1880+
R.string.end_to_end_encryption_folder_not_empty,
1881+
Snackbar.LENGTH_LONG).show());
18751882
} else {
1876-
Snackbar.make(getRecyclerView(),
1877-
R.string.common_error_unknown,
1878-
Snackbar.LENGTH_LONG).show();
1883+
requireActivity().runOnUiThread(() -> Snackbar.make(getRecyclerView(),
1884+
R.string.common_error_unknown,
1885+
Snackbar.LENGTH_LONG).show());
18791886
}
18801887

18811888
} catch (Throwable e) {

0 commit comments

Comments
 (0)