-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] Use the new biometric API
Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
- Loading branch information
1 parent
1c9ce7d
commit ab9088c
Showing
5 changed files
with
141 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...rc/main/java/io/github/muntashirakon/AppManager/compat/BiometricAuthenticatorsCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package io.github.muntashirakon.AppManager.compat; | ||
|
||
import android.os.Build; | ||
|
||
import androidx.biometric.BiometricManager.Authenticators; | ||
|
||
public class BiometricAuthenticatorsCompat { | ||
public static final class Builder { | ||
private boolean mAllowWeak = false; | ||
private boolean mAllowStrong = false; | ||
private boolean mAllowDeviceCredential = false; | ||
private boolean mDeviceCredentialOnly = false; | ||
|
||
public Builder() { | ||
} | ||
|
||
public Builder allowEverything(boolean allow) { | ||
mAllowWeak = allow; | ||
mAllowDeviceCredential = allow; | ||
return this; | ||
} | ||
|
||
public Builder allowWeakBiometric(boolean allow) { | ||
mAllowWeak = allow; | ||
return this; | ||
} | ||
|
||
public Builder allowStrongBiometric(boolean allow) { | ||
mAllowStrong = allow; | ||
return this; | ||
} | ||
|
||
public Builder allowDeviceCredential(boolean allow) { | ||
mAllowDeviceCredential = allow; | ||
return this; | ||
} | ||
|
||
public Builder deviceCredentialOnly(boolean only) { | ||
mDeviceCredentialOnly = only; | ||
return this; | ||
} | ||
|
||
public int build() { | ||
if (mDeviceCredentialOnly) { | ||
return getDeviceCredentialOnlyFlags(); | ||
} | ||
int flags; | ||
if (mAllowWeak) { | ||
flags = Authenticators.BIOMETRIC_WEAK; | ||
} else if (mAllowStrong) { | ||
flags = Authenticators.BIOMETRIC_STRONG; | ||
} else flags = 0; | ||
if (mAllowDeviceCredential) { | ||
if (flags == 0) { | ||
return getDeviceCredentialOnlyFlags(); | ||
} | ||
if (flags == Authenticators.BIOMETRIC_STRONG && ( | ||
Build.VERSION.SDK_INT < Build.VERSION_CODES.P | ||
|| Build.VERSION.SDK_INT > Build.VERSION_CODES.Q)) { | ||
flags = Authenticators.BIOMETRIC_WEAK; | ||
} | ||
return flags | Authenticators.DEVICE_CREDENTIAL; | ||
} | ||
return flags; | ||
} | ||
|
||
private int getDeviceCredentialOnlyFlags() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
return Authenticators.DEVICE_CREDENTIAL; | ||
} | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
return Authenticators.BIOMETRIC_WEAK | Authenticators.DEVICE_CREDENTIAL; | ||
} | ||
return Authenticators.BIOMETRIC_STRONG | Authenticators.DEVICE_CREDENTIAL; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters