Fix biometric bug in recent apps (#940)
Closes #930 Co-authored-by: M M Arif <mmarif@swatian.com> Co-authored-by: opyale <opyale@noreply.codeberg.org> Co-authored-by: 6543 <6543@noreply.codeberg.org> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/940 Co-authored-by: M M Arif <mmarif@noreply.codeberg.org> Co-committed-by: M M Arif <mmarif@noreply.codeberg.org>
This commit is contained in:
parent
1693acaa70
commit
bb392fb639
@ -24,7 +24,7 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
viewBinding = true
|
viewBinding true
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
@ -56,19 +56,19 @@ configurations {
|
|||||||
dependencies {
|
dependencies {
|
||||||
def lifecycle_version = '2.3.1'
|
def lifecycle_version = '2.3.1'
|
||||||
def markwon_version = '4.6.2'
|
def markwon_version = '4.6.2'
|
||||||
def work_version = "2.7.0-alpha04"
|
def work_version = "2.7.0-alpha05"
|
||||||
def acra = "5.7.0"
|
def acra = "5.7.0"
|
||||||
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation 'androidx.appcompat:appcompat:1.4.0-alpha02'
|
implementation 'androidx.appcompat:appcompat:1.4.0-alpha03'
|
||||||
implementation 'com.google.android.material:material:1.3.0'
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
|
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
|
||||||
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test:runner:1.3.0'
|
androidTestImplementation 'androidx.test:runner:1.4.0'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2'
|
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2'
|
||||||
implementation "com.google.code.gson:gson:2.8.6"
|
implementation "com.google.code.gson:gson:2.8.6"
|
||||||
implementation "com.squareup.picasso:picasso:2.71828"
|
implementation "com.squareup.picasso:picasso:2.71828"
|
||||||
|
@ -2,13 +2,17 @@ package org.mian.gitnex.activities;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.biometric.BiometricPrompt;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.TimeHelper;
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.notifications.Notifications;
|
import org.mian.gitnex.notifications.Notifications;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@ -89,6 +93,44 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
Notifications.startWorker(appCtx);
|
Notifications.startWorker(appCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
if(tinyDB.getBoolean("biometricStatus") && !tinyDB.getBoolean("biometricLifeCycle")) {
|
||||||
|
|
||||||
|
Executor executor = ContextCompat.getMainExecutor(this);
|
||||||
|
|
||||||
|
BiometricPrompt biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
|
||||||
|
|
||||||
|
super.onAuthenticationError(errorCode, errString);
|
||||||
|
|
||||||
|
// Authentication error, close the app
|
||||||
|
if(errorCode == BiometricPrompt.ERROR_USER_CANCELED ||
|
||||||
|
errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Authentication succeeded, continue to app
|
||||||
|
@Override public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) { super.onAuthenticationSucceeded(result); tinyDB.putBoolean("biometricLifeCycle", true); }
|
||||||
|
|
||||||
|
// Authentication failed, close the app
|
||||||
|
@Override public void onAuthenticationFailed() { super.onAuthenticationFailed(); }
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
BiometricPrompt.PromptInfo biometricPromptBuilder = new BiometricPrompt.PromptInfo.Builder()
|
||||||
|
.setTitle(getString(R.string.biometricAuthTitle))
|
||||||
|
.setSubtitle(getString(R.string.biometricAuthSubTitle))
|
||||||
|
.setNegativeButtonText(getString(R.string.cancelButton)).build();
|
||||||
|
|
||||||
|
biometricPrompt.authenticate(biometricPromptBuilder);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,9 +17,7 @@ import androidx.appcompat.app.ActionBarDrawerToggle;
|
|||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.biometric.BiometricPrompt;
|
|
||||||
import androidx.cardview.widget.CardView;
|
import androidx.cardview.widget.CardView;
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.core.view.GravityCompat;
|
import androidx.core.view.GravityCompat;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
@ -60,7 +58,6 @@ import org.mian.gitnex.helpers.Toasty;
|
|||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import jp.wasabeef.picasso.transformations.BlurTransformation;
|
import jp.wasabeef.picasso.transformations.BlurTransformation;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
@ -142,43 +139,6 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// biometric auth
|
|
||||||
if(tinyDB.getBoolean("biometricStatus")) {
|
|
||||||
|
|
||||||
Executor executor = ContextCompat.getMainExecutor(this);
|
|
||||||
|
|
||||||
BiometricPrompt biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
|
|
||||||
|
|
||||||
super.onAuthenticationError(errorCode, errString);
|
|
||||||
|
|
||||||
// Authentication error, close the app
|
|
||||||
if(errorCode == BiometricPrompt.ERROR_USER_CANCELED ||
|
|
||||||
errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON) {
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Authentication succeeded, continue to app
|
|
||||||
@Override public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) { super.onAuthenticationSucceeded(result); }
|
|
||||||
|
|
||||||
// Authentication failed, close the app
|
|
||||||
@Override public void onAuthenticationFailed() { super.onAuthenticationFailed(); }
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
BiometricPrompt.PromptInfo biometricPromptBuilder = new BiometricPrompt.PromptInfo.Builder()
|
|
||||||
.setTitle(getString(R.string.biometricAuthTitle))
|
|
||||||
.setSubtitle(getString(R.string.biometricAuthSubTitle))
|
|
||||||
.setNegativeButtonText(getString(R.string.cancelButton)).build();
|
|
||||||
|
|
||||||
biometricPrompt.authenticate(biometricPromptBuilder);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
toolbarTitle.setTypeface(myTypeface);
|
toolbarTitle.setTypeface(myTypeface);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ public class MainApplication extends Application {
|
|||||||
Context appCtx = getApplicationContext();
|
Context appCtx = getApplicationContext();
|
||||||
tinyDB = TinyDB.getInstance(appCtx);
|
tinyDB = TinyDB.getInstance(appCtx);
|
||||||
|
|
||||||
|
tinyDB.putBoolean("biometricLifeCycle", false);
|
||||||
|
|
||||||
setDefaults();
|
setDefaults();
|
||||||
|
|
||||||
switch(tinyDB.getInt("customFontId", -1)) {
|
switch(tinyDB.getInt("customFontId", -1)) {
|
||||||
|
@ -7,7 +7,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:4.2.1'
|
classpath 'com.android.tools.build:gradle:4.2.2'
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user