Search in sources :

Example 6 with ToggleEncryptionRemoteOperation

use of com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation in project android by nextcloud.

the class OCFileListFragment method onMessageEvent.

@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(EncryptionEvent event) {
    final User user = accountManager.getUser();
    try {
        OwnCloudClient client = clientFactory.create(user);
        RemoteOperationResult remoteOperationResult = new ToggleEncryptionRemoteOperation(event.localId, event.remotePath, event.shouldBeEncrypted).execute(client);
        if (remoteOperationResult.isSuccess()) {
            mAdapter.setEncryptionAttributeForItemID(event.remoteId, event.shouldBeEncrypted);
            // check if keys are stored
            ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(requireContext().getContentResolver());
            String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
            String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
            if (publicKey.isEmpty() || privateKey.isEmpty()) {
                Log_OC.d(TAG, "no public key for " + user.getAccountName());
                FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
                int position = mAdapter.getItemPosition(storageManager.getFileByRemoteId(event.remoteId));
                SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
                dialog.setTargetFragment(this, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_REQUEST_CODE);
                dialog.show(getParentFragmentManager(), SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG);
            }
        } else if (remoteOperationResult.getHttpCode() == HttpStatus.SC_FORBIDDEN) {
            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();
        }
    } catch (ClientFactory.CreationException e) {
        Log_OC.e(TAG, "Cannot create client", e);
    }
}
Also used : User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ClientFactory(com.nextcloud.client.network.ClientFactory) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) SetupEncryptionDialogFragment(com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment) ToggleEncryptionRemoteOperation(com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

ToggleEncryptionRemoteOperation (com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation)6 OCFile (com.owncloud.android.datamodel.OCFile)4 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)3 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)2 ReadFolderRemoteOperation (com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation)2 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)2 User (com.nextcloud.client.account.User)1 ClientFactory (com.nextcloud.client.network.ClientFactory)1 DecryptedFolderMetadata (com.owncloud.android.datamodel.DecryptedFolderMetadata)1 EncryptedFolderMetadata (com.owncloud.android.datamodel.EncryptedFolderMetadata)1 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)1 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)1 CreateFolderRemoteOperation (com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation)1 RemoveFileRemoteOperation (com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation)1 RemoveFileOperation (com.owncloud.android.operations.RemoveFileOperation)1 SetupEncryptionDialogFragment (com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment)1 File (java.io.File)1 Subscribe (org.greenrobot.eventbus.Subscribe)1 Test (org.junit.Test)1