Add warning for MIUI users when trying to restore backups with MIUI Optimization disabled

This commit is contained in:
arkon 2021-07-10 11:04:41 -04:00
parent 015e8deb79
commit d4c8480dee
3 changed files with 46 additions and 0 deletions

View File

@ -8,6 +8,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
@ -35,6 +36,7 @@ import eu.kanade.tachiyomi.util.preference.preference
import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.preference.summaryRes
import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.system.MiuiUtil
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ -76,6 +78,11 @@ class SettingsBackupController : SettingsController() {
summaryRes = R.string.pref_restore_backup_summ
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).apply {
addCategory(Intent.CATEGORY_OPENABLE)

View File

@ -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
}
}
}

View File

@ -418,6 +418,7 @@
<string name="backup_choice">What do you want to backup?</string>
<string name="creating_backup">Creating backup</string>
<string name="creating_backup_error">Backup failed</string>
<string name="restore_miui_warning">MIUI Optimization must be enabled for restore to work correctly.</string>
<string name="restore_in_progress">Restore is already in progress</string>
<string name="restoring_backup">Restoring backup</string>
<string name="restoring_backup_error">Restoring backup failed</string>