Skip to content

Commit

Permalink
XiaomiTools: check MIUI not Xiaomi
Browse files Browse the repository at this point in the history
Fixes Xiaomi permission dialog appearing on Xiaomi devices not running MIUI.

Closes #24
  • Loading branch information
jakubvalenta committed Jan 28, 2025
1 parent 1c9cfa8 commit 05edf34
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ open class BaseActivityBehaviorTest {

protected fun waitAndAssertGoogleMapsTextExists(textValue: String) {
// Grant Xiaomi permission
if (xiaomiTools.isXiaomiDevice()) {
if (xiaomiTools.isMiuiDevice()) {
val xiaomiPermissionDialogSelector =
By.res("geoShareXiaomiPermissionDialog")
if (waitForObject(xiaomiPermissionDialogSelector, 1000L)) {
Expand Down
22 changes: 20 additions & 2 deletions app/src/main/java/page/ooooo/geoshare/lib/XiaomiTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,34 @@ import android.content.Intent
import android.os.Build
import android.os.Process
import android.util.Log
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader

class XiaomiTools {

fun isXiaomiDevice() = Build.MANUFACTURER.lowercase().contains("xiaomi")
/**
* See [GitHub Gist](https://gist.github.com/starry-shivam/901267c26eb030eb3faf1ccd4d2bdd32)
*/
fun isMiuiDevice(): Boolean =
setOf("xiaomi", "redmi", "poco").contains(Build.BRAND.lowercase()) &&
(!getRuntimeProperty("ro.miui.ui.version.name").isNullOrBlank() ||
!getRuntimeProperty("ro.mi.os.version.name").isNullOrBlank())

private fun getRuntimeProperty(property: String): String? = try {
Runtime.getRuntime()
.exec("getprop $property").inputStream.use { input ->
BufferedReader(InputStreamReader(input), 1024).readLine()
}
} catch (_: IOException) {
null
}

/**
* See [Stack Overflow](https://stackoverflow.com/a/77842542)
*/
fun isBackgroundStartActivityPermissionGranted(context: Context): Boolean =
if (isXiaomiDevice()) {
if (isMiuiDevice()) {
try {
val appOpsManager =
context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
Expand Down
1 change: 1 addition & 0 deletions metadata/cs-CZ/changelogs/12.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Přidána česká jazyková verze.
- Opravena chyba, kdy se aplikace ptala na oprávnění na zařízeních Xiaomi, která nepoužívala MIUI.
- Opravena chyba, kdy Google Mapy nereagovaly po odmítnutí oprávnění na Xiaomi.
1 change: 1 addition & 0 deletions metadata/en-US/changelogs/12.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Add Czech language version.
- Fix Xiaomi permission dialog appearing on devices not running MIUI.
- Fix unresponsive Google Maps after Xiaomi permission denied.

0 comments on commit 05edf34

Please sign in to comment.