From 31162db14511f92f1e194c2e663fe6fd07212cae Mon Sep 17 00:00:00 2001 From: HaliksaR Date: Sun, 15 Nov 2020 06:24:15 +0700 Subject: [PATCH 1/7] fix MiuiHelper npe --- .../com/vanced/manager/utils/MiuiHelper.kt | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/vanced/manager/utils/MiuiHelper.kt b/app/src/main/java/com/vanced/manager/utils/MiuiHelper.kt index 96434f46..07fe9624 100644 --- a/app/src/main/java/com/vanced/manager/utils/MiuiHelper.kt +++ b/app/src/main/java/com/vanced/manager/utils/MiuiHelper.kt @@ -6,28 +6,20 @@ import java.io.InputStreamReader object MiuiHelper { - fun isMiui(): Boolean = getSystemProps("ro.miui.ui.version.name")!!.isNotEmpty() + private const val MIUI_PROP_NAME = "ro.miui.ui.version.name" + + fun isMiui(): Boolean = !getSystemProps(MIUI_PROP_NAME).isNullOrEmpty() private fun getSystemProps(propname: String): String? { - val line: String var input: BufferedReader? = null - try { - val p = Runtime.getRuntime().exec("getprop $propname") - input = BufferedReader(InputStreamReader(p.inputStream), 1024) - line = input.readLine() - input.close() + return try { + val process = Runtime.getRuntime().exec("getprop $propname") + input = BufferedReader(InputStreamReader(process.inputStream), 1024) + input.readLine() } catch (e: IOException) { - return null + null } finally { - if (input != null) { - try { - input.close() - } catch (e: IOException) { - e.printStackTrace() - } - } + input?.close() } - return line } - } \ No newline at end of file From b7ba61b5e2dedc2386d11e379f529acaa323505e Mon Sep 17 00:00:00 2001 From: HaliksaR Date: Sun, 15 Nov 2020 06:28:11 +0700 Subject: [PATCH 2/7] fix VancedDownloader lang npe --- .../manager/core/downloader/VancedDownloader.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloader.kt b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloader.kt index d906685d..0010e4ba 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloader.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloader.kt @@ -36,7 +36,7 @@ object VancedDownloader { private var installUrl: String? = null private var variant: String? = null private var theme: String? = null - private var lang: MutableList? = null + private var lang = mutableListOf() private lateinit var themePath: String @@ -56,7 +56,9 @@ object VancedDownloader { downloadPath = context.getExternalFilesDir("vanced/$variant")?.path File(downloadPath.toString()).deleteRecursively() installUrl = defPrefs.getInstallUrl() - lang = prefs.getString("lang", getDefaultVancedLanguages())?.split(", ")?.toMutableList() + prefs.getString("lang", getDefaultVancedLanguages())?.let { + lang = it.split(", ").toMutableList() + } theme = prefs.getString("theme", "dark") vancedVersion = defPrefs.getString("vanced_version", "latest")?.getLatestAppVersion(vancedVersions.get()?.value ?: listOf("")) themePath = "$installUrl/apks/v$vancedVersion/$variant/Theme" @@ -112,7 +114,7 @@ object VancedDownloader { "lang" -> { count++ succesfulLangCount++ - if (count < lang?.size!!) + if (count < lang.size) downloadSplits(context, "lang") else startVancedInstall(context) @@ -132,9 +134,9 @@ object VancedDownloader { if (type == "lang") { count++ when { - count < lang?.size!! -> downloadSplits(context, "lang") + count < lang.size -> downloadSplits(context, "lang") succesfulLangCount == 0 -> { - lang?.add("en") + lang.add("en") downloadSplits(context, "lang") } else -> startVancedInstall(context) From 3b092c96527e481ec1d7c9dcda6a7ea41c516f3b Mon Sep 17 00:00:00 2001 From: HaliksaR Date: Sun, 15 Nov 2020 06:31:04 +0700 Subject: [PATCH 3/7] fix VancedLanguageSelectionDialog langPrefs npe --- .../vanced/manager/ui/dialogs/VancedLanguageSelectionDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/vanced/manager/ui/dialogs/VancedLanguageSelectionDialog.kt b/app/src/main/java/com/vanced/manager/ui/dialogs/VancedLanguageSelectionDialog.kt index ddfa8bf0..36bf925e 100644 --- a/app/src/main/java/com/vanced/manager/ui/dialogs/VancedLanguageSelectionDialog.kt +++ b/app/src/main/java/com/vanced/manager/ui/dialogs/VancedLanguageSelectionDialog.kt @@ -70,7 +70,7 @@ class VancedLanguageSelectionDialog : BottomSheetDialogFragment() { val loc = Locale(lang) val box: MaterialCheckBox = MaterialCheckBox(requireActivity()).apply { tag = lang - isChecked = langPrefs!!.contains(lang) + isChecked = langPrefs?.contains(lang) ?: false text = loc.getDisplayLanguage(loc).capitalize(Locale.ROOT) textSize = 18F typeface = ResourcesCompat.getFont(requireActivity(), R.font.exo_bold) From ad173c95879ae7a2c698377279560fc274f2a0ab Mon Sep 17 00:00:00 2001 From: HaliksaR Date: Sun, 15 Nov 2020 06:32:26 +0700 Subject: [PATCH 4/7] fix checkSHA256 npe --- app/src/main/java/com/vanced/manager/utils/InternetTools.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/vanced/manager/utils/InternetTools.kt b/app/src/main/java/com/vanced/manager/utils/InternetTools.kt index d189c051..10bd3a57 100644 --- a/app/src/main/java/com/vanced/manager/utils/InternetTools.kt +++ b/app/src/main/java/com/vanced/manager/utils/InternetTools.kt @@ -100,9 +100,9 @@ object InternetTools { return getJsonString(hashUrl, obj, context) } - fun checkSHA256(sha256: String, updateFile: File?): Boolean { + fun checkSHA256(sha256: String, updateFile: File): Boolean { return try { - val dataBuffer = updateFile!!.readBytes() + val dataBuffer = updateFile.readBytes() // Generate the checksum val sum = generateChecksum(dataBuffer) From 4b100b7b5721326f0be7385ad868279bc3115aff Mon Sep 17 00:00:00 2001 From: HaliksaR Date: Sun, 15 Nov 2020 06:34:03 +0700 Subject: [PATCH 5/7] fix getJson npe --- .../java/com/vanced/manager/utils/JsonHelper.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt b/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt index f2d23911..a4a5bafb 100644 --- a/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt +++ b/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt @@ -12,15 +12,11 @@ object JsonHelper { private var dataMap: HashMap = HashMap() suspend fun getJson(url: String): JsonObject? { - return try { - if(dataMap.containsKey(url)) { - dataMap[url]!! - } else { - dataMap[url] = getSuspendJson(url) - dataMap[url]!! - } - } catch (e: Exception) { - null + return if (dataMap.containsKey(url)) { + dataMap[url] + } else { + dataMap[url] = getSuspendJson(url) + dataMap[url] } } From 7d68735706f5a80f4d0c5544a73ff670b65ab94a Mon Sep 17 00:00:00 2001 From: HaliksaR Date: Sun, 15 Nov 2020 06:37:07 +0700 Subject: [PATCH 6/7] fix doCommitSession npe --- app/src/main/java/com/vanced/manager/utils/PackageHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt b/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt index 3b72d00b..20e8c3e7 100644 --- a/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt +++ b/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt @@ -298,7 +298,7 @@ object PackageHelper { } } finally { - session!!.close() + session?.close() } } From bff06750cd4cc98ec12cdfc9b047546b41ac46b0 Mon Sep 17 00:00:00 2001 From: HaliksaR Date: Sun, 15 Nov 2020 06:38:14 +0700 Subject: [PATCH 7/7] fix PackageHelper.copy npe --- app/src/main/java/com/vanced/manager/utils/PackageHelper.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt b/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt index 20e8c3e7..df07777e 100644 --- a/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt +++ b/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt @@ -579,8 +579,8 @@ object PackageHelper { @Throws(IOException::class) - fun copy(src: File?, dst: File?) { - val cmd = Shell.su("mv ${src!!.absolutePath} ${dst!!.absolutePath}").exec().isSuccess + fun copy(src: File, dst: File) { + val cmd = Shell.su("mv ${src.absolutePath} ${dst.absolutePath}").exec().isSuccess Log.d("ZLog", cmd.toString()) }