From 3f53180b1d8f915ec33508302dd523d17fb8d9b9 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Sat, 31 Aug 2024 19:51:32 +0200 Subject: [PATCH] Unify the check for NativeFileSystem support --- src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.kt | 8 ++++---- .../kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.kt | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.kt b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.kt index 5bcb5ce3..9cb716bc 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.kt +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.kt @@ -41,7 +41,7 @@ class SftpPlugin : Plugin(), OnSharedPreferenceChangeListener { override fun onCreate(): Boolean = true override fun checkRequiredPermissions(): Boolean { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + return if (SimpleSftpServer.SUPPORTS_NATIVEFS) { Environment.isExternalStorageManager() } else { SftpSettingsFragment.getStorageInfoList(context, this).size != 0 @@ -49,7 +49,7 @@ class SftpPlugin : Plugin(), OnSharedPreferenceChangeListener { } override val permissionExplanationDialog: AlertDialogFragment - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + get() = if (SimpleSftpServer.SUPPORTS_NATIVEFS) { StartActivityAlertDialogFragment.Builder() .setTitle(displayName) .setMessage(R.string.sftp_manage_storage_permission_explanation) @@ -90,7 +90,7 @@ class SftpPlugin : Plugin(), OnSharedPreferenceChangeListener { val paths = mutableListOf() val pathNames = mutableListOf() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (SimpleSftpServer.SUPPORTS_NATIVEFS) { val volumes = context.getSystemService( StorageManager::class.java ).storageVolumes @@ -200,7 +200,7 @@ class SftpPlugin : Plugin(), OnSharedPreferenceChangeListener { override val outgoingPacketTypes: Array = arrayOf(PACKET_TYPE_SFTP) - override fun hasSettings(): Boolean = Build.VERSION.SDK_INT < Build.VERSION_CODES.R + override fun hasSettings(): Boolean = !SimpleSftpServer.SUPPORTS_NATIVEFS override fun supportsDeviceSpecificSettings(): Boolean = true diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.kt b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.kt index c1c18a00..e6d24f3f 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.kt +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.kt @@ -86,7 +86,7 @@ internal class SimpleSftpServer { fun initialize(context: Context, device: Device) { val sshd = ServerBuilder.builder().apply { fileSystemFactory( - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (SUPPORTS_NATIVEFS) { NativeFileSystemFactory() } else { safFileSystemFactory = SafFileSystemFactory(context) @@ -262,6 +262,8 @@ internal class SimpleSftpServer { companion object { private const val TAG = "SimpleSftpServer" + val SUPPORTS_NATIVEFS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R + private val PORT_RANGE = 1739..1764 const val USER: String = "kdeconnect"