diff --git a/app/src/main/kotlin/com/fox2code/mmm/NotificationType.kt b/app/src/main/kotlin/com/fox2code/mmm/NotificationType.kt index fa5254cc..16ad9ac8 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/NotificationType.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/NotificationType.kt @@ -261,7 +261,10 @@ enum class NotificationType constructor( // Find the line with id=, and check if it matches the regex BufferedReader(InputStreamReader(zipFile.getInputStream(moduleProp))).use { reader -> var line: String - while (reader.readLine().also { line = it } != null) { + val iterator = reader.lineSequence().iterator() + // same as above but use iterator + while (iterator.hasNext()) { + line = iterator.next() if (line.startsWith("id=")) { val id = line.substring(3) return id.isEmpty() || !id.matches(Regex("^[a-zA-Z][a-zA-Z0-9._-]+$")) diff --git a/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyActivity.kt b/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyActivity.kt index 11334c5f..d22871f9 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyActivity.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyActivity.kt @@ -332,8 +332,14 @@ class AndroidacyActivity : FoxActivity() { } } wbv?.setDownloadListener(DownloadListener setDownloadListener@{ downloadUrl: String, _: String?, _: String?, _: String?, _: Long -> - if (downloadMode || isDownloadUrl(downloadUrl)) return@setDownloadListener + Timber.i("Downloadable URL: %s", downloadUrl) + val pageUrl = wbv.url + if (downloadMode && isDownloadUrl(downloadUrl)) { + megaIntercept(pageUrl, downloadUrl) + } + Timber.i("Download mode is on") if (AndroidacyUtil.isAndroidacyLink(downloadUrl) && !backOnResume) { + Timber.i("Androidacy link detected") val androidacyWebAPI = androidacyWebAPI if (androidacyWebAPI != null) { if (!androidacyWebAPI.downloadMode) { @@ -342,6 +348,7 @@ class AndroidacyActivity : FoxActivity() { // Workaround Androidacy bug val moduleId = moduleIdOfUrl(downloadUrl) if (megaIntercept(wbv.url, downloadUrl)) { + Timber.i("megaIntercept failure 2. Forcing onBackPress") // Block request as Androidacy doesn't allow duplicate requests return@setDownloadListener } else if (moduleId != null) { @@ -356,8 +363,8 @@ class AndroidacyActivity : FoxActivity() { backOnResume = true Timber.i("Exiting WebView %s", AndroidacyUtil.hideToken(downloadUrl)) for (prefix in arrayOf( - "https://production-api.androidacy.com/downloads/", - "https://staging-api.androidacy.com/magisk/downloads/" + "https://production-api.androidacy.com/magisk/file//", + "https://staging-api.androidacy.com/magisk/file/" )) { if (downloadUrl.startsWith(prefix)) { return@setDownloadListener @@ -388,8 +395,8 @@ class AndroidacyActivity : FoxActivity() { private fun moduleIdOfUrl(url: String): String? { for (prefix in arrayOf( - "https://production-api.androidacy.com/downloads/", - "https://staging-api.androidacy.com/downloads/", + "https://production-api.androidacy.com/magisk/file/", + "https://staging-api.androidacy.com/magisk/file/", "https://production-api.androidacy.com/magisk/readme/", "https://staging-api.androidacy.com/magisk/readme/", "https://prodiuction-api.androidacy.com/magisk/info/", @@ -416,20 +423,27 @@ class AndroidacyActivity : FoxActivity() { private fun isFileUrl(url: String?): Boolean { if (url == null) return false for (prefix in arrayOf( - "https://production-api.androidacy.com/downloads/", - "https://staging-api.androidacy.com/downloads/" + "https://production-api.androidacy.com/magisk/file/", + "https://staging-api.androidacy.com/magisk/file/" )) { // Make both staging and non staging act the same - if (url.startsWith(prefix)) return true + if (url.startsWith(prefix)) { + Timber.i("File URL: %s", url) + return true + } + } return false } private fun isDownloadUrl(url: String): Boolean { for (prefix in arrayOf( - "https://production-api.androidacy.com/magisk/downloads/", - "https://staging-api.androidacy.com/magisk/downloads/" + "https://production-api.androidacy.com/magisk/file/", + "https://staging-api.androidacy.com/magisk/file/" )) { // Make both staging and non staging act the same - if (url.startsWith(prefix)) return true + if (url.startsWith(prefix)) { + Timber.i("Download URL: %s", url) + return true + } } return false } @@ -437,7 +451,8 @@ class AndroidacyActivity : FoxActivity() { private fun megaIntercept(pageUrl: String?, fileUrl: String?): Boolean { if (pageUrl == null || fileUrl == null) return false // ensure neither pageUrl nor fileUrl are going to cause a crash - if (pageUrl.contains(" ") || fileUrl.contains(" ")) return false + pageUrl.replace(" ", "%20") + fileUrl.replace(" ", "%20") if (!isFileUrl(fileUrl)) { return false } diff --git a/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyUtil.kt b/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyUtil.kt index d7f03f1b..57c59600 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyUtil.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyUtil.kt @@ -101,7 +101,7 @@ enum class AndroidacyUtil { } fun getChecksumFromURL(moduleUrl: String): String? { - // Get the &version= part + // Get the checksum query param val i = moduleUrl.indexOf("&checksum=") // Match until next & or end if (i != -1) { diff --git a/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerActivity.kt b/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerActivity.kt index 79b4ee13..1beb1489 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerActivity.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerActivity.kt @@ -164,8 +164,7 @@ class InstallerActivity : FoxActivity() { val horizontalScroller = findViewById(R.id.install_horizontal_scroller) var installTerminal: RecyclerView progressIndicator = findViewById(R.id.progress_bar) - val bottomNavigationView = findViewById(R.id.bottom_navigation) - rebootFloatingButton = bottomNavigationView.findViewById(R.id.install_terminal_reboot_fab) + rebootFloatingButton = findViewById(R.id.install_terminal_reboot_fab) cancelFloatingButton = findViewById(R.id.back_installer) val rbtBtn = rebootFloatingButton val cnlBtn = cancelFloatingButton @@ -414,7 +413,10 @@ class InstallerActivity : FoxActivity() { val bufferedReader = BufferedReader(InputStreamReader(zipFile.getInputStream(updateBinary))) var line: String - while (bufferedReader.readLine().also { line = it } != null) { + val iterator = bufferedReader.lineSequence().iterator() + // same as above, but with the iterator + while (iterator.hasNext()) { + line = iterator.next() if (line.contains("AnyKernel3")) { anyKernel3 = true break diff --git a/app/src/main/kotlin/com/fox2code/mmm/manager/ModuleManager.kt b/app/src/main/kotlin/com/fox2code/mmm/manager/ModuleManager.kt index f785b083..a06d8b3c 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/manager/ModuleManager.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/manager/ModuleManager.kt @@ -274,7 +274,9 @@ class ModuleManager private constructor() : SyncManager() { ) ).use { bufferedReader -> var line: String - while (bufferedReader.readLine().also { line = it } != null) { + val iterator = bufferedReader.lineSequence().iterator() + while (iterator.hasNext()) { + line = iterator.next() line = line.trim { it <= ' ' }.replace(' ', '.') if (!line.startsWith("/data/adb/") || line.contains("*") || line.contains("/../") || line.endsWith( "/.." diff --git a/app/src/main/kotlin/com/fox2code/mmm/utils/ZipFileOpener.kt b/app/src/main/kotlin/com/fox2code/mmm/utils/ZipFileOpener.kt index 06d77892..b59e20c8 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/utils/ZipFileOpener.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/utils/ZipFileOpener.kt @@ -68,8 +68,21 @@ class ZipFileOpener : FoxActivity() { } val buffer = ByteArray(4096) var read: Int - while (inputStream.read(buffer).also { read = it } != -1) { - outputStream.write(buffer, 0, read) + try { + while (inputStream.read(buffer).also { read = it } != -1) { + outputStream.write(buffer, 0, read) + } + } catch (e: IOException) { + Timber.e(e, "onCreate: Failed to copy zip file") + runOnUiThread { + Toast.makeText( + this, + R.string.zip_load_failed, + Toast.LENGTH_LONG + ).show() + finishAndRemoveTask() + } + return@Runnable } } } diff --git a/app/src/main/res/layout/installer.xml b/app/src/main/res/layout/installer.xml index e1e196bb..4e6c8122 100644 --- a/app/src/main/res/layout/installer.xml +++ b/app/src/main/res/layout/installer.xml @@ -16,7 +16,7 @@ android:layout_height="0dp" android:background="@color/black" android:overScrollMode="never" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toTopOf="@id/bottom_navigation" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> @@ -40,4 +40,12 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + \ No newline at end of file