mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-22 23:28:29 +00:00
Test processing Shamiko module zip
This commit is contained in:
parent
29043e1684
commit
6c05f2ae85
@ -14,12 +14,15 @@ import com.topjohnwu.magisk.core.tasks.FlashZip
|
|||||||
import com.topjohnwu.magisk.core.tasks.MagiskInstaller
|
import com.topjohnwu.magisk.core.tasks.MagiskInstaller
|
||||||
import com.topjohnwu.superuser.CallbackList
|
import com.topjohnwu.superuser.CallbackList
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||||
|
import org.junit.Assert.assertArrayEquals
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Assume.assumeTrue
|
|
||||||
import org.junit.BeforeClass
|
import org.junit.BeforeClass
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@ -33,6 +36,12 @@ class Environment : BaseTest {
|
|||||||
fun lsposed(): Boolean {
|
fun lsposed(): Boolean {
|
||||||
return Build.VERSION.SDK_INT >= 27 && Build.VERSION.SDK_INT <= 34
|
return Build.VERSION.SDK_INT >= 27 && Build.VERSION.SDK_INT <= 34
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun shamiko(): Boolean {
|
||||||
|
return Build.VERSION.SDK_INT >= 27
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val MODULE_ERROR = "Module zip processing incorrect"
|
||||||
}
|
}
|
||||||
|
|
||||||
object TimberLog : CallbackList<String>(Runnable::run) {
|
object TimberLog : CallbackList<String>(Runnable::run) {
|
||||||
@ -41,6 +50,28 @@ class Environment : BaseTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkModuleZip(file: File) {
|
||||||
|
// Make sure module processing is correct
|
||||||
|
ZipFile.Builder().setFile(file).get().use { zip ->
|
||||||
|
val meta = zip.entries
|
||||||
|
.asSequence()
|
||||||
|
.filter { it.name.startsWith("META-INF") }
|
||||||
|
.toMutableList()
|
||||||
|
assertEquals(MODULE_ERROR, 6, meta.size)
|
||||||
|
|
||||||
|
val binary = zip.getInputStream(
|
||||||
|
zip.getEntry("META-INF/com/google/android/update-binary")
|
||||||
|
).use { it.readBytes() }
|
||||||
|
val ref = appContext.assets.open("module_installer.sh").use { it.readBytes() }
|
||||||
|
assertArrayEquals(MODULE_ERROR, ref, binary)
|
||||||
|
|
||||||
|
val script = zip.getInputStream(
|
||||||
|
zip.getEntry("META-INF/com/google/android/updater-script")
|
||||||
|
).use { it.readBytes() }
|
||||||
|
assertArrayEquals(MODULE_ERROR, "#MAGISK\n".toByteArray(), script)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun setupEnvironment() {
|
fun setupEnvironment() {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@ -50,20 +81,36 @@ class Environment : BaseTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsposed()) {
|
val notify = object : DownloadNotifier {
|
||||||
val notify = object : DownloadNotifier {
|
override val context = appContext
|
||||||
override val context = appContext
|
override fun notifyUpdate(id: Int, editor: (Notification.Builder) -> Unit) {}
|
||||||
override fun notifyUpdate(id: Int, editor: (Notification.Builder) -> Unit) {}
|
}
|
||||||
|
val processor = DownloadProcessor(notify)
|
||||||
|
|
||||||
|
val shamiko = appContext.cachedFile("shamiko.zip")
|
||||||
|
runBlocking {
|
||||||
|
testContext.assets.open("shamiko.zip").use {
|
||||||
|
processor.handleModule(it, shamiko.toUri())
|
||||||
}
|
}
|
||||||
val processor = DownloadProcessor(notify)
|
checkModuleZip(shamiko)
|
||||||
val zip = appContext.cachedFile("lsposed.zip")
|
if (shamiko()) {
|
||||||
runBlocking {
|
assertTrue(
|
||||||
testContext.assets.open("lsposed.zip").use {
|
"Shamiko installation failed",
|
||||||
processor.handleModule(it, zip.toUri())
|
FlashZip(shamiko.toUri(), TimberLog, TimberLog).exec()
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val lsp = appContext.cachedFile("lsposed.zip")
|
||||||
|
runBlocking {
|
||||||
|
testContext.assets.open("lsposed.zip").use {
|
||||||
|
processor.handleModule(it, lsp.toUri())
|
||||||
|
}
|
||||||
|
checkModuleZip(lsp)
|
||||||
|
if (lsposed()) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"LSPosed installation failed",
|
"LSPosed installation failed",
|
||||||
FlashZip(zip.toUri(), TimberLog, TimberLog).exec()
|
FlashZip(lsp.toUri(), TimberLog, TimberLog).exec()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -472,6 +472,11 @@ const val LSPOSED_DOWNLOAD_URL =
|
|||||||
const val LSPOSED_CHECKSUM =
|
const val LSPOSED_CHECKSUM =
|
||||||
"0ebc6bcb465d1c4b44b7220ab5f0252e6b4eb7fe43da74650476d2798bb29622"
|
"0ebc6bcb465d1c4b44b7220ab5f0252e6b4eb7fe43da74650476d2798bb29622"
|
||||||
|
|
||||||
|
const val SHAMIKO_DOWNLOAD_URL =
|
||||||
|
"https://github.com/LSPosed/LSPosed.github.io/releases/download/shamiko-383/Shamiko-v1.2.1-383-release.zip"
|
||||||
|
const val SHAMIKO_CHECKSUM =
|
||||||
|
"93754a038c2d8f0e985bad45c7303b96f70a93d8335060e50146f028d3a9b13f"
|
||||||
|
|
||||||
fun Project.setupTestApk() {
|
fun Project.setupTestApk() {
|
||||||
setupAppCommon()
|
setupAppCommon()
|
||||||
|
|
||||||
@ -481,6 +486,9 @@ fun Project.setupTestApk() {
|
|||||||
from(downloadFile(LSPOSED_DOWNLOAD_URL, LSPOSED_CHECKSUM)) {
|
from(downloadFile(LSPOSED_DOWNLOAD_URL, LSPOSED_CHECKSUM)) {
|
||||||
rename { "lsposed.zip" }
|
rename { "lsposed.zip" }
|
||||||
}
|
}
|
||||||
|
from(downloadFile(SHAMIKO_DOWNLOAD_URL, SHAMIKO_CHECKSUM)) {
|
||||||
|
rename { "shamiko.zip" }
|
||||||
|
}
|
||||||
into("src/${this@all.name}/assets")
|
into("src/${this@all.name}/assets")
|
||||||
}
|
}
|
||||||
mergeAssetsProvider.configure { dependsOn(dlTask) }
|
mergeAssetsProvider.configure { dependsOn(dlTask) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user