Fix biometric lock on devices without biometric data
This commit is contained in:
parent
9e9e02cb01
commit
0153f72aaa
@ -4,7 +4,6 @@ import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRON
|
||||
import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -19,6 +18,7 @@ import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.biometric.BiometricManager;
|
||||
import androidx.biometric.BiometricPrompt;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@ -27,7 +27,7 @@ import com.cringe_studios.cringe_authenticator.databinding.ActivityMainBinding;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeChoiceBinding;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeHotpBinding;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeTotpBinding;
|
||||
import com.cringe_studios.cringe_authenticator.fragment.DynamicFragment;
|
||||
import com.cringe_studios.cringe_authenticator.fragment.GroupFragment;
|
||||
import com.cringe_studios.cringe_authenticator.fragment.HomeFragment;
|
||||
import com.cringe_studios.cringe_authenticator.fragment.MenuFragment;
|
||||
import com.cringe_studios.cringe_authenticator.fragment.SettingsFragment;
|
||||
@ -72,7 +72,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
if(SettingsUtil.isBiometricLock(this)) {
|
||||
if(SettingsUtil.isBiometricLock(this) && BiometricManager.from(this).canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
BiometricPrompt.PromptInfo info = new BiometricPrompt.PromptInfo.Builder()
|
||||
.setTitle("Cringe Authenticator")
|
||||
.setSubtitle("Unlock the authenticator")
|
||||
@ -93,11 +93,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
Fragment fragment = NavigationUtil.getCurrentFragment(this);
|
||||
if(fragment instanceof DynamicFragment) {
|
||||
DynamicFragment frag = (DynamicFragment) fragment;
|
||||
if(fragment instanceof GroupFragment) {
|
||||
GroupFragment frag = (GroupFragment) fragment;
|
||||
frag.addOTP(obj.getData());
|
||||
}
|
||||
Log.i("AMOGUS", "Actually got something bruh" + obj);
|
||||
});
|
||||
}
|
||||
|
||||
@ -198,7 +197,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
binding.inputDigits.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new Integer[]{6, 7, 8, 9, 10, 11, 12}));
|
||||
showCodeDialog(binding.getRoot(), () -> {
|
||||
Fragment fragment = NavigationUtil.getCurrentFragment(this);
|
||||
if(!(fragment instanceof DynamicFragment)) return true;
|
||||
if(!(fragment instanceof GroupFragment)) return true;
|
||||
|
||||
try {
|
||||
String name = binding.inputName.getText().toString();
|
||||
@ -216,7 +215,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
return false;
|
||||
}
|
||||
|
||||
((DynamicFragment) fragment).addOTP(data);
|
||||
((GroupFragment) fragment).addOTP(data);
|
||||
return true;
|
||||
}catch(NumberFormatException e) {
|
||||
showErrorDialog("Invalid number entered");
|
||||
@ -231,7 +230,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
binding.inputDigits.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new Integer[]{6, 7, 8, 9, 10, 11, 12}));
|
||||
showCodeDialog(binding.getRoot(), () -> {
|
||||
Fragment fragment = NavigationUtil.getCurrentFragment(this);
|
||||
if(!(fragment instanceof DynamicFragment)) return true;
|
||||
if(!(fragment instanceof GroupFragment)) return true;
|
||||
|
||||
try {
|
||||
String name = binding.inputName.getText().toString();
|
||||
@ -249,7 +248,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
return false;
|
||||
}
|
||||
|
||||
((DynamicFragment) fragment).addOTP(data);
|
||||
((GroupFragment) fragment).addOTP(data);
|
||||
return true;
|
||||
}catch(NumberFormatException e) {
|
||||
showErrorDialog("Invalid number entered");
|
||||
|
@ -11,7 +11,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentDynamicBinding;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentGroupBinding;
|
||||
import com.cringe_studios.cringe_authenticator.otplist.OTPListAdapter;
|
||||
import com.cringe_studios.cringe_authenticator.otplist.OTPListItem;
|
||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||
@ -20,13 +20,13 @@ import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DynamicFragment extends NamedFragment {
|
||||
public class GroupFragment extends NamedFragment {
|
||||
|
||||
public static final String BUNDLE_GROUP = "group";
|
||||
|
||||
private String groupName;
|
||||
|
||||
private FragmentDynamicBinding binding;
|
||||
private FragmentGroupBinding binding;
|
||||
|
||||
private Handler handler;
|
||||
|
||||
@ -47,9 +47,9 @@ public class DynamicFragment extends NamedFragment {
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentDynamicBinding.inflate(inflater, container, false);
|
||||
binding = FragmentGroupBinding.inflate(inflater, container, false);
|
||||
|
||||
groupName = requireArguments().getString(DynamicFragment.BUNDLE_GROUP);
|
||||
groupName = requireArguments().getString(GroupFragment.BUNDLE_GROUP);
|
||||
|
||||
FabUtil.showFabs(requireActivity());
|
||||
|
@ -35,8 +35,8 @@ public class MenuFragment extends NamedFragment {
|
||||
|
||||
groupListAdapter = new GroupListAdapter(requireContext(), group -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(DynamicFragment.BUNDLE_GROUP, group);
|
||||
NavigationUtil.navigate(this, DynamicFragment.class, bundle);
|
||||
bundle.putString(GroupFragment.BUNDLE_GROUP, group);
|
||||
NavigationUtil.navigate(this, GroupFragment.class, bundle);
|
||||
}, this::removeGroup);
|
||||
|
||||
binding.menuItems.setAdapter(groupListAdapter);
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.cringe_studios.cringe_authenticator.fragment;
|
||||
|
||||
import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
|
||||
import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -9,6 +12,7 @@ import android.widget.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.biometric.BiometricManager;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentSettingsBinding;
|
||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||
@ -31,8 +35,14 @@ public class SettingsFragment extends NamedFragment {
|
||||
binding.settingsEnableIntroVideo.setChecked(SettingsUtil.isIntroVideoEnabled(requireContext()));
|
||||
binding.settingsEnableIntroVideo.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setEnableIntroVideo(requireContext(), checked));
|
||||
|
||||
binding.settingsBiometricLock.setChecked(SettingsUtil.isBiometricLock(requireContext()));
|
||||
binding.settingsBiometricLock.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setBiometricLock(requireContext(), checked));
|
||||
if(BiometricManager.from(requireContext()).canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
binding.settingsBiometricLock.setChecked(SettingsUtil.isBiometricLock(requireContext()));
|
||||
binding.settingsBiometricLock.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setBiometricLock(requireContext(), checked));
|
||||
}else {
|
||||
binding.settingsBiometricLock.setChecked(false);
|
||||
binding.settingsBiometricLock.setEnabled(false);
|
||||
// TODO: inform user
|
||||
}
|
||||
|
||||
binding.settingsTheme.setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, SettingsUtil.THEME_NAMES.toArray(new String[0])));
|
||||
binding.settingsTheme.setSelection(SettingsUtil.THEME_NAMES.indexOf(SettingsUtil.getTheme(requireContext())));
|
||||
|
@ -4,7 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".fragment.DynamicFragment">
|
||||
tools:context=".fragment.GroupFragment">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
@ -25,8 +25,8 @@
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/DynamicFragment"
|
||||
android:name="com.cringe_studios.cringe_authenticator.fragment.DynamicFragment"
|
||||
android:name="com.cringe_studios.cringe_authenticator.fragment.GroupFragment"
|
||||
android:label="Dynamic"
|
||||
tools:layout="@layout/fragment_dynamic">
|
||||
tools:layout="@layout/fragment_group">
|
||||
</fragment>
|
||||
</navigation>
|
Loading…
Reference in New Issue
Block a user