improved MIUI warning

This commit is contained in:
X1nto 2021-02-16 15:00:36 +04:00
parent d0e765fa39
commit 26bf0a90d7
6 changed files with 42 additions and 47 deletions

View File

@ -155,6 +155,7 @@ class MainActivity : AppCompatActivity() {
super.attachBaseContext(Crowdin.wrapContext(LanguageContextWrapper.wrap(newBase))) super.attachBaseContext(Crowdin.wrapContext(LanguageContextWrapper.wrap(newBase)))
} }
//I have no idea why the fuck is super method deprecated
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
@ -198,26 +199,30 @@ class MainActivity : AppCompatActivity() {
urldialog.show(this) urldialog.show(this)
} }
when { if (firstLaunch) {
firstLaunch -> { DialogContainer.showSecurityDialog(this)
DialogContainer.showSecurityDialog(this) with(FirebaseMessaging.getInstance()) {
with(FirebaseMessaging.getInstance()) { subscribeToTopic("Vanced-Update")
subscribeToTopic("Vanced-Update") subscribeToTopic("Music-Update")
subscribeToTopic("Music-Update") subscribeToTopic("MicroG-Update")
subscribeToTopic("MicroG-Update")
}
} }
!prefs.getBoolean("statement", true) -> DialogContainer.statementFalse(this) } else {
variant == "root" -> { if (isMiuiOptimizationsEnabled) {
if (PackageHelper.getPackageVersionName( DialogContainer.applyAccentMiuiDialog(this)
"com.google.android.youtube", }
packageManager }
) == "14.21.54")
DialogContainer.basicDialog( if (!prefs.getBoolean("statement", true)) {
getString(R.string.hold_on), DialogContainer.statementFalse(this)
getString(R.string.magisk_vanced), }
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
)
} }
} }
} }

View File

@ -6,7 +6,7 @@ import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.applyAccent import com.vanced.manager.utils.applyAccent
import com.vanced.manager.utils.isMiui import com.vanced.manager.utils.isMiuiOptimizationsEnabled
import com.vanced.manager.utils.openUrl import com.vanced.manager.utils.openUrl
object DialogContainer { object DialogContainer {
@ -16,15 +16,10 @@ object DialogContainer {
setTitle(context.resources.getString(R.string.welcome)) setTitle(context.resources.getString(R.string.welcome))
setMessage(context.resources.getString(R.string.security_context)) setMessage(context.resources.getString(R.string.security_context))
setPositiveButton(context.resources.getString(R.string.close)) { dialog, _ -> setPositiveButton(context.resources.getString(R.string.close)) { dialog, _ ->
dialog.dismiss() dialog.cancel()
}
setOnDismissListener {
if (isMiui()) {
applyAccentMiuiDialog(context)
}
} }
setOnCancelListener { setOnCancelListener {
if (isMiui()) { if (isMiuiOptimizationsEnabled) {
applyAccentMiuiDialog(context) applyAccentMiuiDialog(context)
} }
} }
@ -35,7 +30,7 @@ object DialogContainer {
prefs.edit { putBoolean("firstLaunch", false) } prefs.edit { putBoolean("firstLaunch", false) }
} }
private fun applyAccentMiuiDialog(context: Context) { fun applyAccentMiuiDialog(context: Context) {
MaterialAlertDialogBuilder(context).apply { MaterialAlertDialogBuilder(context).apply {
setTitle(context.getString(R.string.miui_one_title)) setTitle(context.getString(R.string.miui_one_title))
setMessage(context.getString(R.string.miui_one)) setMessage(context.getString(R.string.miui_one))

View File

@ -127,11 +127,13 @@ object AppUtils: CoroutineScope by CoroutineScope(Dispatchers.IO) {
status.contains("ModApk_Missing") -> context.getString(R.string.modapk_missing) status.contains("ModApk_Missing") -> context.getString(R.string.modapk_missing)
status.contains("Files_Missing_VA") -> context.getString(R.string.files_missing_va) status.contains("Files_Missing_VA") -> context.getString(R.string.files_missing_va)
status.contains("Path_Missing") -> context.getString(R.string.path_missing) status.contains("Path_Missing") -> context.getString(R.string.path_missing)
else -> status.contains("INSTALL_FAILED_INTERNAL_ERROR: Permission Denied") -> {
if (isMiui()) if (isMiuiOptimizationsEnabled)
context.getString(R.string.installation_miui) context.getString(R.string.installation_miui)
else else
context.getString(R.string.installation_failed) context.getString(R.string.installation_blocked)
}
else -> context.getString(R.string.installation_failed)
} }
} }
} }

View File

@ -59,7 +59,7 @@ object DownloadHelper : CoroutineScope by CoroutineScope(Dispatchers.IO) {
} }
} else { } else {
onError(response.errorBody().toString()) onError(response.errorBody().toString())
downloadProgress.postValue(0) downloadProgress.postValue(0)
log("VMDownloader", "Failed to download file: $url") log("VMDownloader", "Failed to download file: $url")
} }
} }

View File

@ -1,22 +1,15 @@
package com.vanced.manager.utils package com.vanced.manager.utils
import java.io.BufferedReader import com.topjohnwu.superuser.Shell
import java.io.IOException
import java.io.InputStreamReader
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? { fun getSystemProperty(propname: String): String? {
var input: BufferedReader? = null
return try { return try {
val process = Runtime.getRuntime().exec("getprop $propname") Shell.sh("getprop $propname").exec().out.joinToString(" ")
input = BufferedReader(InputStreamReader(process.inputStream), 1024) } catch (e: Exception) {
input.readLine()
} catch (e: IOException) {
null null
} finally {
input?.close()
} }
} }

View File

@ -81,8 +81,8 @@
<string name="guide">Guide</string> <string name="guide">Guide</string>
<string name="hold_on">Stop!</string> <string name="hold_on">Stop!</string>
<string name="magisk_vanced">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.</string> <string name="magisk_vanced">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.</string>
<string name="miui_one_title">MIUI detected!</string> <string name="miui_one_title">MIUI Optimizations are enabled!</string>
<string name="miui_one">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)</string> <string name="miui_one">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)</string>
<string name="error">Error</string> <string name="error">Error</string>
<string name="redownload">Redownload</string> <string name="redownload">Redownload</string>
<string name="security_context">Make sure that you downloaded the app from vancedapp.com, the Vanced Discord server, or the Vanced GitHub</string> <string name="security_context">Make sure that you downloaded the app from vancedapp.com, the Vanced Discord server, or the Vanced GitHub</string>