mirror of
https://github.com/bitwarden/android.git
synced 2026-04-29 20:38:41 -05:00
[PM-30394] PM-29960: Skip biometric prompt on Xiaomi HyperOS (#6316)
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.credentials.provider.PasswordCredentialEntry
|
|||||||
import androidx.credentials.provider.PublicKeyCredentialEntry
|
import androidx.credentials.provider.PublicKeyCredentialEntry
|
||||||
import com.bitwarden.annotation.OmitFromCoverage
|
import com.bitwarden.annotation.OmitFromCoverage
|
||||||
import com.bitwarden.core.util.isBuildVersionAtLeast
|
import com.bitwarden.core.util.isBuildVersionAtLeast
|
||||||
|
import com.bitwarden.core.util.isHyperOS
|
||||||
import javax.crypto.Cipher
|
import javax.crypto.Cipher
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +16,7 @@ import javax.crypto.Cipher
|
|||||||
fun PublicKeyCredentialEntry.Builder.setBiometricPromptDataIfSupported(
|
fun PublicKeyCredentialEntry.Builder.setBiometricPromptDataIfSupported(
|
||||||
cipher: Cipher?,
|
cipher: Cipher?,
|
||||||
): PublicKeyCredentialEntry.Builder =
|
): PublicKeyCredentialEntry.Builder =
|
||||||
if (isBuildVersionAtLeast(Build.VERSION_CODES.VANILLA_ICE_CREAM) && cipher != null) {
|
if (isBiometricPromptDataSupported() && cipher != null) {
|
||||||
setBiometricPromptData(
|
setBiometricPromptData(
|
||||||
biometricPromptData = buildPromptDataWithCipher(cipher),
|
biometricPromptData = buildPromptDataWithCipher(cipher),
|
||||||
)
|
)
|
||||||
@@ -29,10 +30,19 @@ fun PublicKeyCredentialEntry.Builder.setBiometricPromptDataIfSupported(
|
|||||||
fun PasswordCredentialEntry.Builder.setBiometricPromptDataIfSupported(
|
fun PasswordCredentialEntry.Builder.setBiometricPromptDataIfSupported(
|
||||||
cipher: Cipher?,
|
cipher: Cipher?,
|
||||||
): PasswordCredentialEntry.Builder =
|
): PasswordCredentialEntry.Builder =
|
||||||
if (isBuildVersionAtLeast(Build.VERSION_CODES.VANILLA_ICE_CREAM) && cipher != null) {
|
if (isBiometricPromptDataSupported() && cipher != null) {
|
||||||
setBiometricPromptData(
|
setBiometricPromptData(
|
||||||
biometricPromptData = buildPromptDataWithCipher(cipher),
|
biometricPromptData = buildPromptDataWithCipher(cipher),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether biometric prompt data is supported on this device.
|
||||||
|
* Note: Xiaomi HyperOS is known to be incompatible.
|
||||||
|
*/
|
||||||
|
private fun isBiometricPromptDataSupported(): Boolean {
|
||||||
|
return isBuildVersionAtLeast(Build.VERSION_CODES.VANILLA_ICE_CREAM) &&
|
||||||
|
!isHyperOS()
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
@file:OmitFromCoverage
|
||||||
|
|
||||||
|
package com.bitwarden.core.util
|
||||||
|
|
||||||
|
import com.bitwarden.annotation.OmitFromCoverage
|
||||||
|
|
||||||
|
private const val KEY_XIAOMI_HYPER_OS_NAME = "ro.mi.os.version.name"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the device is running Xiaomi HyperOS.
|
||||||
|
*/
|
||||||
|
fun isHyperOS(): Boolean = !getSystemProperty(KEY_XIAOMI_HYPER_OS_NAME).isNullOrEmpty()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads an Android system property using the android.os.SystemProperties API
|
||||||
|
*
|
||||||
|
* @param key the name of the system property
|
||||||
|
* @return the property value, or null if unavailable
|
||||||
|
*/
|
||||||
|
@Suppress("SameParameterValue", "PrivateApi")
|
||||||
|
private fun getSystemProperty(key: String): String? {
|
||||||
|
return try {
|
||||||
|
val systemProperties = Class.forName("android.os.SystemProperties")
|
||||||
|
val getMethod = systemProperties.getMethod("get", String::class.java)
|
||||||
|
getMethod.invoke(null, key) as? String
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user