mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.45k stars 1.09k forks source link

🐛 [Android] CodeScanner doesn't work at all on Samsung Galaxy A23 (Android 14) #3248

Open MaksymKuzmych opened 5 days ago

MaksymKuzmych commented 5 days ago

What's happening?

Issue: QR Code Scanner Fails on Samsung A23 (Android 14)

After updating from version 3.8.2 to 4.5.3, I've encountered an issue on the Samsung A23 running Android 14. The QR code scanner doesn't appear, and I'm receiving the following error:

[session/recoverable-error: An unknown error occurred while creating the Camera Session, but the Camera can recover from it.]

If I remove either the "codeScanner" or "format" prop, the camera will mount, but it won't scan any QR codes.

Code Sample (CodeScannerPipeline.kt)

    val image = imageProxy.image ?: throw InvalidImageTypeError()

    try {
        val inputImage = InputImage.fromMediaImage(image, imageProxy.imageInfo.rotationDegrees)
        scanner.process(inputImage)
            .addOnSuccessListener { barcodes ->
                if (barcodes.isNotEmpty()) {
                    callback.onCodeScanned(barcodes, CodeScannerFrame(inputImage.width, inputImage.height))
                }
            }
            .addOnFailureListener { error ->
                Log.e(TAG, "Failed to process Image!", error)
                callback.onError(error)
            }
            .addOnCompleteListener {
                imageProxy.close()
            }
    } catch (e: Throwable) {
        Log.e(TAG, "Failed to process Image!", e)
        imageProxy.close()
    }
}

Issue Details:

Has anyone encountered this issue or found a workaround? Any assistance would be appreciated!

Reproduceable Code

const device = useCameraDevice('back');
const format = useCameraFormat(device, [{videoResolution: 'max'}]);

const isFocused = useIsFocused();
const isForeground = useIsForeground();

const isActive = isFocused && isForeground;

const codeScanner = useCodeScanner({
  codeTypes: ['qr', 'ean-13'],
  onCodeScanned: codes => {
    console.log('codes', codes);
  },
});

<Camera
 device={device}
 key={device.id}
 isActive={isActive}
 focusable
 format={format}
 style={cameraStyles}
 codeScanner={codeScanner}
 outputOrientation="preview"
/>

Relevant log output

For [session/recoverable-error: An unknown error occurred while creating the Camera Session, but the Camera can recover from it.]``` (min log level is error because of a lot of logs):

2024-10-16 10:34:14.550  1453-17126 CameraDeviceClient      cameraserver                         E  notifyError: pid=20146, errorCode=0, errorStreamId=-1, frameNumber=0
2024-10-16 10:34:14.550  1453-17126 CameraDeviceClient      cameraserver                         E  notifyError: pid=20146, skipClientNotification=false
2024-10-16 10:34:14.550  1453-17126 Camera2-Fr...cessorBase cameraserver                         E  removeListener: 
2024-10-16 10:34:14.561 20146-20146 CameraView              com.kryptrchat.debug                 E  invokeOnError(...):
2024-10-16 10:34:14.611 20146-20295 ReactNativeJS           com.kryptrchat.debug                 E  { [session/recoverable-error: An unknown error occurred while creating the Camera Session, but the Camera can recover from it.]
                                                                                                      name: 'session/recoverable-error',
                                                                                                      _code: 'session/recoverable-error',
                                                                                                      _message: 'An unknown error occurred while creating the Camera Session, but the Camera can recover from it.',
                                                                                                      _cause: undefined }
2024-10-16 10:34:14.659  1453-20451 ProcessCallStack        cameraserver                         E  getThreadName: Failed to open /proc/self/task/20454/comm
2024-10-16 10:34:14.673  1453-20451 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 0 frame 28 , due to buffer error.
2024-10-16 10:34:14.673  1453-20451 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 1 frame 28 , due to buffer error.
2024-10-16 10:34:14.673  1453-17126 HidlCamera3-Device      cameraserver                         E  flush: Transaction error: Status(EX_TRANSACTION_FAILED): 'DEAD_OBJECT: '
2024-10-16 10:34:14.673  1453-17126 CameraDeviceClient      cameraserver                         E  detachDevice: flush failed with code 0xffffffe0
2024-10-16 10:34:14.673  1453-17126 Camera3-Device          cameraserver                         E  Camera 0: disconnectImpl: Shutting down in an error state
2024-10-16 10:34:14.674  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 1 frame 27 , due to buffer error.
2024-10-16 10:34:14.675  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 1 frame 26 , due to buffer error.
2024-10-16 10:34:14.675  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 0 frame 27 , due to buffer error.
2024-10-16 10:34:14.675  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 1 frame 25 , due to buffer error.
2024-10-16 10:34:14.676  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 0 frame 26 , due to buffer error.
2024-10-16 10:34:14.676  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 1 frame 24 , due to buffer error.
2024-10-16 10:34:14.676  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 0 frame 25 , due to buffer error.
2024-10-16 10:34:14.676  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 1 frame 23 , due to buffer error.
2024-10-16 10:34:14.677  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 0 frame 24 , due to buffer error.
2024-10-16 10:34:14.677  1453-17126 Camera3-OutputStream    cameraserver                         E  returnBufferCheckedLocked: A frame is dropped for stream 0 frame 23 , due to buffer error.
2024-10-16 10:34:14.848 20744-20744 CamX                    ven...amera.provider@4.0-service_64  E  [ERROR][CORE   ] camxsettingsmanager.cpp:381 UpdateLogSettings() Type: user, CamDebug:0, SysDebug: 1
2024-10-16 10:34:14.856 20744-20744 CamX                    ven...amera.provider@4.0-service_64  E  [ERROR][CORE   ] camxsettingsmanager.cpp:381 UpdateLogSettings() Type: user, CamDebug:0, SysDebug: 1
2024-10-16 10:34:14.860 20744-20744 DEWARP                  ven...amera.provider@4.0-service_64  E  [SS_ERR]camxchinodedewarp.cpp:2297 ChiNodeEntry()Dewarp Node OpenGL CHINODEEntry funtion
2024-10-16 10:34:14.889 20744-20744 vendor.sam...service_64 ven...amera.provider@4.0-service_64  E  ChiAWBAlgorithmEntry
2024-10-16 10:34:14.912 20744-20744 CHI                     ven...amera.provider@4.0-service_64  E  AEC ChiAECAlgorithmEntry
2024-10-16 10:34:14.913 20744-20744 CHI                     ven...amera.provider@4.0-service_64  E  AF ChiAFAlgorithmEntry
2024-10-16 10:34:14.914 20744-20744 CHI                     ven...amera.provider@4.0-service_64  E  AWB ChiAWBAlgorithmEntry
2024-10-16 10:34:14.917  1364-6386  NotificationService     system_server                        E  isPkgBlocked = true
2024-10-16 10:34:14.917  1364-6386  NotificationService     system_server                        E  isRecordBlocked = false
2024-10-16 10:34:14.917  1364-6386  NotificationService     system_server                        E  Suppressing notification from package li.kryptr.areal.support by user request.
2024-10-16 10:34:14.963 31186-19921 WakeLock                com.google.android.gms.persistent    E  GCM_HB_ALARM release without a matched acquire!
2024-10-16 10:34:14.969 31186-19921 WakeLock                com.google.android.gms.persistent    E  GCM_CONN_ALARM release without a matched acquire!
2024-10-16 10:34:14.989  4310-4901  PhoneInterfaceManager   com.android.phone                    E  getCarrierPrivilegeStatusForUid: Invalid subId
2024-10-16 10:34:15.007  1364-2290  JobSchedul...oncurrency system_server                        E  Error executing JobStatus{82f8ca5 #u0a157/2131230721 com.facebook.appmanager/com.facebook.analytics2.logger.LollipopUploadService u=0 s=10157 TIME=-22h6m6s429ms:none NET failures=1 READY}
2024-10-16 10:34:15.013  4310-5053  PhoneInterfaceManager   com.android.phone                    E  getCarrierPrivilegeStatusForUid: Invalid subId
2024-10-16 10:34:15.026  4310-4326  PhoneInterfaceManager   com.android.phone                    E  getCarrierPrivilegeStatusForUid: Invalid subId
2024-10-16 10:34:15.050  1364-4313  SLocation               system_server                        E  SGeofenceCellManager - handleCellLocation phoneState is power off
2024-10-16 10:34:15.127  1364-1837  NotificationService     system_server                        E  isPkgBlocked = true
2024-10-16 10:34:15.127  1364-1837  NotificationService     system_server                        E  isRecordBlocked = false
2024-10-16 10:34:15.127  1364-1837  NotificationService     system_server                        E  Suppressing notification from package li.kryptr.areal.support by user request.
2024-10-16 10:34:15.307  1364-4313  SLocation               system_server                        E  SGeofenceCellManager - handleCellLocation phoneState is power off
2024-10-16 10:34:15.308  4310-28212 PhoneInterfaceManager   com.android.phone                    E  getCarrierPrivilegeStatusForUid: Invalid subId
2024-10-16 10:34:15.320  4310-28212 PhoneInterfaceManager   com.android.phone                    E  getCarrierPrivilegeStatusForUid: Invalid subId
2024-10-16 10:34:15.370  1364-2290  JobSchedul...oncurrency system_server                        E  Error executing JobStatus{82f8ca5 #u0a157/2131230721 com.facebook.appmanager/com.facebook.analytics2.logger.LollipopUploadService u=0 s=10157 TIME=-22h6m6s792ms:none NET failures=1 READY}
2024-10-16 10:34:15.377  4310-4328  PhoneInterfaceManager   com.android.phone                    E  getCarrierPrivilegeStatusForUid: Invalid subId
2024-10-16 10:34:15.428 20146-20304 SequentialExecutor      com.kryptrchat.debug                 E  Exception while executing runnable androidx.camera.camera2.internal.Camera2CameraImpl$$ExternalSyntheticLambda17@d247323
                                                                                                    java.lang.IllegalArgumentException: getCameraCharacteristics:1123: Unable to retrieve camera characteristics for unknown device 1: No such file or directory (-2)
                                                                                                        at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:2014)
                                                                                                        at android.hardware.camera2.CameraManager.getCameraCharacteristics(CameraManager.java:863)
                                                                                                        at android.hardware.camera2.CameraManager.getCameraCharacteristics(CameraManager.java:781)
                                                                                                        at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:937)
                                                                                                        at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:1274)
                                                                                                        at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:1296)
                                                                                                        at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:1171)
                                                                                                        at androidx.camera.camera2.internal.compat.CameraManagerCompatApi29Impl.openCamera(CameraManagerCompatApi29Impl.java:44)
                                                                                                        at androidx.camera.camera2.internal.compat.CameraManagerCompat.openCamera(CameraManagerCompat.java:231)
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.openCameraDevice(Camera2CameraImpl.java:1414)
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.tryForceOpenCameraDevice(Camera2CameraImpl.java:1347)
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.openInternal(Camera2CameraImpl.java:347)
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.tryAttachUseCases(Camera2CameraImpl.java:1003)
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.lambda$attachUseCases$15$androidx-camera-camera2-internal-Camera2CameraImpl(Camera2CameraImpl.java:941)
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl$$ExternalSyntheticLambda17.run(D8$$SyntheticClass:0)
                                                                                                        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:229)
                                                                                                        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:171)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
                                                                                                    Caused by: android.os.ServiceSpecificException: getCameraCharacteristics:1123: Unable to retrieve camera characteristics for unknown device 1: No such file or directory (-2) (code 3)
                                                                                                        at android.os.Parcel.createExceptionOrNull(Parcel.java:3083)
                                                                                                        at android.os.Parcel.createException(Parcel.java:3053)
                                                                                                        at android.os.Parcel.readException(Parcel.java:3036)
                                                                                                        at android.os.Parcel.readException(Parcel.java:2978)
                                                                                                        at android.hardware.ICameraService$Stub$Proxy.getCameraCharacteristics(ICameraService.java:996)
                                                                                                        at android.hardware.camera2.CameraManager.getCameraCharacteristics(CameraManager.java:842)
                                                                                                        at android.hardware.camera2.CameraManager.getCameraCharacteristics(CameraManager.java:781) 
                                                                                                        at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:937) 
                                                                                                        at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:1274) 
                                                                                                        at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:1296) 
                                                                                                        at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:1171) 
                                                                                                        at androidx.camera.camera2.internal.compat.CameraManagerCompatApi29Impl.openCamera(CameraManagerCompatApi29Impl.java:44) 
                                                                                                        at androidx.camera.camera2.internal.compat.CameraManagerCompat.openCamera(CameraManagerCompat.java:231) 
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.openCameraDevice(Camera2CameraImpl.java:1414) 
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.tryForceOpenCameraDevice(Camera2CameraImpl.java:1347) 
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.openInternal(Camera2CameraImpl.java:347) 
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.tryAttachUseCases(Camera2CameraImpl.java:1003) 
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl.lambda$attachUseCases$15$androidx-camera-camera2-internal-Camera2CameraImpl(Camera2CameraImpl.java:941) 
                                                                                                        at androidx.camera.camera2.internal.Camera2CameraImpl$$ExternalSyntheticLambda17.run(D8$$SyntheticClass:0) 
                                                                                                        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:229) 
                                                                                                        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:171) 
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) 
                                                                                                        at java.lang.Thread.run(Thread.java:1012) 
2024-10-16 10:34:15.476 31186-18895 WakeLock                com.google.android.gms.persistent    E  GCM_CONN_ALARM release without a matched acquire!
2024-10-16 10:34:16.310   922-944   Netd                    netd                                 E  interface tun0 not assigned to any netId
2024-10-16 10:34:16.311  1364-3887  ConnectivityService     system_server                        E  Exception in removeRoute: android.os.ServiceSpecificException: No such device (code 19)
2024-10-16 10:34:16.311   922-944   Netd                    netd                                 E  interface tun0 not assigned to any netId
2024-10-16 10:34:16.311  1364-3887  ConnectivityService     system_server                        E  Exception in removeRoute: android.os.ServiceSpecificException: No such device (code 19)
2024-10-16 10:34:16.311   922-944   Netd                    netd                                 E  interface tun0 not assigned to any netId
2024-10-16 10:34:16.312  1364-3887  ConnectivityService     system_server                        E  Exception in removeRoute: android.os.ServiceSpecificException: No such device (code 19)
2024-10-16 10:34:16.312   922-944   Netd                    netd                                 E  interface tun0 not assigned to any netId
2024-10-16 10:34:16.312  1364-3887  ConnectivityService     system_server                        E  Exception in removeRoute: android.os.ServiceSpecificException: No such device (code 19)
2024-10-16 10:34:16.317  1364-4900  NotificationService     system_server                        E  isPkgBlocked = true
2024-10-16 10:34:16.317  1364-4900  NotificationService     system_server                        E  isRecordBlocked = false
2024-10-16 10:34:16.317  1364-4900  NotificationService     system_server                        E  Suppressing notification from package li.kryptr.areal.support by user request.

Camera Device

{
  "formats": [],
  "sensorOrientation": "landscape-left",
  "hardwareLevel": "full",
  "maxZoom": 8,
  "minZoom": 1,
  "maxExposure": 20,
  "supportsLowLightBoost": false,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": false,
  "isMultiCam": false,
  "minFocusDistance": 10,
  "minExposure": -20,
  "name": "0 (BACK) androidx.camera.camera2",
  "hasFlash": true,
  "hasTorch": true,
  "position": "back",
  "id": "0"
}

Device

Samsung Galaxy A23 (Android 14)

VisionCamera Version

4.5.3

Can you reproduce this issue in the VisionCamera Example app?

No, I cannot reproduce the issue in the Example app

Additional information

maintenance-hans[bot] commented 5 days ago

Guten Tag, Hans here! 🍻

This looks like a valid issue and you provided relevant logs, Danke! It seems you have detailed the behaviour on your Samsung Galaxy A23 with Android 14 after updating. However, not being able to reproduce the issue in the Example app suggests that it could be device-specific or related to your specific configuration. I recommend double-checking all your camera permissions and settings.

If the issue persists, please monitor for updates from mrousavy. Feel free to sponsor the project here to support further development!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

MaksymKuzmych commented 5 days ago

Guten Tag, Hans here! 🍻

This looks like a valid issue and you provided relevant logs, Danke! It seems you have detailed the behaviour on your Samsung Galaxy A23 with Android 14 after updating. However, not being able to reproduce the issue in the Example app suggests that it could be device-specific or related to your specific configuration. I recommend double-checking all your camera permissions and settings.

If the issue persists, please monitor for updates from mrousavy. Feel free to sponsor the project here to support further development!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

But it's working with version 3.8.2 of the same model, so it shouldn't be a problem with permissions or settings.

maintenance-hans[bot] commented 5 days ago
it ain't much, but it's honest work
zwerg44 commented 5 days ago

Hi guys, Thanks for a great work on react-native-vision-camera

I'm also experiencing same issue with Samsung A23 5G (SM-A236B) I haven't opened ticket yet, trying to dig for some details first, but I don't have the A23 device. I upgraded from 2.16.1 to 4.5.2 recently and my users with A23 complain that built-in QR-scanning not works. Users with other phones have QR-scanning working.

I'm using now:

@MaksymKuzmych do you have A23 phone on your side to debug this? Could you maybe try to:

Some details from my users:

I found this topic on flutter camera library:

I'm digging in this direction now:

zwerg44 commented 4 days ago

@MaksymKuzmych

And here is a sample with debug output of frame to skia: https://gist.github.com/zwerg44/2284ce92160f7c93184f2b2b899b0da1

But on my phone and also my emulator:

Not sure why? is it issue with resize-plugin? or 4.5.2 produces corrupted frames? I can imagine MLkit can digest sometimes even corrupted frames like this.

My phone output from sample:

Same sample with pixelFormat='rgba':

zwerg44 commented 4 days ago

Updated my gist sample with debug output to skia:

MaksymKuzmych commented 4 days ago

Updated my gist sample with debug output to skia:

Hi, @zwerg44 Thanks for the answer. The first thing I tried to do was just replace my

const format = useCameraFormat(device, [{videoResolution: 'max'}]);

with the format in your suggestion

const format = useCameraFormat(device, [{videoResolution: {width: 640, height: 480}}]);

and for now it works and I don't receive the Error

[session/recoverable-error: An unknown error occurred while creating the Camera Session, but the Camera can recover from it.]

Yes, the quality is worse than before, but it scanning QR codes really good without any problems, so I just did the helper function just for this model:

export const getVideoResolution = () => {
  const deviceName = DeviceInfo.getDeviceNameSync();

  return deviceName === 'Galaxy A23 5G' ? {width: 640, height: 480} : 'max';
};
zwerg44 commented 3 days ago

I also confirm that just passing 640x480 format helped all my users with A23 5G

I used workaround like this:

// constants
const MODEL = DeviceInfo.getModel();
const MODELS_HAS_CAMERA_ISSUE = [
  'SM-A235F',
  'SM-A235M',
  'SM-A235N',
  'SM-A233C',
  'SM-A2360',
  'SM-A236B', // my users
  'SM-A236E',
  'SM-A236M',
  'SM-A236U',
  'SM-A236U1',
  'SM-S236DL',
  'SM-S237VL',
  'SM-A236V',
];
const HAS_CAMERA_ISSUE = MODELS_HAS_CAMERA_ISSUE.includes(MODEL);

...
// and then passed format like this to camera
const selectedFormat = useCameraFormat(device, [{ videoResolution: { width: 640, height: 480 } }]);
const format = HAS_CAMERA_ISSUE ? selectedFormat : undefined;