-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix decodeFile Null Crash #556
Open
tobitech
wants to merge
21
commits into
main
Choose a base branch
from
fix-decodefile-null-crash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4c8bfef
Use app-specific external storage for saving images via getExternalFi…
tobitech ccfe6b3
remove comment.
tobitech ed4421a
handle decodefile error and let the user retake the selfie when image…
tobitech 002a2b8
code formatting.
tobitech ee3808f
code formatting
tobitech 5836931
pass the bitmap from selfie view model to the capture screen for imag…
tobitech 2c9da86
remove imports no longer needed.
tobitech 329e7a3
revert bitmap back for decodefile
tobitech 688d6f3
linting
tobitech 944cfb9
Merge branch 'main' into fix-decodefile-null-crash
tobitech 8969a00
add a new error message and also check if selfie file is null in view…
tobitech 8008918
set the result for the callback and also capture the exception for se…
tobitech c6d518c
code formatting.
tobitech f2eac6b
add a file validity check for selfie file.
tobitech f5714c7
reset liveness files if selfie file is null before image confirmation.
tobitech 558e0bd
update changelog.
tobitech 528ad37
revert back to internal storage directory.
tobitech 1447e27
Merge branch 'main' into fix-decodefile-null-crash
tobitech b9f2797
changelog update.
tobitech aeb1d4c
reworked document and selfie file handling
jumaallan 38d890b
to delete this commit
jumaallan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.smileidentity.compose.document | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import androidx.activity.compose.rememberLauncherForActivityResult | ||
import androidx.activity.result.PickVisualMediaRequest | ||
|
@@ -55,6 +56,7 @@ import com.smileidentity.compose.preview.Preview | |
import com.smileidentity.compose.preview.SmilePreviews | ||
import com.smileidentity.models.v2.Metadatum | ||
import com.smileidentity.util.createDocumentFile | ||
import com.smileidentity.util.isNull | ||
import com.smileidentity.util.isValidDocumentImage | ||
import com.smileidentity.util.toast | ||
import com.smileidentity.util.writeUriToFile | ||
|
@@ -155,37 +157,49 @@ fun DocumentCaptureScreen( | |
) | ||
} | ||
|
||
documentImageToConfirm != null -> { | ||
!documentImageToConfirm.isNull() -> { | ||
val painter = remember { | ||
val path = documentImageToConfirm.absolutePath | ||
val path = documentImageToConfirm?.absolutePath | ||
try { | ||
BitmapPainter(BitmapFactory.decodeFile(path).asImageBitmap()) | ||
BitmapFactory.decodeFile(path)?.let { bitmap: Bitmap -> | ||
BitmapPainter(bitmap.asImageBitmap()) | ||
} ?: run { | ||
SmileIDCrashReporting.hub.addBreadcrumb( | ||
"Failed to decode document image at $path", | ||
) | ||
ColorPainter(Color.Black) | ||
} | ||
} catch (e: Exception) { | ||
SmileIDCrashReporting.hub.addBreadcrumb("Error loading document image at $path") | ||
SmileIDCrashReporting.hub.addBreadcrumb( | ||
"Error loading document image at $path", | ||
) | ||
SmileIDCrashReporting.hub.captureException(e) | ||
onError(e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jumaallan I think we might have deleted the onError by accident? We should likely keep it to trigger the error screen. |
||
ColorPainter(Color.Black) | ||
} | ||
} | ||
if (showConfirmation) { | ||
ImageCaptureConfirmationDialog( | ||
titleText = stringResource(id = R.string.si_doc_v_confirmation_dialog_title), | ||
subtitleText = stringResource( | ||
id = R.string.si_doc_v_confirmation_dialog_subtitle, | ||
), | ||
painter = painter, | ||
scaleFactor = PREVIEW_SCALE_FACTOR, | ||
confirmButtonText = stringResource( | ||
id = R.string.si_doc_v_confirmation_dialog_confirm_button, | ||
), | ||
onConfirm = { viewModel.onConfirm(documentImageToConfirm, onConfirm) }, | ||
retakeButtonText = stringResource( | ||
id = R.string.si_doc_v_confirmation_dialog_retake_button, | ||
), | ||
onRetake = viewModel::onRetry, | ||
) | ||
} else { | ||
viewModel.onConfirm(documentImageToConfirm, onConfirm) | ||
documentImageToConfirm?.let { | ||
if (showConfirmation) { | ||
ImageCaptureConfirmationDialog( | ||
titleText = stringResource( | ||
id = R.string.si_doc_v_confirmation_dialog_title, | ||
), | ||
subtitleText = stringResource( | ||
id = R.string.si_doc_v_confirmation_dialog_subtitle, | ||
), | ||
painter = painter, | ||
scaleFactor = PREVIEW_SCALE_FACTOR, | ||
confirmButtonText = stringResource( | ||
id = R.string.si_doc_v_confirmation_dialog_confirm_button, | ||
), | ||
onConfirm = { viewModel.onConfirm(documentImageToConfirm, onConfirm) }, | ||
retakeButtonText = stringResource( | ||
id = R.string.si_doc_v_confirmation_dialog_retake_button, | ||
), | ||
onRetake = viewModel::onRetry, | ||
) | ||
} else { | ||
viewModel.onConfirm(documentImageToConfirm, onConfirm) | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
package com.smileidentity.compose.selfie | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.consumeWindowInsets | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.statusBars | ||
import androidx.compose.foundation.layout.windowInsetsPadding | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.runtime.snapshots.SnapshotStateList | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.asImageBitmap | ||
import androidx.compose.ui.graphics.painter.BitmapPainter | ||
import androidx.compose.ui.graphics.painter.ColorPainter | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import com.smileidentity.R | ||
import com.smileidentity.SmileIDCrashReporting | ||
import com.smileidentity.compose.components.ImageCaptureConfirmationDialog | ||
import com.smileidentity.compose.components.LocalMetadata | ||
import com.smileidentity.compose.components.ProcessingScreen | ||
import com.smileidentity.models.v2.Metadatum | ||
import com.smileidentity.results.SmartSelfieResult | ||
import com.smileidentity.results.SmileIDCallback | ||
import com.smileidentity.util.isNull | ||
import com.smileidentity.util.randomJobId | ||
import com.smileidentity.util.randomUserId | ||
import com.smileidentity.viewmodel.SelfieViewModel | ||
|
@@ -70,67 +78,92 @@ | |
) { | ||
val uiState = viewModel.uiState.collectAsStateWithLifecycle().value | ||
var acknowledgedInstructions by rememberSaveable { mutableStateOf(false) } | ||
Box( | ||
Column ( | ||
modifier = modifier | ||
.background(color = MaterialTheme.colorScheme.background) | ||
.windowInsetsPadding(WindowInsets.statusBars) | ||
.consumeWindowInsets(WindowInsets.statusBars) | ||
.fillMaxSize(), | ||
) { | ||
when { | ||
showInstructions && !acknowledgedInstructions -> SmartSelfieInstructionsScreen( | ||
showAttribution = showAttribution, | ||
) { | ||
acknowledgedInstructions = true | ||
} | ||
Text("The count is ${uiState.counttt}") | ||
SelfieCaptureScreen( | ||
userId = userId, | ||
jobId = jobId, | ||
isEnroll = isEnroll, | ||
allowAgentMode = allowAgentMode, | ||
skipApiSubmission = skipApiSubmission, | ||
) | ||
|
||
uiState.processingState != null -> ProcessingScreen( | ||
processingState = uiState.processingState, | ||
inProgressTitle = stringResource(R.string.si_smart_selfie_processing_title), | ||
inProgressSubtitle = stringResource(R.string.si_smart_selfie_processing_subtitle), | ||
inProgressIcon = painterResource(R.drawable.si_smart_selfie_processing_hero), | ||
successTitle = stringResource(R.string.si_smart_selfie_processing_success_title), | ||
successSubtitle = uiState.errorMessage.resolve().takeIf { it.isNotEmpty() } | ||
?: stringResource(R.string.si_smart_selfie_processing_success_subtitle), | ||
successIcon = painterResource(R.drawable.si_processing_success), | ||
errorTitle = stringResource(R.string.si_smart_selfie_processing_error_title), | ||
errorSubtitle = uiState.errorMessage.resolve().takeIf { it.isNotEmpty() } | ||
?: stringResource(id = R.string.si_processing_error_subtitle), | ||
errorIcon = painterResource(R.drawable.si_processing_error), | ||
continueButtonText = stringResource(R.string.si_continue), | ||
onContinue = { viewModel.onFinished(onResult) }, | ||
retryButtonText = stringResource(R.string.si_smart_selfie_processing_retry_button), | ||
onRetry = viewModel::onRetry, | ||
closeButtonText = stringResource(R.string.si_smart_selfie_processing_close_button), | ||
onClose = { viewModel.onFinished(onResult) }, | ||
) | ||
|
||
uiState.selfieToConfirm != null -> ImageCaptureConfirmationDialog( | ||
titleText = stringResource(R.string.si_smart_selfie_confirmation_dialog_title), | ||
subtitleText = stringResource( | ||
R.string.si_smart_selfie_confirmation_dialog_subtitle, | ||
), | ||
painter = BitmapPainter( | ||
BitmapFactory.decodeFile(uiState.selfieToConfirm.absolutePath).asImageBitmap(), | ||
), | ||
confirmButtonText = stringResource( | ||
R.string.si_smart_selfie_confirmation_dialog_confirm_button, | ||
), | ||
onConfirm = viewModel::submitJob, | ||
retakeButtonText = stringResource( | ||
R.string.si_smart_selfie_confirmation_dialog_retake_button, | ||
), | ||
onRetake = viewModel::onSelfieRejected, | ||
scaleFactor = 1.25f, | ||
) | ||
|
||
else -> SelfieCaptureScreen( | ||
userId = userId, | ||
jobId = jobId, | ||
isEnroll = isEnroll, | ||
allowAgentMode = allowAgentMode, | ||
skipApiSubmission = skipApiSubmission, | ||
) | ||
} | ||
// when { | ||
// showInstructions && !acknowledgedInstructions -> SmartSelfieInstructionsScreen( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undo/delete? |
||
// showAttribution = showAttribution, | ||
// ) { | ||
// acknowledgedInstructions = true | ||
// } | ||
// | ||
// uiState.processingState != null -> ProcessingScreen( | ||
// processingState = uiState.processingState, | ||
// inProgressTitle = stringResource(R.string.si_smart_selfie_processing_title), | ||
// inProgressSubtitle = stringResource(R.string.si_smart_selfie_processing_subtitle), | ||
// inProgressIcon = painterResource(R.drawable.si_smart_selfie_processing_hero), | ||
// successTitle = stringResource(R.string.si_smart_selfie_processing_success_title), | ||
// successSubtitle = uiState.errorMessage.resolve().takeIf { it.isNotEmpty() } | ||
// ?: stringResource(R.string.si_smart_selfie_processing_success_subtitle), | ||
// successIcon = painterResource(R.drawable.si_processing_success), | ||
// errorTitle = stringResource(R.string.si_smart_selfie_processing_error_title), | ||
// errorSubtitle = uiState.errorMessage.resolve().takeIf { it.isNotEmpty() } | ||
// ?: stringResource(id = R.string.si_processing_error_subtitle), | ||
// errorIcon = painterResource(R.drawable.si_processing_error), | ||
// continueButtonText = stringResource(R.string.si_continue), | ||
// onContinue = { viewModel.onFinished(onResult) }, | ||
// retryButtonText = stringResource(R.string.si_smart_selfie_processing_retry_button), | ||
// onRetry = viewModel::onRetry, | ||
// closeButtonText = stringResource(R.string.si_smart_selfie_processing_close_button), | ||
// onClose = { viewModel.onFinished(onResult) }, | ||
// ) | ||
// | ||
// // !uiState.selfieToConfirm.isNull() -> ImageCaptureConfirmationDialog( | ||
// // titleText = stringResource(R.string.si_smart_selfie_confirmation_dialog_title), | ||
// // subtitleText = stringResource( | ||
// // R.string.si_smart_selfie_confirmation_dialog_subtitle, | ||
// // ), | ||
// // painter = remember { | ||
// // val path = uiState.selfieToConfirm?.absolutePath | ||
// // try { | ||
// // BitmapFactory.decodeFile(path)?.let { bitmap: Bitmap -> | ||
// // BitmapPainter(bitmap.asImageBitmap()) | ||
// // } ?: run { | ||
// // SmileIDCrashReporting.hub.addBreadcrumb( | ||
// // "Failed to decode selfie image at $path", | ||
// // ) | ||
// // ColorPainter(Color.Black) | ||
// // } | ||
// // } catch (e: Exception) { | ||
// // SmileIDCrashReporting.hub.addBreadcrumb( | ||
// // "Error loading selfie image at $path", | ||
// // ) | ||
// // SmileIDCrashReporting.hub.captureException(e) | ||
// // ColorPainter(Color.Black) | ||
// // } | ||
// // }, | ||
// // confirmButtonText = stringResource( | ||
// // R.string.si_smart_selfie_confirmation_dialog_confirm_button, | ||
// // ), | ||
// // onConfirm = viewModel::submitJob, | ||
// // retakeButtonText = stringResource( | ||
// // R.string.si_smart_selfie_confirmation_dialog_retake_button, | ||
// // ), | ||
// // onRetake = viewModel::onSelfieRejected, | ||
// // scaleFactor = 1.25f, | ||
// // ) | ||
// | ||
// else -> SelfieCaptureScreen( | ||
// userId = userId, | ||
// jobId = jobId, | ||
// isEnroll = isEnroll, | ||
// allowAgentMode = allowAgentMode, | ||
// skipApiSubmission = skipApiSubmission, | ||
// ) | ||
// } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as long as we don't sample this bitmap this will always crash with OOM