Skip to content

Commit 49e85d0

Browse files
Merge pull request #16638 from nextcloud/feat/show-indicator-during-decrypting
style(setup-encryption-dialog): show progress bar during decryption
2 parents f38124a + c7fc1d6 commit 49e85d0

2 files changed

Lines changed: 77 additions & 55 deletions

File tree

app/src/main/java/com/owncloud/android/ui/dialog/setupEncryption/SetupEncryptionDialogFragment.kt

Lines changed: 65 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class SetupEncryptionDialogFragment :
115115

116116
// Setup layout
117117
viewThemeUtils.material.colorTextInputLayout(binding.encryptionPasswordInputContainer)
118+
viewThemeUtils.material.colorProgressBar(binding.progressBar)
118119

119120
val builder = buildMaterialAlertDialog(binding.root)
120121
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(requireContext(), builder)
@@ -158,70 +159,79 @@ class SetupEncryptionDialogFragment :
158159
private fun decryptPrivateKey(dialog: DialogInterface) {
159160
Log_OC.d(TAG, "Decrypt private key")
160161
binding.encryptionStatus.setText(R.string.end_to_end_encryption_decrypting)
162+
binding.progressBar.visibility = View.VISIBLE
161163

162-
try {
163-
if (downloadKeyResult !is DownloadKeyResult.Success) {
164-
Log_OC.d(TAG, "DownloadKeyResult is not success")
165-
return
166-
}
164+
lifecycleScope.launch(Dispatchers.IO) {
165+
try {
166+
if (downloadKeyResult !is DownloadKeyResult.Success) {
167+
Log_OC.d(TAG, "DownloadKeyResult is not success")
168+
return@launch
169+
}
167170

168-
val privateKey = (downloadKeyResult as DownloadKeyResult.Success).privateKey
169-
if (privateKey.isNullOrEmpty()) {
170-
Log_OC.e(TAG, "privateKey is null or empty")
171-
return
172-
}
173-
val mnemonicUnchanged = binding.encryptionPasswordInput.text.toString().trim()
174-
val mnemonic =
175-
binding.encryptionPasswordInput.text.toString().replace("\\s".toRegex(), "")
176-
.lowercase()
177-
val decryptedPrivateKey = CryptoHelper.decryptPrivateKey(
178-
privateKey,
179-
mnemonic
180-
)
181-
val accountName = user?.accountName ?: return
171+
val privateKey = (downloadKeyResult as DownloadKeyResult.Success).privateKey
172+
if (privateKey.isNullOrEmpty()) {
173+
Log_OC.e(TAG, "privateKey is null or empty")
174+
return@launch
175+
}
176+
val mnemonicUnchanged = binding.encryptionPasswordInput.text.toString().trim()
177+
val mnemonic =
178+
binding.encryptionPasswordInput.text.toString().replace("\\s".toRegex(), "")
179+
.lowercase()
180+
val decryptedPrivateKey = CryptoHelper.decryptPrivateKey(
181+
privateKey,
182+
mnemonic
183+
)
184+
val accountName = user?.accountName ?: return@launch
182185

183-
arbitraryDataProvider?.storeOrUpdateKeyValue(
184-
accountName,
185-
EncryptionUtils.PRIVATE_KEY,
186-
decryptedPrivateKey
187-
)
188-
dialog.dismiss()
186+
arbitraryDataProvider?.storeOrUpdateKeyValue(
187+
accountName,
188+
EncryptionUtils.PRIVATE_KEY,
189+
decryptedPrivateKey
190+
)
189191

190-
Log_OC.d(TAG, "Private key successfully decrypted and stored")
192+
Log_OC.d(TAG, "Private key successfully decrypted and stored")
191193

192-
arbitraryDataProvider?.storeOrUpdateKeyValue(
193-
accountName,
194-
EncryptionUtils.MNEMONIC,
195-
mnemonicUnchanged
196-
)
194+
arbitraryDataProvider?.storeOrUpdateKeyValue(
195+
accountName,
196+
EncryptionUtils.MNEMONIC,
197+
mnemonicUnchanged
198+
)
197199

198-
// check if private key and public key match
199-
val publicKey = arbitraryDataProvider?.getValue(
200-
accountName,
201-
EncryptionUtils.PUBLIC_KEY
202-
)
200+
// check if private key and public key match
201+
val publicKey = arbitraryDataProvider?.getValue(
202+
accountName,
203+
EncryptionUtils.PUBLIC_KEY
204+
)
203205

204-
val firstKey = EncryptionUtils.generateKey()
205-
val base64encodedKey = EncryptionUtils.encodeBytesToBase64String(firstKey)
206-
val encryptedString = EncryptionUtils.encryptStringAsymmetric(
207-
base64encodedKey,
208-
publicKey
209-
)
210-
val decryptedString = EncryptionUtils.decryptStringAsymmetric(
211-
encryptedString,
212-
decryptedPrivateKey
213-
)
214-
val secondKey = EncryptionUtils.decodeStringToBase64Bytes(decryptedString)
206+
val firstKey = EncryptionUtils.generateKey()
207+
val base64encodedKey = EncryptionUtils.encodeBytesToBase64String(firstKey)
208+
val encryptedString = EncryptionUtils.encryptStringAsymmetric(
209+
base64encodedKey,
210+
publicKey
211+
)
212+
val decryptedString = EncryptionUtils.decryptStringAsymmetric(
213+
encryptedString,
214+
decryptedPrivateKey
215+
)
216+
val secondKey = EncryptionUtils.decodeStringToBase64Bytes(decryptedString)
215217

216-
if (!firstKey.contentEquals(secondKey)) {
217-
EncryptionUtils.reportE2eError(arbitraryDataProvider, user)
218-
throw Exception("Keys do not match")
219-
}
218+
if (!firstKey.contentEquals(secondKey)) {
219+
EncryptionUtils.reportE2eError(arbitraryDataProvider, user)
220+
throw Exception("Keys do not match")
221+
}
220222

221-
notifyResult()
222-
} catch (e: Exception) {
223-
binding.encryptionStatus.setText(R.string.end_to_end_encryption_wrong_password)
224-
Log_OC.e(TAG, "Error while decrypting private key: " + e.message)
223+
withContext(Dispatchers.Main) {
224+
dialog.dismiss()
225+
notifyResult()
226+
}
227+
} catch (e: Exception) {
228+
Log_OC.e(TAG, "Error while decrypting private key: " + e.message)
229+
230+
withContext(Dispatchers.Main) {
231+
binding.encryptionStatus.setText(R.string.end_to_end_encryption_wrong_password)
232+
binding.progressBar.visibility = View.GONE
233+
}
234+
}
225235
}
226236
}
227237

app/src/main/res/layout/setup_encryption_dialog.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
xmlns:tools="http://schemas.android.com/tools"
1212
android:layout_width="match_parent"
1313
android:layout_height="match_parent"
14+
xmlns:app="http://schemas.android.com/apk/res-auto"
1415
android:gravity="clip_horizontal"
1516
android:orientation="vertical"
1617
android:padding="@dimen/dialog_padding">
@@ -35,6 +36,17 @@
3536
tools:text="@string/placeholder_passphrase"
3637
tools:visibility="visible" />
3738

39+
<com.google.android.material.progressindicator.LinearProgressIndicator
40+
android:id="@+id/progressBar"
41+
android:layout_width="match_parent"
42+
android:layout_height="wrap_content"
43+
android:layout_marginBottom="@dimen/standard_margin"
44+
android:visibility="gone"
45+
tools:visibility="visible"
46+
android:indeterminate="true"
47+
app:indicatorColor="?attr/colorPrimary"
48+
app:trackColor="?attr/colorSurfaceContainerHighest" />
49+
3850
<com.google.android.material.textfield.TextInputLayout
3951
android:id="@+id/encryption_passwordInput_container"
4052
android:layout_width="match_parent"

0 commit comments

Comments
 (0)