From 2308deba3302c6cd7c967f587426813a39008603 Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Sat, 3 Jan 2026 15:41:50 +0100 Subject: [PATCH] Only pass encoding hint in automatic if UTF-8 If zxing is not explicitly told a barcode is UTF-8, it may render it incorrectly. Which caused https://github.com/CatimaLoyalty/Android/issues/2555. However, when an encode hint is set, it will cause zxing to set an ECI hint inside the barcode, which some scanners may trip over and cause scanning failures, leading to https://github.com/CatimaLoyalty/Android/issues/2921. This change only passes the encoding in automatic mode if zxing explicitly guesses it to be UTF-8, and otherwise doesn't pass anything, to keep the ECI empty. This might need to be expanded for other types like SJIS, but as nobody ever reported such a bug let's assume it's not necessary for now. --- .../protect/card_locker/BarcodeImageWriterTask.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java b/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java index 0588bffda8..a8ca9df1e8 100644 --- a/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java +++ b/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java @@ -22,6 +22,7 @@ import java.lang.ref.WeakReference; import java.nio.charset.Charset; import java.util.Map; +import java.util.Objects; import protect.card_locker.async.CompatCallable; @@ -190,7 +191,16 @@ private Bitmap generate() { } else { String guessedEncoding = StringUtils.guessEncoding(cardId.getBytes(), new ArrayMap<>()); Log.d(TAG, "Guessed encoding: " + guessedEncoding); - encodeHints.put(EncodeHintType.CHARACTER_SET, Charset.forName(guessedEncoding)); + + // We don't want to pass the gussed encoding as an encoding hint unless it is UTF-8 as + // zxing is likely to add the mentioned encoding hint as ECI inside the barcode. + // + // Due to many barcode scanners in the wild being badly coded they may trip over ECI + // info existing and fail to scan, such as in https://github.com/CatimaLoyalty/Android/issues/2921 + if (Objects.equals(guessedEncoding, "UTF8")) { + Log.d(TAG, "Guessed encoding is UTF8, so passing as encoding hint"); + encodeHints.put(EncodeHintType.CHARACTER_SET, Charset.forName(guessedEncoding)); + } } BitMatrix bitMatrix;