app: replace some uses of getEncryptedGitPrefs
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
434329268a
commit
5e9a91a3b8
3 changed files with 30 additions and 6 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue