Compare commits
1 commit
4462d569f2
...
bdf39d741b
Author | SHA1 | Date | |
---|---|---|---|
bdf39d741b |
2 changed files with 107 additions and 0 deletions
|
@ -8,6 +8,7 @@ plugins {
|
||||||
apply {
|
apply {
|
||||||
plugin<MyVersioningPlugin>()
|
plugin<MyVersioningPlugin>()
|
||||||
plugin<MySigningPlugin>()
|
plugin<MySigningPlugin>()
|
||||||
|
plugin<MagiskModule>()
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
package im.angry.openeuicc.build
|
||||||
|
|
||||||
|
import com.android.build.api.dsl.ApplicationDefaultConfig
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.net.URI
|
||||||
|
import java.net.URL
|
||||||
|
import java.util.zip.ZipEntry
|
||||||
|
import java.util.zip.ZipOutputStream
|
||||||
|
import kotlin.io.path.Path
|
||||||
|
import kotlin.io.path.name
|
||||||
|
|
||||||
|
|
||||||
|
class MagiskModule : Plugin<Project> {
|
||||||
|
override fun apply(target: Project) {
|
||||||
|
target.tasks.register("assembleMagiskModule") {
|
||||||
|
group = "magisk"
|
||||||
|
description = "Assembles the Magisk Module"
|
||||||
|
|
||||||
|
project.layout.buildDirectory
|
||||||
|
.file("outputs/magisk-module.zip")
|
||||||
|
.get().asFile
|
||||||
|
.writeBytes(buildMagiskModule(target))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildMagiskModule(target: Project) = buildZipFile {
|
||||||
|
val defaultConfig = target.defaultConfig
|
||||||
|
val appId = defaultConfig.applicationId
|
||||||
|
val apkPath = "system/system_ext/priv-app/OpenEUICC/OpenEUICC.apk"
|
||||||
|
put("module.prop") {
|
||||||
|
val module = buildList {
|
||||||
|
add("id" to appId.toString())
|
||||||
|
add("name" to "OpenEUICC")
|
||||||
|
add("version" to defaultConfig.versionName + defaultConfig.versionNameSuffix.orEmpty())
|
||||||
|
add("versionCode" to defaultConfig.versionCode.toString())
|
||||||
|
add("author" to "Peter Cai")
|
||||||
|
add("description" to "OpenEUICC provides system-level eUICC integration")
|
||||||
|
add("updateJson" to "")
|
||||||
|
}
|
||||||
|
module
|
||||||
|
.joinToString("\n") { (key, value) -> "${key}=${value}" }
|
||||||
|
.encodeToByteArray()
|
||||||
|
}
|
||||||
|
put("customize.sh") {
|
||||||
|
val copiedApkPath = "\$TMPDIR/${Path(apkPath).name}"
|
||||||
|
val script = buildString {
|
||||||
|
appendLine("chmod u+x \"\$MODPATH/uninstall.sh\"")
|
||||||
|
|
||||||
|
appendLine("cp \"\$MODPATH/$apkPath\" \"$copiedApkPath\"")
|
||||||
|
appendLine("pm install -r \"$copiedApkPath\"")
|
||||||
|
appendLine("rm -f \"$copiedApkPath\"")
|
||||||
|
|
||||||
|
appendLine("pm grant \"${appId}\" android.permission.READ_PHONE_STATE")
|
||||||
|
}
|
||||||
|
script.encodeToByteArray()
|
||||||
|
}
|
||||||
|
put("uninstall.sh") {
|
||||||
|
"pm uninstall ${appId}\n".encodeToByteArray()
|
||||||
|
}
|
||||||
|
put("META-INF/com/google/android/update-binary") {
|
||||||
|
val installerUri =
|
||||||
|
URI("https://github.com/topjohnwu/Magisk/raw/bf4ed29/scripts/module_installer.sh")
|
||||||
|
val connection = URL.of(installerUri, null).openConnection()
|
||||||
|
connection.inputStream.readBytes()
|
||||||
|
}
|
||||||
|
put("META-INF/com/google/android/updater-script") {
|
||||||
|
"#MAGISK\n".encodeToByteArray()
|
||||||
|
}
|
||||||
|
put(apkPath) {
|
||||||
|
target.layout.buildDirectory
|
||||||
|
.file("outputs/apk/debug/app-debug.apk")
|
||||||
|
.get().asFile
|
||||||
|
.readBytes()
|
||||||
|
}
|
||||||
|
put("system/system_ext/etc/permissions/privapp_whitelist_${appId}.xml") {
|
||||||
|
target.rootProject
|
||||||
|
.file("privapp_whitelist_${appId}.xml")
|
||||||
|
.readBytes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildZipFile(builderAction: MutableMap<String, (ZipEntry) -> ByteArray>.() -> Unit): ByteArray {
|
||||||
|
val out = ByteArrayOutputStream()
|
||||||
|
val zip = ZipOutputStream(out)
|
||||||
|
for ((name, invoke) in buildMap(builderAction)) {
|
||||||
|
val entry = ZipEntry(name)
|
||||||
|
entry.time = 0 // reproducible builds
|
||||||
|
zip.putNextEntry(entry)
|
||||||
|
zip.write(invoke(entry))
|
||||||
|
zip.closeEntry()
|
||||||
|
}
|
||||||
|
zip.close()
|
||||||
|
out.close()
|
||||||
|
return out.toByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val Project.defaultConfig: ApplicationDefaultConfig
|
||||||
|
get() = when (val android = extensions.findByName("android")) {
|
||||||
|
is com.android.build.gradle.AppExtension -> android.defaultConfig
|
||||||
|
is com.android.build.api.dsl.ApplicationExtension -> android.defaultConfig
|
||||||
|
else -> throw Exception("Unavailable Android configuration")
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue