Skip to content

Commit

Permalink
more bugfixes
Browse files Browse the repository at this point in the history
Signed-off-by: androidacy-user <[email protected]>
  • Loading branch information
androidacy-user committed Jun 29, 2023
1 parent be34fc0 commit 005c5ce
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 21 deletions.
5 changes: 4 additions & 1 deletion app/src/main/kotlin/com/fox2code/mmm/NotificationType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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._-]+$"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -356,8 +363,8 @@ class AndroidacyActivity : FoxActivity() {
backOnResume = true
Timber.i("Exiting WebView %s", AndroidacyUtil.hideToken(downloadUrl))
for (prefix in arrayOf<String>(
"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
Expand Down Expand Up @@ -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/",
Expand All @@ -416,28 +423,36 @@ 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
}

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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ class InstallerActivity : FoxActivity() {
val horizontalScroller = findViewById<View>(R.id.install_horizontal_scroller)
var installTerminal: RecyclerView
progressIndicator = findViewById(R.id.progress_bar)
val bottomNavigationView = findViewById<BottomNavigationView>(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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"/.."
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/kotlin/com/fox2code/mmm/utils/ZipFileOpener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/layout/installer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -40,4 +40,12 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/install_horizontal_scroller"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_nav_install" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 005c5ce

Please sign in to comment.