Create cancellation signal closer to where face detection runs
With this change the detectCancellationSignal only gets modified from the main thread.
The nonNull check started appearing (rarely) out in the wild from 2023-12-05 a couple of days after we moved flows to the bg dispatcher, that meant this line was being executed in the background thread.
This error stopped in builds appearing created after 2023-12-13 after we reverted the change.
This change is a no-op right now
Bug: 316255379
Flag: NONE
Test: everything builds.
Change-Id: Ied8c792344a75329a799d53ebc586490f028d51c
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt
index 4d60dd0..17d7836 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt
@@ -626,17 +626,19 @@
faceAuthLogger.skippingDetection(_isAuthRunning.value, detectCancellationSignal != null)
return
}
- detectCancellationSignal?.cancel()
- detectCancellationSignal = CancellationSignal()
withContext(mainDispatcher) {
// We always want to invoke face detect in the main thread.
faceAuthLogger.faceDetectionStarted()
- faceManager?.detectFace(
- checkNotNull(detectCancellationSignal),
- detectionCallback,
- SysUiFaceAuthenticateOptions(currentUserId, uiEvent, uiEvent.extraInfo)
- .toFaceAuthenticateOptions()
- )
+ detectCancellationSignal?.cancel()
+ detectCancellationSignal = CancellationSignal()
+ detectCancellationSignal?.let {
+ faceManager?.detectFace(
+ it,
+ detectionCallback,
+ SysUiFaceAuthenticateOptions(currentUserId, uiEvent, uiEvent.extraInfo)
+ .toFaceAuthenticateOptions()
+ )
+ }
}
}