Skip to content

Commit

Permalink
[Refactor] Fix unresponsive continue button in BuildExpiryChecker
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Dec 23, 2024
1 parent 51f107f commit a8442fe
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,38 @@ protected final void onCreate(@Nullable Bundle savedInstanceState) {
}
if (Boolean.TRUE.equals(BuildExpiryChecker.buildExpired())) {
// Build has expired
BuildExpiryChecker.getBuildExpiredDialog(this).show();
BuildExpiryChecker.getBuildExpiredDialog(this, (dialog, which) -> doAuthenticate(savedInstanceState)).show();
return;
}
// Run authentication
doAuthenticate(savedInstanceState);
}

protected abstract void onAuthenticated(@Nullable Bundle savedInstanceState);

@CallSuper
@Override
protected void onStart() {
super.onStart();
if (mViewModel != null && mViewModel.isAuthenticating() && mAlertDialog != null) {
if (mDisplayLoader) {
mAlertDialog.show();
} else {
mAlertDialog.hide();
}
}
}

@CallSuper
@Override
protected void onStop() {
if (mAlertDialog != null) {
mAlertDialog.dismiss();
}
super.onStop();
}

private void doAuthenticate(@Nullable Bundle savedInstanceState) {
mViewModel = new ViewModelProvider(this).get(SecurityAndOpsViewModel.class);
mBiometricPrompt = new BiometricPrompt(this, ContextCompat.getMainExecutor(this),
new BiometricPrompt.AuthenticationCallback() {
Expand Down Expand Up @@ -145,47 +173,19 @@ public void onAuthenticationFailed() {
});
if (!mViewModel.isAuthenticating()) {
mViewModel.setAuthenticating(true);
authenticate();
}
}

protected abstract void onAuthenticated(@Nullable Bundle savedInstanceState);

@CallSuper
@Override
protected void onStart() {
super.onStart();
if (mViewModel != null && mViewModel.isAuthenticating() && mAlertDialog != null) {
if (mDisplayLoader) {
mAlertDialog.show();
} else {
mAlertDialog.hide();
// Check KeyStore
if (KeyStoreManager.hasKeyStorePassword()) {
// We already have a working keystore password.
// Only need authentication and/or verify mode of operation.
ensureSecurityAndModeOfOp();
return;
}
Intent keyStoreIntent = new Intent(this, KeyStoreActivity.class)
.putExtra(KeyStoreActivity.EXTRA_KS, true);
mKeyStoreActivity.launch(keyStoreIntent);
}
}

@CallSuper
@Override
protected void onStop() {
if (mAlertDialog != null) {
mAlertDialog.dismiss();
}
super.onStop();
}

private void authenticate() {
// Check KeyStore
if (KeyStoreManager.hasKeyStorePassword()) {
// We already have a working keystore password.
// Only need authentication and/or verify mode of operation.
ensureSecurityAndModeOfOp();
return;
}
Intent keyStoreIntent = new Intent(this, KeyStoreActivity.class)
.putExtra(KeyStoreActivity.EXTRA_KS, true);
mKeyStoreActivity.launch(keyStoreIntent);
}

private void ensureSecurityAndModeOfOp() {
if (!Prefs.Privacy.isScreenLockEnabled()) {
// No security enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,23 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Boolean.TRUE.equals(BuildExpiryChecker.buildExpired())) {
// Build has expired
BuildExpiryChecker.getBuildExpiredDialog(this).show();
BuildExpiryChecker.getBuildExpiredDialog(this, (dialog, which) -> processIntentAndFinish(getIntent())).show();
return;
}
if (getIntent() != null) {
onNewIntent(getIntent());
} else finish();
processIntentAndFinish(getIntent());
}

@Override
protected void onNewIntent(Intent intent) {
protected void onNewIntent(@NonNull Intent intent) {
super.onNewIntent(intent);
processIntentAndFinish(intent);
}

private void processIntentAndFinish(@Nullable Intent intent) {
if (intent == null) {
finish();
return;
}
String alias = intent.getStringExtra(EXTRA_ALIAS);
if (alias != null) {
displayInputKeyStoreAliasPassword(alias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,24 @@ protected final void onCreate(@Nullable Bundle savedInstanceState) {
}
if (Boolean.TRUE.equals(BuildExpiryChecker.buildExpired())) {
// Build has expired
BuildExpiryChecker.getBuildExpiredDialog(this).show();
BuildExpiryChecker.getBuildExpiredDialog(this, (dialog, which) -> doAuthenticate()).show();
return;
}
// Run authentication
doAuthenticate();
}

@CallSuper
@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (menu instanceof MenuBuilder) {
((MenuBuilder) menu).setOptionalIconsVisible(true);
}
return super.onCreateOptionsMenu(menu);
}

private void doAuthenticate() {
mViewModel = new ViewModelProvider(this).get(SecurityAndOpsViewModel.class);
mBiometricPrompt = new BiometricPrompt(this, ContextCompat.getMainExecutor(this),
new BiometricPrompt.AuthenticationCallback() {
Expand Down Expand Up @@ -135,31 +149,17 @@ public void onAuthenticationFailed() {
});
if (!mViewModel.isAuthenticating()) {
mViewModel.setAuthenticating(true);
authenticate();
}
}

@CallSuper
@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (menu instanceof MenuBuilder) {
((MenuBuilder) menu).setOptionalIconsVisible(true);
}
return super.onCreateOptionsMenu(menu);
}

private void authenticate() {
// Check KeyStore
if (KeyStoreManager.hasKeyStorePassword()) {
// We already have a working keystore password.
// Only need authentication and/or verify mode of operation.
ensureSecurityAndModeOfOp();
return;
// Check KeyStore
if (KeyStoreManager.hasKeyStorePassword()) {
// We already have a working keystore password.
// Only need authentication and/or verify mode of operation.
ensureSecurityAndModeOfOp();
return;
}
Intent keyStoreIntent = new Intent(this, KeyStoreActivity.class)
.putExtra(KeyStoreActivity.EXTRA_KS, true);
mKeyStoreActivity.launch(keyStoreIntent);
}
Intent keyStoreIntent = new Intent(this, KeyStoreActivity.class)
.putExtra(KeyStoreActivity.EXTRA_KS, true);
mKeyStoreActivity.launch(keyStoreIntent);
}

private void ensureSecurityAndModeOfOp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package io.github.muntashirakon.AppManager.self.life;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;

Expand Down Expand Up @@ -48,7 +49,8 @@ public final class BuildExpiryChecker {
};

@NonNull
public static AlertDialog getBuildExpiredDialog(@NonNull FragmentActivity activity) {
public static AlertDialog getBuildExpiredDialog(@NonNull FragmentActivity activity,
@Nullable DialogInterface.OnClickListener continueClickListener) {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(activity)
.setTitle(R.string.app_manager_build_expired)
.setMessage(R.string.app_manager_build_expired_message)
Expand All @@ -68,7 +70,7 @@ public static AlertDialog getBuildExpiredDialog(@NonNull FragmentActivity activi
activity.finishAndRemoveTask();
});
if (getBuildType() == BUILD_TYPE_STABLE) {
builder.setNeutralButton(R.string.action_continue, null);
builder.setNeutralButton(R.string.action_continue, continueClickListener);
}
return builder.create();
}
Expand Down

0 comments on commit a8442fe

Please sign in to comment.