Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
JNdhlovu committed Oct 18, 2024
2 parents bc27fe8 + 03112e1 commit 457c92e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Release Notes

(Unreleased)

* Added inflow navigation as well as individual navigation for compose screens
## 10.3.2

* Document capture throw OOM when encountered

## 10.3.1

Expand Down
2 changes: 1 addition & 1 deletion lib/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.3.2-SNAPSHOT
10.3.3-SNAPSHOT
3 changes: 3 additions & 0 deletions lib/src/main/java/com/smileidentity/util/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ internal fun postProcessImageBitmap(
/**
* Post-processes the image stored in [file] in-place
*/
@Throws(IOException::class, OutOfMemoryError::class)
internal fun postProcessImage(
file: File,
processRotation: Boolean = true,
Expand All @@ -221,6 +222,8 @@ internal fun postProcessImage(
): File {
val options = Options().apply { inMutable = true }
val bitmap = BitmapFactory.decodeFile(file.absolutePath, options)
?: throw IOException("Failed to decode file: ${file.absolutePath}")

return postProcessImageBitmap(
bitmap = bitmap,
file = file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.google.mlkit.vision.objects.ObjectDetection
import com.google.mlkit.vision.objects.ObjectDetector
import com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions
import com.smileidentity.R
import com.smileidentity.SmileIDCrashReporting
import com.smileidentity.compose.document.DocumentCaptureSide
import com.smileidentity.models.v2.DocumentImageOriginValue
import com.smileidentity.models.v2.Metadatum
Expand All @@ -23,15 +24,20 @@ import com.smileidentity.util.createDocumentFile
import com.smileidentity.util.postProcessImage
import com.ujizin.camposer.state.CameraState
import com.ujizin.camposer.state.ImageCaptureResult
import io.sentry.Breadcrumb
import io.sentry.SentryLevel
import java.io.File
import java.io.IOException
import kotlin.math.abs
import kotlin.time.Duration.Companion.seconds
import kotlin.time.TimeSource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber

private const val ANALYSIS_SAMPLE_INTERVAL_MS = 350
Expand Down Expand Up @@ -148,19 +154,63 @@ class DocumentCaptureViewModel(
cameraState.takePicture(documentFile) { result ->
when (result) {
is ImageCaptureResult.Success -> {
_uiState.update {
it.copy(
documentImageToConfirm = postProcessImage(
documentFile,
desiredAspectRatio = uiState.value.idAspectRatio,
),
showCaptureInProgress = false,
)
viewModelScope.launch {
try {
val processedImage = withContext(Dispatchers.Default) {
postProcessImage(
documentFile,
desiredAspectRatio = uiState.value.idAspectRatio,
)
}
_uiState.update {
it.copy(
documentImageToConfirm = processedImage,
showCaptureInProgress = false,
)
}
} catch (e: IOException) {
Timber.e(e, "IOException processing captured image")
SmileIDCrashReporting.hub.captureException(e) {
it.level = SentryLevel.INFO
it.addBreadcrumb(
Breadcrumb(
"Smile ID DocumentCaptureViewModel " +
"IOException",
),
)
}
_uiState.update {
it.copy(captureError = e, showCaptureInProgress = false)
}
} catch (e: OutOfMemoryError) {
Timber.e(e, "OutOfMemoryError processing captured image")
SmileIDCrashReporting.hub.captureException(e) {
it.level = SentryLevel.INFO
it.addBreadcrumb(
Breadcrumb(
"Smile ID DocumentCaptureViewModel " +
"OutOfMemoryError",
),
)
}
_uiState.update {
it.copy(captureError = e, showCaptureInProgress = false)
}
}
}
}

is ImageCaptureResult.Error -> {
Timber.e("Error capturing document", result.throwable)
Timber.e("ImageCaptureResult.Error capturing document", result.throwable)
SmileIDCrashReporting.hub.captureException(result.throwable) {
it.level = SentryLevel.INFO
it.addBreadcrumb(
Breadcrumb(
"Smile ID DocumentCaptureViewModel " +
"ImageCaptureResult.Error",
),
)
}
_uiState.update {
it.copy(captureError = result.throwable, showCaptureInProgress = false)
}
Expand Down

0 comments on commit 457c92e

Please sign in to comment.