Make sure a fingerprint is enrolled before showing the fingerprint option

pull/41/head
Alexander Bakker 7 years ago
parent 1fd85e360a
commit 862533286b

@ -1,13 +1,9 @@
package me.impy.aegis; package me.impy.aegis;
import android.Manifest;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
@ -30,7 +26,7 @@ import me.impy.aegis.crypto.slots.FingerprintSlot;
import me.impy.aegis.crypto.slots.PasswordSlot; import me.impy.aegis.crypto.slots.PasswordSlot;
import me.impy.aegis.crypto.slots.Slot; import me.impy.aegis.crypto.slots.Slot;
import me.impy.aegis.crypto.slots.SlotCollection; import me.impy.aegis.crypto.slots.SlotCollection;
import me.impy.aegis.finger.FingerprintUiHelper; import me.impy.aegis.helpers.FingerprintUiHelper;
import me.impy.aegis.helpers.AuthHelper; import me.impy.aegis.helpers.AuthHelper;
public class AuthActivity extends AppCompatActivity implements FingerprintUiHelper.Callback, SlotCollectionTask.Callback { public class AuthActivity extends AppCompatActivity implements FingerprintUiHelper.Callback, SlotCollectionTask.Callback {
@ -56,11 +52,8 @@ public class AuthActivity extends AppCompatActivity implements FingerprintUiHelp
_slots = (SlotCollection) intent.getSerializableExtra("slots"); _slots = (SlotCollection) intent.getSerializableExtra("slots");
// only show the fingerprint controls if the api version is new enough, permission is granted, a scanner is found and a fingerprint slot is found // only show the fingerprint controls if the api version is new enough, permission is granted, a scanner is found and a fingerprint slot is found
Context context = getApplicationContext(); FingerprintManager manager = FingerprintUiHelper.getManager(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (manager != null && _slots.has(FingerprintSlot.class)) {
FingerprintManager manager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED && manager.isHardwareDetected()) {
if (_slots.has(FingerprintSlot.class)) {
try { try {
KeyStoreHandle handle = new KeyStoreHandle(); KeyStoreHandle handle = new KeyStoreHandle();
if (handle.keyExists()) { if (handle.keyExists()) {
@ -73,8 +66,6 @@ public class AuthActivity extends AppCompatActivity implements FingerprintUiHelp
throw new UndeclaredThrowableException(e); throw new UndeclaredThrowableException(e);
} }
} }
}
}
Button button = findViewById(R.id.button_decrypt); Button button = findViewById(R.id.button_decrypt);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {

@ -22,10 +22,9 @@ import java.lang.reflect.UndeclaredThrowableException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import me.impy.aegis.crypto.CryptoUtils;
import me.impy.aegis.crypto.KeyStoreHandle; import me.impy.aegis.crypto.KeyStoreHandle;
import me.impy.aegis.crypto.slots.Slot; import me.impy.aegis.crypto.slots.Slot;
import me.impy.aegis.finger.FingerprintUiHelper; import me.impy.aegis.helpers.FingerprintUiHelper;
import me.impy.aegis.helpers.AuthHelper; import me.impy.aegis.helpers.AuthHelper;
public class CustomAuthenticatedSlide extends Fragment implements FingerprintUiHelper.Callback, ISlidePolicy, ISlideSelectionListener { public class CustomAuthenticatedSlide extends Fragment implements FingerprintUiHelper.Callback, ISlidePolicy, ISlideSelectionListener {

@ -1,14 +1,10 @@
package me.impy.aegis; package me.impy.aegis;
import android.Manifest;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -19,6 +15,8 @@ import android.widget.TextView;
import com.github.paolorotolo.appintro.ISlidePolicy; import com.github.paolorotolo.appintro.ISlidePolicy;
import me.impy.aegis.helpers.FingerprintUiHelper;
public class CustomAuthenticationSlide extends Fragment implements ISlidePolicy, RadioGroup.OnCheckedChangeListener { public class CustomAuthenticationSlide extends Fragment implements ISlidePolicy, RadioGroup.OnCheckedChangeListener {
public static final int CRYPT_TYPE_INVALID = 0; public static final int CRYPT_TYPE_INVALID = 0;
public static final int CRYPT_TYPE_NONE = 1; public static final int CRYPT_TYPE_NONE = 1;
@ -31,22 +29,19 @@ public class CustomAuthenticationSlide extends Fragment implements ISlidePolicy,
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_authentication_slide, container, false); final View view = inflater.inflate(R.layout.fragment_authentication_slide, container, false);
final Context context = getContext();
_buttonGroup = view.findViewById(R.id.rg_authenticationMethod); _buttonGroup = view.findViewById(R.id.rg_authenticationMethod);
_buttonGroup.setOnCheckedChangeListener(this); _buttonGroup.setOnCheckedChangeListener(this);
onCheckedChanged(_buttonGroup, _buttonGroup.getCheckedRadioButtonId()); onCheckedChanged(_buttonGroup, _buttonGroup.getCheckedRadioButtonId());
// only show the fingerprint option if the api version is new enough, permission is granted and a scanner is found // only show the fingerprint option if the api version is new enough, permission is granted and a scanner is found
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { FingerprintManager manager = FingerprintUiHelper.getManager(getContext());
FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE); if (manager != null) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED && fingerprintManager.isHardwareDetected()) {
RadioButton button = view.findViewById(R.id.rb_fingerprint); RadioButton button = view.findViewById(R.id.rb_fingerprint);
TextView text = view.findViewById(R.id.text_rb_fingerprint); TextView text = view.findViewById(R.id.text_rb_fingerprint);
button.setVisibility(View.VISIBLE); button.setVisibility(View.VISIBLE);
text.setVisibility(View.VISIBLE); text.setVisibility(View.VISIBLE);
} }
}
view.findViewById(R.id.main).setBackgroundColor(_bgColor); view.findViewById(R.id.main).setBackgroundColor(_bgColor);
return view; return view;

@ -17,8 +17,10 @@
* limitations under the License * limitations under the License
*/ */
package me.impy.aegis.finger; package me.impy.aegis.helpers;
import android.Manifest;
import android.content.Context;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
import android.os.Build; import android.os.Build;
import android.os.CancellationSignal; import android.os.CancellationSignal;
@ -57,6 +59,18 @@ public class FingerprintUiHelper extends FingerprintManager.AuthenticationCallba
mCallback = callback; mCallback = callback;
} }
public static FingerprintManager getManager(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (PermissionHelper.granted(context, Manifest.permission.USE_FINGERPRINT)) {
FingerprintManager manager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
if (manager != null && manager.isHardwareDetected() && manager.hasEnrolledFingerprints()) {
return manager;
}
}
}
return null;
}
public boolean isFingerprintAuthAvailable() { public boolean isFingerprintAuthAvailable() {
// The line below prevents the false positive inspection from Android Studio // The line below prevents the false positive inspection from Android Studio
// noinspection ResourceType // noinspection ResourceType

@ -1,8 +1,10 @@
package me.impy.aegis.helpers; package me.impy.aegis.helpers;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -12,10 +14,14 @@ public class PermissionHelper {
} }
public static boolean granted(Context context, String permission) {
return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
}
public static boolean request(Activity activity, int requestCode, String... perms) { public static boolean request(Activity activity, int requestCode, String... perms) {
List<String> deniedPerms = new ArrayList<>(); List<String> deniedPerms = new ArrayList<>();
for (String permission : perms) { for (String permission : perms) {
if (ActivityCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_DENIED) { if (!granted(activity, permission)) {
deniedPerms.add(permission); deniedPerms.add(permission);
} }
} }

Loading…
Cancel
Save