Only cache magisk zips

This commit is contained in:
topjohnwu 2019-09-05 11:26:35 -04:00
parent ee39616a8b
commit ff828116bc
3 changed files with 6 additions and 39 deletions

View File

@ -47,7 +47,6 @@ object Config : PreferenceModel, DBConfig {
const val DARK_THEME = "dark_theme"
const val REPO_ORDER = "repo_order"
const val SHOW_SYSTEM_APP = "show_system"
const val DOWNLOAD_CACHE = "download_cache"
const val DOWNLOAD_PATH = "download_path"
// system state
@ -101,7 +100,6 @@ object Config : PreferenceModel, DBConfig {
if (Utils.isCanary) Value.CANARY_DEBUG_CHANNEL
else Value.DEFAULT_CHANNEL
var isDownloadCacheEnabled by preference(Key.DOWNLOAD_CACHE, true)
var downloadPath by preference(Key.DOWNLOAD_PATH, Environment.DIRECTORY_DOWNLOADS)
var repoOrder by preference(Key.REPO_ORDER, Value.ORDER_DATE)

View File

@ -4,11 +4,9 @@ import android.app.Activity
import android.content.Intent
import androidx.core.app.NotificationCompat
import com.skoumal.teanity.extensions.subscribeK
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.data.network.GithubRawServices
import com.topjohnwu.magisk.di.NullActivity
import com.topjohnwu.magisk.extensions.firstMap
import com.topjohnwu.magisk.extensions.get
import com.topjohnwu.magisk.extensions.writeTo
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
@ -20,19 +18,12 @@ import io.reactivex.Completable
import okhttp3.ResponseBody
import org.koin.android.ext.android.inject
import timber.log.Timber
import java.io.File
import java.io.InputStream
abstract class RemoteFileService : NotificationService() {
private val service: GithubRawServices by inject()
private val supportedFolders
get() = listOf(
cacheDir,
Config.downloadDirectory
)
override val defaultNotification: NotificationCompat.Builder
get() = Notifications.progress(this, "")
@ -43,7 +34,7 @@ abstract class RemoteFileService : NotificationService() {
// ---
private fun start(subject: DownloadSubject) = search(subject)
private fun start(subject: DownloadSubject) = checkExisting(subject)
.onErrorResumeNext { download(subject) }
.doOnSubscribe { update(subject.hashCode()) { it.setContentTitle(subject.title) } }
.subscribeK(onError = {
@ -60,16 +51,12 @@ abstract class RemoteFileService : NotificationService() {
}
}
private fun search(subject: DownloadSubject) = Completable.fromAction {
if (!Config.isDownloadCacheEnabled || subject is Manager) {
throw IllegalStateException("The download cache is disabled")
}
private fun checkExisting(subject: DownloadSubject) = Completable.fromAction {
check(subject is Magisk) { "Download cache is disabled" }
supportedFolders.firstMap { it.find(subject.file.name) }.also {
if (subject is Magisk) {
if (!ShellUtils.checkSum("MD5", it, subject.magisk.md5)) {
throw IllegalStateException("The given file doesn't match the md5")
}
subject.file.also {
check(it.exists() && ShellUtils.checkSum("MD5", it, subject.magisk.md5)) {
"The given file does not match checksum"
}
}
}
@ -88,12 +75,6 @@ abstract class RemoteFileService : NotificationService() {
handleAPK(subject)
}
// ---
private fun File.find(name: String) = list()
?.firstOrNull { it == name }
?.let { File(this, it) }
private fun ResponseBody.toStream(id: Int): InputStream {
val maxRaw = contentLength()
val max = maxRaw / 1_000_000f

View File

@ -29,18 +29,6 @@
android:summary="@string/settings_restore_manager_summary"
android:title="@string/settings_restore_manager_title" />
</PreferenceCategory>
<PreferenceCategory
android:key="downloads"
android:title="@string/settings_downloads_category">
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="download_cache"
android:summary="@string/settings_download_cache_summary"
android:title="@string/settings_download_cache_title" />
<Preference
android:key="download_path"
android:title="@string/settings_download_path_title" />