From 041f2af0ea0f2384294434256ded7cc494679ea3 Mon Sep 17 00:00:00 2001 From: Raymond Lai Date: Sat, 23 Mar 2024 16:15:54 +0800 Subject: [PATCH 1/2] Add guard for empty ports in SSH URI Fixes #4122 --- .../filemanager/ui/dialogs/SftpConnectDialog.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/ui/dialogs/SftpConnectDialog.kt b/app/src/main/java/com/amaze/filemanager/ui/dialogs/SftpConnectDialog.kt index c6446bf3b7..e707128bd7 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/dialogs/SftpConnectDialog.kt +++ b/app/src/main/java/com/amaze/filemanager/ui/dialogs/SftpConnectDialog.kt @@ -32,7 +32,6 @@ import android.text.Editable import android.text.InputFilter import android.text.TextUtils import android.text.TextWatcher -import android.view.LayoutInflater import android.view.View import android.widget.AdapterView import android.widget.ArrayAdapter @@ -55,6 +54,7 @@ import com.amaze.filemanager.fileoperations.filesystem.OpenMode import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool.FTPS_URI_PREFIX import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool.FTP_URI_PREFIX +import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool.SSH_DEFAULT_PORT import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool.SSH_URI_PREFIX import com.amaze.filemanager.filesystem.ftp.NetCopyClientUtils import com.amaze.filemanager.filesystem.ftp.NetCopyConnectionInfo.Companion.COLON @@ -82,7 +82,6 @@ import java.io.BufferedReader import java.lang.ref.WeakReference import java.security.KeyPair import java.security.PublicKey -import java.util.* import java.util.concurrent.Callable /** SSH/SFTP connection setup dialog. */ @@ -132,7 +131,7 @@ class SftpConnectDialog : DialogFragment() { @Suppress("ComplexMethod") override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { ctx = WeakReference(activity) - binding = SftpDialogBinding.inflate(LayoutInflater.from(context)) + binding = SftpDialogBinding.inflate(layoutInflater) val utilsProvider: UtilitiesProvider = AppConfig.getInstance().utilsProvider val edit = requireArguments().getBoolean(ARG_EDIT, false) @@ -790,7 +789,13 @@ class SftpConnectDialog : DialogFragment() { prefix = getProtocolPrefixFromDropdownSelection(), connectionName = binding.connectionET.text.toString(), hostname = binding.ipET.text.toString(), - port = binding.portET.text.toString().toInt(), + port = binding.portET.text.toString().let { + if (it.isEmpty() || it.isBlank()) { + SSH_DEFAULT_PORT + } else { + it.toInt() + } + }, defaultPath = binding.defaultPathET.text.toString(), username = binding.usernameET.text.toString().urlEncoded(), password = if (true == binding.passwordET.text?.isEmpty()) { From 7e0478d3f75fa9fa57e6de41eaa409168f5d8e3a Mon Sep 17 00:00:00 2001 From: Raymond Lai Date: Tue, 20 Feb 2024 00:11:53 +0800 Subject: [PATCH 2/2] Fix UiPrefsFragmentTest failure by removing redundant languages at preference At ContextLocaleExt.kt, remove conflicting locales API 24 or above --- .../java/com/amaze/filemanager/utils/ContextLocaleExt.kt | 8 ++++++++ .../fragments/preferencefragments/UiPrefsFragmentTest.kt | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/amaze/filemanager/utils/ContextLocaleExt.kt b/app/src/main/java/com/amaze/filemanager/utils/ContextLocaleExt.kt index 5ef6bdf387..e674f6ed43 100644 --- a/app/src/main/java/com/amaze/filemanager/utils/ContextLocaleExt.kt +++ b/app/src/main/java/com/amaze/filemanager/utils/ContextLocaleExt.kt @@ -21,6 +21,8 @@ package com.amaze.filemanager.utils import android.content.Context +import android.os.Build +import android.os.Build.VERSION_CODES.N import androidx.appcompat.app.AppCompatDelegate import androidx.core.os.LocaleListCompat import com.amaze.filemanager.R @@ -50,6 +52,12 @@ fun Context.getLocaleListFromXml(): LocaleListCompat { e.printStackTrace() } + // Remove locale tags that would produce same locale on Android N or above + if (Build.VERSION.SDK_INT >= N) { + tagsList.remove("id") + tagsList.remove("he") + } + return LocaleListCompat.forLanguageTags(tagsList.joinToString(",")) } diff --git a/app/src/test/java/com/amaze/filemanager/ui/fragments/preferencefragments/UiPrefsFragmentTest.kt b/app/src/test/java/com/amaze/filemanager/ui/fragments/preferencefragments/UiPrefsFragmentTest.kt index d974fb57fa..d4c6a42981 100644 --- a/app/src/test/java/com/amaze/filemanager/ui/fragments/preferencefragments/UiPrefsFragmentTest.kt +++ b/app/src/test/java/com/amaze/filemanager/ui/fragments/preferencefragments/UiPrefsFragmentTest.kt @@ -51,7 +51,12 @@ import kotlin.random.Random * Tests for [UiPrefsFragment]. */ @Config( - sdk = [Build.VERSION_CODES.KITKAT, Build.VERSION_CODES.P, Build.VERSION_CODES.R], + sdk = [ + Build.VERSION_CODES.KITKAT, + Build.VERSION_CODES.N, + Build.VERSION_CODES.P, + Build.VERSION_CODES.R + ], shadows = [ ShadowMultiDex::class, ShadowStorageManager::class,