Skip to content

Commit

Permalink
guard Trace calls with API check
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimblebee committed Dec 7, 2023
1 parent 78d8ccf commit d571419
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ constructor(
}
}

@RequiresApi(Build.VERSION_CODES.Q)
override suspend fun takePicture() {
val imageDeferred = CompletableDeferred<ImageProxy>()

Expand All @@ -144,7 +143,9 @@ constructor(
override fun onCaptureSuccess(imageProxy: ImageProxy) {
Log.d(TAG, "onCaptureSuccess")
imageDeferred.complete(imageProxy)
Trace.endAsyncSection(IMAGE_CAPTURE_TRACE, 0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Trace.endAsyncSection(IMAGE_CAPTURE_TRACE, 0)
}
}

override fun onError(exception: ImageCaptureException) {
Expand Down Expand Up @@ -253,7 +254,7 @@ constructor(
Log.d(
TAG,
"Changing CaptureMode: singleStreamCaptureEnabled:" +
(captureMode == CaptureMode.SINGLE_STREAM)
(captureMode == CaptureMode.SINGLE_STREAM)
)
updateUseCaseGroup()
rebindUseCases()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ private const val IMAGE_CAPTURE_TRACE = "JCA Image Capture"
/**
* Screen used for the Preview feature.
*/
@RequiresApi(Build.VERSION_CODES.Q)
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun PreviewScreen(
Expand Down Expand Up @@ -216,7 +215,7 @@ fun PreviewScreen(
// enable only when phone has front and rear camera
enabledCondition =
previewUiState.currentCameraSettings.isBackCameraAvailable &&
previewUiState.currentCameraSettings.isFrontCameraAvailable
previewUiState.currentCameraSettings.isFrontCameraAvailable
)
}
}
Expand All @@ -226,8 +225,10 @@ fun PreviewScreen(
modifier = Modifier
.testTag(CAPTURE_BUTTON),
onClick = {
// this trace is closed at the imageCaptureUseCase callback in CameraxCameraUseCase
Trace.beginAsyncSection(IMAGE_CAPTURE_TRACE, 0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// this trace is closed at the imageCaptureUseCase callback in CameraxCameraUseCase
Trace.beginAsyncSection(IMAGE_CAPTURE_TRACE, 0)
}
multipleEventsCutter.processEvent { viewModel.captureImage() }
},
onLongPress = { viewModel.startVideoRecording() },
Expand Down

0 comments on commit d571419

Please sign in to comment.