Skip to content

Commit 005c5ce

Browse files
more bugfixes
Signed-off-by: androidacy-user <[email protected]>
1 parent be34fc0 commit 005c5ce

File tree

7 files changed

+64
-21
lines changed

7 files changed

+64
-21
lines changed

app/src/main/kotlin/com/fox2code/mmm/NotificationType.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ enum class NotificationType constructor(
261261
// Find the line with id=, and check if it matches the regex
262262
BufferedReader(InputStreamReader(zipFile.getInputStream(moduleProp))).use { reader ->
263263
var line: String
264-
while (reader.readLine().also { line = it } != null) {
264+
val iterator = reader.lineSequence().iterator()
265+
// same as above but use iterator
266+
while (iterator.hasNext()) {
267+
line = iterator.next()
265268
if (line.startsWith("id=")) {
266269
val id = line.substring(3)
267270
return id.isEmpty() || !id.matches(Regex("^[a-zA-Z][a-zA-Z0-9._-]+$"))

app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyActivity.kt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,14 @@ class AndroidacyActivity : FoxActivity() {
332332
}
333333
}
334334
wbv?.setDownloadListener(DownloadListener setDownloadListener@{ downloadUrl: String, _: String?, _: String?, _: String?, _: Long ->
335-
if (downloadMode || isDownloadUrl(downloadUrl)) return@setDownloadListener
335+
Timber.i("Downloadable URL: %s", downloadUrl)
336+
val pageUrl = wbv.url
337+
if (downloadMode && isDownloadUrl(downloadUrl)) {
338+
megaIntercept(pageUrl, downloadUrl)
339+
}
340+
Timber.i("Download mode is on")
336341
if (AndroidacyUtil.isAndroidacyLink(downloadUrl) && !backOnResume) {
342+
Timber.i("Androidacy link detected")
337343
val androidacyWebAPI = androidacyWebAPI
338344
if (androidacyWebAPI != null) {
339345
if (!androidacyWebAPI.downloadMode) {
@@ -342,6 +348,7 @@ class AndroidacyActivity : FoxActivity() {
342348
// Workaround Androidacy bug
343349
val moduleId = moduleIdOfUrl(downloadUrl)
344350
if (megaIntercept(wbv.url, downloadUrl)) {
351+
Timber.i("megaIntercept failure 2. Forcing onBackPress")
345352
// Block request as Androidacy doesn't allow duplicate requests
346353
return@setDownloadListener
347354
} else if (moduleId != null) {
@@ -356,8 +363,8 @@ class AndroidacyActivity : FoxActivity() {
356363
backOnResume = true
357364
Timber.i("Exiting WebView %s", AndroidacyUtil.hideToken(downloadUrl))
358365
for (prefix in arrayOf<String>(
359-
"https://production-api.androidacy.com/downloads/",
360-
"https://staging-api.androidacy.com/magisk/downloads/"
366+
"https://production-api.androidacy.com/magisk/file//",
367+
"https://staging-api.androidacy.com/magisk/file/"
361368
)) {
362369
if (downloadUrl.startsWith(prefix)) {
363370
return@setDownloadListener
@@ -388,8 +395,8 @@ class AndroidacyActivity : FoxActivity() {
388395

389396
private fun moduleIdOfUrl(url: String): String? {
390397
for (prefix in arrayOf(
391-
"https://production-api.androidacy.com/downloads/",
392-
"https://staging-api.androidacy.com/downloads/",
398+
"https://production-api.androidacy.com/magisk/file/",
399+
"https://staging-api.androidacy.com/magisk/file/",
393400
"https://production-api.androidacy.com/magisk/readme/",
394401
"https://staging-api.androidacy.com/magisk/readme/",
395402
"https://prodiuction-api.androidacy.com/magisk/info/",
@@ -416,28 +423,36 @@ class AndroidacyActivity : FoxActivity() {
416423
private fun isFileUrl(url: String?): Boolean {
417424
if (url == null) return false
418425
for (prefix in arrayOf(
419-
"https://production-api.androidacy.com/downloads/",
420-
"https://staging-api.androidacy.com/downloads/"
426+
"https://production-api.androidacy.com/magisk/file/",
427+
"https://staging-api.androidacy.com/magisk/file/"
421428
)) { // Make both staging and non staging act the same
422-
if (url.startsWith(prefix)) return true
429+
if (url.startsWith(prefix)) {
430+
Timber.i("File URL: %s", url)
431+
return true
432+
}
433+
423434
}
424435
return false
425436
}
426437

427438
private fun isDownloadUrl(url: String): Boolean {
428439
for (prefix in arrayOf(
429-
"https://production-api.androidacy.com/magisk/downloads/",
430-
"https://staging-api.androidacy.com/magisk/downloads/"
440+
"https://production-api.androidacy.com/magisk/file/",
441+
"https://staging-api.androidacy.com/magisk/file/"
431442
)) { // Make both staging and non staging act the same
432-
if (url.startsWith(prefix)) return true
443+
if (url.startsWith(prefix)) {
444+
Timber.i("Download URL: %s", url)
445+
return true
446+
}
433447
}
434448
return false
435449
}
436450

437451
private fun megaIntercept(pageUrl: String?, fileUrl: String?): Boolean {
438452
if (pageUrl == null || fileUrl == null) return false
439453
// ensure neither pageUrl nor fileUrl are going to cause a crash
440-
if (pageUrl.contains(" ") || fileUrl.contains(" ")) return false
454+
pageUrl.replace(" ", "%20")
455+
fileUrl.replace(" ", "%20")
441456
if (!isFileUrl(fileUrl)) {
442457
return false
443458
}

app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ enum class AndroidacyUtil {
101101
}
102102

103103
fun getChecksumFromURL(moduleUrl: String): String? {
104-
// Get the &version= part
104+
// Get the checksum query param
105105
val i = moduleUrl.indexOf("&checksum=")
106106
// Match until next & or end
107107
if (i != -1) {

app/src/main/kotlin/com/fox2code/mmm/installer/InstallerActivity.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ class InstallerActivity : FoxActivity() {
164164
val horizontalScroller = findViewById<View>(R.id.install_horizontal_scroller)
165165
var installTerminal: RecyclerView
166166
progressIndicator = findViewById(R.id.progress_bar)
167-
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_navigation)
168-
rebootFloatingButton = bottomNavigationView.findViewById(R.id.install_terminal_reboot_fab)
167+
rebootFloatingButton = findViewById(R.id.install_terminal_reboot_fab)
169168
cancelFloatingButton = findViewById(R.id.back_installer)
170169
val rbtBtn = rebootFloatingButton
171170
val cnlBtn = cancelFloatingButton
@@ -414,7 +413,10 @@ class InstallerActivity : FoxActivity() {
414413
val bufferedReader =
415414
BufferedReader(InputStreamReader(zipFile.getInputStream(updateBinary)))
416415
var line: String
417-
while (bufferedReader.readLine().also { line = it } != null) {
416+
val iterator = bufferedReader.lineSequence().iterator()
417+
// same as above, but with the iterator
418+
while (iterator.hasNext()) {
419+
line = iterator.next()
418420
if (line.contains("AnyKernel3")) {
419421
anyKernel3 = true
420422
break

app/src/main/kotlin/com/fox2code/mmm/manager/ModuleManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ class ModuleManager private constructor() : SyncManager() {
274274
)
275275
).use { bufferedReader ->
276276
var line: String
277-
while (bufferedReader.readLine().also { line = it } != null) {
277+
val iterator = bufferedReader.lineSequence().iterator()
278+
while (iterator.hasNext()) {
279+
line = iterator.next()
278280
line = line.trim { it <= ' ' }.replace(' ', '.')
279281
if (!line.startsWith("/data/adb/") || line.contains("*") || line.contains("/../") || line.endsWith(
280282
"/.."

app/src/main/kotlin/com/fox2code/mmm/utils/ZipFileOpener.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,21 @@ class ZipFileOpener : FoxActivity() {
6868
}
6969
val buffer = ByteArray(4096)
7070
var read: Int
71-
while (inputStream.read(buffer).also { read = it } != -1) {
72-
outputStream.write(buffer, 0, read)
71+
try {
72+
while (inputStream.read(buffer).also { read = it } != -1) {
73+
outputStream.write(buffer, 0, read)
74+
}
75+
} catch (e: IOException) {
76+
Timber.e(e, "onCreate: Failed to copy zip file")
77+
runOnUiThread {
78+
Toast.makeText(
79+
this,
80+
R.string.zip_load_failed,
81+
Toast.LENGTH_LONG
82+
).show()
83+
finishAndRemoveTask()
84+
}
85+
return@Runnable
7386
}
7487
}
7588
}

app/src/main/res/layout/installer.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
android:layout_height="0dp"
1717
android:background="@color/black"
1818
android:overScrollMode="never"
19-
app:layout_constraintBottom_toBottomOf="parent"
19+
app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
2020
app:layout_constraintEnd_toEndOf="parent"
2121
app:layout_constraintStart_toStartOf="parent"
2222
app:layout_constraintTop_toTopOf="parent">
@@ -40,4 +40,12 @@
4040
app:layout_constraintStart_toStartOf="parent"
4141
app:layout_constraintTop_toTopOf="parent" />
4242

43+
<com.google.android.material.bottomnavigation.BottomNavigationView
44+
android:id="@+id/bottom_navigation"
45+
android:layout_width="match_parent"
46+
android:layout_height="wrap_content"
47+
app:layout_constraintTop_toBottomOf="@id/install_horizontal_scroller"
48+
app:layout_constraintBottom_toBottomOf="parent"
49+
app:menu="@menu/bottom_nav_install" />
50+
4351
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)