yasirkula/UnityNativeCamera

Fatal Exception on specific device

dandre9 opened this issue · 7 comments

Description of the bug

On a specific device (I will provide below) when trying to access the camera the app crashes with the following information at crashlytics:

NativeCameraPictureFragment.java line 116
com.yasirkula.unity.NativeCameraPictureFragment.onCreate

Fatal Exception: java.lang.Error
FATAL EXCEPTION [main] Unity version : 2020.3.30f1 Device model : motorola Moto Z3 Play Device fingerprint: motorola/beckham/beckham:9/PPWS29.131-27-1-27/34b6d:user/release-keys Build Type : Release Scripting Backend : IL2CPP ABI : arm64-v8a Strip Engine Code : true

Caused by java.lang.SecurityException
Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=droom.sleepIfUCan/.view.activity.FakeActivity clip={text/uri-list U:content://com.RadarStudio.RadarFit.NativeCameraContentProvider/devroot/data/data/com.RadarStudio.RadarFit/cache/IMG_camera.jpg} (has extras) } from ProcessRecord{13dcb1d 23445:com.RadarStudio.RadarFit/u0a381} (pid=23445, uid=10381) not exported from uid 10162

Caused by android.os.RemoteException
Remote stack trace: at com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1866) at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:727) at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:551) at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:1114) at com.android.server.am.ActivityStarter.execute(ActivityStarter.java:492)

Obs: This happens only, as far as we know, with this specific user, we have others using the app normally

Reproduction steps

The bug happens when user tries to open the native camera, but even before the camera open the app crashes. The native camera UI does not appear

Platform specs

Please provide the following info if this is a Unity 3D repository.

  • Unity version: 2020.3.30f1
  • Platform: Android
  • Device: Moto Z3 Play, Android 9 Build PPWS29.131-27-1-27
  • How did you download the plugin: Via Package Manager in Unity

Additional info

Screen Shot 2022-05-25 at 10 51 29

I'd guess that the default camera app installed on that particular device is faulty for not having android:exported="true" tag in its AndroidManifest. If you wish, you can try calling the following code in Awake/Start, it should let the user pick the camera app from the list of all installed camera apps, instead of using the default camera app:

#if UNITY_ANDROID
using( AndroidJavaClass ajc = new AndroidJavaClass( "com.yasirkula.unity.NativeCamera" ) )
	ajc.SetStatic<bool>( "UseDefaultCameraApp", false );
#endif

Thanks for the reply,

The issue still remains, even with the solution you have suggested above
I forgot to say that the Native Camera version is 1.3.3, I believe this is the latest one

The list, to select a different camera app, appears at the devices that the plugin is working properly,
but with this user does not appear and keeps crashing

I dont know if a permission to access the cache folder is related to the problem, although the system dialog to give this permission shows normally with this user

I haven't seen SecurityException with the same error message for IMAGE_CAPTURE intent anywhere else on the internet. I guess we could catch SecurityException and show a "No apps can perform this action." toast message to the user although that'd be misleading but I can't think of anything else to prevent the crash.

By the way, the "droom.sleepIfUCan" package mentioned in the error message points to this app, is this app installed on the user's device by any chance?

Yes, the user has this app installed on her device
We will ask her to uninstall ours and this Alarmy app and then to install ours again to see if the problem is solved
I will give you a feedback as soon as this resolution is done

Good news, the problem solved after user uninstalled that other app and installed ours afterwards

Thank you very much!

Do you have any clues why that other app was conflicting with ours?

The app's AndroidManifest had an intent-filter for IMAGE_CAPTURE intent with an android:exported="false" tag and the operating system was opening that app by default for IMAGE_CAPTURE intent for unknown reasons.

<activity
	android:label="@ref/0x7f1304e1"
	android:name="droom.sleepIfUCan.view.activity.FakeActivity"
	android:exported="false">

	<intent-filter>

		<action
			android:name="android.intent.action.MAIN" />

		<action
			android:name="android.media.action.IMAGE_CAPTURE" />

		<category
			android:name="android.intent.category.DEFAULT" />
	</intent-filter>
</activity>