cordova-plugin-camera icon indicating copy to clipboard operation
cordova-plugin-camera copied to clipboard

Xiaomi Redmi 7A camera crash

Open amanfreda opened this issue 3 years ago • 4 comments

Bug Report

Problem

I am looking for help, with a camera crashing problem on an Xiaomi Redmi 7A mobile device.

What is expected to happen?

In my Cordova application (https://github.com/amanfreda/cordova-camera-debug), I want to utilize the camera. I tried using this plugin to achieve that. The app is just a simple button, that should return the image uri.

What does actually happen?

It works fine on most devices, except on Xiaomi Redmi 7A. On this specific device, the application crashes at the moment the camera is opened and the picture is taken (as seen in the logs). Then, when the plugin wants to return the image data to the application, the application restarts and the image data is lost. After some googling, the issue seems to be, that Xiaomi's MIUI OS is pretty aggressive with killing background processes.

Information

Solutions I Tried

  • Set the applications battery settings to "No restrictions", and lock the application, so it should stay running in the background. Somthing like https://dontkillmyapp.com/xiaomi
  • Use cordova-plugin-background-mode (https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background) to force my application, to run in the backround. I also tried running it with disableBatteryOptimizations and disableWebViewOptimizations.

Both obvously didn't work. This is as far as I got, before I was out of ideas. The github link to the application includes the sample application (nothing fancy, just a button that opens the camera with the plugin), and also some logcat logs in the log folder. The logcat logs contain a verbose output of all the logs, application logs, chromium logs and adb bugreport. The chrome://inspect console is not much use in this case, because no errors were logged.

So, if anyone came across similar issues I would be grateful for any sort of info that could be provided.

Command or Code

Install the app listed above with:

npm i
cordova platform add android
cordova run android

Feel free to bump the cordova and plugin versions (I tried with cordova 10 and cordova-plugin-camera 6, but the problem persists). The versions listed are just the ones I use in my production app.

Environment, Platform, Device

Device: Xiaomi Redmi 7A, 2GB RAM 16GB ROM, MIUI 12.5.3 Platform: Android 10

Version information

Nodejs: 10.24.1 Application Framework: Cordova 9.0.0 Plugins: cordova-plugin-camera 5.0.3, cordova-plugin-background-mode

Checklist

  • [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

amanfreda avatar Jan 17 '22 10:01 amanfreda

I tried also with cordova cli 11 and lastest versions of cordova-android and camera plugin and still same

phyr0s avatar Feb 05 '22 10:02 phyr0s

If we can't solve the problems of the camera plugin right away, it would be very helpful to have a list of devices with the problem.

whria78 avatar Mar 07 '22 11:03 whria78

The provided logcat logs shows no crash, but it does show the result is being delivered via android activity result.

01-11 11:13:16.690: W/Activity(12063): Slow Operation: Activity io.cordova.hellocordova/.MainActivity onCreate took 1006ms 01-11 11:13:16.692: I/AdrenoGLES(12063): PFP: 0x005ff112, ME: 0x005ff066 01-11 11:13:16.701: D/CordovaActivity(12063): Started the activity. 01-11 11:13:16.705: D/CordovaActivity(12063): Incoming Result. Request code = 34 01-11 11:13:16.712: D/PluginManager(12063): getPlugin - put: Camera 01-11 11:13:16.713: D/CordovaInterfaceImpl(12063): Sending activity result to plugin

This means the OS killed the activity and the activity (and the webview) needs to be created when the app returns, and the results from the camera will be available through the onResume event. Read more

This quirk is documented here. Unfortunately there isn't a way around this issue. That is how android operates.

Regarding the dont kill my app / running in background, I don't know too much about this but android apps does have a concept of running in the background without an actual UI activity, so I suspect these "no restrictions" on background activity just allows more CPU power to be allocated by your app running in the background for app services, but doesn't mean the OS won't kill the app's foreground activity. Note that in native android app development, it's expected by the developer to save the state of the app so that they can restore the state when this does occur, granted it's easier to do this on native views than it is to reconstruct the webview's document.

Can you confirm that the plugin response data is available via the resume event?

breautek avatar Mar 07 '22 13:03 breautek

Same issue with Android Device Name: Redmi Note 7 pro MIUI Version 12.5.1

mobiliseapplabllp avatar Aug 04 '22 05:08 mobiliseapplabllp