Skip to content

Instantly share code, notes, and snippets.

View husaynhakeem's full-sized avatar

Husayn Hakeem husaynhakeem

View GitHub Profile
CameraView CameraController
- getInitializationFuture()
createAndStoreSecretKey()
val cipher = createAndConfigureCipher()
val cryptoObject = CryptoObject(cipher)
biometricPrompt.authenticate(promptinfo, cyptoObject)
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
val cipher = result.cryptoObject?.cipher ?: return
val plainData = "Hello world!" // Whatever data you want to encrypt
val cipherData = cipher.doFinal(plainData.toByteArray(Charsets.UTF_8)) // Encrypted data
// Do something with the encrypted data
}
val biometricManager = BiometricManager.from(context)
val authenticationTypes = BIOMETRIC_WEAK or DEVICE_CREDENTIAL
val canAuthenticate = biometricManager.canAuthenticate(authenticationTypes)
if (canAuthenticate == BIOMETRIC_SUCCESS) {
// The device supports weak biometric authentication or non-biometric authentication, e.g. PIN
}
Pre-Android R Android R and above
Check if biometric authentication is supported BiometricsManager.canAuthenticate() BiometricsManager.canAuthenticate(authenticators)
Define allowed authenticators PromptInfo.Builder.setDeviceCredentialAllowed(boolean) PromptInfo.Builder.setAllowedAuthenticators(authenticators)
val biometricPrompt = BiometricPrompt(
activity, // Activity or Fragment
executor, // Optional. Defines the executor on which the callbacks are triggered
authenticationCallback
)
// Show the authentication prompt
biometricPrompt.authenticate(promptInfo)
val builder = PromptInfo.Builder()
.setTitle(/* Title */)
.setSubtitle(/* Subtitle */)
.setDescription(/* Description */)
// Set a negative button. It would typically display "Cancel"
builder.setNegativeButtonText(/* Negative button label. E.g. "Cancel" */)
// Show a confirmation button after authentication succeeds
// Useful for certain operations, e.g. Ones that involve payment
val authenticationCallback = object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
// Authentication succeeded
}
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
// Authentication errored out. Verify error code and message
}
override fun onAuthenticationFailed() {
val biometricManager = BiometricManager.from(context)
val canAuthenticate = biometricManager.canAuthenticate()
if (canAuthenticate == BIOMETRIC_SUCCESS) {
// The device supports biometric authentication
}
Thermal status code Description Example of use
NONE No throttling Enable features
LIGHT Light throttling where the UX isn't impacted Disable features the user may not notice
MODERATE Moderate throttling where the UX is not largely impacted Disable add-on features
SEVERE Severe throttling where the UX is largely impacted Warn the user of the thermal issues
CRITICAL Platform has done everything to reduce power Disable non-essential features to keep only basic functionality
EMERGENCY Key components in platform are shutting down. Device functionalities will be limited Prepare for shutdown
SHUTDOWN Must shutdown immediately -