Repository: flutter
Issue: [camera_android_camerax] Camera Image Stream is randomly stopping
Labels: c: crash,platform-android,p: camera,package,P2,team-android,triaged-android

### What package does this bug report belong to?

camera

### What target platforms are you seeing this bug on?

Android

### Have you already upgraded your packages?

Yes

### Steps to reproduce

1. Execute `flutter run` on the code below. This is using the latest version 0.11.0+1.
2.  Wait and watch for the platform exception below to appear in the terminal. It usually happens after running it for a while. You may have to tap your phone every little bit to prevent it from falling asleep. Move the phone around a bit so the camera does some work.

### Expected results

No exception is output and the image stream never stops.

### Actual results

The image stream stops and the platform exception shown below in the log is output. This happens randomly, sometimes after running it for a few minutes, other times after running it for longer like 8ish minutes. This has been run on an s23 ultra. It happens quicker if I do something with the image that the stream is giving me.  It doesn't happen if I comment out the startImageStream line.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) => MaterialApp(
        title: 'Stream Test',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: const CameraWidget(),
      );
}

class CameraWidget extends StatefulWidget {
  const CameraWidget({super.key});

  @override
  State<CameraWidget> createState() => _CameraWidgetState();
}

class _CameraWidgetState extends State<CameraWidget>
    with WidgetsBindingObserver {
  late List<CameraDescription> cameras;

  CameraController? _cameraController;

  get _controller => _cameraController;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    _initStateAsync();
  }

  void _initStateAsync() async {
    _initializeCamera();
  }

  void _initializeCamera() async {
    cameras = await availableCameras();
    _cameraController = CameraController(
      cameras[0],
      ResolutionPreset.high,
      enableAudio: false,
    )..initialize().then((_) async {
        await _controller.startImageStream(onLatestImageAvailable);
        setState(() {});
      });
  }

  @override
  Widget build(BuildContext context) {
    if (_cameraController == null || !_controller.value.isInitialized) {
      return const SizedBox.shrink();
    }

    var aspect = 1 / _controller.value.aspectRatio;

    return Stack(
      children: [
        AspectRatio(
          aspectRatio: aspect,
          child: CameraPreview(_controller),
        )
      ],
    );
  }

  void onLatestImageAvailable(CameraImage cameraImage) async {
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) async {
    switch (state) {
      case AppLifecycleState.inactive:
        _cameraController?.stopImageStream();
        break;
      case AppLifecycleState.resumed:
        _initStateAsync();
        break;
      default:
    }
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    _cameraController?.dispose();
    super.dispose();
  }
}
```

</details>


### Screenshots or Videos

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
I/CameraManagerGlobal( 8806): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client com.example.lamp API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.snapchat.android API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 2 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client android.system API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 20 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client com.sec.android.app.camera API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 21 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client android.system API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 23 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client android.system API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client android.system API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 4 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client android.system API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 52 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client android.system API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 54 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client android.system API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 56 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client com.sec.android.app.camera API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 58 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client android.system API Level 2 User Id 0
I/CameraManagerGlobal( 8806): Camera 90 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client android.system API Level 2 User Id 0
D/CameraRepository( 8806): Added camera: 0
I/Camera2CameraInfo( 8806): Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_3
I/CameraManager( 8806): registerAvailabilityCallback: Is device callback = false
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 0 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 1 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 2 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 3 status STATUS_PRESENT
D/CameraRepository( 8806): Added camera: 1
I/Camera2CameraInfo( 8806): Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_FULL
I/CameraManager( 8806): registerAvailabilityCallback: Is device callback = false
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 0 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 1 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 2 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 3 status STATUS_PRESENT
D/CameraRepository( 8806): Added camera: 2
I/Camera2CameraInfo( 8806): Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED
I/CameraManager( 8806): registerAvailabilityCallback: Is device callback = false
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 0 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 1 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 2 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 3 status STATUS_PRESENT
D/CameraRepository( 8806): Added camera: 3
I/Camera2CameraInfo( 8806): Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_FULL
I/CameraManager( 8806): registerAvailabilityCallback: Is device callback = false
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 0 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 1 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 2 status STATUS_PRESENT
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 3 status STATUS_PRESENT
D/CameraValidator( 8806): Verifying camera lens facing on dm3q, lensFacingInteger: null
I/BLASTBufferQueue( 8806): [SurfaceView[com.example.lamp/com.example.live_object_detection_ssd_mobilenet.MainActivity]@0#1](f:0,a:0,s:0) onFrameAvailable the first frame is available
D/SurfaceView@98475c0( 8806): 159675840 setAlpha: alpha=1.0
I/SurfaceView( 8806): 159675840 Changes: creating=false format=false size=false visible=false alpha=true hint=false visible=false left=false top=false z=false attached=true lifecycleStrategy=false
I/SurfaceView@98475c0( 8806): 159675840 Cur surface: Surface(name=null)/@0xafedb05
I/SurfaceView@98475c0( 8806): updateSurface: mVisible = true mSurface.isValid() = true
I/SurfaceView@98475c0( 8806): updateSurface: mSurfaceCreated = true surfaceChanged = false visibleChanged = false
I/SurfaceView( 8806): 159675840 surfaceRedrawNeeded
I/SurfaceView( 8806): 159675840 finishedDrawing
V/SurfaceView@98475c0( 8806): Layout: x=0 y=0 w=1440 h=3032, frame=Rect(0, 0 - 1440, 3032)
I/ViewRootImpl@70d56ee[MainActivity]( 8806): Setup new sync=wmsSync-ViewRootImpl@70d56ee[MainActivity]#2
I/ViewRootImpl@70d56ee[MainActivity]( 8806): Creating new active sync group ViewRootImpl@70d56ee[MainActivity]#3
I/ViewRootImpl@70d56ee[MainActivity]( 8806): registerCallbacksForSync syncBuffer=false
D/SurfaceView( 8806): 159675840 updateSurfacePosition RenderWorker, frameNr = 1, position = [0, 0, 1440, 3032] surfaceSize = 1440x3032
I/SurfaceView@98475c0( 8806): uSP: rtp = Rect(0, 0 - 1440, 3032) rtsw = 1440 rtsh = 3032
I/SurfaceView@98475c0( 8806): onSSPAndSRT: pl = 0 pt = 0 sx = 1.0 sy = 1.0
I/SurfaceView@98475c0( 8806): aOrMT: ViewRootImpl@70d56ee[MainActivity] t = android.view.SurfaceControl$Transaction@809abf8 fN = 1 android.view.SurfaceView.-$$Nest$mapplyOrMergeTransaction:0 android.view.SurfaceView$SurfaceViewPositionUpdateListener.positionChanged:1666 android.graphics.RenderNode$CompositePositionUpdateListener.positionChanged:369
I/ViewRootImpl@70d56ee[MainActivity]( 8806): mWNT: t=0xb4000079b4d5a880 mBlastBufferQueue=0xb4000079b5b31d00 fn= 1 mRenderHdrSdrRatio=1.0 caller= android.view.SurfaceView.applyOrMergeTransaction:1598 android.view.SurfaceView.-$$Nest$mapplyOrMergeTransaction:0 android.view.SurfaceView$SurfaceViewPositionUpdateListener.positionChanged:1666
I/ViewRootImpl@70d56ee[MainActivity]( 8806): Received frameDrawingCallback syncResult=0 frameNum=1.
I/ViewRootImpl@70d56ee[MainActivity]( 8806): mWNT: t=0xb4000079b4d9b680 mBlastBufferQueue=0xb4000079b5b31d00 fn= 1 mRenderHdrSdrRatio=1.0 caller= android.view.ViewRootImpl$8.onFrameDraw:13841 android.view.ThreadedRenderer$1.onFrameDraw:792 <bottom of call stack>
I/ViewRootImpl@70d56ee[MainActivity]( 8806): Setting up sync and frameCommitCallback
I/BLASTBufferQueue( 8806): [ViewRootImpl@70d56ee[MainActivity]#0](f:0,a:0,s:0) onFrameAvailable the first frame is available
I/ViewRootImpl@70d56ee[MainActivity]( 8806): Received frameCommittedCallback lastAttemptedDrawFrameNum=1 didProduceBuffer=true
D/OpenGLRenderer( 8806): CFMS:: SetUp Pid : 8806    Tid : 8871
I/ViewRootImpl@70d56ee[MainActivity]( 8806): reportDrawFinished seqId=0
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
I/ViewRootImpl@70d56ee[MainActivity]( 8806): handleWindowFocusChanged: 1 0 call from android.view.ViewRootImpl.-$$Nest$mhandleWindowFocusChanged:0
D/ViewRootImpl@70d56ee[MainActivity]( 8806): mThreadedRenderer.initializeIfNeeded()#2 mSurface={isValid=true 0xb400007a41542000}
D/InputMethodManagerUtils( 8806): startInputInner - Id : 0
I/InputMethodManager( 8806): startInputInner - IInputMethodManagerGlobalInvoker.startInputOrWindowGainedFocus
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=270, isOppositeFacing=false, result=270
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=270, isOppositeFacing=false, result=270
D/InputMethodManagerUtils( 8806): startInputInner - Id : 0
I/InsetsController( 8806): onStateChanged: host=com.example.lamp/com.example.live_object_detection_ssd_mobilenet.MainActivity, from=android.view.ViewRootImpl$ViewRootHandler.handleMessageImpl:7209, state=InsetsState: {mDisplayFrame=Rect(0, 0 - 1440, 3088), mDisplayCutout=DisplayCutout{insets=Rect(0, 100 - 0, 0) waterfall=Insets{left=0, top=0, right=0, bottom=0} boundingRect={Bounds=[Rect(0, 0 - 0, 0), Rect(685, 0 - 756, 100), Rect(0, 0 - 0, 0), Rect(0, 0 - 0, 0)]} cutoutPathParserInfo={CutoutPathParserInfo{displayWidth=1440 displayHeight=3088 physicalDisplayWidth=1440 physicalDisplayHeight=3088 density={3.75} cutoutSpec={M 0,0 H -9.466666666666667 V 26.66666666666667‬ H 9.466666666666667 V 0 H 0 Z @dp} rotation={0} scale={1.0} physicalPixelDisplaySizeRatio={1.0}}}}, mRoundedCorners=RoundedCorners{[RoundedCorner{position=TopLeft, radius=15, center=Point(15, 15)}, RoundedCorner{position=TopRight, radius=15, center=Point(1425, 15)}, RoundedCor
ner{position=BottomRight, radius=15, center=Point(1425, 3073)}, RoundedCorner{position=BottomLeft, radius=15, center=Point(15, 3073)}]}  mRoundedCornerFrame=Rect(0, 0 - 1440, 3088), mPrivacyIndicatorBounds=PrivacyIndicatorBounds {static bounds=Rect(1275, 0 - 1440, 100) rotation=0}, mDisplayShape=DisplayShape{ spec=-311912193 displayWidth=1440 displayHeight=3088 physicalPixelDisplaySizeRatio=1.0 rotation=0 offsetX=0 offsetY=0 scale=1.0}, mSources= { InsetsSource: {fdc30000 mType=statusBars mFrame=[0,0][1440,100] mVisible=true mFlags=[]}, InsetsSource: {fdc30005 mType=mandatorySystemGestures mFrame=[0,0][1440,145] mVisible=true mFlags=[]}, InsetsSource: {fdc30006 mType=tappableElement mFrame=[0,0][1440,100] mVisible=true mFlags=[]}, InsetsSource: {3 mType=ime mFrame=[0,0][0,0] mVisible=false mFlags=[]}, InsetsSource: {27 mType=displayCutout mFrame=[0,0][1440,100] mVisible=true mFlags=[]}, InsetsSource: {46700001 mType=navigationBars mFrame=[0,3032][1440,3088] mVisible=true mFlags=[SUPPRESS_SCRIM]}, InsetsSource: {46700004 mType=systemGestures mFrame=[0,0][112,3088] mVisible=true mFlags=[]}, InsetsSource: {46700005 mType=mandatorySystemGestures mFrame=[0,2968][1440,3088] mVisible=true mFlags=[]}, InsetsSource: {46700006 mType=tappableElement mFrame=[0,0][0,0] mVisible=true mFlags=[]}, InsetsSource: {46700024 mType=systemGestures mFrame=[1328,0][1440,3088] mVisible=true mFlags=[]} }
I/InsetsSourceConsumer( 8806): applyRequestedVisibilityToControl: visible=false, type=ime, host=com.example.lamp/com.example.live_object_detection_ssd_mobilenet.MainActivity
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/DynamicRangeResolver( 8806): Resolved dynamic range for use case androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e2 to no compatible HDR dynamic ranges.
D/DynamicRangeResolver( 8806): DynamicRange@b98fc00{encoding=UNSPECIFIED, bitDepth=0}
D/DynamicRangeResolver( 8806): ->
D/DynamicRangeResolver( 8806): DynamicRange@b271283{encoding=SDR, bitDepth=8}
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/DeferrableSurface( 8806): Surface created[total_surfaces=1, used_surfaces=0](androidx.camera.core.processing.SurfaceEdge$SettableSurface@3fea2f5}
D/DeferrableSurface( 8806): Surface created[total_surfaces=2, used_surfaces=0](androidx.camera.core.SurfaceRequest$2@4e37971}
D/DeferrableSurface( 8806): New surface in use[total_surfaces=2, used_surfaces=1](androidx.camera.core.SurfaceRequest$2@4e37971}
D/DeferrableSurface( 8806): use count+1, useCount=1 androidx.camera.core.SurfaceRequest$2@4e37971
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/ImageCapture( 8806): createPipeline(cameraId: 0, streamSpec: StreamSpec{resolution=1280x720, dynamicRange=DynamicRange@b271283{encoding=SDR, bitDepth=8}, expectedFrameRateRange=[0, 0], implementationOptions=androidx.camera.camera2.impl.Camera2ImplConfig@d174ee2})
D/CompatibilityChangeReporter( 8806): Compat change id reported: 236825255; UID 10071; state: ENABLED
D/DeferrableSurface( 8806): Surface created[total_surfaces=3, used_surfaces=1](androidx.camera.core.impl.ImmediateSurface@1c1a273}
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Use case androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770 ACTIVE
D/UseCaseAttachState( 8806): Active and attached use case: [] for camera: 0
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/DeferrableSurface( 8806): Surface created[total_surfaces=4, used_surfaces=1](androidx.camera.core.impl.ImmediateSurface@c89f2cf}
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Use case androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047 ACTIVE
D/UseCaseAttachState( 8806): Active and attached use case: [] for camera: 0
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Use case androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770 ACTIVE
D/UseCaseAttachState( 8806): Active and attached use case: [] for camera: 0
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Use case androidx.camera.core.ImageAnalysis-67e5fe33-bd23-419f-91ab-2c0f74c15589101068192 INACTIVE
D/UseCaseAttachState( 8806): Active and attached use case: [] for camera: 0
D/UseCaseAttachState( 8806): Active and attached use case: [] for camera: 0
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Use cases [androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047, androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.ImageAnalysis-67e5fe33-bd23-419f-91ab-2c0f74c15589101068192] now ATTACHED      
D/UseCaseAttachState( 8806): All use case: [androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047, androidx.camera.core.ImageAnalysis-67e5fe33-bd23-419f-91ab-2c0f74c15589101068192] for camera: 0
D/UseCaseAttachState( 8806): Active and attached use case: [androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047] for camera: 0
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Resetting Capture Session
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Releasing session in state INITIALIZED
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Attempting to force open the camera.
D/CameraStateRegistry( 8806): tryOpenCamera(Camera@3ecadf1[id=0]) [Available Cameras: 1, Already Open: false (Previous state: null)] --> SUCCESS
D/CameraStateRegistry( 8806): Recalculating open cameras:
D/CameraStateRegistry( 8806): Camera                                       State
D/CameraStateRegistry( 8806): -------------------------------------------------------------------
D/CameraStateRegistry( 8806): Camera@6d4a0e0[id=3]                         UNKNOWN
D/CameraStateRegistry( 8806): Camera@ad080c8[id=2]                         UNKNOWN
D/CameraStateRegistry( 8806): Camera@2322a29[id=1]                         UNKNOWN
D/CameraStateRegistry( 8806): Camera@3ecadf1[id=0]                         OPENING
D/CameraStateRegistry( 8806): -------------------------------------------------------------------
D/CameraStateRegistry( 8806): Open count: 1 (Max allowed: 1)
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Opening camera.
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Transitioning camera internal state: INITIALIZED --> OPENING
D/CameraStateMachine( 8806): New public camera state CameraState{type=OPENING, error=null} from OPENING and null
D/CameraStateMachine( 8806): Publishing new public camera state CameraState{type=OPENING, error=null}
D/UseCaseAttachState( 8806): All use case: [androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047, androidx.camera.core.ImageAnalysis-67e5fe33-bd23-419f-91ab-2c0f74c15589101068192] for camera: 0
D/CameraOrientationUtil( 8806): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
I/CameraManagerGlobal( 8806): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPENING for client com.example.lamp API Level 2 User Id 0
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 0 status STATUS_NOT_AVAILABLE
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 0 status STATUS_NOT_AVAILABLE
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 0 status STATUS_NOT_AVAILABLE
I/CameraManagerGlobal( 8806): postSingleUpdate device: camera id 0 status STATUS_NOT_AVAILABLE
I/CameraManagerGlobal( 8806): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPEN for client com.example.lamp API Level 2 User Id 0
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Use case androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047 ACTIVE
D/UseCaseAttachState( 8806): Active and attached use case: [androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047] for camera: 0
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Use case androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770 ACTIVE
D/UseCaseAttachState( 8806): Active and attached use case: [androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047] for camera: 0
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Use case androidx.camera.core.ImageAnalysis-67e5fe33-bd23-419f-91ab-2c0f74c15589101068192 INACTIVE
D/UseCaseAttachState( 8806): Active and attached use case: [androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047] for camera: 0
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Use case androidx.camera.core.ImageAnalysis-67e5fe33-bd23-419f-91ab-2c0f74c15589101068192 ACTIVE
D/UseCaseAttachState( 8806): Active and attached use case: [androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047, androidx.camera.core.ImageAnalysis-67e5fe33-bd23-419f-91ab-2c0f74c15589101068192] for camera: 0       
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} CameraDevice.onOpened()
D/Camera2CameraImpl( 8806): {Camera@3ecadf1[id=0]} Transitioning camera internal state: OPENING --> OPENED
D/CameraStateRegistry( 8806): Recalculating open cameras:
D/CameraStateRegistry( 8806): Camera                                       State
D/CameraStateRegistry( 8806): -------------------------------------------------------------------
D/CameraStateRegistry( 8806): Camera@6d4a0e0[id=3]                         UNKNOWN
D/CameraStateRegistry( 8806): Camera@ad080c8[id=2]                         UNKNOWN
D/CameraStateRegistry( 8806): Camera@2322a29[id=1]                         UNKNOWN
D/CameraStateRegistry( 8806): Camera@3ecadf1[id=0]                         OPEN
D/CameraStateRegistry( 8806): -------------------------------------------------------------------
D/CameraStateRegistry( 8806): Open count: 1 (Max allowed: 1)
D/CameraStateMachine( 8806): New public camera state CameraState{type=OPEN, error=null} from OPEN and null
D/CameraStateMachine( 8806): Publishing new public camera state CameraState{type=OPEN, error=null}
D/UseCaseAttachState( 8806): All use case: [androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047, androidx.camera.core.ImageAnalysis-67e5fe33-bd23-419f-91ab-2c0f74c15589101068192] for camera: 0
D/UseCaseAttachState( 8806): Active and attached use case: [androidx.camera.core.ImageCapture-08246426-0a49-416d-96c3-0c6cb8ac64bf259810770, androidx.camera.core.Preview-8e6bdcb0-6edb-464f-b7ac-41df85f444e243639047, androidx.camera.core.ImageAnalysis-67e5fe33-bd23-419f-91ab-2c0f74c15589101068192] for camera: 0       
D/SyncCaptureSessionBase( 8806): [androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl@a1489f9] getSurface...done
D/CaptureSession( 8806): Opening capture session.
D/DeferrableSurface( 8806): use count+1, useCount=2 androidx.camera.core.SurfaceRequest$2@4e37971
D/DeferrableSurface( 8806): New surface in use[total_surfaces=4, used_surfaces=2](androidx.camera.core.impl.ImmediateSurface@1c1a273}
D/DeferrableSurface( 8806): use count+1, useCount=1 androidx.camera.core.impl.ImmediateSurface@1c1a273
D/DeferrableSurface( 8806): New surface in use[total_surfaces=4, used_surfaces=3](androidx.camera.core.impl.ImmediateSurface@c89f2cf}
D/DeferrableSurface( 8806): use count+1, useCount=1 androidx.camera.core.impl.ImmediateSurface@c89f2cf
Syncing files to device SM S918U1...                               407ms
D/CaptureSession( 8806): Attempting to send capture request onConfigured
D/CaptureSession( 8806): Issuing request for session.
D/Camera2CaptureRequestBuilder( 8806): createCaptureRequest
D/CaptureSession( 8806): CameraCaptureSession.onConfigured() mState=OPENED
D/CaptureSession( 8806): CameraCaptureSession.onReady() OPENED
I/CameraManagerGlobal( 8806): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_ACTIVE for client com.example.lamp API Level 2 User Id 0
I/ViewRootImpl@70d56ee[MainActivity]( 8806): onDisplayChanged oldDisplayState=2 newDisplayState=2

Flutter run key commands.
r Hot reload.
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on SM S918U1 is available at: http://127.0.0.1:57305/r_4lx0bGKWc=/
I/om.example.lamp( 8806): EglImage dataspace changed, need recreate
W/qdgralloc( 8806): getInterlacedFlag: getMetaData returned 3, defaulting to interlaced_flag = 0
I/om.example.lamp( 8806): EglImage dataspace changed, need recreate
W/qdgralloc( 8806): getInterlacedFlag: getMetaData returned 3, defaulting to interlaced_flag = 0
The Flutter DevTools debugger and profiler on SM S918U1 is available at: http://127.0.0.1:9102?uri=http://127.0.0.1:57305/r_4lx0bGKWc=/
I/om.example.lamp( 8806): EglImage dataspace changed, need recreate
W/qdgralloc( 8806): getInterlacedFlag: getMetaData returned 3, defaulting to interlaced_flag = 0
I/om.example.lamp( 8806): EglImage dataspace changed, need recreate
W/qdgralloc( 8806): getInterlacedFlag: getMetaData returned 3, defaulting to interlaced_flag = 0
I/om.example.lamp( 8806): Background concurrent mark compact GC freed 88369(10MB) AllocSpace objects, 77(53MB) LOS objects, 49% free, 12MB/24MB, paused 80us,6.677ms total 32.733ms
I/om.example.lamp( 8806): EglImage dataspace changed, need recreate
W/qdgralloc( 8806): getInterlacedFlag: getMetaData returned 3, defaulting to interlaced_flag = 0
I/om.example.lamp( 8806): EglImage dataspace changed, need recreate
W/qdgralloc( 8806): getInterlacedFlag: getMetaData returned 3, defaulting to interlaced_flag = 0
I/om.example.lamp( 8806): EglImage dataspace changed, need recreate
W/qdgralloc( 8806): getInterlacedFlag: getMetaData returned 3, defaulting to interlaced_flag = 0
I/om.example.lamp( 8806): Background concurrent mark compact GC freed 363(252KB) AllocSpace objects, 12(9036KB) LOS objects, 53% free, 5389KB/11MB, paused 35us,13.950ms total 24.327ms
I/om.example.lamp( 8806): EglImage dataspace changed, need recreate
W/qdgralloc( 8806): getInterlacedFlag: getMetaData returned 3, defaulting to interlaced_flag = 0
I/om.example.lamp( 8806): Background concurrent mark compact GC freed 1770(353KB) AllocSpace objects, 38(27MB) LOS objects, 64% free, 3449KB/9593KB, paused 35us,8.766ms total 18.005ms
I/InsetsSourceConsumer( 8806): applyRequestedVisibilityToControl: visible=true, type=statusBars, host=com.example.lamp/com.example.live_object_detection_ssd_mobilenet.MainActivity
D/ProfileInstaller( 8806): Installing profile for com.example.lamp
I/ViewRootImpl@70d56ee[MainActivity]( 8806): ViewPostIme pointer 0
I/ViewRootImpl@70d56ee[MainActivity]( 8806): ViewPostIme pointer 1
I/om.example.lamp( 8806): Background concurrent mark compact GC freed 425(252KB) AllocSpace objects, 12(9036KB) LOS objects, 53% free, 5301KB/11MB, paused 65us,5.532ms total 17.876ms
I/om.example.lamp( 8806): Background concurrent mark compact GC freed 320(252KB) AllocSpace objects, 12(9036KB) LOS objects, 53% free, 5314KB/11MB, paused 33us,7.136ms total 17.282ms
I/ViewRootImpl@70d56ee[MainActivity]( 8806): ViewPostIme pointer 0
I/ViewRootImpl@70d56ee[MainActivity]( 8806): ViewPostIme pointer 1
I/ViewRootImpl@70d56ee[MainActivity]( 8806): ViewPostIme pointer 0
I/ViewRootImpl@70d56ee[MainActivity]( 8806): ViewPostIme pointer 1
I/ViewRootImpl@70d56ee[MainActivity]( 8806): ViewPostIme pointer 0
I/ViewRootImpl@70d56ee[MainActivity]( 8806): ViewPostIme pointer 1
E/flutter ( 8806): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(java.lang.NullPointerException, NullPointerException, Cause: null, Stacktrace: java.lang.NullPointerException
E/flutter ( 8806):      at java.util.Objects.requireNonNull(Objects.java:207)
E/flutter ( 8806):      at io.flutter.plugins.camerax.ImageProxyHostApiImpl.getImageProxyInstance(ImageProxyHostApiImpl.java:80)
E/flutter ( 8806):      at io.flutter.plugins.camerax.ImageProxyHostApiImpl.close(ImageProxyHostApiImpl.java:73)
E/flutter ( 8806):      at io.flutter.plugins.camerax.GeneratedCameraXLibrary$ImageProxyHostApi.lambda$setup$1(GeneratedCameraXLibrary.java:3455)
E/flutter ( 8806):      at io.flutter.plugins.camerax.GeneratedCameraXLibrary$ImageProxyHostApi$$ExternalSyntheticLambda1.onMessage(Unknown Source:2)
E/flutter ( 8806):      at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:261)
E/flutter ( 8806):      at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/flutter ( 8806):      at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter ( 8806):      at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter ( 8806):      at android.os.Handler.handleCallback(Handler.java:958)
E/flutter ( 8806):      at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 8806):      at android.os.Looper.loopOnce(Looper.java:230)
E/flutter ( 8806):      at android.os.Looper.loop(Looper.java:319)
E/flutter ( 8806):      at android.app.ActivityThread.main(ActivityThread.java:8919)
E/flutter ( 8806):      at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 8806):      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
E/flutter ( 8806):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
E/flutter ( 8806): , null)
E/flutter ( 8806): #0      ImageProxyHostApi.close (package:camera_android_camerax/src/camerax_library.g.dart:2764:7)
E/flutter ( 8806): <asynchronous suspension>
E/flutter ( 8806): #1      AndroidCameraCameraX._configureImageAnalysis.analyze (package:camera_android_camerax/src/android_camera_camerax.dart:1236:7)
E/flutter ( 8806): <asynchronous suspension>
E/flutter ( 8806):
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [Version 10.0.19045.4651], locale en-US)
    • Flutter version 3.22.2 on channel stable at C:\dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (8 weeks ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\Administrator\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.36)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.11.34902.97
    X The current Visual Studio installation is incomplete.
      Please use Visual Studio Installer to complete the installation or reinstall Visual Studio.

[√] Android Studio (version 2023.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)

[√] VS Code (version 1.91.1)
    • VS Code at C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.92.0

[√] Connected device (4 available)
    • SM S918U1 (mobile) • R3CW50M09SD • android-arm64  • Android 14 (API 34)
    • Windows (desktop)  • windows     • windows-x64    • Microsoft Windows [Version 10.0.19045.4651]
    • Chrome (web)       • chrome      • web-javascript • Google Chrome 127.0.6533.73
    • Edge (web)         • edge        • web-javascript • Microsoft Edge 127.0.2651.74

[√] Network resources
    • All expected network resources are available.
```

</details>