From 9225b4756818ad01b307922165168a50163c4d11 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 6 Oct 2020 04:58:46 -0700 Subject: [PATCH] Tidy up network services Add jsdelivr CDN for several files --- .../java/com/topjohnwu/magisk/core/Const.kt | 8 +-- .../magisk/core/UpdateCheckService.kt | 6 +- .../magisk/core/download/BaseDownloader.kt | 4 +- .../magisk/core/model/module/Repo.kt | 8 +-- .../magisk/core/tasks/MagiskInstaller.kt | 4 +- .../topjohnwu/magisk/core/tasks/PatchAPK.kt | 4 +- .../magisk/core/tasks/RepoUpdater.kt | 6 +- .../{GithubServices.kt => NetworkServices.kt} | 57 +++++++--------- .../data/repository/MagiskRepository.kt | 39 ----------- .../magisk/data/repository/NetworkService.kt | 68 +++++++++++++++++++ .../data/repository/StringRepository.kt | 16 ----- .../topjohnwu/magisk/di/NetworkingModule.kt | 11 +-- .../topjohnwu/magisk/di/RepositoryModule.kt | 6 +- .../topjohnwu/magisk/ui/home/HomeViewModel.kt | 6 +- .../magisk/ui/install/InstallViewModel.kt | 6 +- .../ui/safetynet/CheckSafetyNetEvent.kt | 4 +- .../topjohnwu/magisk/view/MarkDownWindow.kt | 6 +- 17 files changed, 132 insertions(+), 127 deletions(-) rename app/src/main/java/com/topjohnwu/magisk/data/network/{GithubServices.kt => NetworkServices.kt} (69%) delete mode 100644 app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/data/repository/StringRepository.kt diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Const.kt b/app/src/main/java/com/topjohnwu/magisk/core/Const.kt index 36903f78b..c4cab04a6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Const.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Const.kt @@ -12,8 +12,8 @@ object Const { // Versions const val SNET_EXT_VER = 15 - const val SNET_REVISION = "d494bc726e86166913a13629e3b1336728ec5d7f" - const val BOOTCTL_REVISION = "a6c47f86f10b310358afa9dbe837037dd5d561df" + const val SNET_REVISION = "18ab78817087c337ae0edd1ecac38aec49217880" + const val BOOTCTL_REVISION = "18ab78817087c337ae0edd1ecac38aec49217880" // Misc const val ANDROID_MANIFEST = "AndroidManifest.xml" @@ -51,14 +51,14 @@ object Const { const val SOURCE_CODE_URL = "https://github.com/topjohnwu/Magisk" const val GITHUB_RAW_URL = "https://raw.githubusercontent.com/" - const val GITHUB_API_URL = "https://api.github.com/users/Magisk-Modules-Repo/" + const val GITHUB_API_URL = "https://api.github.com/" const val GITHUB_PAGE_URL = "https://topjohnwu.github.io/magisk_files/" + const val JS_DELIVR_URL = "https://cdn.jsdelivr.net/gh/" } object Key { // others const val LINK_KEY = "Link" - const val IF_NONE_MATCH = "If-None-Match" const val ETAG_KEY = "ETag" // intents const val OPEN_SECTION = "section" diff --git a/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt b/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt index df2c2b360..bae7b7630 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt @@ -3,7 +3,7 @@ package com.topjohnwu.magisk.core import android.content.Context import androidx.work.* import com.topjohnwu.magisk.BuildConfig -import com.topjohnwu.magisk.data.repository.MagiskRepository +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.view.Notifications import com.topjohnwu.superuser.Shell import kotlinx.coroutines.Dispatchers @@ -15,14 +15,14 @@ import java.util.concurrent.TimeUnit class UpdateCheckService(context: Context, workerParams: WorkerParameters) : CoroutineWorker(context, workerParams), KoinComponent { - private val magiskRepo: MagiskRepository by inject() + private val svc: NetworkService by inject() override suspend fun doWork(): Result { // Make sure shell initializer was ran withContext(Dispatchers.IO) { Shell.getShell() } - return magiskRepo.fetchUpdate()?.let { + return svc.fetchUpdate()?.let { if (BuildConfig.VERSION_CODE < it.app.versionCode) Notifications.managerUpdate(applicationContext) else if (Info.env.isActive && Info.env.magiskVersionCode < it.magisk.versionCode) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/download/BaseDownloader.kt b/app/src/main/java/com/topjohnwu/magisk/core/download/BaseDownloader.kt index 59ba9db72..b0394b8ec 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/download/BaseDownloader.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/download/BaseDownloader.kt @@ -11,7 +11,7 @@ import com.topjohnwu.magisk.core.base.BaseService import com.topjohnwu.magisk.core.utils.MediaStoreUtils.checkSum import com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream import com.topjohnwu.magisk.core.utils.ProgressInputStream -import com.topjohnwu.magisk.data.network.GithubRawServices +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.ktx.withStreams import com.topjohnwu.magisk.view.Notifications import kotlinx.coroutines.CoroutineScope @@ -34,7 +34,7 @@ abstract class BaseDownloader : BaseService(), KoinComponent { private val notifications = Collections.synchronizedMap(HashMap()) private val coroutineScope = CoroutineScope(Dispatchers.IO) - val service: GithubRawServices by inject() + val service: NetworkService by inject() // -- Service overrides diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/module/Repo.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/module/Repo.kt index 5f6ca98de..0e7c249ef 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/module/Repo.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/module/Repo.kt @@ -4,7 +4,7 @@ import android.os.Parcelable import androidx.room.Entity import androidx.room.PrimaryKey import com.topjohnwu.magisk.core.Const -import com.topjohnwu.magisk.data.repository.StringRepository +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.ktx.get import com.topjohnwu.magisk.ktx.legalFilename import kotlinx.android.parcel.Parcelize @@ -23,7 +23,7 @@ data class Repo( var last_update: Long ) : BaseModule(), Parcelable { - private val stringRepo: StringRepository get() = get() + private val svc: NetworkService get() = get() val lastUpdate get() = Date(last_update) @@ -31,7 +31,7 @@ data class Repo( val downloadFilename: String get() = "$name-$version($versionCode).zip".legalFilename() - suspend fun readme() = stringRepo.getReadme(this) + suspend fun readme() = svc.fetchReadme(this) val zipUrl: String get() = Const.Url.ZIP_URL.format(id) @@ -53,7 +53,7 @@ data class Repo( @Throws(IllegalRepoException::class) suspend fun update(lastUpdate: Date? = null) { lastUpdate?.let { last_update = it.time } - loadProps(stringRepo.getMetadata(this)) + loadProps(svc.fetchMetadata(this)) } class IllegalRepoException(message: String) : Exception(message) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index a9de775ae..3e14ca431 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -13,7 +13,7 @@ import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.utils.MediaStoreUtils import com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream import com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream -import com.topjohnwu.magisk.data.network.GithubRawServices +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.di.Protected import com.topjohnwu.magisk.events.dialog.EnvFixDialog import com.topjohnwu.magisk.ktx.reboot @@ -53,7 +53,7 @@ abstract class MagiskInstallImpl : KoinComponent { private val logs: MutableList private var tarOut: TarOutputStream? = null - private val service: GithubRawServices by inject() + private val service: NetworkService by inject() protected val context: Context by inject() protected constructor() { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/PatchAPK.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/PatchAPK.kt index 9b8b7d0ae..21c50cd3c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/PatchAPK.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/PatchAPK.kt @@ -10,7 +10,7 @@ import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.isRunningAsStub import com.topjohnwu.magisk.core.utils.AXML import com.topjohnwu.magisk.core.utils.Keygen -import com.topjohnwu.magisk.data.network.GithubRawServices +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.ktx.get import com.topjohnwu.magisk.ktx.writeTo import com.topjohnwu.magisk.utils.Utils @@ -91,7 +91,7 @@ object PatchAPK { val dlStub = !isRunningAsStub && SDK_INT >= 28 && Const.Version.atLeast_20_2() val src = if (dlStub) { val stub = File(context.cacheDir, "stub.apk") - val svc = get() + val svc = get() try { svc.fetchFile(Info.remote.stub.link).byteStream().use { it.writeTo(stub) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt index d66ecfdc4..e6d41337d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt @@ -4,7 +4,7 @@ import com.squareup.moshi.JsonClass import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.model.module.Repo import com.topjohnwu.magisk.data.database.RepoDao -import com.topjohnwu.magisk.data.network.GithubApiServices +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.ktx.synchronized import kotlinx.coroutines.* import timber.log.Timber @@ -14,7 +14,7 @@ import java.util.* import kotlin.collections.HashSet class RepoUpdater( - private val api: GithubApiServices, + private val svc: NetworkService, private val repoDB: RepoDao ) { @@ -66,7 +66,7 @@ class RepoUpdater( etag: String = "" ): PageResult = coroutineScope { runCatching { - val result = api.fetchRepos(page, etag) + val result = svc.fetchRepos(page, etag) result.run { if (code() == HttpURLConnection.HTTP_NOT_MODIFIED) return@coroutineScope PageResult.CACHED diff --git a/app/src/main/java/com/topjohnwu/magisk/data/network/GithubServices.kt b/app/src/main/java/com/topjohnwu/magisk/data/network/NetworkServices.kt similarity index 69% rename from app/src/main/java/com/topjohnwu/magisk/data/network/GithubServices.kt rename to app/src/main/java/com/topjohnwu/magisk/data/network/NetworkServices.kt index bfb76bc76..29d7290dd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/network/GithubServices.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/network/NetworkServices.kt @@ -7,6 +7,15 @@ import okhttp3.ResponseBody import retrofit2.Response import retrofit2.http.* +private const val REVISION = "revision" +private const val MODULE = "module" +private const val FILE = "file" +private const val IF_NONE_MATCH = "If-None-Match" + +private const val MAGISK_FILES = "topjohnwu/magisk_files" +private const val MAGISK_MASTER = "topjohnwu/Magisk/master" +private const val MAGISK_MODULES = "Magisk-Modules-Repo" + interface GithubPageServices { @GET("stable.json") @@ -16,30 +25,25 @@ interface GithubPageServices { suspend fun fetchBetaUpdate(): UpdateInfo } +interface JSDelivrServices { + + @GET("$MAGISK_FILES@{$REVISION}/snet") + @Streaming + suspend fun fetchSafetynet(@Path(REVISION) revision: String = Const.SNET_REVISION): ResponseBody + + @GET("$MAGISK_FILES@{$REVISION}/bootctl") + @Streaming + suspend fun fetchBootctl(@Path(REVISION) revision: String = Const.BOOTCTL_REVISION): ResponseBody +} + interface GithubRawServices { - //region topjohnwu/magisk_files - - @GET("$MAGISK_FILES/master/stable.json") - suspend fun fetchStableUpdate(): UpdateInfo - - @GET("$MAGISK_FILES/master/beta.json") - suspend fun fetchBetaUpdate(): UpdateInfo - @GET("$MAGISK_FILES/canary/debug.json") suspend fun fetchCanaryUpdate(): UpdateInfo @GET suspend fun fetchCustomUpdate(@Url url: String): UpdateInfo - @GET("$MAGISK_FILES/{$REVISION}/snet.jar") - @Streaming - suspend fun fetchSafetynet(@Path(REVISION) revision: String = Const.SNET_REVISION): ResponseBody - - @GET("$MAGISK_FILES/{$REVISION}/bootctl") - @Streaming - suspend fun fetchBootctl(@Path(REVISION) revision: String = Const.BOOTCTL_REVISION): ResponseBody - @GET("$MAGISK_MASTER/scripts/module_installer.sh") @Streaming suspend fun fetchInstaller(): ResponseBody @@ -47,8 +51,6 @@ interface GithubRawServices { @GET("$MAGISK_MODULES/{$MODULE}/master/{$FILE}") suspend fun fetchModuleFile(@Path(MODULE) id: String, @Path(FILE) file: String): String - //endregion - /** * This method shall be used exclusively for fetching files from urls from previous requests. * Him, who uses it in a wrong way, shall die in an eternal flame. @@ -60,28 +62,17 @@ interface GithubRawServices { @GET suspend fun fetchString(@Url url: String): String - - companion object { - private const val REVISION = "revision" - private const val MODULE = "module" - private const val FILE = "file" - - - private const val MAGISK_FILES = "topjohnwu/magisk_files" - private const val MAGISK_MASTER = "topjohnwu/Magisk/master" - private const val MAGISK_MODULES = "Magisk-Modules-Repo" - } - } interface GithubApiServices { - @GET("repos") + @GET("users/${MAGISK_MODULES}/repos") + @Headers("Accept: application/vnd.github.v3+json") suspend fun fetchRepos( @Query("page") page: Int, - @Header(Const.Key.IF_NONE_MATCH) etag: String, + @Header(IF_NONE_MATCH) etag: String, @Query("sort") sort: String = "pushed", @Query("per_page") count: Int = 100 ): Response> - } + diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt deleted file mode 100644 index d7d6294f7..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.topjohnwu.magisk.data.repository - -import com.topjohnwu.magisk.core.Config -import com.topjohnwu.magisk.core.Info -import com.topjohnwu.magisk.data.network.GithubPageServices -import com.topjohnwu.magisk.data.network.GithubRawServices -import retrofit2.HttpException -import timber.log.Timber -import java.io.IOException - -class MagiskRepository( - private val rawSvc: GithubRawServices, - private val pageSvc: GithubPageServices -) { - - suspend fun fetchUpdate() = try { - var info = when (Config.updateChannel) { - Config.Value.DEFAULT_CHANNEL, Config.Value.STABLE_CHANNEL -> pageSvc.fetchStableUpdate() - Config.Value.BETA_CHANNEL -> pageSvc.fetchBetaUpdate() - Config.Value.CANARY_CHANNEL -> rawSvc.fetchCanaryUpdate() - Config.Value.CUSTOM_CHANNEL -> rawSvc.fetchCustomUpdate(Config.customChannelUrl) - else -> throw IllegalArgumentException() - } - if (info.magisk.versionCode < Info.env.magiskVersionCode && - Config.updateChannel == Config.Value.DEFAULT_CHANNEL) { - Config.updateChannel = Config.Value.BETA_CHANNEL - info = pageSvc.fetchBetaUpdate() - } - Info.remote = info - info - } catch (e: IOException) { - Timber.e(e) - null - } catch (e: HttpException) { - Timber.e(e) - null - } - -} diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt new file mode 100644 index 000000000..5d5e662b5 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt @@ -0,0 +1,68 @@ +package com.topjohnwu.magisk.data.repository + +import com.topjohnwu.magisk.core.Config +import com.topjohnwu.magisk.core.Config.Value.BETA_CHANNEL +import com.topjohnwu.magisk.core.Config.Value.CANARY_CHANNEL +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.STABLE_CHANNEL +import com.topjohnwu.magisk.core.Info +import com.topjohnwu.magisk.core.model.module.Repo +import com.topjohnwu.magisk.data.network.GithubApiServices +import com.topjohnwu.magisk.data.network.GithubPageServices +import com.topjohnwu.magisk.data.network.GithubRawServices +import com.topjohnwu.magisk.data.network.JSDelivrServices +import retrofit2.HttpException +import timber.log.Timber +import java.io.IOException + +class NetworkService( + private val pages: GithubPageServices, + private val raw: GithubRawServices, + private val jsd: JSDelivrServices, + private val api: GithubApiServices +) { + suspend fun fetchUpdate() = try { + var info = when (Config.updateChannel) { + DEFAULT_CHANNEL, STABLE_CHANNEL -> fetchStableUpdate() + BETA_CHANNEL -> fetchBetaUpdate() + CANARY_CHANNEL -> fetchCanaryUpdate() + CUSTOM_CHANNEL -> fetchCustomUpdate(Config.customChannelUrl) + else -> throw IllegalArgumentException() + } + if (info.magisk.versionCode < Info.env.magiskVersionCode && + Config.updateChannel == DEFAULT_CHANNEL + ) { + Config.updateChannel = BETA_CHANNEL + info = fetchBetaUpdate() + } + Info.remote = info + info + } catch (e: IOException) { + Timber.e(e) + null + } catch (e: HttpException) { + Timber.e(e) + null + } + + // UpdateInfo + suspend fun fetchStableUpdate() = pages.fetchStableUpdate() + suspend fun fetchBetaUpdate() = pages.fetchBetaUpdate() + suspend fun fetchCanaryUpdate() = raw.fetchCanaryUpdate() + suspend fun fetchCustomUpdate(url: String) = raw.fetchCustomUpdate(url) + + // Byte streams + suspend fun fetchSafetynet() = jsd.fetchSafetynet() + suspend fun fetchBootctl() = jsd.fetchBootctl() + suspend fun fetchInstaller() = raw.fetchInstaller() + suspend fun fetchFile(url: String) = raw.fetchFile(url) + + // Strings + suspend fun fetchMetadata(repo: Repo) = raw.fetchModuleFile(repo.id, "module.prop") + suspend fun fetchReadme(repo: Repo) = raw.fetchModuleFile(repo.id, "README.md") + suspend fun fetchString(url: String) = raw.fetchString(url) + + // API calls + suspend fun fetchRepos(page: Int, etag: String) = api.fetchRepos(page, etag) +} diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/StringRepository.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/StringRepository.kt deleted file mode 100644 index e7889ef59..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/StringRepository.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.topjohnwu.magisk.data.repository - -import com.topjohnwu.magisk.core.model.module.Repo -import com.topjohnwu.magisk.data.network.GithubRawServices - -class StringRepository( - private val api: GithubRawServices -) { - - suspend fun getString(url: String) = api.fetchString(url) - - suspend fun getMetadata(repo: Repo) = api.fetchModuleFile(repo.id, "module.prop") - - suspend fun getReadme(repo: Repo) = api.fetchModuleFile(repo.id, "README.md") - -} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt index 5cc7eeb48..7cf1939c3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt @@ -9,6 +9,7 @@ import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.data.network.GithubApiServices import com.topjohnwu.magisk.data.network.GithubPageServices import com.topjohnwu.magisk.data.network.GithubRawServices +import com.topjohnwu.magisk.data.network.JSDelivrServices import com.topjohnwu.magisk.ktx.precomputedText import com.topjohnwu.magisk.net.Networking import com.topjohnwu.magisk.net.NoSSLv3SocketFactory @@ -19,6 +20,7 @@ import okhttp3.Dns import okhttp3.HttpUrl import okhttp3.OkHttpClient import okhttp3.dnsoverhttps.DnsOverHttps +import okhttp3.logging.HttpLoggingInterceptor import org.koin.dsl.module import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory @@ -32,6 +34,7 @@ val networkingModule = module { single { createApiService(get(), Const.Url.GITHUB_RAW_URL) } single { createApiService(get(), Const.Url.GITHUB_API_URL) } single { createApiService(get(), Const.Url.GITHUB_PAGE_URL) } + single { createApiService(get(), Const.Url.JS_DELIVR_URL) } single { createMarkwon(get(), get()) } } @@ -75,10 +78,10 @@ private class DnsResolver(client: OkHttpClient) : Dns { fun createOkHttpClient(context: Context): OkHttpClient { val builder = OkHttpClient.Builder() -// val httpLoggingInterceptor = HttpLoggingInterceptor().apply { -// level = HttpLoggingInterceptor.Level.HEADERS -// } -// builder.addInterceptor(httpLoggingInterceptor) + val httpLoggingInterceptor = HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.HEADERS + } + builder.addInterceptor(httpLoggingInterceptor) if (!Networking.init(context)) { Info.hasGMS = false diff --git a/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt index 6f2de1747..72ac72315 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt @@ -1,13 +1,11 @@ package com.topjohnwu.magisk.di import com.topjohnwu.magisk.data.repository.LogRepository -import com.topjohnwu.magisk.data.repository.MagiskRepository -import com.topjohnwu.magisk.data.repository.StringRepository +import com.topjohnwu.magisk.data.repository.NetworkService import org.koin.dsl.module val repositoryModule = module { - single { MagiskRepository(get(), get()) } single { LogRepository(get()) } - single { StringRepository(get()) } + single { NetworkService(get(), get(), get(), get()) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index 0cbdf5b83..b244f5a44 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -12,7 +12,7 @@ import com.topjohnwu.magisk.core.download.Subject import com.topjohnwu.magisk.core.download.Subject.Manager import com.topjohnwu.magisk.core.model.MagiskJson import com.topjohnwu.magisk.core.model.ManagerJson -import com.topjohnwu.magisk.data.repository.MagiskRepository +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.events.OpenInappLinkEvent import com.topjohnwu.magisk.events.SnackbarEvent import com.topjohnwu.magisk.events.dialog.EnvFixDialog @@ -32,7 +32,7 @@ enum class MagiskState { } class HomeViewModel( - private val repoMagisk: MagiskRepository + private val svc: NetworkService ) : BaseViewModel() { @get:Bindable @@ -84,7 +84,7 @@ class HomeViewModel( state = State.LOADING notifyPropertyChanged(BR.showUninstall) notifyPropertyChanged(BR.showSafetyNet) - repoMagisk.fetchUpdate()?.apply { + svc.fetchUpdate()?.apply { state = State.LOADED stateMagisk = when { !Info.env.isActive -> MagiskState.NOT_INSTALLED diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt index 1c8c4a8cc..e5b3cc1aa 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt @@ -11,7 +11,7 @@ import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.download.Action import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.core.download.Subject -import com.topjohnwu.magisk.data.repository.StringRepository +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.events.MagiskInstallFileEvent import com.topjohnwu.magisk.events.dialog.SecondSlotWarningDialog import com.topjohnwu.magisk.utils.set @@ -21,7 +21,7 @@ import org.koin.core.get import kotlin.math.roundToInt class InstallViewModel( - stringRepo: StringRepository + svc: NetworkService ) : BaseViewModel(State.LOADED) { val isRooted = Shell.rootAccess() @@ -64,7 +64,7 @@ class InstallViewModel( init { viewModelScope.launch { - notes = stringRepo.getString(Info.remote.magisk.note) + notes = svc.fetchString(Info.remote.magisk.note) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/CheckSafetyNetEvent.kt b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/CheckSafetyNetEvent.kt index 2913ee8ab..c712f6780 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/CheckSafetyNetEvent.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/CheckSafetyNetEvent.kt @@ -5,7 +5,7 @@ import com.topjohnwu.magisk.R import com.topjohnwu.magisk.arch.ContextExecutor import com.topjohnwu.magisk.arch.ViewEventWithScope import com.topjohnwu.magisk.core.Const -import com.topjohnwu.magisk.data.network.GithubRawServices +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.ktx.DynamicClassLoader import com.topjohnwu.magisk.ktx.writeTo import com.topjohnwu.magisk.view.MagiskDialog @@ -28,7 +28,7 @@ class CheckSafetyNetEvent( private val callback: (SafetyNetResult) -> Unit = {} ) : ViewEventWithScope(), ContextExecutor, KoinComponent, SafetyNetHelper.Callback { - private val svc by inject() + private val svc by inject() private lateinit var apk: File private lateinit var dex: File diff --git a/app/src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.kt b/app/src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.kt index 0ac51f161..743e24458 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.kt @@ -4,7 +4,7 @@ import android.content.Context import android.view.LayoutInflater import android.widget.TextView import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.data.repository.StringRepository +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.ktx.coroutineScope import io.noties.markwon.Markwon import kotlinx.coroutines.CancellationException @@ -18,12 +18,12 @@ import kotlin.coroutines.coroutineContext object MarkDownWindow : KoinComponent { - private val repo: StringRepository by inject() + private val svc: NetworkService by inject() private val markwon: Markwon by inject() suspend fun show(activity: Context, title: String?, url: String) { show(activity, title) { - repo.getString(url) + svc.fetchString(url) } }