Fuse Community

Camera crash on Android 10

Hello. I’m wondering if anyone has experienced some issues with Camera module on Android 10.

Simple Camera code:

function capturePhoto() {
	Camera.takePicture()
		.then(function (photo) {})
		.catch(function (error) {});
}

Information I’m getting from the debugger:

12-01 11:16:25.486  4058  4223 I InputDispatcher: Delivering touch to (8532): action: 0x0, f=0x0, d=0, 'fb5bd58', t=1
12-01 11:16:25.487  8532  8532 D ViewRootImpl@b37a917[APP]: ViewPostIme pointer 0
12-01 11:16:25.584  4058  4223 I InputDispatcher: Delivering touch to (8532): action: 0x1, f=0x0, d=0, 'fb5bd58', t=1
12-01 11:16:25.601  8532  8532 D ViewRootImpl@b37a917[APP]: ViewPostIme pointer 1
12-01 11:16:25.826  8532  8532 D ViewRootImpl@b37a917[APP]: MSG_WINDOW_FOCUS_CHANGED 0 1
12-01 11:16:25.828  8532  8532 D InputMethodManager: prepareNavigationBarInfo() DecorView@933ba[APP]
12-01 11:16:25.828  8532  8532 D InputMethodManager: getNavigationBarColor() -855310
12-01 11:16:25.832  3644  3644 I SurfaceFlinger:      DEVICE | 0xf0f50440 | 0000 | RGBA_8888 |   0.0    0.0 1200.0 1920.0 |    0    0 1200 1920 | com.app.example/com.app.example.APP$_8532#0
12-01 11:16:25.852  4058  4077 D InputDispatcher: Focus left window (8532): fb5bd58 in display 0 0
12-01 11:16:25.964  3644  3644 I SurfaceFlinger:      DEVICE | 0xf0f50440 | 0000 | RGBA_8888 |   0.0    1.0 1200.0 1920.0 |    0    0 1200 1920 | com.app.example/com.app.example.APP$_8532#0
12-01 11:16:25.983  3644  3644 I SurfaceFlinger:      CLIENT | 0xf0f50440 | 0000 | RGBA_8888 |   0.0    3.0 1200.0 1920.0 |    0    0 1200 1918 | com.app.example/com.app.example.APP$_8532#0
12-01 11:16:26.271  8532  8532 D SurfaceView: onWindowVisibilityChanged(8) false android.view.SurfaceView{b762a7a V.E...... ........ 0,0-1200,1920} of ViewRootImpl@b37a917[APP]
12-01 11:16:26.272  8532  8532 D SurfaceView: surfaceDestroyed callback.size 1 #2 android.view.SurfaceView{b762a7a V.E...... ........ 0,0-1200,1920}
12-01 11:16:26.278  8532  8532 W libEGL  : EGLNativeWindowType 0xbbb80808 disconnect failed
12-01 11:16:26.282  8532  8532 D SurfaceView: remove() android.view.SurfaceView{b762a7a V.E...... ........ 0,0-1200,1920} Surface(name=SurfaceView - com.app.example/com.app.example.APP@b762a7a@0)/@0xf6173d4
12-01 11:16:26.285  8532 13308 D OpenGLRenderer: makeCurrent EglSurface : 0xded1b2a0 -> 0x0
12-01 11:16:26.286  8532 13308 D OpenGLRenderer: destroyEglSurface : 0xded1b2a0
12-01 11:16:26.291  3644  6415 E BufferQueueProducer: [com.app.example/com.app.example.APP$_8532#0] disconnect: not connected (req=1)
12-01 11:16:26.291  8532 13308 W libEGL  : EGLNativeWindowType 0xdcc56e08 disconnect failed
12-01 11:16:26.291  8532 13308 D OpenGLRenderer: ~ReliableSurface : 0xdcc56e00
12-01 11:16:26.301  4058  4695 V WindowManager: Relayout 8532: mAttrs={(0,0)(fillxfill) sim={adjust=resize} ty=BASE_APPLICATION fmt=TRANSPARENT wanim=0x1030305
12-01 11:16:26.309  8532  8532 D ViewRootImpl@b37a917[APP]: Relayout returned: old=(0,0,1200,1920) new=(0,0,1200,1920) req=(1200,1920)8 dur=14 res=0x5 s={false 0} ch=true
12-01 11:16:27.329  8532  8532 D InputTransport: Input channel destroyed: 'ClientS', fd=79
12-01 11:16:27.338  4058  4695 V InputMethodManagerService: Disabling: SessionState{uid 10216 pid 8532 method 3e751a4 session c9aaff1 channel ClientState{964017b uid=10216 pid=8532 displayId=0} (server)}
12-01 11:16:27.401  8532  8532 D ViewRootImpl@b37a917[APP]: stopped(true) old=false
12-01 11:16:27.417  8532  8532 D SurfaceView: windowStopped(true) false android.view.SurfaceView{b762a7a V.E...... ........ 0,0-1200,1920} of ViewRootImpl@b37a917[APP]
12-01 11:16:27.496  4058  4533 I WindowManager: Destroying surface Surface(name=com.app.example/com.app.example.APP$_8532)/@0xa957720 called by com.android.server.wm.WindowStateAnimator.destroySurface:1790 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:720 com.android.server.wm.WindowState.destroySurfaceUnchecked:3540 com.android.server.wm.WindowState.destroySurface:3514 com.android.server.wm.AppWindowToken.destroySurfaces:1234 com.android.server.wm.AppWindowToken.destroySurfaces:1215 com.android.server.wm.AppWindowToken.notifyAppStopped:1270 com.android.server.wm.ActivityRecord.activityStoppedLocked:2653
12-01 11:16:27.497  3644  3705 I Layer   : id=2595 removeFromCurrentState com.app.example/com.app.example.APP$_8532#0 (65)
12-01 11:16:28.316  4058  5802 I ActivityManager: Process com.app.example (pid 8532) has died: prev LAST(390,93)
12-01 11:16:28.316  4058  5802 D ActivityManager_KPM: Killed Process Scenario:74 , App PID:8532 , App Name:com.app.example , App ADJ:700 , App AdjType:previous , Current CCH-ACT Count:1 , Proc State:16
12-01 11:16:28.316  3644  5309 I SurfaceFlinger: id=2595 Removed com.app.example/com.app.example.APP$_8532#0 (60)
12-01 11:16:28.318  3598  3598 I Zygote  : Process 8532 exited due to signal 9 (Killed)
12-01 11:16:28.323  4058  4100 I libprocessgroup: Successfully killed process cgroup uid 10216 pid 8532 in 7ms
12-01 11:16:28.326  4058  4092 W ActivityManager: setHasOverlayUi called on unknown pid: 8532
12-01 11:16:28.330  3644  3644 I Layer   : id=2595[1] Destroyed com.app.example/com.app.example.APP$_8532#0

Any idea what can be the issue here? Any possible fix?

Hi. When exactly it crashes? (When try to open Camera, after took a picture, etc …)

Well the camera starts without any problem but application crashes in background.

I can still can take a picture (click “Ok” to accept the picture) but my application is restarted or switched off.

CameraRoll is working without any issues.

After some googling I found that the “Process 8532 exited due to signal 9 (Killed)” means the app was killed due to memory leaking. Possibly this module was not optimized for Android’s 10 SDK. Maybe it has different logic of image processing after capture

Did you tested your app on earlier versions of an Android?

Is this is the all your code in post or you cutted out some inner logic (inside .then()) ?

I have some more code inside like FileSystem.readBufferFromFileSync() and Base64.encodeBuffer() but I have tested application only with code I have presented her and problem appears anyway.

Camera worked without any issues on early Android versions.

What version of Fuselibs do you use?

I’m using 1.14.0 Fuselibs. Fuse-sdk updated to 1.14.1.

I looked at the source code of Camera Module 1.14.0, and yes, it has some code of support Android X way of working with files. Seems this have to be tested deeper

It alot easier to debug if we can get some minimal reproducible code / test code that cause the error

Ok, so here is my JS code I’m using. I have also got feedback that problem only happens on Android tablets like Samsung Galaxy Tab

let Observable = require('FuseJS/Observable');
let Camera = require('FuseJS/Camera');
let FileSystem = require('FuseJS/FileSystem');
let Base64 = require('FuseJS/Base64');
let Environment = require('FuseJS/Environment');
let CameraRoll = require('FuseJS/CameraRoll');
let ImageTools = require('FuseJS/ImageTools');

let showLoading = Observable(false);
let images = Observable();
    
function capturePhoto() {
    	showLoading.value = true;
    	Camera.takePicture()
    		.then(function (photo) {
    			CameraRoll.publishImage(photo).then(() => {
    				const aspectMode =  (Environment.android) ? ImageTools.KEEP_ASPECT : ImageTools.IGNORE_ASPECT;
    				
    				let options = {
    					mode: aspectMode,
    					desiredWidth: 480,
    					desiredHeight: 640
    				};

    				ImageTools.resize(photo, options).then((newImage) => {
    					let arrayBuff = FileSystem.readBufferFromFileSync(
    						newImage.path
    					);
    					let b64data = Base64.encodeBuffer(arrayBuff);

    					images.add({
    						path: newImage.path,
    						name: photo.name,
    						img: b64data,
    						desc: Observable('')
    					});
    				}).then(() => {
    					showLoading.value = false;
    				})
    			})
    		})
    		.catch(function (error) {
    			showLoading.value = false;
    			console.log('Failed to capture photo: ' + error);
    		});
    }

It might be something to do with the out of memory problem, just like in the discussion of this thread.

Try to call takePicture with the size of the parameters like: Camera.TakePicture(640,480) to limit the size of the picture is taken.

I tried your solution but it didn’t work.

I did some testing and it look like the camera is killing the application when there are a lot of observables showing on page. It looks like it works without any problems on empty pages.

I tried to do some profiling for memory leaks with Android Studio but the app crashes already from the start.

It looks like the problem appears only for Samsung devices.