Repository navigation
fix(auth): rebuild app lock lifecycle handling - #6892
SeniorZhai wants to merge 9 commits into
Conversation
|
AI review done for Quality: The lifecycle changes are readable and covered by focused tests, but the follow-up introduces two user-visible security and routing regressions in supported scenarios. Verification included the full incremental diff, surrounding activity lifecycle call sites, SDK configuration, and passing whitespace checks. Unit tests were not runnable in this checkout because the Gradle environment could not resolve its required plugin offline.
|
| return false | ||
| } | ||
| if (!isLocked && !foregroundChecked) { | ||
| foregroundChecked = true |
There was a problem hiding this comment.
A deep link handled entirely in onCreate can leave app lock disabled past its timeout. For example, a rejected WalletConnect link opened during the grace period sets foregroundChecked here, then finishes before onStart, so no onStop clears the flag. The next launch skips the timeout check. Keep the early deep-link check, but only mark the foreground session checked once an activity has started.
|
|
||
| private fun bindPinVerification(dialog: VerifyBottomSheetDialogFragment) { | ||
| dialog.setOnPinSuccess { | ||
| if (!lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) return@setOnPinSuccess |
There was a problem hiding this comment.
If PIN verification succeeds while the lock screen is stopped, this guard drops the unlock. The verification coroutine continues while stopped, so the PIN sheet still dismisses and shows “Successful,” but the user has to authenticate again. If unlocking must wait until the activity starts, defer applying the result and showing success until then.
| if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { | ||
| applyPinSuccessUnlock() | ||
| } else { | ||
| pendingPinUnlock = true |
There was a problem hiding this comment.
If PIN verification succeeds after onSaveInstanceState, this updates only the current activity. The PIN sheet still dismisses and requests a success toast, but a recreated activity restores pendingPinUnlock = false from the earlier snapshot and asks for authentication again. Keep the verified result in an activity-scoped ViewModel that survives configuration changes, and show success when the unlock is applied.
There was a problem hiding this comment.
AI review · GPT + Grok · 870e043
Request changes. git diff --check passed for both the full PR and the changes since 22f939e. Neither targeted auth test suite ran because the Gradle wrapper could not download its distribution and the installed Gradle did not reach test execution.
| moveTaskToBack(true) | ||
| private fun schedulePrompt(delayMs: Long = 100) { | ||
| if (promptActive || authenticated || isFinishing) return | ||
| if (supportFragmentManager.findFragmentByTag(VerifyBottomSheetDialogFragment.TAG) != null) return |
There was a problem hiding this comment.
Closing the PIN sheet without verifying leaves the biometric prompt closed. The result callback runs during onDismiss, while the sheet is still discoverable by tag, so this guard drops the retry before posting it. Queue the retry from the dismissal callback and check for the sheet when the runnable executes.
| if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { | ||
| applyPinSuccessUnlock() | ||
| } else { | ||
| pendingPinUnlock = true |
There was a problem hiding this comment.
The previous PIN recreation issue still applies. If verification succeeds after state is saved, this updates only the old activity. The sheet reports success, but the recreated activity reads false from the saved snapshot and asks the user to authenticate again. Retain the verified result in an activity-scoped ViewModel and show success when the unlock is applied.
| override fun onAuthenticationFailed() { | ||
| refreshSwirl(getString(R.string.Not_recognized), false) | ||
| BiometricPrompt.ERROR_CANCELED -> { | ||
| retryPromptOnResume = true |
There was a problem hiding this comment.
If ERROR_CANCELED arrives while the activity is resumed, the prompt closes and this flag waits for another onResume. The screen still asks for a fingerprint with no prompt active. Schedule a delayed retry when already resumed and defer to onResume when paused.
870e043 to
04db351
Compare
There was a problem hiding this comment.
AI review · GPT + Grok · 04db351
Request changes. The previous review commit is no longer an ancestor, so I reviewed the full PR and confirmed the three prior lifecycle findings remain, plus the new dialog-window screen-capture gap. git diff --check passed for both requested ranges. The focused auth unit tests could not start because the Gradle wrapper could not download Gradle 9.9.1, while installed Gradle 9.8.2 could not resolve the Foojay resolver plugin.
|
|
||
| fun onActivityCreated(activity: Activity) { | ||
| val reason = secureReasons.getOrPut(activity) { | ||
| FlagSecureReason(activity.window) { isEnabled() } |
There was a problem hiding this comment.
App Lock still does not protect content shown in bottom-sheet dialogs. onActivityCreated secures only activity.window, but GroupBottomSheetDialogFragment uses a separate MixinBottomSheetDialog window whose base onCreateDialog does not set FLAG_SECURE. Opening group info can therefore expose the group name and announcement to screen capture while the activity window is protected. Apply the same secure-window tracking to dialog windows created while App Lock is enabled, including the existing lifecycle for enabling and disabling the setting.
| if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { | ||
| applyPinSuccessUnlock() | ||
| } else { | ||
| pendingPinUnlock = true |
There was a problem hiding this comment.
A successful PIN verification can still be lost across activity recreation. onSaveInstanceState snapshots pendingPinUnlock, but a later success only sets that field on the old activity instance when its lifecycle is below STARTED. If that instance is recreated, the replacement restores the earlier false value and shows the lock screen again. Store the verified result in an activity-scoped retained state holder such as a ViewModel, and consume it when the replacement activity starts.
| moveTaskToBack(true) | ||
| private fun schedulePrompt(delayMs: Long = 100) { | ||
| if (promptActive || authenticated || isFinishing) return | ||
| if (supportFragmentManager.findFragmentByTag(VerifyBottomSheetDialogFragment.TAG) != null) return |
There was a problem hiding this comment.
Dismissing the PIN sheet can still drop the biometric retry. setOnResult is invoked from the sheet's onDismiss before the fragment removal transaction completes, so findFragmentByTag still returns the sheet and this guard returns without posting showPromptRunnable. Queue the retry first and perform the sheet lookup when the runnable executes, after dismissal has completed.
| override fun onAuthenticationFailed() { | ||
| refreshSwirl(getString(R.string.Not_recognized), false) | ||
| BiometricPrompt.ERROR_CANCELED -> { | ||
| retryPromptOnResume = true |
There was a problem hiding this comment.
ERROR_CANCELED while the activity remains resumed leaves the lock screen without an active biometric prompt. This branch only sets retryPromptOnResume, but onResume will not run again unless the activity pauses and resumes. Schedule a delayed retry immediately when the activity is already resumed, while retaining the current deferred behavior for a paused or stopped activity.
There was a problem hiding this comment.
AI review · GPT (Grok failed) · 5c3aa3f
Request changes because Compose alert dialogs remain outside the new App Lock window tracking and can expose dialog content in screenshots or Recents previews. Source inspection confirmed reachable production call sites, git diff --check passed for the review range, and the focused Gradle tests were blocked by the environment before compilation.
| context: Context, | ||
| overrideThemeResId: Int, | ||
| ) : MaterialAlertDialogBuilder(context, overrideThemeResId) { | ||
| override fun create(): AlertDialog { |
There was a problem hiding this comment.
This protection path only instruments MaterialAlertDialogBuilder instances and DialogFragment windows. Compose AlertDialog creates its own platform dialog window, so callers such as MixinAlertDialog in EmergencyContactPage still show their confirmation text without FLAG_SECURE while App Lock is enabled. Attach the App Lock secure reason to Compose dialog windows as they enter and leave composition, or route these dialogs through the shared tracked-window mechanism.
There was a problem hiding this comment.
AI review · GPT + Grok · b443341
Request changes because Compose alert dialogs remain outside the new secure-window tracking and can expose dialog content in screenshots or Recents previews when App Lock is enabled. git diff --check passed for both the PR and post-review ranges. The focused unit tests could not run because Gradle failed before compilation with a permissions error creating /Users/binyang/.gradle/wrapper/...zip.lck.
| import one.mixin.android.R | ||
| import one.mixin.android.util.FlagSecureReason | ||
|
|
||
| private class SecureMaterialAlertDialogBuilder( |
There was a problem hiding this comment.
This secure-dialog path still covers only MaterialAlertDialogBuilder instances. MixinAlertDialog in compose/Dialogs.kt uses Compose AlertDialog, which creates a separate platform dialog window and never calls attachSecureWindow, so its confirmation text remains capturable while App Lock is enabled. Add a tracked secure-window effect for the Compose dialog window, or route it through the same shared window-tracking mechanism. Reachable callers include the emergency-contact, account, and permission dialogs.
| private val preferenceListener = | ||
| SharedPreferences.OnSharedPreferenceChangeListener { _, key -> | ||
| if (key == null || key == PREF_APP_AUTH) { | ||
| invalidateSecureWindows() |
There was a problem hiding this comment.
A MixinAlertDialog that is already open when App Lock is enabled can remain capturable. This listener refreshes registered windows, and Compose only copies the host’s FLAG_SECURE when it applies dialog parameters. Bind the Compose dialog’s own window to App Lock changes for as long as the dialog is mounted.
There was a problem hiding this comment.
AI review · GPT · ec7c13f
Request changes. Both git diff --check runs passed, and the candle-chart files brought in by the merge match the PR base. The focused App Lock tests could not run because the wrapper could not write to its Gradle home and system Gradle could not resolve the Foojay plugin offline.
| private val preferenceListener = | ||
| SharedPreferences.OnSharedPreferenceChangeListener { _, key -> | ||
| if (key == null || key == PREF_APP_AUTH) { | ||
| invalidateSecureWindows() |
There was a problem hiding this comment.
An already-open MixinAlertDialog can remain visible in screenshots after App Lock is enabled. This listener refreshes registered windows, while Compose copies the host’s FLAG_SECURE to its separate dialog window when it reapplies dialog parameters. Bind the dialog’s own window to App Lock state for as long as the dialog is mounted.
There was a problem hiding this comment.
AI review · GPT · 9f3d8c1
No blocking findings in the follow-up. Both diff checks passed. The focused App Lock and dialog tests could not run because the wrapper could not write to its Gradle home and system Gradle could not resolve the Foojay plugin offline.
There was a problem hiding this comment.
AI review · GPT · 5929e97
Needs fixes before merge. The restored-task deep-link handling can route users to another task’s link, and API 26–32 loses App Lock Recents protection after the FLAG_SECURE tracking was removed. git diff --check passed for both the full PR and the post-review incremental diff.
| if (activity is AppAuthActivity) { | ||
| authActivities.add(activity) | ||
| pendingTasks.remove(activity.taskId) | ||
| if (pendingDeepLink == null) { |
There was a problem hiding this comment.
[P1] Keep the deep link associated with the lock screen/task that is being unlocked. pendingDeepLink is populated only when it is null, so after process restoration the first restored AppAuthActivity permanently wins even if the user switches to another restored task whose lock screen carries a different URI. onAuthenticated() then returns that stale URI and AppAuthActivity opens the wrong link. Track the URI per task/auth activity, or prefer the currently authenticated activity’s intent when resolving the link.
| } | ||
|
|
||
| private fun syncRecentsScreenshot(activity: Activity) { | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { |
There was a problem hiding this comment.
[P1] Preserve screenshot protection on API 26–32. The app supports minSdk = 26, but this branch skips setRecentsScreenshotEnabled() below API 33, while the PR removes the previous FLAG_SECURE tracking from activity windows. On Android 8 through 12L, locking the app therefore leaves ordinary activity content available in the Recents preview. Retain the legacy FLAG_SECURE mechanism for these versions and use the Recents API on API 33+.
No description provided.