diff --git a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt index f14c8342..7565ccb1 100644 --- a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt +++ b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt @@ -155,6 +155,7 @@ class MainActivity : AppCompatActivity() { super.attachBaseContext(Crowdin.wrapContext(LanguageContextWrapper.wrap(newBase))) } + //I have no idea why the fuck is super method deprecated @Suppress("DEPRECATION") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) @@ -198,26 +199,30 @@ class MainActivity : AppCompatActivity() { urldialog.show(this) } - when { - firstLaunch -> { - DialogContainer.showSecurityDialog(this) - with(FirebaseMessaging.getInstance()) { - subscribeToTopic("Vanced-Update") - subscribeToTopic("Music-Update") - subscribeToTopic("MicroG-Update") - } + if (firstLaunch) { + DialogContainer.showSecurityDialog(this) + with(FirebaseMessaging.getInstance()) { + subscribeToTopic("Vanced-Update") + subscribeToTopic("Music-Update") + subscribeToTopic("MicroG-Update") } - !prefs.getBoolean("statement", true) -> DialogContainer.statementFalse(this) - variant == "root" -> { - if (PackageHelper.getPackageVersionName( - "com.google.android.youtube", - packageManager - ) == "14.21.54") - DialogContainer.basicDialog( - getString(R.string.hold_on), - getString(R.string.magisk_vanced), - this - ) + } else { + if (isMiuiOptimizationsEnabled) { + DialogContainer.applyAccentMiuiDialog(this) + } + } + + if (!prefs.getBoolean("statement", true)) { + DialogContainer.statementFalse(this) + } + + if (variant == "root") { + if (PackageHelper.getPackageVersionName("com.google.android.youtube", packageManager) == "14.21.54") { + DialogContainer.basicDialog( + getString(R.string.hold_on), + getString(R.string.magisk_vanced), + this + ) } } } diff --git a/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt b/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt index ae8f76a5..769dc2a7 100644 --- a/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt +++ b/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt @@ -6,7 +6,7 @@ import androidx.preference.PreferenceManager import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.vanced.manager.R import com.vanced.manager.utils.applyAccent -import com.vanced.manager.utils.isMiui +import com.vanced.manager.utils.isMiuiOptimizationsEnabled import com.vanced.manager.utils.openUrl object DialogContainer { @@ -16,15 +16,10 @@ object DialogContainer { setTitle(context.resources.getString(R.string.welcome)) setMessage(context.resources.getString(R.string.security_context)) setPositiveButton(context.resources.getString(R.string.close)) { dialog, _ -> - dialog.dismiss() - } - setOnDismissListener { - if (isMiui()) { - applyAccentMiuiDialog(context) - } + dialog.cancel() } setOnCancelListener { - if (isMiui()) { + if (isMiuiOptimizationsEnabled) { applyAccentMiuiDialog(context) } } @@ -35,7 +30,7 @@ object DialogContainer { prefs.edit { putBoolean("firstLaunch", false) } } - private fun applyAccentMiuiDialog(context: Context) { + fun applyAccentMiuiDialog(context: Context) { MaterialAlertDialogBuilder(context).apply { setTitle(context.getString(R.string.miui_one_title)) setMessage(context.getString(R.string.miui_one)) diff --git a/app/src/main/java/com/vanced/manager/utils/AppUtils.kt b/app/src/main/java/com/vanced/manager/utils/AppUtils.kt index acd00a01..b0922699 100644 --- a/app/src/main/java/com/vanced/manager/utils/AppUtils.kt +++ b/app/src/main/java/com/vanced/manager/utils/AppUtils.kt @@ -127,11 +127,13 @@ object AppUtils: CoroutineScope by CoroutineScope(Dispatchers.IO) { status.contains("ModApk_Missing") -> context.getString(R.string.modapk_missing) status.contains("Files_Missing_VA") -> context.getString(R.string.files_missing_va) status.contains("Path_Missing") -> context.getString(R.string.path_missing) - else -> - if (isMiui()) + status.contains("INSTALL_FAILED_INTERNAL_ERROR: Permission Denied") -> { + if (isMiuiOptimizationsEnabled) context.getString(R.string.installation_miui) else - context.getString(R.string.installation_failed) + context.getString(R.string.installation_blocked) + } + else -> context.getString(R.string.installation_failed) } } } \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/utils/DownloadHelper.kt b/app/src/main/java/com/vanced/manager/utils/DownloadHelper.kt index 34495cd0..28223d14 100644 --- a/app/src/main/java/com/vanced/manager/utils/DownloadHelper.kt +++ b/app/src/main/java/com/vanced/manager/utils/DownloadHelper.kt @@ -59,7 +59,7 @@ object DownloadHelper : CoroutineScope by CoroutineScope(Dispatchers.IO) { } } else { onError(response.errorBody().toString()) - downloadProgress.postValue(0) + downloadProgress.postValue(0) log("VMDownloader", "Failed to download file: $url") } } diff --git a/app/src/main/java/com/vanced/manager/utils/MiuiHelper.kt b/app/src/main/java/com/vanced/manager/utils/MiuiHelper.kt index 5b02ab48..8aa2b40b 100644 --- a/app/src/main/java/com/vanced/manager/utils/MiuiHelper.kt +++ b/app/src/main/java/com/vanced/manager/utils/MiuiHelper.kt @@ -1,22 +1,15 @@ package com.vanced.manager.utils -import java.io.BufferedReader -import java.io.IOException -import java.io.InputStreamReader +import com.topjohnwu.superuser.Shell -private const val MIUI_PROP_NAME = "ro.miui.ui.version.name" +private const val MIUI_OPTIMIZATIONS_PROP = "persist.sys.miui_optimization" -fun isMiui(): Boolean = !getSystemProps(MIUI_PROP_NAME).isNullOrEmpty() +val isMiuiOptimizationsEnabled get() = getSystemProperty(MIUI_OPTIMIZATIONS_PROP) == "true" -private fun getSystemProps(propname: String): String? { - var input: BufferedReader? = null +fun getSystemProperty(propname: String): String? { return try { - val process = Runtime.getRuntime().exec("getprop $propname") - input = BufferedReader(InputStreamReader(process.inputStream), 1024) - input.readLine() - } catch (e: IOException) { + Shell.sh("getprop $propname").exec().out.joinToString(" ") + } catch (e: Exception) { null - } finally { - input?.close() } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2397990e..bea06c1b 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -81,8 +81,8 @@ Guide Stop! You are using the Magisk/TWRP version of Vanced, which is discontinued and cannot be updated using this app. Please remove it by removing the Magisk module/using TWRP Vanced uninstaller. - MIUI detected! - To install Vanced, you MUST disable MIUI Optimisations in the developer settings. (You can ignore this warning if you are using 20.2.20 or later xiaomi.eu based ROM) + MIUI Optimizations are enabled! + To install Vanced, you MUST disable MIUI Optimizations in the developer settings. (You can ignore this warning if you are using 20.2.20 or later xiaomi.eu based ROM) Error Redownload Make sure that you downloaded the app from vancedapp.com, the Vanced Discord server, or the Vanced GitHub