Skip to content

[camera_android_camerax] Fix video recording after backgrounding app#12145

Draft
camsim99 wants to merge 3 commits into
flutter:mainfrom
camsim99:cos_background
Draft

[camera_android_camerax] Fix video recording after backgrounding app#12145
camsim99 wants to merge 3 commits into
flutter:mainfrom
camsim99:cos_background

Conversation

@camsim99

@camsim99 camsim99 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

WIP towards fixing flutter/flutter#183880.

As of now, reviewers focus on issues implemenation_plan.md.


Normal pull request information above the line.

This pull request is an attempt to "oneshot" fixing flutter/flutter#183880. Using antigravity to execute a plan that is collaboratively worked on. The "rules" are to not allow human authored code to camera_android_camerax and to not rely on human code review feedback for code iteration.

We can add documentation, skills, mcp servers, presubmit test etc. Basically any "support infrastructure" for development is allowed but the package changes must be generated as a single pass.
When we discover that the plan is not good enough we will blow the package changes away and either modify the plan or add more support infrastructure and try again.

For more information see the working doc in go/flutter-project-one-shot

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

Comment thread packages/camera/camera_android_camerax/implementation_plan.md
dart run ../../../script/tool/bin/flutter_plugin_tools.dart integration-test --android --packages=camera_android_camerax
```

### Manual Verification

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an ideal world, it would know how to launch the emulator and test but I actually don't know if the agent would have any way of interacting with the emulator after that in a meaningful way (even if it were a more minimal app than the example).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do this via an espresso test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea! Yes, definitely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well wait a quick search makes it seem like we would need UiAutomator to get real camera recordings. We could mock it but I'll have to look into what that would look like.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread packages/camera/camera_android_camerax/implementation_plan.md
});
```

## Verification Plan

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our first plan, we had it explicitly list out the steps it would take to make sure that the code is high quality. I'm ok with that not being explicitly included because it will be in our AGENTS.md and the skills, but just noting in case other reviewers do not agree.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now I think the verification steps should be listed especially if there are no artifacts of that verification.

For a human, this would be something like, I ran it on a pixel device and swapped between front facing and rear facing camera and it the example app did not crash.

```

### Manual Verification
1. Run the example app (`example/lib/main.dart`) on an Android device.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very least it can run the example app and see if it builds (or at least try a flutter build apk).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not be the final AGENTS.md we use in the plugin, but included my draft for now in case some of the core information was useful for creating the implementation plan.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#12066 is my actual proposal.

Comment thread packages/camera/camera_android_camerax/implementation_plan.md
Comment thread packages/camera/camera_android_camerax/implementation_plan.md
dart run ../../../script/tool/bin/flutter_plugin_tools.dart integration-test --android --packages=camera_android_camerax
```

### Manual Verification

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do this via an espresso test?

dart run ../../../script/tool/bin/flutter_plugin_tools.dart integration-test --android --packages=camera_android_camerax
```

### Manual Verification

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean for a one-shot plan to have a manual verification step? Does that mean that the reviewer is expected to read and carry out this section as part of the code review?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In both of our one-shot plan attempts, we did not ask for this section specifically, but I assume it's generated because the agent assumes it can't verify the solution itself. I do wonder if that's true, though. It can definitely launch an emulator and run the app, but I need to verify it could interact with it as we'd expect.

@reidbaker reidbaker Jul 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is expected to be done by the reviewer we should call the section "reviewer verification" and it should be required to be part of the pull request.

In my experience "manual verification" were steps that did not produce artifacts like automated tests that were done to ensure the code was correct and they were only done once near the end but not after all final edits.

/// Releases the resources of the accessed camera with ID [cameraId].
@override
Future<void> dispose(int cameraId) async {
await preview?.releaseSurfaceProvider();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this change can be considered out of scope) Do these need to be awaited in order? can we instead record a future for each of them then await the set?

await deviceOrientationManager.stopListeningForDeviceOrientationChange();
+ recording = null;
+ pendingRecording = null;
+ videoOutputPath = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something in the code above stores the video safely when the camera is disposed. Instead of setting these values to null here can we make that code null out the recording?

For example if there is a lifecycle event from the camerax library for native recording stop can we forward that call instead of relying on the dispose? (maybe dispose is the call being forwarded?)

```

#### [MODIFY] android_camera_camerax_test.dart
Add assertions in the `dispose` test to ensure that the recording state variables are properly nullified when `dispose()` completes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW It feels like a pattern that information about camera is in a bunch of variables that need their state cleared. Is there a better pattern for this that we can use. Maybe a CameraState object that we can call dispose on that handles all its own variables and makes the lifecycle more clear.

verify(mockDeviceOrientationManager
.stopListeningForDeviceOrientationChange());
+
+ // Verify state is cleared

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this test also ensure that the video was saved correctly?

Comment on lines +115 to +119
I will run the following commands:
```bash
# Verify the example APK builds successfully without errors
cd example/android && ./gradlew assembleDebug

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont this is the way we want to verify the android code builds. It should use the flutter tool.

dart run ../../../script/tool/bin/flutter_plugin_tools.dart dart-test --packages=camera_android_camerax
```

### Manual Verification (What requires human interaction/devices)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment thread about this being reviewer verification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants