mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 20:15:29 +00:00
Update module download pipeline
This commit is contained in:
parent
2b1b970e78
commit
cdaff5b39c
@ -37,6 +37,10 @@ interface GithubRawApiServices {
|
|||||||
@Streaming
|
@Streaming
|
||||||
fun fetchBootctl(@Path(REVISION) revision: String = Const.BOOTCTL_REVISION): Single<ResponseBody>
|
fun fetchBootctl(@Path(REVISION) revision: String = Const.BOOTCTL_REVISION): Single<ResponseBody>
|
||||||
|
|
||||||
|
@GET("$MAGISK_MASTER/scripts/module_installer.sh")
|
||||||
|
@Streaming
|
||||||
|
fun fetchInstaller(): Single<ResponseBody>
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,4 +8,6 @@ class FileRepository(
|
|||||||
|
|
||||||
fun downloadFile(url: String) = api.fetchFile(url)
|
fun downloadFile(url: String) = api.fetchFile(url)
|
||||||
|
|
||||||
|
fun downloadInstaller() = api.fetchInstaller()
|
||||||
|
|
||||||
}
|
}
|
@ -8,8 +8,6 @@ import com.topjohnwu.magisk.data.network.GithubRawApiServices
|
|||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import retrofit2.CallAdapter
|
|
||||||
import retrofit2.Converter
|
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
||||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||||
@ -17,9 +15,8 @@ import se.ansman.kotshi.KotshiJsonAdapterFactory
|
|||||||
|
|
||||||
val networkingModule = module {
|
val networkingModule = module {
|
||||||
single { createOkHttpClient() }
|
single { createOkHttpClient() }
|
||||||
single { createConverterFactory() }
|
single { createMoshiConverterFactory() }
|
||||||
single { createCallAdapterFactory() }
|
single { createRetrofit(get(), get()) }
|
||||||
single { createRetrofit(get(), get(), get()) }
|
|
||||||
single { createApiService<GithubRawApiServices>(get(), Const.Url.GITHUB_RAW_API_URL) }
|
single { createApiService<GithubRawApiServices>(get(), Const.Url.GITHUB_RAW_API_URL) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,34 +33,25 @@ fun createOkHttpClient(): OkHttpClient {
|
|||||||
return builder.build()
|
return builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createConverterFactory(): Converter.Factory {
|
fun createMoshiConverterFactory(): MoshiConverterFactory {
|
||||||
val moshi = Moshi.Builder()
|
val moshi = Moshi.Builder()
|
||||||
.add(JsonAdapterFactory.INSTANCE)
|
.add(KotshiJsonAdapterFactory)
|
||||||
.build()
|
.build()
|
||||||
return MoshiConverterFactory.create(moshi)
|
return MoshiConverterFactory.create(moshi)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createCallAdapterFactory(): CallAdapter.Factory {
|
|
||||||
return RxJava2CallAdapterFactory.create()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createRetrofit(
|
fun createRetrofit(
|
||||||
okHttpClient: OkHttpClient,
|
okHttpClient: OkHttpClient,
|
||||||
converterFactory: Converter.Factory,
|
converterFactory: MoshiConverterFactory
|
||||||
callAdapterFactory: CallAdapter.Factory
|
|
||||||
): Retrofit.Builder {
|
): Retrofit.Builder {
|
||||||
return Retrofit.Builder()
|
return Retrofit.Builder()
|
||||||
.addConverterFactory(converterFactory)
|
.addConverterFactory(converterFactory)
|
||||||
.addCallAdapterFactory(callAdapterFactory)
|
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||||
.client(okHttpClient)
|
.client(okHttpClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
@KotshiJsonAdapterFactory
|
@KotshiJsonAdapterFactory
|
||||||
abstract class JsonAdapterFactory : JsonAdapter.Factory {
|
abstract class JsonAdapterFactory : JsonAdapter.Factory
|
||||||
companion object {
|
|
||||||
val INSTANCE: JsonAdapterFactory = KotshiJsonAdapterFactory
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <reified T> createApiService(retrofitBuilder: Retrofit.Builder, baseUrl: String): T {
|
inline fun <reified T> createApiService(retrofitBuilder: Retrofit.Builder, baseUrl: String): T {
|
||||||
return retrofitBuilder
|
return retrofitBuilder
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Intent
|
|||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.skoumal.teanity.extensions.subscribeK
|
import com.skoumal.teanity.extensions.subscribeK
|
||||||
import com.topjohnwu.magisk.Config
|
import com.topjohnwu.magisk.Config
|
||||||
import com.topjohnwu.magisk.Const
|
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.data.repository.FileRepository
|
import com.topjohnwu.magisk.data.repository.FileRepository
|
||||||
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
|
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
|
||||||
@ -71,13 +70,11 @@ abstract class RemoteFileService : NotificationService() {
|
|||||||
|
|
||||||
private fun download(subject: DownloadSubject) = repo.downloadFile(subject.url)
|
private fun download(subject: DownloadSubject) = repo.downloadFile(subject.url)
|
||||||
.map { it.toStream(subject.hashCode()) }
|
.map { it.toStream(subject.hashCode()) }
|
||||||
.map {
|
.flatMap { stream ->
|
||||||
subject.file.apply {
|
when (subject) {
|
||||||
when (subject) {
|
is Module -> repo.downloadInstaller()
|
||||||
is Module -> it.toModule(this,
|
.map { stream.toModule(subject.file, it.byteStream()); subject.file }
|
||||||
repo.downloadFile(Const.Url.MODULE_INSTALLER).blockingGet().byteStream())
|
else -> Single.fromCallable { stream.writeTo(subject.file); subject.file }
|
||||||
else -> it.writeTo(this)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user