apache / cordova-plugin-camera

Apache Cordova Plugin camera
https://cordova.apache.org/
Apache License 2.0
966 stars 1.55k forks source link

The app crashes when taking photos on Android 14 #891

Closed nomori7010 closed 1 month ago

nomori7010 commented 4 months ago

Bug Report

Problem Description

Expected Behavior

To be able to take photos using the camera.

Actual Behavior

The app crashes.

Related Information

cordova plugin list

"cordova-custom-config": "5.1.1", "cordova-plugin-camera": "7.0.0", "cordova-plugin-dialogs": "2.0.2", "cordova-plugin-file": "8.1.0", "cordova-plugin-geolocation": "5.0.0", "cordova-plugin-inappbrowser": "6.0.0", "monaca-plugin-monaca-core": "3.3.1", "ncmb-push-monaca-plugin": "3.2.2", "cordova-plugin-network-information": "3.0.0", "cordova-plugin-device": "3.0.0", "monaca-plugin-webintent": "1.0.1", "cordova.plugins.diagnostic": ""

Command or Code

navigator.camera.getPicture(
  function(imgUri){
    this.photoSelected = new Date().getFullYear() + "/" + (new Date().getMonth() + 1)  + "/" + new Date().getDate() + " " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds();
    window.resolveLocalFileSystemURL(imgUri, 
      function(fileEntry)
      {
        fileEntry.file(
          function(file){ 
            var reader = new FileReader();
            reader.onloadend = function(event){callback(new Blob([event.target.result]));}
            reader.readAsArrayBuffer(file);
          }, 
          function(error){
            try{errcallback(error)}catch(e){}
          }
        );
      }, 
      function(error)
      {
        try{errcallback(error)}catch(e){}
      }
    );
  }, 
  function(message){
    try{
      errcallback(error)
    }catch(e){}
  }, 
  { 
    quality: this.quality,
    destinationType: 1,
    allowEdit: false,
    encodingType: 0, 
    correctOrientation: true, 
    saveToPhotoAlbum: true,
    sourceType: (options === undefined || options.sourceType === undefined)? 1: options.sourceType
  }
);

Environment, Platform, Device

Version Information

Checklist

nomori7010 commented 4 months ago

Below is the detailed crash log.

Exception java.lang.RuntimeException:
  at android.app.ActivityThread.deliverResults (ActivityThread.java:5528)
  at android.app.ActivityThread.handleSendResult (ActivityThread.java:5567)
  at android.app.servertransaction.ActivityResultItem.execute (ActivityResultItem.java:67)
  at android.app.servertransaction.ActivityTransactionItem.execute (ActivityTransactionItem.java:45)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:139)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:96)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2444)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loopOnce (Looper.java:205)
  at android.os.Looper.loop (Looper.java:294)
  at android.app.ActivityThread.main (ActivityThread.java:8223)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:552)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:977)
Caused by android.app.RecoverableSecurityException:
  at android.app.RecoverableSecurityException$1.createFromParcel (RecoverableSecurityException.java:197)
  at android.app.RecoverableSecurityException$1.createFromParcel (RecoverableSecurityException.java:194)
  at android.os.Parcel.readParcelableInternal (Parcel.java:4870)
  at android.os.Parcel.readParcelable (Parcel.java:4852)
  at android.os.Parcel.createExceptionOrNull (Parcel.java:3052)
  at android.os.Parcel.createException (Parcel.java:3041)
  at android.os.Parcel.readException (Parcel.java:3024)
  at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:190)
  at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:142)
  at android.content.ContentProviderProxy.delete (ContentProviderNative.java:661)
  at android.content.ContentResolver.delete (ContentResolver.java:2352)
  at android.content.ContentResolver.delete (ContentResolver.java:2318)
  at org.apache.cordova.camera.CameraLauncher.checkForDuplicateImage (CameraLauncher.java:1277)
  at org.apache.cordova.camera.CameraLauncher.cleanup (CameraLauncher.java:1242)
  at org.apache.cordova.camera.CameraLauncher.processResultFromCamera (CameraLauncher.java:626)
  at org.apache.cordova.camera.CameraLauncher.onActivityResult (CameraLauncher.java:877)
  at org.apache.cordova.CordovaInterfaceImpl.onActivityResult (CordovaInterfaceImpl.java:160)
  at org.apache.cordova.CordovaActivity.onActivityResult (CordovaActivity.java:375)
  at android.app.Activity.dispatchActivityResult (Activity.java:8943)
  at android.app.ActivityThread.deliverResults (ActivityThread.java:5521)
breautek commented 4 months ago

Below is the detailed crash log.

Thanks the stacktrace helps associate the kind of bug, it should be resolved by #781 but the PR needs some work I think.

Gaidralimo commented 3 months ago

Is there any news regarding this issue?

paraschivionut commented 3 months ago

This is also a blocking issue for us. Any news on this?

JohnCastle4 commented 2 months ago

Just to confirm that our customers are experiencing this issue, so resolving it would be greatly appreciated.

Kind regards, John

geoidesic commented 2 months ago

Same problem on iOS but I can't capture any logs there as the safari console log window crashes too. Not sure how else to capture the crash log? I looked in Xcode devices for it but it's not generating any crash logs there either.

lmarcelocc commented 2 months ago

Same problem on iOS but I can't capture any logs there as the safari console log window crashes too. Not sure how else to capture the crash log? I looked in Xcode devices for it but it's not generating any crash logs there either.

Maybe try "Console". Search for "console" on Spotlight.

geoidesic commented 2 months ago

Same problem on iOS but I can't capture any logs there as the safari console log window crashes too. Not sure how else to capture the crash log? I looked in Xcode devices for it but it's not generating any crash logs there either.

Maybe try "Console". Search for "console" on Spotlight.

Thanks, I did that, it brings up a window where I can see crash logs from the iPhone... but there are none. So it's crashing without generating a crash log as far as I can tell.

However, using the log stream on that console, I was able to capture what looks like relevant error messages:

error   12:22:09.929039+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100 complete (res=0x00000000)
error   12:22:09.930191+0100    appleh13camerad Client disconnecting (pid <private>)
error   12:22:09.930814+0100    appleh13camerad Failed to send the com.apple.applecamerad.FlickerDetection event into the diagnostics system 00000000
error   12:22:09.931140+0100    appleh13camerad Failed to report the ISP Flicker Detection to analyticsd: E00002BC
error   12:22:09.928884+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100 complete (res=0x00000000)
error   12:22:09.930119+0100    appleh13camerad Client disconnecting (pid <private>)
error   12:22:09.930740+0100    appleh13camerad Failed to send the com.apple.applecamerad.FlickerDetection event into the diagnostics system 00000000
error   12:22:09.931065+0100    appleh13camerad Failed to report the ISP Flicker Detection to analyticsd: E00002BC
error   12:22:09.997504+0100    appleh13camerad Removing client: pid <private>
error   12:22:09.997653+0100    appleh13camerad Total number of connections: 0
error   12:22:09.999315+0100    appleh13camerad Failed to report the ISP Pearl statistics to analyticsd: E00002BC
error   12:22:10.000122+0100    appleh13camerad Failed to report the ISP Power status to analyticsd: E00002BC
error   12:22:10.000344+0100    appleh13camerad Failed to send the com.apple.applecamerad.FaultManagementStatus event into the diagnostics system 0
error   12:22:09.997431+0100    appleh13camerad Removing client: pid <private>
error   12:22:09.997581+0100    appleh13camerad Total number of connections: 0
error   12:22:09.999243+0100    appleh13camerad Failed to report the ISP Pearl statistics to analyticsd: E00002BC
error   12:22:10.000067+0100    appleh13camerad Failed to report the ISP Power status to analyticsd: E00002BC
error   12:22:10.000287+0100    appleh13camerad Failed to send the com.apple.applecamerad.FaultManagementStatus event into the diagnostics system 0
error   12:22:10.339852+0100    appleh13camerad New connection: kernel
error   12:22:10.339910+0100    appleh13camerad Total number of connections: 1
error   12:22:10.339822+0100    appleh13camerad New connection: kernel
error   12:22:10.339881+0100    appleh13camerad Total number of connections: 1
error   12:22:10.498281+0100    appleh13camerad addClient: Photon Detector device open returned 0
error   12:22:10.510610+0100    appleh13camerad addClient: Photon Detector power on device returned 0
error   12:22:10.498337+0100    appleh13camerad addClient: Photon Detector device open returned 0
error   12:22:10.510689+0100    appleh13camerad addClient: Photon Detector power on device returned 0
error   12:22:10.517538+0100    appleh13camerad New connection: pid <private>
error   12:22:10.517683+0100    appleh13camerad Total number of connections: 2
error   12:22:10.518157+0100    appleh13camerad H13ISPServicesAssistant: getProperty 103
error   12:22:10.518304+0100    appleh13camerad H13ISPServicesAssistant: getProperty 103 complete (res=0x00000000)
error   12:22:10.518920+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100
error   12:22:10.517608+0100    appleh13camerad New connection: pid <private>
error   12:22:10.517755+0100    appleh13camerad Total number of connections: 2
error   12:22:10.518229+0100    appleh13camerad H13ISPServicesAssistant: getProperty 103
error   12:22:10.518377+0100    appleh13camerad H13ISPServicesAssistant: getProperty 103 complete (res=0x00000000)
error   12:22:10.518994+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100
error   12:22:10.588699+0100    biometrickitd   PearlCoreAnalyticsEvent postEvent: com.apple.biometrickit.pearl.faceDetectAttempt result:0
error   12:22:10.588727+0100    biometrickitd   PearlCoreAnalyticsEvent postEvent: com.apple.biometrickit.pearl.faceDetectAttempt result:0
error   12:22:10.591763+0100    biometrickitd   PearlCoreAnalyticsEvent postEvent: com.apple.biometrickit.pearl.attentionCheck result:0
error   12:22:10.591784+0100    biometrickitd   PearlCoreAnalyticsEvent postEvent: com.apple.biometrickit.pearl.attentionCheck result:0
error   12:22:10.688056+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100 complete (res=0x00000000)
error   12:22:10.688322+0100    appleh13camerad Active client pid = 70
error   12:22:10.688394+0100    appleh13camerad Removing client: kernel
error   12:22:10.688019+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100 complete (res=0x00000000)
error   12:22:10.688283+0100    appleh13camerad Active client pid = 70
error   12:22:10.688359+0100    appleh13camerad Removing client: kernel
error   12:22:10.692032+0100    appleh13camerad Total number of connections: 1
error   12:22:10.692338+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100
error   12:22:10.692069+0100    appleh13camerad Total number of connections: 1
error   12:22:10.692375+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100
error   12:22:10.802237+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100 complete (res=0x00000000)
error   12:22:10.802774+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100
error   12:22:10.802320+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100 complete (res=0x00000000)
error   12:22:10.802850+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100
error   12:22:10.930290+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100 complete (res=0x00000000)
error   12:22:10.930449+0100    appleh13camerad H13ISPServicesAssistant: getProperty 100 complete (res=0x00000000)
error   12:22:10.932548+0100    appleh13camerad Client disconnecting (pid <private>)
error   12:22:10.933212+0100    appleh13camerad Failed to send the com.apple.applecamerad.FlickerDetection event into the diagnostics system 00000000
error   12:22:10.933362+0100    appleh13camerad Failed to report the ISP Flicker Detection to analyticsd: E00002BC
error   12:22:10.932621+0100    appleh13camerad Client disconnecting (pid <private>)
error   12:22:10.933286+0100    appleh13camerad Failed to send the com.apple.applecamerad.FlickerDetection event into the diagnostics system 00000000
error   12:22:10.933435+0100    appleh13camerad Failed to report the ISP Flicker Detection to analyticsd: E00002BC
error   12:22:11.002644+0100    appleh13camerad Removing client: pid <private>
error   12:22:11.002615+0100    appleh13camerad Removing client: pid <private>
error   12:22:11.002672+0100    appleh13camerad Total number of connections: 0
error   12:22:11.002700+0100    appleh13camerad Total number of connections: 0
error   12:22:11.002928+0100    appleh13camerad Failed to report the ISP Pearl statistics to analyticsd: E00002BC
error   12:22:11.002902+0100    appleh13camerad Failed to report the ISP Pearl statistics to analyticsd: E00002BC
error   12:22:11.003097+0100    appleh13camerad Failed to report the ISP Power status to analyticsd: E00002BC
error   12:22:11.003070+0100    appleh13camerad Failed to report the ISP Power status to analyticsd: E00002BC
error   12:22:11.003210+0100    appleh13camerad Failed to send the com.apple.applecamerad.FaultManagementStatus event into the diagnostics system 0
error   12:22:11.003182+0100    appleh13camerad Failed to send the com.apple.applecamerad.FaultManagementStatus event into the diagnostics system 0
error   12:22:11.253637+0100    Sportch Unknown chipRevisionID (0xffffffff)
error   12:22:11.254942+0100    Sportch Attempted to change to mode Portrait with an unsupported device (BackWideDual). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
error   12:22:11.254993+0100    Sportch Attempted to change to mode Portrait with an unsupported device (BackWideDual). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
error   12:22:11.253613+0100    Sportch Unknown chipRevisionID (0xffffffff)
error   12:22:11.254906+0100    Sportch Attempted to change to mode Portrait with an unsupported device (BackWideDual). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
error   12:22:11.254970+0100    Sportch Attempted to change to mode Portrait with an unsupported device (BackWideDual). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
sithwarrior commented 1 month ago

We are having the same issue for some users

Exception java.lang.RuntimeException: at android.app.ActivityThread.deliverResults (ActivityThread.java:6063) at android.app.ActivityThread.handleSendResult (ActivityThread.java:6102) at android.app.servertransaction.ActivityResultItem.execute (ActivityResultItem.java:67) at android.app.servertransaction.ActivityTransactionItem.execute (ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:139) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:96) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2685) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loopOnce (Looper.java:230) at android.os.Looper.loop (Looper.java:319) at android.app.ActivityThread.main (ActivityThread.java:8919) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:578) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103) Caused by android.app.RecoverableSecurityException: at android.app.RecoverableSecurityException$1.createFromParcel (RecoverableSecurityException.java:197) at android.app.RecoverableSecurityException$1.createFromParcel (RecoverableSecurityException.java:194) at android.os.Parcel.readParcelableInternal (Parcel.java:4882) at android.os.Parcel.readParcelable (Parcel.java:4864) at android.os.Parcel.createExceptionOrNull (Parcel.java:3064) at android.os.Parcel.createException (Parcel.java:3053) at android.os.Parcel.readException (Parcel.java:3036) at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:190) at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:142) at android.content.ContentProviderProxy.delete (ContentProviderNative.java:661) at android.content.ContentResolver.delete (ContentResolver.java:2349) at android.content.ContentResolver.delete (ContentResolver.java:2315) at org.apache.cordova.camera.CameraLauncher.checkForDuplicateImage (CameraLauncher.java:1277) at org.apache.cordova.camera.CameraLauncher.cleanup (CameraLauncher.java:1242) at org.apache.cordova.camera.CameraLauncher.processResultFromCamera (CameraLauncher.java:626) at org.apache.cordova.camera.CameraLauncher.onActivityResult (CameraLauncher.java:877) at org.apache.cordova.CordovaInterfaceImpl.onActivityResult (CordovaInterfaceImpl.java:160) at org.apache.cordova.CordovaActivity.onActivityResult (CordovaActivity.java:375) at android.app.Activity.dispatchActivityResult (Activity.java:9362) at android.app.ActivityThread.deliverResults (ActivityThread.java:6056)

lmarcelocc commented 1 month ago

We are having the same issue for some users

Exception java.lang.RuntimeException: at android.app.ActivityThread.deliverResults (ActivityThread.java:6063) at android.app.ActivityThread.handleSendResult (ActivityThread.java:6102) at android.app.servertransaction.ActivityResultItem.execute (ActivityResultItem.java:67) at android.app.servertransaction.ActivityTransactionItem.execute (ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:139) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:96) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2685) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loopOnce (Looper.java:230) at android.os.Looper.loop (Looper.java:319) at android.app.ActivityThread.main (ActivityThread.java:8919) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:578) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103) Caused by android.app.RecoverableSecurityException: at android.app.RecoverableSecurityException$1.createFromParcel (RecoverableSecurityException.java:197) at android.app.RecoverableSecurityException$1.createFromParcel (RecoverableSecurityException.java:194) at android.os.Parcel.readParcelableInternal (Parcel.java:4882) at android.os.Parcel.readParcelable (Parcel.java:4864) at android.os.Parcel.createExceptionOrNull (Parcel.java:3064) at android.os.Parcel.createException (Parcel.java:3053) at android.os.Parcel.readException (Parcel.java:3036) at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:190) at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:142) at android.content.ContentProviderProxy.delete (ContentProviderNative.java:661) at android.content.ContentResolver.delete (ContentResolver.java:2349) at android.content.ContentResolver.delete (ContentResolver.java:2315) at org.apache.cordova.camera.CameraLauncher.checkForDuplicateImage (CameraLauncher.java:1277) at org.apache.cordova.camera.CameraLauncher.cleanup (CameraLauncher.java:1242) at org.apache.cordova.camera.CameraLauncher.processResultFromCamera (CameraLauncher.java:626) at org.apache.cordova.camera.CameraLauncher.onActivityResult (CameraLauncher.java:877) at org.apache.cordova.CordovaInterfaceImpl.onActivityResult (CordovaInterfaceImpl.java:160) at org.apache.cordova.CordovaActivity.onActivityResult (CordovaActivity.java:375) at android.app.Activity.dispatchActivityResult (Activity.java:9362) at android.app.ActivityThread.deliverResults (ActivityThread.java:6056)

I would suggest that you try this commit changes to see if it works.

The error you're encountering, specifically the RecoverableSecurityException, is related to Android's scoped storage changes that were introduced in Android 10 (API level 29) and refined in Android 11 (API level 30). This exception typically occurs when the app attempts to modify or delete a file it doesn't have proper access to, especially files managed by the MediaStore.

Here's a breakdown of the issue in your stack trace:

The exception is triggered when trying to delete an image in CameraLauncher.checkForDuplicateImage using ContentResolver.delete(). In recent Android versions, apps require explicit permission to delete files from shared storage unless the file was created by the app itself. Why this happens: Starting from Android 10 (API level 29), apps can no longer directly access files in shared storage (such as the camera folder) unless they have been granted proper permissions, and apps may need to request user confirmation to delete or modify files that are not part of their own directory.

The RecoverableSecurityException is specifically thrown when the app tries to delete or modify files without having the necessary permissions, but the operation can still be recoverable by requesting the user's consent.

AndreeaMrgCB commented 1 month ago

Has anyone managed to find a fix for this? When I click on my button that triggers getPicture(), nothing happens on Android 14.

lmarcelocc commented 1 month ago

Has anyone managed to find a fix for this? When I click on my button that triggers getPicture(), nothing happens on Android 14.

You need to check the log. I'm on Android 14 using cordova-plugin-camera@7.0.0 and it works.