diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2021-05-30 02:59:13 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2021-05-30 11:43:54 +0530 |
commit | 5e9a91a3b821e356f74f1728372a58220c49069c (patch) | |
tree | 5724c6254eb6761074a8eef56d56ac48383d9a8c /app | |
parent | 434329268a8410e817af1007165065e838c3f1fc (diff) |
app: replace some uses of getEncryptedGitPrefs
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app')
3 files changed, 30 insertions, 6 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt index 1d917a3a..b3155264 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt @@ -4,6 +4,7 @@ */ package dev.msfjarvis.aps.ui.git.base +import android.content.SharedPreferences import androidx.appcompat.app.AppCompatActivity import androidx.core.content.edit import com.github.ajalt.timberkt.d @@ -14,7 +15,7 @@ import com.github.michaelbull.result.mapError import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import dev.msfjarvis.aps.R -import dev.msfjarvis.aps.util.extensions.getEncryptedGitPrefs +import dev.msfjarvis.aps.injection.prefs.GitPreferences import dev.msfjarvis.aps.util.extensions.sharedPrefs import dev.msfjarvis.aps.util.git.ErrorMessages import dev.msfjarvis.aps.util.git.operation.BreakOutOfDetached @@ -52,6 +53,7 @@ abstract class BaseGitActivity : ContinuationContainerActivity() { } @Inject lateinit var gitSettings: GitSettings + @GitPreferences @Inject lateinit var gitPrefs: SharedPreferences /** * Attempt to launch the requested Git operation. @@ -85,7 +87,7 @@ abstract class BaseGitActivity : ContinuationContainerActivity() { suspend fun promptOnErrorHandler(err: Throwable, onPromptDone: () -> Unit = {}) { val error = rootCauseException(err) if (!isExplicitlyUserInitiatedError(error)) { - getEncryptedGitPrefs().edit { remove(PreferenceKeys.HTTPS_PASSWORD) } + gitPrefs.edit { remove(PreferenceKeys.HTTPS_PASSWORD) } sharedPrefs.edit { remove(PreferenceKeys.SSH_OPENKEYSTORE_KEYID) } d(error) withContext(Dispatchers.Main) { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt index cc2cd4c7..83f44aa6 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt @@ -4,6 +4,7 @@ */ package dev.msfjarvis.aps.ui.sshkeygen +import android.content.SharedPreferences import android.os.Bundle import android.security.keystore.UserNotAuthenticatedException import android.view.MenuItem @@ -16,13 +17,15 @@ import androidx.lifecycle.lifecycleScope import com.github.michaelbull.result.fold import com.github.michaelbull.result.runCatching import com.google.android.material.dialog.MaterialAlertDialogBuilder +import dagger.hilt.android.AndroidEntryPoint import dev.msfjarvis.aps.R import dev.msfjarvis.aps.databinding.ActivitySshKeygenBinding +import dev.msfjarvis.aps.injection.prefs.GitPreferences import dev.msfjarvis.aps.util.auth.BiometricAuthenticator -import dev.msfjarvis.aps.util.extensions.getEncryptedGitPrefs import dev.msfjarvis.aps.util.extensions.keyguardManager import dev.msfjarvis.aps.util.extensions.viewBinding import dev.msfjarvis.aps.util.git.sshj.SshKey +import javax.inject.Inject import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine import kotlinx.coroutines.Dispatchers @@ -41,10 +44,12 @@ private enum class KeyGenType(val generateKey: suspend (requireAuthentication: B }), } +@AndroidEntryPoint class SshKeyGenActivity : AppCompatActivity() { private var keyGenType = KeyGenType.Ecdsa private val binding by viewBinding(ActivitySshKeygenBinding::inflate) + @GitPreferences @Inject lateinit var gitPrefs: SharedPreferences override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -129,7 +134,7 @@ class SshKeyGenActivity : AppCompatActivity() { keyGenType.generateKey(requireAuthentication) } } - getEncryptedGitPrefs().edit { remove("ssh_key_local_passphrase") } + gitPrefs.edit { remove("ssh_key_local_passphrase") } binding.generate.apply { text = getString(R.string.ssh_keygen_generate) isEnabled = true diff --git a/app/src/main/java/dev/msfjarvis/aps/util/git/operation/CredentialFinder.kt b/app/src/main/java/dev/msfjarvis/aps/util/git/operation/CredentialFinder.kt index e06cc996..8f9b5efc 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/git/operation/CredentialFinder.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/git/operation/CredentialFinder.kt @@ -6,6 +6,7 @@ package dev.msfjarvis.aps.util.git.operation import android.annotation.SuppressLint +import android.content.SharedPreferences import android.view.LayoutInflater import androidx.annotation.StringRes import androidx.core.content.edit @@ -15,8 +16,12 @@ import com.google.android.material.checkbox.MaterialCheckBox import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputLayout +import dagger.hilt.EntryPoint +import dagger.hilt.InstallIn +import dagger.hilt.android.EntryPointAccessors +import dagger.hilt.components.SingletonComponent import dev.msfjarvis.aps.R -import dev.msfjarvis.aps.util.extensions.getEncryptedGitPrefs +import dev.msfjarvis.aps.injection.prefs.GitPreferences import dev.msfjarvis.aps.util.extensions.requestInputFocusOnView import dev.msfjarvis.aps.util.git.sshj.InteractivePasswordFinder import dev.msfjarvis.aps.util.settings.AuthMode @@ -27,8 +32,14 @@ import kotlin.coroutines.resume class CredentialFinder(val callingActivity: FragmentActivity, val authMode: AuthMode) : InteractivePasswordFinder() { + private val hiltEntryPoint = + EntryPointAccessors.fromApplication( + callingActivity.applicationContext, + CredentialFinderEntryPoint::class.java, + ) + override fun askForPassword(cont: Continuation<String?>, isRetry: Boolean) { - val gitOperationPrefs = callingActivity.getEncryptedGitPrefs() + val gitOperationPrefs = hiltEntryPoint.gitPrefs() val credentialPref: String @StringRes val messageRes: Int @StringRes val hintRes: Int @@ -96,4 +107,10 @@ class CredentialFinder(val callingActivity: FragmentActivity, val authMode: Auth cont.resume(storedCredential) } } + + @EntryPoint + @InstallIn(SingletonComponent::class) + interface CredentialFinderEntryPoint { + @GitPreferences fun gitPrefs(): SharedPreferences + } } |