Set FLAG_SECURE, Add biometric lock setting
This commit is contained in:
parent
8e6bc903c1
commit
37e80f60d1
@ -1,10 +1,14 @@
|
|||||||
package com.cringe_studios.cringe_authenticator;
|
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.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -46,6 +50,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
|
||||||
|
|
||||||
Integer themeID = SettingsUtil.THEMES.get(SettingsUtil.getTheme(this));
|
Integer themeID = SettingsUtil.THEMES.get(SettingsUtil.getTheme(this));
|
||||||
if(themeID != null) {
|
if(themeID != null) {
|
||||||
setTheme(themeID);
|
setTheme(themeID);
|
||||||
@ -66,15 +72,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*BiometricPrompt.PromptInfo info = new BiometricPrompt.PromptInfo.Builder()
|
if(SettingsUtil.isBiometricLock(this)) {
|
||||||
.setTitle("Biometric login for my app")
|
BiometricPrompt.PromptInfo info = new BiometricPrompt.PromptInfo.Builder()
|
||||||
.setSubtitle("Log in using your biometric credential")
|
.setTitle("Cringe Authenticator")
|
||||||
|
.setSubtitle("Unlock the authenticator")
|
||||||
.setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)
|
.setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
prompt.authenticate(info);*/
|
prompt.authenticate(info);
|
||||||
|
}else {
|
||||||
launchApp();
|
launchApp();
|
||||||
|
}
|
||||||
|
|
||||||
startQRCodeScan = registerForActivityResult(new QRScannerContract(), obj -> {
|
startQRCodeScan = registerForActivityResult(new QRScannerContract(), obj -> {
|
||||||
if(obj == null) return; // Cancelled
|
if(obj == null) return; // Cancelled
|
||||||
|
@ -31,6 +31,9 @@ public class SettingsFragment extends NamedFragment {
|
|||||||
binding.settingsEnableIntroVideo.setChecked(SettingsUtil.isIntroVideoEnabled(requireContext()));
|
binding.settingsEnableIntroVideo.setChecked(SettingsUtil.isIntroVideoEnabled(requireContext()));
|
||||||
binding.settingsEnableIntroVideo.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setEnableIntroVideo(requireContext(), checked));
|
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.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.setSelection(SettingsUtil.THEME_NAMES.indexOf(SettingsUtil.getTheme(requireContext())));
|
||||||
binding.settingsTheme.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
binding.settingsTheme.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
|
@ -61,7 +61,6 @@ public class GroupListAdapter extends RecyclerView.Adapter<GroupListItem> {
|
|||||||
.setNegativeButton("No", (dialog, which) -> {})
|
.setNegativeButton("No", (dialog, which) -> {})
|
||||||
.show();
|
.show();
|
||||||
// TODO: better method?
|
// TODO: better method?
|
||||||
// TODO: actually delete
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import android.net.Uri;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -51,6 +52,8 @@ public class QRScannerActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(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) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
||||||
requestPermissions(new String[] {Manifest.permission.CAMERA}, 1234);
|
requestPermissions(new String[] {Manifest.permission.CAMERA}, 1234);
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,15 @@ public class SettingsUtil {
|
|||||||
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("enableIntroVideo", true);
|
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) {
|
public static void setTheme(Context ctx, String theme) {
|
||||||
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
|
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
|
||||||
prefs.edit().putString("theme", theme).apply();
|
prefs.edit().putString("theme", theme).apply();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@ -18,6 +17,12 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Enable intro video" />
|
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
|
<Spinner
|
||||||
android:id="@+id/settings_theme"
|
android:id="@+id/settings_theme"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user