mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	Add warning for MIUI users when trying to restore backups with MIUI Optimization disabled
This commit is contained in:
		| @@ -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) | ||||
|   | ||||
| @@ -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 | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user