Set FLAG_SECURE, Add biometric lock setting

This commit is contained in:
MrLetsplay 2023-06-27 21:42:06 +02:00
parent 8e6bc903c1
commit 37e80f60d1
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
6 changed files with 37 additions and 10 deletions

View File

@ -1,10 +1,14 @@
package com.cringe_studios.cringe_authenticator;
import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
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;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
@ -46,6 +50,8 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
Integer themeID = SettingsUtil.THEMES.get(SettingsUtil.getTheme(this));
if(themeID != null) {
setTheme(themeID);
@ -66,15 +72,17 @@ public class MainActivity extends AppCompatActivity {
}
});
/*BiometricPrompt.PromptInfo info = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setSubtitle("Log in using your biometric credential")
.setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)
.build();
if(SettingsUtil.isBiometricLock(this)) {
BiometricPrompt.PromptInfo info = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Cringe Authenticator")
.setSubtitle("Unlock the authenticator")
.setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)
.build();
prompt.authenticate(info);*/
launchApp();
prompt.authenticate(info);
}else {
launchApp();
}
startQRCodeScan = registerForActivityResult(new QRScannerContract(), obj -> {
if(obj == null) return; // Cancelled

View File

@ -31,6 +31,9 @@ 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));
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())));
binding.settingsTheme.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

View File

@ -61,7 +61,6 @@ public class GroupListAdapter extends RecyclerView.Adapter<GroupListItem> {
.setNegativeButton("No", (dialog, which) -> {})
.show();
// TODO: better method?
// TODO: actually delete
return true;
});
}

View File

@ -9,6 +9,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -51,6 +52,8 @@ public class QRScannerActivity extends AppCompatActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {Manifest.permission.CAMERA}, 1234);
}

View File

@ -91,6 +91,15 @@ public class SettingsUtil {
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("enableIntroVideo", true);
}
public static void setBiometricLock(Context ctx, boolean biometricLock) {
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
prefs.edit().putBoolean("biometricLock", biometricLock).apply();
}
public static boolean isBiometricLock(Context ctx) {
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("biometricLock", true);
}
public static void setTheme(Context ctx, String theme) {
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
prefs.edit().putString("theme", theme).apply();

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -18,6 +17,12 @@
android:layout_height="wrap_content"
android:text="Enable intro video" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/settings_biometric_lock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Require biometric unlock" />
<Spinner
android:id="@+id/settings_theme"
android:layout_width="match_parent"