From 1ee75b6aa61ab8643c326f65350ffe166446929b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 8 Jun 2019 01:39:22 -0700 Subject: [PATCH] Download snet package without legacy impl --- .../main/java/com/topjohnwu/magisk/Const.kt | 2 -- .../data/repository/MagiskRepository.kt | 4 +--- .../topjohnwu/magisk/ui/home/HomeFragment.kt | 19 +++++++++++++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/Const.kt b/app/src/main/java/com/topjohnwu/magisk/Const.kt index 8e6616772..96cc094fa 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Const.kt +++ b/app/src/main/java/com/topjohnwu/magisk/Const.kt @@ -67,8 +67,6 @@ object Const { const val XDA_THREAD = "http://forum.xda-developers.com/showthread.php?t=3432382" const val SOURCE_CODE_URL = "https://github.com/topjohnwu/Magisk" @JvmField - val SNET_URL = getRaw("b66b1a914978e5f4c4bbfd74a59f4ad371bac107", "snet.apk") - @JvmField val BOOTCTL_URL = getRaw("9c5dfc1b8245c0b5b524901ef0ff0f8335757b77", "bootctl") const val GITHUB_RAW_API_URL = "https://raw.githubusercontent.com/" 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 index 4bc7f2cd7..7987091d5 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt @@ -37,9 +37,7 @@ class MagiskRepository( .flatMap { apiRaw.fetchFile(it.uninstaller.link) } .map { it.writeToFile(context, FILE_UNINSTALLER_ZIP) } - fun fetchSafetynet() = apiRaw - .fetchSafetynet() - .map { it.writeToFile(context, FILE_SAFETY_NET_APK) } + fun fetchSafetynet() = apiRaw.fetchSafetynet() fun fetchBootctl() = apiRaw .fetchBootctl() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt index a04f3ee3e..554e3ff9c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt @@ -1,16 +1,20 @@ package com.topjohnwu.magisk.ui.home import android.app.Activity +import android.os.Bundle +import com.skoumal.teanity.extensions.subscribeK import com.skoumal.teanity.viewevents.ViewEvent import com.topjohnwu.magisk.* +import com.topjohnwu.magisk.data.repository.MagiskRepository import com.topjohnwu.magisk.databinding.FragmentMagiskBinding import com.topjohnwu.magisk.model.events.* import com.topjohnwu.magisk.ui.base.MagiskActivity import com.topjohnwu.magisk.ui.base.MagiskFragment import com.topjohnwu.magisk.utils.ISafetyNetHelper +import com.topjohnwu.magisk.utils.copyTo +import com.topjohnwu.magisk.utils.inject import com.topjohnwu.magisk.view.MarkDownWindow import com.topjohnwu.magisk.view.dialogs.* -import com.topjohnwu.net.Networking import com.topjohnwu.superuser.Shell import dalvik.system.DexClassLoader import org.koin.androidx.viewmodel.ext.android.viewModel @@ -21,6 +25,8 @@ class HomeFragment : MagiskFragment(), override val layoutRes: Int = R.layout.fragment_magisk override val viewModel: HomeViewModel by viewModel() + val magiskRepo: MagiskRepository by inject() + lateinit var EXT_FILE: File override fun onResponse(responseCode: Int) = viewModel.finishSafetyNetCheck(responseCode) @@ -37,6 +43,11 @@ class HomeFragment : MagiskFragment(), } } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + EXT_FILE = File("${requireActivity().filesDir.parent}/snet", "snet.apk") + } + override fun onStart() { super.onStart() setHasOptionsMenu(true) @@ -61,9 +72,9 @@ class HomeFragment : MagiskFragment(), .show(requireActivity(), null, resources.openRawResource(R.raw.changelog)) private fun downloadSafetyNet(requiresUserInput: Boolean = true) { - fun download() = Networking - .get(Const.Url.SNET_URL) - .getAsFile(EXT_APK) { updateSafetyNet(true) } + fun download() = magiskRepo.fetchSafetynet() + .map { it.byteStream().copyTo(EXT_FILE) } + .subscribeK { updateSafetyNet(true) } if (!requiresUserInput) { download()