From a8442fe9a906ef2e58acfffdf1fa9ae3f565fae3 Mon Sep 17 00:00:00 2001 From: Muntashir Al-Islam Date: Mon, 23 Dec 2024 13:41:13 -0800 Subject: [PATCH] [Refactor] Fix unresponsive continue button in BuildExpiryChecker Signed-off-by: Muntashir Al-Islam --- .../AppManager/BaseActivity.java | 76 +++++++++---------- .../crypto/ks/KeyStoreActivity.java | 16 ++-- .../AppManager/main/SplashActivity.java | 50 ++++++------ .../self/life/BuildExpiryChecker.java | 6 +- 4 files changed, 78 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/BaseActivity.java b/app/src/main/java/io/github/muntashirakon/AppManager/BaseActivity.java index e2adb440fc7..7b60a4b61ac 100644 --- a/app/src/main/java/io/github/muntashirakon/AppManager/BaseActivity.java +++ b/app/src/main/java/io/github/muntashirakon/AppManager/BaseActivity.java @@ -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() { @@ -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 diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/crypto/ks/KeyStoreActivity.java b/app/src/main/java/io/github/muntashirakon/AppManager/crypto/ks/KeyStoreActivity.java index 3f79831ac1b..88e02b00546 100644 --- a/app/src/main/java/io/github/muntashirakon/AppManager/crypto/ks/KeyStoreActivity.java +++ b/app/src/main/java/io/github/muntashirakon/AppManager/crypto/ks/KeyStoreActivity.java @@ -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); diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/main/SplashActivity.java b/app/src/main/java/io/github/muntashirakon/AppManager/main/SplashActivity.java index 6bf4b36d928..5d453cf90db 100644 --- a/app/src/main/java/io/github/muntashirakon/AppManager/main/SplashActivity.java +++ b/app/src/main/java/io/github/muntashirakon/AppManager/main/SplashActivity.java @@ -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() { @@ -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() { diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/self/life/BuildExpiryChecker.java b/app/src/main/java/io/github/muntashirakon/AppManager/self/life/BuildExpiryChecker.java index b6f647023c3..671a9b8d8f4 100644 --- a/app/src/main/java/io/github/muntashirakon/AppManager/self/life/BuildExpiryChecker.java +++ b/app/src/main/java/io/github/muntashirakon/AppManager/self/life/BuildExpiryChecker.java @@ -2,6 +2,7 @@ package io.github.muntashirakon.AppManager.self.life; +import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; @@ -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) @@ -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(); }