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

Camera Plugin crashes the APP on android 9 #479

Open
nicsaravanan opened this issue Jul 12, 2019 · 11 comments
Open

Camera Plugin crashes the APP on android 9 #479

nicsaravanan opened this issue Jul 12, 2019 · 11 comments

Comments

@nicsaravanan
Copy link

Bug Report

Log cat snippet

07-12 17:14:04.884 1312-1483/in.test.app D/SERVER: Handling local request: http://localhost/svg/md-camera.svg
07-12 17:14:06.114 1312-1585/in.test.app I/Timeline: Timeline: Activity_launch_request time:1083912826 intent:Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 clip={text/uri-list U:content://in.test.app.provider/external_files/Android/data/in.test.app/cache/.Pic.jpg} (has extras) }
07-12 17:14:06.126 1312-1312/in.test.app D/CordovaActivity: Paused the activity.
07-12 17:14:06.127 1312-1585/in.test.app W/PluginManager: THREAD WARNING: exec() call to Camera.takePicture blocked the main thread for 42ms. Plugin should use CordovaInterface.getThreadPool().
07-12 17:14:06.128 1312-1312/in.test.app I/com.tenforwardconsulting.bgloc.cordova.BackgroundGeolocationPlugin: App will be paused multitasking=true
07-12 17:14:06.215 1312-1312/in.test.app I/com.marianhello.bgloc.service.LocationServiceImpl: Creating LocationServiceImpl
07-12 17:14:06.254 1312-1312/in.test.app I/com.marianhello.bgloc.PostLocationTask: Creating PostLocationTask
07-12 17:14:06.262 1312-1895/in.test.app I/com.marianhello.bgloc.service.LocationServiceImpl: Network condition changed has connectivity: true
07-12 17:14:06.273 1312-1312/in.test.app D/com.marianhello.bgloc.service.LocationServiceImpl: Service in [NOT STARTED] state. cmdId: [3]. startId: [1]
07-12 17:14:07.228 1312-1312/in.test.app D/CordovaActivity: Stopped the activity.
07-12 17:14:07.229 1312-1312/in.test.app I/com.tenforwardconsulting.bgloc.cordova.BackgroundGeolocationPlugin: App is no longer visible

Problem

Camera plugin crashes the App on getPicture

What is expected to happen?

we should get the image back

What does actually happen?

app crashes

Information

ionic 4
Android 9
Xiomi Mi 6 Pro device

Command or Code

Environment, Platform, Device

ionic 4
Android 9
Xiomi Mi 6 Pro device

Version information

  • [ x] I searched for existing GitHub issues
  • [x ] I updated all Cordova tooling to most recent version
  • [ x] I included all the necessary information above
@nasasutisna
Copy link

I have the same problem, can anyone help?

@timbru31
Copy link
Member

Is this reproducible in a new, plain Cordova app? A minimal reproduction repository would really help to debug and later fix this issue. More information on how to create one: https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md

@abhinavkumar-utsa
Copy link

@timbru31 yes this is reproducible, the app launches the black camera view with the crash pop up on invoking the getPicture() function. My test device is Samsung Galaxy s9 running Android 9.

@jpike88
Copy link

jpike88 commented Aug 26, 2019

@abhinavkumar-utsa can you zip up an android project where this bug occurs and put it up

@alindzon
Copy link

did this get solved?

@mirko77
Copy link

mirko77 commented Dec 4, 2019

Any updates?

@breautek
Copy link
Contributor

breautek commented Dec 4, 2019

Not exactly clear based on the provided log, but one reason an activity could be stopped is due to this android quirk

Android uses intents to launch the camera activity on the device to capture images, and on phones with low memory, the Cordova activity may be killed. In this scenario, the result from the plugin call will be delivered via the resume event. See the Android Lifecycle guide for more information. The pendingResult.result value will contain the value that would be passed to the callbacks (either the URI/URL or an error message). Check the pendingResult.pluginStatus to determine whether or not the call was successful.

This isn't a crash, however the webview will lose it's state and therefore likely load up your default view. It's up to the developer to handle this case and save the application state somewhere where it can be restored.

@mirko77
Copy link

mirko77 commented Dec 4, 2019

@breautek We are a bit puzzled this is still the case in 2020 with Android phones more powerful than a laptop.
We understand having a lot of RAM does not mean the app never gets killed, but there might be something introduced in Android 9 which is causing it. There were just a few to no issues at all going from Android 4 to android 8.1 using the same exact code, but now there are more and more reports of this happening.

@breautek
Copy link
Contributor

breautek commented Dec 4, 2019

Having lots of ram doesn't mean an individual app can allocate all of said ram. Many phones only allows limited quota to the ram.

Additionally, the camera app is also ram heavy (relatively speaking), due to its processing of a very large resolution image/video.

There were just a few to no issues at all going from Android 4 to android 8.1

Again different phones have different specs, and different screen resolutions, and different vendors, all with different ram requirements and probably different ram management. These older devices while they may of had less RAM, they also had much less screen resolution and image resolution images and thus also required less ram to process and overall may actually be less stressful on the ram on the phones.

To be clear, I'm not claiming that this issue is due to the android quirk, but I am saying it is a possibility. The given log information shows no crash stacktrace, but it does show the app went into a paused state, then later was killed, so this behaviour does match the android quirk. One quick and easy way to test this is to actually listen to the resume event of the app, and test to see if there is a pendingResult. You can see the documentation here

If there is a pendingResult, then you are hitting the android quirk, and unfortunately there isn't a way around that when using the camera intent. If you don't want to deal with the android quirk, one potential workaround is to find a plugin that uses the camera APIs directly (rather than going through the intent), but the drawbacks of that method is your app will require privacy-sensitive permissions that the user has to accept.

@alindzon
Copy link

alindzon commented Dec 4, 2019

I had an issue with the camera on any snapdragon device. I found replacing the default camera app with just about any other one from the playstore fixed it. I have tested Open Camera. So I suspect there is an issue in the camera app itself caused somehow by qualcomm.

@mirko77
Copy link

mirko77 commented Dec 4, 2019

Again different phones have different specs, and different screen resolutions, and different vendors, all with different ram requirements and probably different ram management. These older devices while they may of had less RAM, they also had much less screen resolution and image resolution images and thus also required less ram to process and overall may actually be less stressful on the ram on the phones.

Allocated ram increases with screen resolution on Android https://drive.google.com/file/d/0B7Vx1OvzrLa3Y0R0X1BZbUpicGc/view

We are facing the issue also on old devices after upgrading to Android 9.

With the same app, we are able to shoot 4K videos (cordova-media-capture plugin) and not a single restart so far, the app has been on the Play Store for ~4 years.

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

No branches or pull requests

8 participants