mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 11:51:50 +01:00
Add warning for MIUI users when trying to restore backups with MIUI Optimization disabled
This commit is contained in:
parent
ae65677a37
commit
b92a93a8f3
@ -7,6 +7,7 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
@ -25,6 +26,7 @@ import eu.kanade.tachiyomi.data.backup.legacy.LegacyBackupRestoreValidator
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.util.system.getFilePicker
|
||||
import eu.kanade.tachiyomi.util.system.MiuiUtil
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.view.requestFilePermissionsSafe
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@ -67,6 +69,11 @@ class SettingsBackupController : SettingsController() {
|
||||
summaryRes = R.string.restore_from_backup_file
|
||||
|
||||
onClick {
|
||||
if (MiuiUtil.isMiui() && MiuiUtil.isMiuiOptimizationDisabled()) {
|
||||
context.toast(R.string.restore_miui_warning, Toast.LENGTH_LONG)
|
||||
return@onClick
|
||||
}
|
||||
|
||||
if (!BackupRestoreService.isRunning(context)) {
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
|
@ -0,0 +1,38 @@
|
||||
package eu.kanade.tachiyomi.util.system
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import timber.log.Timber
|
||||
|
||||
object MiuiUtil {
|
||||
|
||||
fun isMiui(): Boolean {
|
||||
return getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false
|
||||
}
|
||||
|
||||
@SuppressLint("PrivateApi")
|
||||
fun isMiuiOptimizationDisabled(): Boolean {
|
||||
if ("0" == getSystemProperty("persist.sys.miui_optimization")) {
|
||||
return true
|
||||
}
|
||||
|
||||
return try {
|
||||
Class.forName("android.miui.AppOpsUtils")
|
||||
.getDeclaredMethod("isXOptMode")
|
||||
.invoke(null) as Boolean
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("PrivateApi")
|
||||
private fun getSystemProperty(key: String?): String? {
|
||||
return try {
|
||||
Class.forName("android.os.SystemProperties")
|
||||
.getDeclaredMethod("get", String::class.java)
|
||||
.invoke(null, key) as String
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e, "Unable to use SystemProperties.get")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
@ -680,6 +680,7 @@
|
||||
<string name="what_should_backup">What do you want to backup?</string>
|
||||
<string name="restoring_backup">Restoring backup</string>
|
||||
<string name="restore_duration">%02d min, %02d sec</string>
|
||||
<string name="restore_miui_warning">MIUI Optimization must be enabled for restore to work correctly.</string>
|
||||
<string name="progress">Progress</string>
|
||||
<string name="complete">Complete</string>
|
||||
<plurals name="restore_completed_message">
|
||||
|
Loading…
Reference in New Issue
Block a user