Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import com.getcode.theme.GradientSpec
import com.getcode.theme.White
import com.getcode.ui.utils.toAGColor
import com.getcode.util.resources.ResourceHelper
import com.getcode.utils.TraceType
import com.getcode.utils.decodeBase64
import com.getcode.utils.trace
import androidx.lifecycle.ViewModel
import com.getcode.view.LoadingSuccessState
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -91,15 +93,28 @@ abstract class BaseAccessKeyViewModel(
}

viewModelScope.launch(dispatchers.IO) {
val accessKeyBitmap = createBitmapForExport(drawBackground = true, words = words, entropyB64 = entropyB64)
val accessKeyBitmapDisplay = createBitmapForExport(drawBackground = false, words, entropyB64)
val accessKeyCroppedBitmap =
Bitmap.createBitmap(accessKeyBitmapDisplay, 0, 500, 1200, 1450)

uiFlow.update {
it.copy(
accessKeyBitmap = accessKeyBitmap,
accessKeyCroppedBitmap = accessKeyCroppedBitmap
runCatching {
val accessKeyBitmap = createBitmapForExport(drawBackground = true, words = words, entropyB64 = entropyB64)
val accessKeyBitmapDisplay = createBitmapForExport(drawBackground = false, words, entropyB64)
val accessKeyCroppedBitmap =
Bitmap.createBitmap(accessKeyBitmapDisplay, 0, 500, 1200, 1450)

uiFlow.update {
it.copy(
accessKeyBitmap = accessKeyBitmap,
accessKeyCroppedBitmap = accessKeyCroppedBitmap
)
}
}.onFailure { error ->
if (error is kotlin.coroutines.cancellation.CancellationException) throw error
// Bitmap rendering can fail on some OEM devices with
// "width and height must be > 0". Report as a non-fatal instead
// of crashing; the UI handles null bitmaps. Refs Bugsnag 6a4528ca.
trace(
tag = "access-key",
message = "Failed to render access key bitmap",
error = error,
type = TraceType.Error,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ internal fun generateQr(
null
}

val matrixWidth = bitmapMatrix?.width ?: size
val matrixHeight = bitmapMatrix?.height ?: size
// Guard against a zero/negative dimension reaching Bitmap.createBitmap,
// which throws IllegalArgumentException("width and height must be > 0").
val matrixWidth = (bitmapMatrix?.width ?: size).coerceAtLeast(1)
val matrixHeight = (bitmapMatrix?.height ?: size).coerceAtLeast(1)

val newBitmap = createBitmap(bitmapMatrix?.width ?: size, bitmapMatrix?.height ?: size)
val newBitmap = createBitmap(matrixWidth, matrixHeight)

val pixels = IntArray(matrixWidth * matrixHeight)

Expand Down
Loading