minor fixes

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/89/head
androidacy-user 2 years ago
parent 81616cd0c7
commit 9c465f075e

@ -10,6 +10,7 @@
package com.fox2code.mmm
import android.content.Intent
import android.net.Uri
import android.view.View
import android.widget.Toast
import androidx.annotation.AttrRes
@ -20,18 +21,11 @@ import com.fox2code.mmm.module.ModuleViewListBuilder
import com.fox2code.mmm.repo.RepoManager
import com.fox2code.mmm.utils.IntentHelper
import com.fox2code.mmm.utils.IntentHelper.Companion.OnFileReceivedCallback
import com.fox2code.mmm.utils.io.Files
import com.fox2code.mmm.utils.io.Files.Companion.patchModuleSimple
import com.fox2code.mmm.utils.io.net.Http
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import timber.log.Timber
import java.io.BufferedReader
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStreamReader
import java.util.Date
import java.util.zip.ZipFile
@Suppress("SameParameterValue")
@ -84,19 +78,6 @@ enum class NotificationType(
}
},
@JvmStatic
NO_MAGISK(R.string.fail_magisk_missing,
R.drawable.ic_baseline_numbers_24,
View.OnClickListener { v: View ->
IntentHelper.openUrl(
v.context, "https://github.com/topjohnwu/Magisk/blob/master/docs/install.md"
)
}) {
override fun shouldRemove(): Boolean {
return InstallerInitializer.errorNotification !== this
}
},
@JvmStatic
NO_ROOT(R.string.fail_root_magisk, R.drawable.ic_baseline_numbers_24) {
override fun shouldRemove(): Boolean {
@ -118,7 +99,7 @@ enum class NotificationType(
)
}) {
override fun shouldRemove(): Boolean {
return InstallerInitializer.peekMagiskPath() == null || InstallerInitializer.peekMagiskVersion() >= Constants.MAGISK_VER_CODE_INSTALL_COMMAND
return InstallerInitializer.isKsu || InstallerInitializer.peekMagiskPath() == null || InstallerInitializer.peekMagiskVersion() >= Constants.MAGISK_VER_CODE_INSTALL_COMMAND
}
},
@ -210,29 +191,23 @@ enum class NotificationType(
override fun onReceived(
target: File?,
uri: android.net.Uri?,
uri: Uri?,
response: Int
) {
val companion = NotificationType.Companion
Companion
if (response == IntentHelper.RESPONSE_FILE) {
try {
if (companion.needPatch(target)) {
patchModuleSimple(
Files.read(target),
FileOutputStream(target)
)
}
if (companion.needPatch(target)) {
if (target?.exists() == true && !target.delete()) Timber.w("Failed to delete non module zip")
// ensure file exists
if (!target!!.exists()) {
Toast.makeText(
compatActivity,
R.string.invalid_format,
Toast.LENGTH_SHORT
R.string.install_from_storage_file_not_found,
Toast.LENGTH_LONG
).show()
} else {
return
}
IntentHelper.openInstaller(
compatActivity,
target?.absolutePath,
target.absolutePath,
compatActivity.getString(
R.string.local_install_title
),
@ -242,15 +217,6 @@ enum class NotificationType(
BuildConfig.DEBUG && // Use debug mode if no root
InstallerInitializer.peekMagiskPath() == null
)
}
} catch (ignored: IOException) {
if (target?.exists() == true && !target.delete()) Timber.w("Failed to delete invalid module")
Toast.makeText(
compatActivity,
R.string.invalid_format,
Toast.LENGTH_SHORT
).show()
}
} else if (response == IntentHelper.RESPONSE_URL) {
IntentHelper.openInstaller(
compatActivity,
@ -304,44 +270,6 @@ enum class NotificationType(
if (!shouldRemove()) moduleViewListBuilder.addNotification(this)
}
companion object {
fun needPatch(target: File?): Boolean {
try {
ZipFile(target).use { zipFile ->
var validEntries = zipFile.getEntry("module.prop") != null
// ensure there's no anykernel.sh
validEntries = validEntries and (zipFile.getEntry("anykernel.sh") == null)
if (validEntries) {
// Ensure id of module is not empty and matches ^[a-zA-Z][a-zA-Z0-9._-]+$ regex
// We need to get the module.prop and parse the id= line
val moduleProp = zipFile.getEntry("module.prop")
// Parse the module.prop
if (moduleProp != null) {
// Find the line with id=, and check if it matches the regex
BufferedReader(InputStreamReader(zipFile.getInputStream(moduleProp))).use { reader ->
var line: String
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._-]+$"))
}
}
}
} else {
return true
}
} else {
return true
}
}
} catch (e: IOException) {
return true
}
return false
}
}
companion object
}

@ -426,4 +426,5 @@
<string name="reinstall_warning_v2">This module is available from an online source and a local one. For security, you\'ll need to head over to the online tab to update. If there\'s no update available, you may need to remove this module before attemtping to reinstall.</string>
<string name="update_failed">Could not check for updates</string>
<string name="update_failed_description">Failed to check for updates. If this keeps happening, please ensure the app is not restricted from background usage.</string>
<string name="install_from_storage_file_not_found">Could not find selected file. Please try again.</string>
</resources>

Loading…
Cancel
Save