From 571ab4e78e022ba7c9f0b8e20d3dd81f371d1b3c Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 14 Sep 2021 22:37:55 +0530 Subject: [PATCH] Gopenpgp related fixes (#1503) * app: rename new crypto activities (cherry picked from commit 89be012f995b878affb7e7a592750e130c7f0f2c) * app: allow alt backends to work without OpenKeychain (cherry picked from commit 7bf9f01e5ef7bb24700ce3f242e5aabbabbff09e) * app: rename ENABLE_GOPENPGP to ENABLE_PGP_V2_BACKEND --- app/src/main/AndroidManifest.xml | 6 +++--- ...tivity.kt => AutofillDecryptActivityV2.kt} | 20 +++++++++---------- .../aps/ui/autofill/AutofillFilterActivity.kt | 4 ++-- .../aps/ui/crypto/BasePgpActivity.kt | 2 ++ ...ecryptActivity.kt => DecryptActivityV2.kt} | 15 ++++++++------ ...ivity.kt => PasswordCreationActivityV2.kt} | 14 ++++++------- .../aps/ui/passwords/PasswordStore.kt | 6 +++--- .../dev/msfjarvis/aps/util/FeatureFlags.kt | 2 +- .../autofill/Api30AutofillResponseBuilder.kt | 6 +++--- .../util/autofill/AutofillResponseBuilder.kt | 6 +++--- 10 files changed, 43 insertions(+), 38 deletions(-) rename app/src/main/java/dev/msfjarvis/aps/ui/autofill/{GopenpgpAutofillDecryptActivity.kt => AutofillDecryptActivityV2.kt} (87%) rename app/src/main/java/dev/msfjarvis/aps/ui/crypto/{GopenpgpDecryptActivity.kt => DecryptActivityV2.kt} (92%) rename app/src/main/java/dev/msfjarvis/aps/ui/crypto/{GopenpgpPasswordCreationActivity.kt => PasswordCreationActivityV2.kt} (97%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 98d28f0ae..94ad96fb8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -45,7 +45,7 @@ android:windowSoftInputMode="adjustResize" /> - @@ -137,7 +137,7 @@ android:name=".ui.autofill.AutofillDecryptActivity" android:theme="@style/NoBackgroundTheme" /> - e(e) { "Decryption with Gopenpgp failed" } + e(e) { "Decryption failed" } return null } .onSuccess { result -> diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillFilterActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillFilterActivity.kt index 1d5160e22..04fb83d56 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillFilterActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/autofill/AutofillFilterActivity.kt @@ -221,8 +221,8 @@ class AutofillFilterView : AppCompatActivity() { AutofillMatcher.addMatchFor(applicationContext, formOrigin, item.file) // intent?.extras? is checked to be non-null in onCreate decryptAction.launch( - if (FeatureFlags.ENABLE_GOPENPGP) { - GopenpgpAutofillDecryptActivity.makeDecryptFileIntent(item.file, intent!!.extras!!, this) + if (FeatureFlags.ENABLE_PGP_V2_BACKEND) { + AutofillDecryptActivityV2.makeDecryptFileIntent(item.file, intent!!.extras!!, this) } else { AutofillDecryptActivity.makeDecryptFileIntent(item.file, intent!!.extras!!, this) } diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/BasePgpActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/BasePgpActivity.kt index ee753fe5d..0a1148277 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/BasePgpActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/BasePgpActivity.kt @@ -27,6 +27,7 @@ import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint import dev.msfjarvis.aps.R import dev.msfjarvis.aps.injection.prefs.SettingsPreferences +import dev.msfjarvis.aps.util.FeatureFlags import dev.msfjarvis.aps.util.extensions.OPENPGP_PROVIDER import dev.msfjarvis.aps.util.extensions.clipboard import dev.msfjarvis.aps.util.extensions.getString @@ -126,6 +127,7 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou /** Method for subclasses to initiate binding with [OpenPgpServiceConnection]. */ fun bindToOpenKeychain(onBoundListener: OpenPgpServiceConnection.OnBound) { + if (FeatureFlags.ENABLE_PGP_V2_BACKEND) return val installed = runCatching { packageManager.getPackageInfo(OPENPGP_PROVIDER, 0) diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/GopenpgpDecryptActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivityV2.kt similarity index 92% rename from app/src/main/java/dev/msfjarvis/aps/ui/crypto/GopenpgpDecryptActivity.kt rename to app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivityV2.kt index 159354d2d..b000d21d4 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/GopenpgpDecryptActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivityV2.kt @@ -31,7 +31,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @AndroidEntryPoint -class GopenpgpDecryptActivity : BasePgpActivity() { +class DecryptActivityV2 : BasePgpActivity() { private val binding by viewBinding(DecryptLayoutBinding::inflate) @Inject lateinit var passwordEntryFactory: PasswordEntryFactory @@ -96,13 +96,16 @@ class GopenpgpDecryptActivity : BasePgpActivity() { * result triggers they can be repopulated with new data. */ private fun editPassword() { - val intent = Intent(this, PasswordCreationActivity::class.java) + val intent = Intent(this, PasswordCreationActivityV2::class.java) intent.putExtra("FILE_PATH", relativeParentPath) intent.putExtra("REPO_PATH", repoPath) - intent.putExtra(PasswordCreationActivity.EXTRA_FILE_NAME, name) - intent.putExtra(PasswordCreationActivity.EXTRA_PASSWORD, passwordEntry?.password) - intent.putExtra(PasswordCreationActivity.EXTRA_EXTRA_CONTENT, passwordEntry?.extraContentString) - intent.putExtra(PasswordCreationActivity.EXTRA_EDITING, true) + intent.putExtra(PasswordCreationActivityV2.EXTRA_FILE_NAME, name) + intent.putExtra(PasswordCreationActivityV2.EXTRA_PASSWORD, passwordEntry?.password) + intent.putExtra( + PasswordCreationActivityV2.EXTRA_EXTRA_CONTENT, + passwordEntry?.extraContentString + ) + intent.putExtra(PasswordCreationActivityV2.EXTRA_EDITING, true) startActivity(intent) finish() } diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/GopenpgpPasswordCreationActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivityV2.kt similarity index 97% rename from app/src/main/java/dev/msfjarvis/aps/ui/crypto/GopenpgpPasswordCreationActivity.kt rename to app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivityV2.kt index bbce67f38..645d6c47a 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/GopenpgpPasswordCreationActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivityV2.kt @@ -51,7 +51,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @AndroidEntryPoint -class GopenpgpPasswordCreationActivity : BasePgpActivity() { +class PasswordCreationActivityV2 : BasePgpActivity() { private val binding by viewBinding(PasswordCreationActivityBinding::inflate) @Inject lateinit var passwordEntryFactory: PasswordEntryFactory @@ -96,7 +96,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() { otpImportButton.setOnClickListener { supportFragmentManager.setFragmentResultListener( OTP_RESULT_REQUEST_KEY, - this@GopenpgpPasswordCreationActivity + this@PasswordCreationActivityV2 ) { requestKey, bundle -> if (requestKey == OTP_RESULT_REQUEST_KEY) { val contents = bundle.getString(RESULT) @@ -113,12 +113,12 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() { getString(R.string.otp_import_qr_code), getString(R.string.otp_import_manual_entry) ) - MaterialAlertDialogBuilder(this@GopenpgpPasswordCreationActivity) + MaterialAlertDialogBuilder(this@PasswordCreationActivityV2) .setItems(items) { _, index -> when (index) { 0 -> otpImportAction.launch( - IntentIntegrator(this@GopenpgpPasswordCreationActivity) + IntentIntegrator(this@PasswordCreationActivityV2) .setOrientationLocked(false) .setBeepEnabled(false) .setDesiredBarcodeFormats(QR_CODE) @@ -156,7 +156,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() { // in the encrypted extras. This only makes sense if the directory structure is // FileBased. if (suggestedName == null && - AutofillPreferences.directoryStructure(this@GopenpgpPasswordCreationActivity) == + AutofillPreferences.directoryStructure(this@PasswordCreationActivityV2) == DirectoryStructure.FileBased ) { encryptUsername.apply { @@ -367,7 +367,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() { val oldFile = File("$repoPath/${oldCategory?.trim('/')}/$oldFileName.gpg") if (oldFile.path != file.path && !oldFile.delete()) { setResult(RESULT_CANCELED) - MaterialAlertDialogBuilder(this@GopenpgpPasswordCreationActivity) + MaterialAlertDialogBuilder(this@PasswordCreationActivityV2) .setTitle(R.string.password_creation_file_fail_title) .setMessage( getString(R.string.password_creation_file_delete_fail_message, oldFileName) @@ -395,7 +395,7 @@ class GopenpgpPasswordCreationActivity : BasePgpActivity() { if (e is IOException) { e(e) { "Failed to write password file" } setResult(RESULT_CANCELED) - MaterialAlertDialogBuilder(this@GopenpgpPasswordCreationActivity) + MaterialAlertDialogBuilder(this@PasswordCreationActivityV2) .setTitle(getString(R.string.password_creation_file_fail_title)) .setMessage(getString(R.string.password_creation_file_write_fail_message)) .setCancelable(false) diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt index cd720d3c2..a44d4ed0d 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt @@ -39,7 +39,7 @@ import dev.msfjarvis.aps.data.password.PasswordItem import dev.msfjarvis.aps.data.repo.PasswordRepository import dev.msfjarvis.aps.ui.crypto.BasePgpActivity.Companion.getLongName import dev.msfjarvis.aps.ui.crypto.DecryptActivity -import dev.msfjarvis.aps.ui.crypto.GopenpgpDecryptActivity +import dev.msfjarvis.aps.ui.crypto.DecryptActivityV2 import dev.msfjarvis.aps.ui.crypto.PasswordCreationActivity import dev.msfjarvis.aps.ui.dialogs.BasicBottomSheet import dev.msfjarvis.aps.ui.dialogs.FolderCreationDialogFragment @@ -426,8 +426,8 @@ class PasswordStore : BaseGitActivity() { (authDecryptIntent.clone() as Intent).setComponent( ComponentName( this, - if (FeatureFlags.ENABLE_GOPENPGP) { - GopenpgpDecryptActivity::class.java + if (FeatureFlags.ENABLE_PGP_V2_BACKEND) { + DecryptActivityV2::class.java } else { DecryptActivity::class.java } diff --git a/app/src/main/java/dev/msfjarvis/aps/util/FeatureFlags.kt b/app/src/main/java/dev/msfjarvis/aps/util/FeatureFlags.kt index 09544267e..59fe361d7 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/FeatureFlags.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/FeatureFlags.kt @@ -2,5 +2,5 @@ package dev.msfjarvis.aps.util /** Naive feature flagging functionality to allow merging incomplete features */ object FeatureFlags { - const val ENABLE_GOPENPGP = false + const val ENABLE_PGP_V2_BACKEND = false } diff --git a/app/src/main/java/dev/msfjarvis/aps/util/autofill/Api30AutofillResponseBuilder.kt b/app/src/main/java/dev/msfjarvis/aps/util/autofill/Api30AutofillResponseBuilder.kt index 80891f3a0..14cc634cc 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/autofill/Api30AutofillResponseBuilder.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/autofill/Api30AutofillResponseBuilder.kt @@ -22,10 +22,10 @@ import com.github.androidpasswordstore.autofillparser.fillWith import com.github.michaelbull.result.fold import dev.msfjarvis.aps.autofill.oreo.ui.AutofillSmsActivity import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivity +import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivityV2 import dev.msfjarvis.aps.ui.autofill.AutofillFilterView import dev.msfjarvis.aps.ui.autofill.AutofillPublisherChangedActivity import dev.msfjarvis.aps.ui.autofill.AutofillSaveActivity -import dev.msfjarvis.aps.ui.autofill.GopenpgpAutofillDecryptActivity import dev.msfjarvis.aps.util.FeatureFlags import java.io.File @@ -71,8 +71,8 @@ class Api30AutofillResponseBuilder(form: FillableForm) { if (!scenario.hasFieldsToFillOn(AutofillAction.Match)) return null val metadata = makeFillMatchMetadata(context, file) val intentSender = - if (FeatureFlags.ENABLE_GOPENPGP) { - GopenpgpAutofillDecryptActivity.makeDecryptFileIntentSender(file, context) + if (FeatureFlags.ENABLE_PGP_V2_BACKEND) { + AutofillDecryptActivityV2.makeDecryptFileIntentSender(file, context) } else { AutofillDecryptActivity.makeDecryptFileIntentSender(file, context) } diff --git a/app/src/main/java/dev/msfjarvis/aps/util/autofill/AutofillResponseBuilder.kt b/app/src/main/java/dev/msfjarvis/aps/util/autofill/AutofillResponseBuilder.kt index 2f3568c47..1a825de81 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/autofill/AutofillResponseBuilder.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/autofill/AutofillResponseBuilder.kt @@ -22,10 +22,10 @@ import com.github.androidpasswordstore.autofillparser.fillWith import com.github.michaelbull.result.fold import dev.msfjarvis.aps.autofill.oreo.ui.AutofillSmsActivity import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivity +import dev.msfjarvis.aps.ui.autofill.AutofillDecryptActivityV2 import dev.msfjarvis.aps.ui.autofill.AutofillFilterView import dev.msfjarvis.aps.ui.autofill.AutofillPublisherChangedActivity import dev.msfjarvis.aps.ui.autofill.AutofillSaveActivity -import dev.msfjarvis.aps.ui.autofill.GopenpgpAutofillDecryptActivity import dev.msfjarvis.aps.util.FeatureFlags import java.io.File @@ -59,8 +59,8 @@ class AutofillResponseBuilder(form: FillableForm) { if (!scenario.hasFieldsToFillOn(AutofillAction.Match)) return null val metadata = makeFillMatchMetadata(context, file) val intentSender = - if (FeatureFlags.ENABLE_GOPENPGP) { - GopenpgpAutofillDecryptActivity.makeDecryptFileIntentSender(file, context) + if (FeatureFlags.ENABLE_PGP_V2_BACKEND) { + AutofillDecryptActivityV2.makeDecryptFileIntentSender(file, context) } else { AutofillDecryptActivity.makeDecryptFileIntentSender(file, context) }