Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[camera] Switch to internal method channels #5943

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ packages/webview_flutter/** @bparrishMines
packages/**/*_web/** @ditman

# - Android
packages/camera/camera/android/** @camsim99
packages/camera/camera_android/** @camsim99
packages/espresso/** @blasten
packages/flutter_plugin_android_lifecycle/** @blasten
packages/google_maps_flutter/google_maps_flutter/android/** @GaryQian
Expand All @@ -40,7 +40,7 @@ packages/url_launcher/url_launcher_android/** @GaryQian
packages/video_player/video_player_android/** @blasten

# - iOS
packages/camera/camera/ios/** @hellohuanlin
packages/camera/camera_avfoundation/** @hellohuanlin
packages/google_maps_flutter/google_maps_flutter/ios/** @cyanglaz
packages/google_sign_in/google_sign_in_ios/** @jmagman
packages/image_picker/image_picker_ios/** @cyanglaz
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.8

* Switches to internal method channel implementation.

## 0.9.7+1

* Splits from `camera` as a federated implementation.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ enum CameraEventType {
* the main thread. The handler is mainly supplied so it will be easier test this class.
*/
DartMessenger(BinaryMessenger messenger, long cameraId, @NonNull Handler handler) {
cameraChannel = new MethodChannel(messenger, "flutter.io/cameraPlugin/camera" + cameraId);
deviceChannel = new MethodChannel(messenger, "flutter.io/cameraPlugin/device");
cameraChannel =
new MethodChannel(messenger, "plugins.flutter.io/camera_android/camera" + cameraId);
deviceChannel = new MethodChannel(messenger, "plugins.flutter.io/camera_android/fromPlatform");
this.handler = handler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ final class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {
this.permissionsRegistry = permissionsAdder;
this.textureRegistry = textureRegistry;

methodChannel = new MethodChannel(messenger, "plugins.flutter.io/camera");
imageStreamChannel = new EventChannel(messenger, "plugins.flutter.io/camera/imageStream");
methodChannel = new MethodChannel(messenger, "plugins.flutter.io/camera_android");
Copy link
Contributor

Choose a reason for hiding this comment

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

is it part of the effort that move logic from platform to dart?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renaming the method channels is to prevent a mistake I made in one early case where I didn't actually set up Dart registration correctly, but didn't notice because the platform-specific and shared method channels were still identical, so everything (temporarily) worked. That would have cause problems later as the implementations started to diverge, but it would have been very hard to debug. This causes any such mistake to be obvious immediately.

It's also proved useful for some edge cases. E.g., debugging issues with people running plugins in isolates, where there's no Dart auto-registration. This means they fail with an error message that we can easily see a root cause for, rather than having subtle breakage like a mismatch in arguments as channel implementations start to diverge.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Are we moving towards a world where ideally the platform native code simply one-line adapts native API, so channel method names and params likely diverge across multiple platforms in that world?

Copy link
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 direction we're exploring (currently with webview), but it's not the only outcome where this is useful. The design doc linked from the associated bug has a discussion of the the benefits here.

Recent examples of places where just having flexibility helped us include:

imageStreamChannel =
new EventChannel(messenger, "plugins.flutter.io/camera_android/imageStream");
methodChannel.setMethodCallHandler(this);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/camera/camera_android/lib/camera_android.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'src/android_camera.dart';
Loading