From d4379a47791ea0002eda9821f35c632f1e224962 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 16 Jul 2020 12:18:38 +0530 Subject: Remove manual key selection and start actually using `.gpg-id` (#916) Co-authored-by: Aditya Wasan Co-authored-by: Fabian Henneke --- .../com/zeapo/pwdstore/crypto/BasePgpActivity.kt | 31 +++++----------------- 1 file changed, 6 insertions(+), 25 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/crypto/BasePgpActivity.kt') diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/BasePgpActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/BasePgpActivity.kt index 39164e8f..ec8e7f9b 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/BasePgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/BasePgpActivity.kt @@ -14,8 +14,6 @@ import android.os.Build import android.os.Bundle import android.text.format.DateUtils import android.view.WindowManager -import android.widget.Toast -import androidx.activity.result.ActivityResultLauncher import androidx.annotation.CallSuper import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity @@ -26,7 +24,7 @@ import com.github.ajalt.timberkt.i import com.google.android.material.snackbar.Snackbar import com.zeapo.pwdstore.ClipboardService import com.zeapo.pwdstore.R -import com.zeapo.pwdstore.UserPreference +import com.zeapo.pwdstore.utils.OPENPGP_PROVIDER import com.zeapo.pwdstore.utils.PreferenceKeys import com.zeapo.pwdstore.utils.clipboard import com.zeapo.pwdstore.utils.snackbar @@ -73,12 +71,6 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou */ val settings: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(this) } - /** - * Read-only field for getting the list of OpenPGP key IDs that we have access to. - */ - var keyIDs = emptySet() - private set - /** * Handle to the [OpenPgpApi] instance that is used by subclasses to interface with OpenKeychain. */ @@ -87,15 +79,13 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou /** * [onCreate] sets the window up with the right flags to prevent auth leaks through screenshots - * or recent apps screen and fills in [keyIDs] from [settings] + * or recent apps screen. */ @CallSuper override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE) tag(TAG) - - keyIDs = settings.getStringSet(PreferenceKeys.OPENPGP_KEY_IDS_SET, null) ?: emptySet() } /** @@ -128,20 +118,11 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou } /** - * Method for subclasses to initiate binding with [OpenPgpServiceConnection]. The design choices - * here are a bit dubious at first glance. We require passing a [ActivityResultLauncher] because - * it lets us react to having a OpenPgp provider selected without relying on the now deprecated - * [startActivityForResult]. + * Method for subclasses to initiate binding with [OpenPgpServiceConnection]. */ - fun bindToOpenKeychain(onBoundListener: OpenPgpServiceConnection.OnBound, activityResult: ActivityResultLauncher) { - val providerPackageName = settings.getString(PreferenceKeys.OPENPGP_PROVIDER_LIST, "") - if (providerPackageName.isNullOrEmpty()) { - Toast.makeText(this, resources.getString(R.string.provider_toast_text), Toast.LENGTH_LONG).show() - activityResult.launch(Intent(this, UserPreference::class.java)) - } else { - serviceConnection = OpenPgpServiceConnection(this, providerPackageName, onBoundListener) - serviceConnection?.bindToService() - } + fun bindToOpenKeychain(onBoundListener: OpenPgpServiceConnection.OnBound) { + serviceConnection = OpenPgpServiceConnection(this, OPENPGP_PROVIDER, onBoundListener) + serviceConnection?.bindToService() } /** -- cgit v1.2.3