Fix abandoned BufferQueue and CameraX crash by unmounting UsbCameraView when obscured; fix permission receiver leak
This commit is contained in:
1 parent
a49e30c553
commit
1468b2d0c7
11 files changed
+79
-36
No files matched your search
@@ -24,6 +24,9 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
|
||||
private val onCameraError by EventDispatcher()
|
||||
private val onCameraState by EventDispatcher()
|
||||
|
||||
private var permissionReceiver: android.content.BroadcastReceiver? = null
|
||||
private var registeredContext: Context? = null
|
||||
|
||||
init {
|
||||
textureView = AspectRatioTextureView(context)
|
||||
addView(textureView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
|
||||
@@ -65,7 +68,7 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
|
||||
android.util.Log.e("UsbCameraView", "Error checking USB devices: ${e.message}", e)
|
||||
}
|
||||
|
||||
val permissionReceiver = object : android.content.BroadcastReceiver() {
|
||||
permissionReceiver = object : android.content.BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: android.content.Intent) {
|
||||
if ("com.schnappix.USB_PERMISSION" == intent.action) {
|
||||
synchronized(this) {
|
||||
@@ -82,6 +85,7 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
|
||||
}
|
||||
|
||||
val filter = android.content.IntentFilter("com.schnappix.USB_PERMISSION")
|
||||
registeredContext = activityContext
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
|
||||
activityContext.registerReceiver(permissionReceiver, filter, Context.RECEIVER_EXPORTED)
|
||||
} else {
|
||||
@@ -206,6 +210,16 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
|
||||
}
|
||||
|
||||
fun onDestroy() {
|
||||
try {
|
||||
permissionReceiver?.let {
|
||||
registeredContext?.unregisterReceiver(it)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
permissionReceiver = null
|
||||
registeredContext = null
|
||||
|
||||
try {
|
||||
cameraClient?.closeCamera()
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in new issue
Block a user