Embed module installer in APK

This commit is contained in:
topjohnwu 2022-01-27 05:24:05 -08:00
parent 0726a00e3b
commit 928b3425e3
5 changed files with 6 additions and 21 deletions

View File

@ -66,7 +66,7 @@ class DownloadService : BaseService() {
val stream = service.fetchFile(subject.url).toProgressStream(subject) val stream = service.fetchFile(subject.url).toProgressStream(subject)
when (subject) { when (subject) {
is Subject.Manager -> handleAPK(subject, stream) is Subject.Manager -> handleAPK(subject, stream)
else -> stream.toModule(subject.file, service.fetchInstaller().byteStream()) is Subject.Module -> stream.toModule(subject.file, assets.open("module_installer.sh"))
} }
val activity = ActivityTracker.foreground val activity = ActivityTracker.foreground
if (activity != null && subject.autoStart) { if (activity != null && subject.autoStart) {

View File

@ -6,26 +6,16 @@ import com.topjohnwu.magisk.core.model.UpdateInfo
import okhttp3.ResponseBody import okhttp3.ResponseBody
import retrofit2.http.* import retrofit2.http.*
private const val REVISION = "revision"
private const val BRANCH = "branch" private const val BRANCH = "branch"
private const val REPO = "repo" private const val REPO = "repo"
private const val FILE = "file" private const val FILE = "file"
const val MAGISK_MAIN = "topjohnwu/Magisk"
interface GithubPageServices { interface GithubPageServices {
@GET("{$FILE}") @GET("{$FILE}")
suspend fun fetchUpdateJSON(@Path(FILE) file: String): UpdateInfo suspend fun fetchUpdateJSON(@Path(FILE) file: String): UpdateInfo
} }
interface JSDelivrServices {
@GET("$MAGISK_MAIN@{$REVISION}/scripts/module_installer.sh")
@Streaming
suspend fun fetchInstaller(@Path(REVISION) revision: String): ResponseBody
}
interface RawServices { interface RawServices {
@GET @GET

View File

@ -7,7 +7,9 @@ import com.topjohnwu.magisk.core.Config.Value.CUSTOM_CHANNEL
import com.topjohnwu.magisk.core.Config.Value.DEFAULT_CHANNEL import com.topjohnwu.magisk.core.Config.Value.DEFAULT_CHANNEL
import com.topjohnwu.magisk.core.Config.Value.STABLE_CHANNEL import com.topjohnwu.magisk.core.Config.Value.STABLE_CHANNEL
import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.data.network.* import com.topjohnwu.magisk.data.network.GithubApiServices
import com.topjohnwu.magisk.data.network.GithubPageServices
import com.topjohnwu.magisk.data.network.RawServices
import retrofit2.HttpException import retrofit2.HttpException
import timber.log.Timber import timber.log.Timber
import java.io.IOException import java.io.IOException
@ -15,7 +17,6 @@ import java.io.IOException
class NetworkService( class NetworkService(
private val pages: GithubPageServices, private val pages: GithubPageServices,
private val raw: RawServices, private val raw: RawServices,
private val jsd: JSDelivrServices,
private val api: GithubApiServices private val api: GithubApiServices
) { ) {
suspend fun fetchUpdate() = safe { suspend fun fetchUpdate() = safe {
@ -59,13 +60,7 @@ class NetworkService(
} }
// Fetch files // Fetch files
suspend fun fetchInstaller() = wrap {
val sha = fetchMainVersion()
jsd.fetchInstaller(sha)
}
suspend fun fetchFile(url: String) = wrap { raw.fetchFile(url) } suspend fun fetchFile(url: String) = wrap { raw.fetchFile(url) }
suspend fun fetchString(url: String) = wrap { raw.fetchString(url) } suspend fun fetchString(url: String) = wrap { raw.fetchString(url) }
suspend fun fetchModuleJson(url: String) = wrap { raw.fetchModuleJson(url) } suspend fun fetchModuleJson(url: String) = wrap { raw.fetchModuleJson(url) }
private suspend fun fetchMainVersion() = api.fetchBranch(MAGISK_MAIN, "master").commit.sha
} }

View File

@ -47,7 +47,6 @@ object ServiceLocator {
NetworkService( NetworkService(
createApiService(retrofit, Const.Url.GITHUB_PAGE_URL), createApiService(retrofit, Const.Url.GITHUB_PAGE_URL),
createApiService(retrofit, Const.Url.GITHUB_RAW_URL), createApiService(retrofit, Const.Url.GITHUB_RAW_URL),
createApiService(retrofit, Const.Url.JS_DELIVR_URL),
createApiService(retrofit, Const.Url.GITHUB_API_URL) createApiService(retrofit, Const.Url.GITHUB_API_URL)
) )
} }

View File

@ -123,7 +123,8 @@ fun Project.setupApp() {
inputs.property("versionCode", Config.versionCode) inputs.property("versionCode", Config.versionCode)
into("src/main/assets") into("src/main/assets")
from(rootProject.file("scripts")) { from(rootProject.file("scripts")) {
include("util_functions.sh", "boot_patch.sh", "uninstaller.sh", "addon.d.sh") include("util_functions.sh", "boot_patch.sh", "addon.d.sh")
include("uninstaller.sh", "module_installer.sh")
} }
from(rootProject.file("tools/bootctl")) from(rootProject.file("tools/bootctl"))
into("chromeos") { into("chromeos") {