more bugfixes

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/89/head
androidacy-user 2 years ago
parent be34fc0f59
commit 005c5ceb9d

@ -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._-]+$"))

@ -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<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
@ -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
}

@ -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) {

@ -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
@ -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

@ -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(
"/.."

@ -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
}
}
}

@ -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" />
<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>
Loading…
Cancel
Save