Add edge cases to detect MIUI & Huawei devices to select correct installer and apply spoof

This commit is contained in:
Rahul Kumar Patel
2021-02-25 16:21:04 +05:30
parent 51c4e3f27f
commit 5aa4d6fe5e
17 changed files with 659 additions and 70 deletions

View File

@@ -0,0 +1,63 @@
/*
* Aurora Store
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
*
* Aurora Store is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Aurora Store is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.aurora.extensions
import android.content.Context
import android.content.DialogInterface
import android.graphics.drawable.ColorDrawable
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
fun Context.showDialog(@StringRes titleId: Int, @StringRes messageId: Int) {
runOnUiThread {
val backgroundColor: Int = getStyledAttributeColor(android.R.attr.colorBackground)
val builder = MaterialAlertDialogBuilder(this).apply {
setTitle(titleId)
setMessage(messageId)
setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _ -> dialog.dismiss() }
background = ColorDrawable(backgroundColor)
}.create()
builder.show()
}
}
fun Context.showDialog(title: String, message: String) {
runOnUiThread {
val backgroundColor: Int = getStyledAttributeColor(android.R.attr.colorBackground)
val builder = MaterialAlertDialogBuilder(this).apply {
setTitle(title)
setMessage(message)
setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _ -> dialog.dismiss() }
background = ColorDrawable(backgroundColor)
}.create()
builder.show()
}
}
fun Fragment.showDialog(@StringRes titleId: Int, @StringRes messageId: Int) {
requireContext().showDialog(titleId, messageId)
}
fun Fragment.showDialog(title: String, message: String) {
requireContext().showDialog(title, message)
}

View File

@@ -19,7 +19,9 @@
package com.aurora.extensions
import android.annotation.SuppressLint
import android.os.Build
import java.util.*
fun isLAndAbove(): Boolean {
@@ -48,4 +50,47 @@ fun isQAndAbove(): Boolean {
fun isRAndAbove(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
}
fun isMIUI(): Boolean {
return getSystemProperty("ro.miui.ui.version.name").isNotEmpty()
}
fun isHuawei(): Boolean {
return Build.MANUFACTURER.toLowerCase(Locale.getDefault()).contains("huawei")
|| Build.HARDWARE.toLowerCase(Locale.getDefault()).contains("kirin")
|| Build.HARDWARE.toLowerCase(Locale.getDefault()).contains("hi3")
}
fun getMIUIVersion(): String {
val version = getSystemProperty("ro.miui.ui.version.name")
val versionCode = getSystemProperty("ro.miui.ui.version.code")
return if (version.isNotEmpty() && versionCode.isNotEmpty())
"$version.$versionCode"
else
"unknown"
}
@SuppressLint("PrivateApi")
fun isMiuiOptimizationDisabled(): Boolean {
if ("0" == getSystemProperty("persist.sys.miui_optimization")) {
return true
} else try {
return Class.forName("android.miui.AppOpsUtils")
.getDeclaredMethod("isXOptMode")
.invoke(null) as Boolean
} catch (e: java.lang.Exception) {
return false
}
}
@SuppressLint("PrivateApi")
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) {
""
}
}