Skip to content
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

App crashes with RecoverableSecurityException after URI resolves to content://media/<path> #679

Closed
3 tasks done
gerardoemr opened this issue Oct 21, 2020 · 32 comments
Closed
3 tasks done

Comments

@gerardoemr
Copy link

gerardoemr commented Oct 21, 2020

Bug Report

Problem

App crashes when using Timestamp app to take a picture.

What is expected to happen?

App should inform that the URI is not accessible by app, not crash.

I have tried converting the "content://media/" into a "file://" without succes.

I verified all permissions and the function works fine when using device's camera.

What does actually happen?

App is killed by OS...

Log from adb logcat

10-20 23:27:29.354 13405 13405 E AndroidRuntime: FATAL EXCEPTION: main
10-20 23:27:29.354 13405 13405 E AndroidRuntime: Process: io.gits.form, PID: 13405
10-20 23:27:29.354 13405 13405 E AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=34, result=-1, data=null} to activity {io.gits.form/io.gits.form.MainActivity}: android.app.RecoverableSecurityException: io.gits.form has no access to content://media/external/images/media/6625
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5097)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:5138)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:107)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:237)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7814)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: Caused by: android.app.RecoverableSecurityException: io.gits.form has no access to content://media/external/images/media/6625
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:197)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:194)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.os.Parcel.readParcelable(Parcel.java:2990)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.os.Parcel.createException(Parcel.java:2083)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.os.Parcel.readException(Parcel.java:2056)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.content.ContentProviderProxy.delete(ContentProviderNative.java:553)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.content.ContentResolver.delete(ContentResolver.java:1956)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at org.apache.cordova.camera.CameraLauncher.checkForDuplicateImage(CameraLauncher.java:1234)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at org.apache.cordova.camera.CameraLauncher.cleanup(CameraLauncher.java:1200)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at org.apache.cordova.camera.CameraLauncher.processResultFromCamera(CameraLauncher.java:601)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at org.apache.cordova.camera.CameraLauncher.onActivityResult(CameraLauncher.java:806)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:159)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:361)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.Activity.dispatchActivityResult(Activity.java:8292)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5090)
10-20 23:27:29.354 13405 13405 E AndroidRuntime: 	... 11 more
10-20 23:27:29.365 22238 22238 D ActivityThread: setConscryptValidator
10-20 23:27:29.366 22238 22238 D ActivityThread: setConscryptValidator - put
10-20 23:27:29.369  4678  6839 I ActivityManager: DSS OFF for com.samsung.android.bixby.service
10-20 23:27:29.386  4243  7458 I CameraService: onUidStateChanged: uid=10024, procState=4

Information

Command or Code

takePicture(fieldId){
    console.log("Taking picture...");
    this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.CAMERA).then( 
      response => {
        console.log("Permission status:", response);
        console.log("Resolving file path...");
        this.camera.getPicture().then( uriPath => {
          this.fileCordova.resolveLocalFilesystemUrl(uriPath).then( resultPath => {
            console.log(resultPath);
          }).catch(error => console.log(error));
      }, err => {console.log(err)})
  }, err => {console.log(err)}
  )
}

Environment, Platform, Device

Bug occurs on different Android 9 devices.

Version information

ionic info
Ionic:

Ionic CLI : 5.4.9 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 5.0.0
@angular-devkit/build-angular : 0.803.24
@angular-devkit/schematics : 8.3.25
@angular/cli : 8.3.25
@ionic/angular-toolkit : 2.1.2

Cordova:

Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 7.1.0, browser 6.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 15 other plugins)

Utility:

cordova-res : not installed
native-run : 1.2.1 (update available: 1.2.2)

System:

NodeJS : v14.2.0 (/home/gerardo/.nvm/versions/node/v14.2.0/bin/node)
npm : 6.14.4
OS : Linux 5.4

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

I'm trying to retrieve plugin callback as mentioned in :
https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#upgrading (Last section)

@breautek
Copy link
Contributor

If you're targeting android target 30, I'll downgrade for the time being. There are breaking changes in the android filesystem APIs that Cordova doesn't currently support. You can downgrade the target API via android-targetSdkVersion preference.

If you're targeting android target 29, then I'd either downgrade to API 28* using the preference noted above or try the master branch of cordova-plugin-file (for testing purposes).

  • Note: If you're building a new app, Google won't allow you to publish an app build with API 28. If you're updating an existing app, Google will allow API 28 until November, which is creeping up fast.

@gerardoemr
Copy link
Author

gerardoemr commented Oct 21, 2020

You're right, downgrading to android-targetSdkVersion = 28 stopped the app from crashing and is working as before.

The app needs to be published eventually, do you think trying out the cordova-custom-config to try to access the content URI is worth the try? (I will also try the master branch of cordova-plugin-file )

Thanks for the help!

@breautek
Copy link
Contributor

With API 29, you'll need https://github.com/apache/cordova-plugin-file/pull/417/files which the cordova-plugin-file has, but is not released yet.

So if you can add the android:requestLegacyExternalStorage flag using the cordova-custom-config plugin, then that could be a workaround for the time being.

The android:requestLegacyExternalStorage is only introduced in API 29 and will be ignored in API 30, forcing app developers to actually use the new FS system that android has.

@leonardoMoliveira
Copy link

same problem here, fixed temporarily with @breautek solution, and there is no fix for Android 11... :(

@rejneesh1
Copy link

rejneesh1 commented Feb 15, 2021

Any solution found for android 11?

@Houdhey
Copy link

Houdhey commented Feb 15, 2021

@breautek Do you know when we will have any informations about this Android 11 problem and Cordova? Is someone working on this?

@breautek
Copy link
Contributor

@breautek Do you know when we will have any informations about this Android 11 problem and Cordova? Is someone working on this?

Afaik, no one is allocating time on API 30 FS problems. We need to figure out how to incorporate the MediaStore APIs for API 30.

MediaStore API is significantly different than the raw file system APIs so it may be out of scope for the file plugin itself. Someone needs to analyse this problem in great detail to understand the full scope of the problem (i.e: it obviously it affects the file system usage, but does it also affect this camera plugin? file transfer plugin? media-capture plugin? etc...). Based on this ticket, the answer to each of those questions is probably a "yes". Help is wanted for this.

@interstellerS
Copy link

Google play store will not allow publishing ionic applications with android:requestLegacyExternalStorage:true 5 Mai .

Are there any alternative solution to keep this plugin work ? Or use another Similar one.

@Houdhey
Copy link

Houdhey commented Apr 30, 2021

Google play store will not allow publishing ionic applications with android:requestLegacyExternalStorage:true 5 Mai .

Are there any alternative solution to keep this plugin work ? Or use another Similar one.

Could you give me the source of this information please? Thank you.
This is gonna be problematic, please maintainers inform us about changes to come

@interstellerS
Copy link

the last Time i published , the Ionic APK to play store , I Got this warning :

From May 5, you will need to tell us why your app requires extended storage access
We have detected the requestLegacyExternalStorage flag in the manifest file of one or more of your app's app bundles or APKs.
Developers whose apps are running on Android 11 or later should make use of siled storage space so that users can better control access to their device's storage space. As of May 5, to offer your app on Android 11 or later, you will need to follow one of the procedures below:
Update your application to follow best practices that are more respectful of confidentiality, for example thanks to the Storage Access Framework or Media Store APIs
Update your application to declare permission to access all files (MANAGE_EXTERNAL_STORAGE) in the manifest file, and complete the permission to access all files statement in the Play Console from May 5th
Remove permission to access all files in your app
For apps targeting Android 11, the requestLegacyExternalStorage flag will be ignored. You must use the All Files Access permission to maintain extended access.
Apps that ask for permission to access all files when they are not allowed to do so will be removed from Google Play, and you will not be able to update them.

In my Case , I commented the code line that crash the Plugin in a fork branch (interstellerS@884ff37 ) , Then both the image capture and save to gallery worked just Fine!

I wonder if the entrerpise version of this plugin has a fix for this .

ibcomputing added a commit to ibcomputing/cordova-plugin-camera that referenced this issue Jun 29, 2021
Workaround for issue described here: apache#679
@jkorrek
Copy link

jkorrek commented Sep 22, 2021

From what I can tell, taking a picture with this plugin might always add the picture to the phones gallery (=MediaStore), even if saveToPhotoAlbum is false. I think that this is related to camera app that used on the phone, but I am not completely sure about that.

The deletion of files in the MediaStore changed with the Scoped Storage changes introduced in SDK 29.
As far as I can tell, deletion will only be possible if the user manually approves the modification.

In SDK 29 this permission may be requested via the RecoverableSecurityException. Starting from SDK 30, a delete request can be created.

You can find a simple implementation for this here: https://github.com/jkorrek/cordova-plugin-camera/blob/sdk-30-deletion/src/android/CameraLauncher.java#L1267

As I am not sure if I want to bother our users with this deletion request, I also added a flag to explicitly activate this behaviour.

For Android 10 / SDK 29 the confirmation request show to the user will look like this:
deletion_confirmation

I wasn't able to test this for Android 11 / SDK 30 yet.

@LucasBourgeois
Copy link

LucasBourgeois commented Nov 4, 2021

Hi,
Im having this issue too but it seems to be caused by the device itself as it tested my app and the camera.takePicture feature on many different devices all on android 10.. (even a fairPhone is working well).
It's working also well on android 9, 11 and 12.

Im ​having this issue with a Lenovo tab.

Using the requestLegacyFileStorage flag is not an option as targetting api level 30 is mandatory.
I should probably try to upgrade to v6 of this plugin but needs to upgrade cordova-android to > 10 also and it's quit scary and cause many other bugs for me.

And as it's working well on most device, I believe thats i do not really need to upgrade the plugin version.

Somebody have a workaround ?

Its seems to crash on the checkForDuplicate function in cameraLuncher.java when trying to delete the image using the uri...

im quite hopeless as im starting to change the java file for debugging ....

Thx in advance

Edit : Copy of my logcat :

Caused by: android.app.RecoverableSecurityException: com.xxx.xxx has no access to content://media/external/images/media/25
        at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:197)
        at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:194)
        at android.os.Parcel.readParcelable(Parcel.java:2973)
        at android.os.Parcel.createException(Parcel.java:2066)
        at android.os.Parcel.readException(Parcel.java:2039)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
        at android.content.ContentProviderProxy.delete(ContentProviderNative.java:553)
        at android.content.ContentResolver.delete(ContentResolver.java:1949)
        at org.apache.cordova.camera.CameraLauncher.checkForDuplicateImage(CameraLauncher.java:1234)
        at org.apache.cordova.camera.CameraLauncher.cleanup(CameraLauncher.java:1200)
        at org.apache.cordova.camera.CameraLauncher.processResultFromCamera(CameraLauncher.java:597)
        at org.apache.cordova.camera.CameraLauncher.onActivityResult(CameraLauncher.java:829)
        at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:159)
        at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:368)
        at android.app.Activity.dispatchActivityResult(Activity.java:8170)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4870)

@sithwarrior
Copy link

Any update on this? I see there is a PR 781

After updating to the latest version of the camera plugin, our Android Crashes and ANR in the Play Developer Console, shows a number of users experiencing this issue.

java.lang.RuntimeException: at android.app.ActivityThread.deliverResults (ActivityThread.java:5579) at android.app.ActivityThread.handleSendResult (ActivityThread.java:5620) at android.app.servertransaction.ActivityResultItem.execute (ActivityResultItem.java:51) at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2325) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:246) at android.app.ActivityThread.main (ActivityThread.java:8633) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130) 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.readParcelable (Parcel.java:3293) at android.os.Parcel.createExceptionOrNull (Parcel.java:2380) at android.os.Parcel.createException (Parcel.java:2369) at android.os.Parcel.readException (Parcel.java:2352) at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:190) at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:142) at android.content.ContentProviderProxy.delete (ContentProviderNative.java:624) at android.content.ContentResolver.delete (ContentResolver.java:2299) at android.content.ContentResolver.delete (ContentResolver.java:2265) at org.apache.cordova.camera.CameraLauncher.checkForDuplicateImage (CameraLauncher.java:1242) at org.apache.cordova.camera.CameraLauncher.cleanup (CameraLauncher.java:1208) at org.apache.cordova.camera.CameraLauncher.processResultFromCamera (CameraLauncher.java:592) at org.apache.cordova.camera.CameraLauncher.onActivityResult (CameraLauncher.java:843) at org.apache.cordova.CordovaInterfaceImpl.onActivityResult (CordovaInterfaceImpl.java:160) at org.apache.cordova.CordovaActivity.onActivityResult (CordovaActivity.java:368) at android.app.Activity.dispatchActivityResult (Activity.java:8550) at android.app.ActivityThread.deliverResults (ActivityThread.java:5572)

meidlinga added a commit to spotteron/cordova-plugin-camera that referenced this issue Apr 27, 2022
This implementation just swallows the Exception, because we do not want to bother our users with a permission question for each photo we take.
For more information and other approaches refer to apache#679
meidlinga added a commit to spotteron/cordova-plugin-camera that referenced this issue Apr 27, 2022
This implementation just swallows the Exception, because we do not want to bother our users with a permission question for each photo we take.
For more information and other approaches refer to apache#679
meidlinga added a commit to spotteron/cordova-plugin-camera that referenced this issue Apr 27, 2022
This implementation just swallows the Exception, because we do not want to bother our users with a permission question for each photo we take.
For more information and other approaches refer to apache#679
@sithwarrior
Copy link

@breautek anything we can do to push the PR along? We are seeing a bit of crashes of users with non default camera apps.

@sithwarrior
Copy link

@breautek We have a user experiencing these crashes, and gave them a .apk of our app with the code in proposed 6.01 patch or rather to be precise we installed this version of the plugin dongourdet@fa95703

This fixed the issue for our user.. Is there a timeline for getting this fix out in the wild in the official plugin?

@PabbleDabble
Copy link

I took the fork commit from dongourdet@fa95703 and rebased it on top of the main repo's current master (2023-06-08 23642f0 ) and built on an Android 12 before and after and this fix also looks like it solves the problem for our Android device as well.

I see https://github.com/apache/cordova-plugin-camera/milestone/4
If it would help anyone else I can publish / clean up my rebased fork for this fix (there's some whitespace noise in the current PR in case anyone was wondering).

Great plugin, great work identifying the issue!

@JeffBerman
Copy link

I did the same as @PabbleDabble and sent our app to a customer who experiences the crashing issue on their tablet. It resolved the crash, but they state that every time they take a photo it asks for permission to modify the picture. I'm still waiting to hear back from them on the exact message they see.

Is anyone experiencing this? I don't see what could make Android ask for permission every single time a photo is taken. Thanks!

@PabbleDabble
Copy link

@JeffBerman I only did a quick test so this could be happening, not sure. We just send build to QA, I'll ask our Android 12 user to test again and update asap.

@JeffBerman
Copy link

Just a little update: I'm not sure how relevant this is, but our customer says the patched camera plugin works with their Galaxy tablet but not their Lenovo ones. The Galaxy uses the com.sec.android.app.camera camera package, while the Lenovo uses the com.mediatek.camera package. I'm not too familiar with how Android works, but it sounds like there's some incompatibility between the Mediatek camera software and either Android 11 or this plugin, that causes it to ask for permission with every photo they take.

@PabbleDabble
Copy link

@JeffBerman The person who has the Android 12 still hasn't tested, but now Android 13 is a whole new issue for us...

Here's the comment path I've used that seems to work on 13 (still other related issues with cordoav-plugin-file and copying file from gallery)

#825 (comment)
#826 (comment)

I'm PRAYING that forks fixed the Android 12 issue as well, so I can just used that and not need to merge in DonGourdet's changes as well. I will update if I test the fork for Android 13 on an Android 12 device with my results.

@PabbleDabble
Copy link

PabbleDabble commented Jul 11, 2023

Update to my above comment:

I tested on Android 12 with JUST the fork for Android 13 here (hoping it was the same issue), but it was not apparently.

I then combined both the Android 13 fork here and the Android 12 fork (here) and rebuilt and tested on both Android 12 and 13. I had to update cordova-plugin-file from 6->8 which required me to update cordova-android as well, and not with my customer double fork, it looks like I have both working.

I got the custom double for by doing the following:

  • clone cordova-plugin-camera master
  • add fork1 author as a remote
  • cherry-pick fork1 master commit
  • add fork2 author as a remote
  • cherry-pick fork2 master commit (resolve conflict from whitespace)
  • install that to my app using ionic cordova plugin add LOCAL_REPO_FOLDER_FOR_CUSTOM_PLUGINS/cordova-plugin-camera

I'll document locally, and then when either / both of these fixes go through, I can revert back to installing from the plugin's page.

@PabbleDabble
Copy link

they state that every time they take a photo it asks for permission to modify the picture

Yes. This is happening to me as well. It's better than crashing. Maybe worth pinging the fork author? I don't know if that's correct etiquette here tho.

@breautek
Copy link
Contributor

they state that every time they take a photo it asks for permission to modify the picture

Yes. This is happening to me as well. It's better than crashing. Maybe worth pinging the fork author? I don't know if that's correct etiquette here tho.

I don't think the permission grant thing addressable. The removal of the WRITE_EXTERNAL_STORAGE permission with scoped storage means apps no longer have free/permanent access across the board of external storage.

This means if you're modifying a file that is owned by another app, you must obtain permission to write to that file. This permission grant is a temporarily grant and is only valid for that specific file. So if you're trying to modify multiple files owned by another app, then you must be granted permission for each file.

I believe the permission grant is valid for as long as your android activity lives. Whenever your app's activity gets killed, any permission grants to uris is revoked if I recall correctly.

@andrerds
Copy link

Hi everyone,

I am having the same problem here, happening on different devices, Samsung -
Galaxy M31 , Galaxy A02s , Motorola - Moto G(8) Power Lite, Xiaomi - Redmi Note 9
with Android 10 and 12.
The photo taking feature was recently implemented in our app, and I saw that there is a possible solution in the comments. Will this solution be applied to the plugin in question?

Thanks!

@zubus
Copy link

zubus commented Jul 25, 2023

Any update on this?

@JeffBerman
Copy link

I don't think the permission grant thing addressable. The removal of the WRITE_EXTERNAL_STORAGE permission with scoped storage means apps no longer have free/permanent access across the board of external storage.

This means if you're modifying a file that is owned by another app, you must obtain permission to write to that file. This permission grant is a temporarily grant and is only valid for that specific file. So if you're trying to modify multiple files owned by another app, then you must be granted permission for each file.

@breautek In our customers' case, they are the ones taking the photo. Our mobile app uses the camera plugin to take a photo, then the same app sends the photo to a server. Customers are complaining that every time they snap a photo it asks for permission. Does this scenario sound consistent with your understanding of how Android now handles these things?

@zubus
Copy link

zubus commented Jul 27, 2023

Hi @PabbleDabble Would you consider creating a fork or a pull request with your changes on the original cordova-plugin-camera repository? This could really help others in the community.

Thanks for your contribution!

@PabbleDabble
Copy link

PabbleDabble commented Jul 28, 2023

Hi @PabbleDabble Would you consider creating a fork or a pull request with your changes on the original cordova-plugin-camera repository? This could really help others in the community.

Thanks for your contribution!

https://github.com/PabbleDabble/cordova-plugin-camera

Here's the steps I took after forking master from this main

$ git clone https://github.com/PabbleDabble/cordova-plugin-camera.git
$ cd cordova-plugin-camera
$ git remote add a12-fork https://github.com/dongourdet/cordova-plugin-camera
$ git remote add a13-fork https://github.com/jalios/cordova-plugin-camera
$ git fetch --all

# just a fast-forward
$ git cherry-pick a13-fork/master

# second pick had to resolve conflicts (just whitespace / confirm)
$ git cherry-pick a12-fork/master
$ git status
$ git push

For the record, I think the A12 cherry-pick is still probably not perfect as it asks for permission to delete the temp file after capture each time which is not great (but better than a crash).

Here's where I found comments / notes to why I did what I did...
Link to A12 issue - #679
Link to A13 issue - #826 (comment)

@zubus
Copy link

zubus commented Jul 28, 2023

Thank you very much. It's almost the same as the changes I implemented. But I still don't understand why, even though I work with the image as a blob (last option), it keeps trying to access content://media/external/images/media/ and generating android.app.RecoverableSecurityException. On Android 10 devices, the application crashes; however, on version 13, it generates the error but doesn't close the app.

@breautek
Copy link
Contributor

breautek commented Sep 6, 2023

This was originally opened for API 30 which should have already been fixed in v6 of the plugin, but the issue would re-appear for API 33 devices, which will be resolved by #844

@breautek breautek closed this as completed Sep 6, 2023
@josh-cloudscape
Copy link

Can anyone confirm if this is fixed in 7.0.0? Noticed that this error was occurring for some users and I was able to reproduce it using the Timestamp even when using 7.0.0. Perhaps I'm doing something else wrong.

@JohnCastle4
Copy link

We are using 7.0.0. In the Google Play Store logs we two variations of this error:
Exception java.lang.RuntimeException:
at android.app.ActivityThread.deliverResults (ActivityThread.java:6020)
at android.app.ActivityThread.handleSendResult (ActivityThread.java:6059)
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:135)
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2584)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loopOnce (Looper.java:226)
at android.os.Looper.loop (Looper.java:313)
at android.app.ActivityThread.main (ActivityThread.java:8810)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)
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:4787)
at android.os.Parcel.readParcelable (Parcel.java:4755)
at android.os.Parcel.createExceptionOrNull (Parcel.java:3018)
at android.os.Parcel.createException (Parcel.java:3007)
at android.os.Parcel.readException (Parcel.java:2990)
at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:142)
at android.content.ContentProviderProxy.delete (ContentProviderNative.java:629)
at android.content.ContentResolver.delete (ContentResolver.java:2340)
at android.content.ContentResolver.delete (ContentResolver.java:2306)
at org.apache.cordova.camera.CameraLauncher.checkForDuplicateImage (CameraLauncher.java:1287)
at org.apache.cordova.camera.CameraLauncher.cleanup (CameraLauncher.java:1253)
at org.apache.cordova.camera.CameraLauncher.processResultFromCamera (CameraLauncher.java:637)
at org.apache.cordova.camera.CameraLauncher.onActivityResult (CameraLauncher.java:888)
at org.apache.cordova.CordovaInterfaceImpl.onActivityResult (CordovaInterfaceImpl.java:160)
at org.apache.cordova.CordovaActivity.onActivityResult (CordovaActivity.java:368)
at android.app.Activity.dispatchActivityResult (Activity.java:9017)
at android.app.ActivityThread.deliverResults (ActivityThread.java:6013)

And:
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 java.lang.SecurityException:
at android.os.Parcel.createExceptionOrNull (Parcel.java:3069)
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 can't reproduce on our devices, but our customers can according to the crash logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment