-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[camera] Migrate to the new embedding #2165
Conversation
cyanglaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with some non-blocking comments
| /** | ||
| * Plugin implementation that uses the {@code io.flutter.embedding} package. | ||
| * | ||
| * <p>Instantiate this in an add to app scenario to gracefully handle activity and context changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits(non-blocking): Is there a link can be provided here to explain more on how to use this in add to app scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworded this.
packages/camera/android/src/main/java/io/flutter/plugins/camera/CameraPlugin.java
Outdated
Show resolved
Hide resolved
| </activity> | ||
| <activity | ||
| android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection" | ||
| android:exported="true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it is supposed to be in the EmbeddingV1Activity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| */ | ||
| public static void registerWith(Registrar registrar) { | ||
| if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | ||
| if (registrar.activity() == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should talk about this. We recommend against this pattern because background vs foreground views are not distinguishable in most cases (a background view can switch to foreground).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I'll remove this and update the below comment. I saw the comment and noticed that the code didn't match it and assumed that there was a mistake. The code must have been patched at some point and the comment wasn't updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this a bit more and we also want to keep the logic the same on both the old and new plugin registration path. So I moved this guard into startListening and renamed that to maybeStartListening.
/cc @cyanglaz this means that now sometimes it is expected that when we call onDetached methodCallHandler is null after all. So I removed the Log.wtf from the guard clause there and replaced it with a comment explaining the known case where that could happen.
bparrishMines
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { | ||
| flutterEngine.getPlugins().add(new CameraPlugin()); | ||
|
|
||
| ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea to register these first. Given that they're required by CameraPlugin, it is conceivable that CameraPlugin could immediately attempt to utilize them, in which case this would fail. So it looks like an implementation detail that this happens to work. But up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense to me, but GeneratedPluginRegistrant registers them in this order. I thought it was better to match that.
Migrates the camera plugin to the new embedding and adds an example activity exercising it. DO NOT MERGE until we have an e2e testing solution and are clear to land this without having any issues with stable. However this is still ready for an initial review. Unlike some of the previous PRs on this, this is the minimal migration that would land this without adding any tech debt. From previous offline discussions we'd like to scope these migrations to the bare minimum required to keep the patches small. See #2114 for a migration combined with a refactoring. That said there are still some minor changes to prevent this from adding additional tech debt, unlike #2118: - The new code has been moved from `io` to `dev`. This is for consistency with the other migrated plugins. - `#onMethodCall` has been split up into its own `MethodCallHandlerImpl` class to try and keep `CameraPlugin` from mixing concerns. Before the migration, _all_ it was doing was responding to method calls. Now there's a significant amount of logic just based around responding to lifecycle events. It still seemed better to split that into a seperate file than to try and manage that logic all in one place. Other than the above refactorings, the original logic is untouched.
- Update version in pubspec and changelog. - Migrate tests to use e2e. Make them runnable (in at least one case). - Add dynamic Gradle include script.
mklim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest patch should add everything necessary for this to merge.
- e2e tests (Only works on Android because I need to programmatically grant camera permissions to runt hem)
- New flutter min SDK requirements
- Pubspec increment/changelog
- Dynamic gradle inclusion script
| public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { | ||
| flutterEngine.getPlugins().add(new CameraPlugin()); | ||
|
|
||
| ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense to me, but GeneratedPluginRegistrant registers them in this order. I thought it was better to match that.
|
@mklim After this merge using the camera plugin on a Note 10+ (and other devices) to stream images is useless. Everything freezes after a couple of seconds moving the camera around. Log shows this: |
|
Thanks for reporting the issue and the stack trace @PerLycke, sorry about the regression. Do you mind also posting steps on how to reproduce the crash? A small test case would help too if the example app isn't enough to cause it. |
|
@mklim Never mind my report, after some additional debugging it seems like it's device specific to the Note 10+, and not connected to this commit in particular. Sorry for the confusion, and keep up the good work. |
|
@PerLycke no problem, thanks for debugging this further too. Looks like the Note 10+ issue is now being tracked at flutter/flutter#43566. |
Migrates the camera plugin to the new embedding and adds an example activity exercising it. Unlike some of the previous PRs on this, this is the minimal migration that would land this without adding any tech debt. From previous offline discussions we'd like to scope these migrations to the bare minimum required to keep the patches small. See flutter#2114 for a migration combined with a refactoring. That said there are still some minor changes to prevent this from adding additional tech debt, going a little beyond flutter#2118: - `#onMethodCall` has been split up into its own `MethodCallHandlerImpl` class to try and keep `CameraPlugin` from mixing concerns. Before the migration, _all_ it was doing was responding to method calls. Now there's a significant amount of logic just based around responding to lifecycle events. It still seemed better to split that into a separate file than to try and manage that logic all in one place. Other than the above refactor, the original logic is untouched.
Migrates the camera plugin to the new embedding and adds an example activity exercising it. Unlike some of the previous PRs on this, this is the minimal migration that would land this without adding any tech debt. From previous offline discussions we'd like to scope these migrations to the bare minimum required to keep the patches small. See flutter#2114 for a migration combined with a refactoring. That said there are still some minor changes to prevent this from adding additional tech debt, going a little beyond flutter#2118: - `#onMethodCall` has been split up into its own `MethodCallHandlerImpl` class to try and keep `CameraPlugin` from mixing concerns. Before the migration, _all_ it was doing was responding to method calls. Now there's a significant amount of logic just based around responding to lifecycle events. It still seemed better to split that into a separate file than to try and manage that logic all in one place. Other than the above refactor, the original logic is untouched.
Migrates the camera plugin to the new embedding and adds an example activity exercising it. Unlike some of the previous PRs on this, this is the minimal migration that would land this without adding any tech debt. From previous offline discussions we'd like to scope these migrations to the bare minimum required to keep the patches small. See flutter#2114 for a migration combined with a refactoring. That said there are still some minor changes to prevent this from adding additional tech debt, going a little beyond flutter#2118: - `#onMethodCall` has been split up into its own `MethodCallHandlerImpl` class to try and keep `CameraPlugin` from mixing concerns. Before the migration, _all_ it was doing was responding to method calls. Now there's a significant amount of logic just based around responding to lifecycle events. It still seemed better to split that into a separate file than to try and manage that logic all in one place. Other than the above refactor, the original logic is untouched.
Description
Migrates the camera plugin to the new embedding and adds an example
activity exercising it.
Unlike some of the previous PRs on this, this is the minimal migration
that would land this without adding any tech debt. From previous offline
discussions we'd like to scope these migrations to the bare minimum
required to keep the patches small. See #2114 for a migration combined
with a refactoring.
That said there are still some minor changes to prevent this from adding
additional tech debt, going a little beyond #2118:
#onMethodCallhas been split up into its ownMethodCallHandlerImplclass to try and keep
CameraPluginfrom mixing concerns. Before themigration, all it was doing was responding to method calls. Now
there's a significant amount of logic just based around responding to
lifecycle events. It still seemed better to split that into a separate
file than to try and manage that logic all in one place.
Other than the above refactorings, the original logic is untouched.
Related Issues
Fixes flutter/flutter#41834.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?