Skip to content

Commit

Permalink
Merge pull request #113 from amberin/git-sync-requires-api-24
Browse files Browse the repository at this point in the history
Disable Git repos on API <24 (Android <7)
  • Loading branch information
amberin authored Dec 6, 2023
2 parents 19753f3 + dae0cd5 commit 0983cf2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GitSshKeyTransportSetter: GitTransportSetter {
)
}

@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
override fun getDefaultKeys(@NonNull sshDir: File): Iterable<KeyPair>? {
return if (SshKey.exists) {
listOf(SshKey.getKeyPair())
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/orgzly/android/git/SshKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object SshKey {
val exists
get() = type != null
private val mustAuthenticate: Boolean
@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
get() {
return runCatching {
if (type !in listOf(Type.KeystoreNative, Type.KeystoreWrappedEd25519)) return false
Expand Down Expand Up @@ -128,7 +128,7 @@ object SshKey {
}
}

@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
enum class Algorithm(
val algorithm: String,
val applyToSpec: KeyGenParameterSpec.Builder.() -> Unit
Expand Down Expand Up @@ -217,7 +217,7 @@ object SshKey {
type = Type.KeystoreWrappedEd25519
}

@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
fun generateKeystoreNativeKey(algorithm: Algorithm, requireAuthentication: Boolean) {
delete()

Expand Down Expand Up @@ -248,7 +248,7 @@ object SshKey {
type = Type.KeystoreNative
}

@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
fun getKeyPair(): KeyPair {
var privateKey: PrivateKey? = null
var privateKeyLoadAttempts = 0
Expand Down Expand Up @@ -348,7 +348,7 @@ object SshKey {
return KeyPair(publicKey, privateKey)
}

@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
fun promptForKeyGeneration() {
val activity = App.getCurrentActivity()
if (activity != null) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/orgzly/android/ui/SshKeygenActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
private enum class KeyGenType(val generateKey: suspend (requireAuthentication: Boolean) -> Unit) {
Rsa({ requireAuthentication ->
SshKey.generateKeystoreNativeKey(SshKey.Algorithm.Rsa, requireAuthentication)
Expand All @@ -34,7 +34,7 @@ private enum class KeyGenType(val generateKey: suspend (requireAuthentication: B
}),
}

@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
class SshKeygenActivity : CommonActivity() {

private var keyGenType = KeyGenType.Ecdsa
Expand Down Expand Up @@ -84,7 +84,7 @@ class SshKeygenActivity : CommonActivity() {
}
}
val keyguardManager: KeyguardManager = getSystemService(KEYGUARD_SERVICE) as KeyguardManager
keyRequireAuthentication.isEnabled = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
keyRequireAuthentication.isEnabled = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
false
} else {
keyguardManager.isDeviceSecure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class GitRepoActivity : CommonActivity(), GitPreferences {
return
}
val repoScheme = getRepoScheme()
@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
if (repoScheme != "https" && !SshKey.exists) {
SshKey.promptForKeyGeneration()
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP
}

// Disable Git repos completely on API < 23
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
preference(R.string.pref_key_git_is_enabled)?.let {
preferenceScreen.removePreference(it)
}
Expand Down

0 comments on commit 0983cf2

Please sign in to comment.