Skip to content

[google_maps_flutter] Semi-convert remaining Android host API calls to Pigeon#6980

Merged
auto-submit[bot] merged 6 commits intoflutter:mainfrom
stuartmorgan-g:maps-pigeon-android-host-api-updates-shallow
Jul 1, 2024
Merged

[google_maps_flutter] Semi-convert remaining Android host API calls to Pigeon#6980
auto-submit[bot] merged 6 commits intoflutter:mainfrom
stuartmorgan-g:maps-pigeon-android-host-api-updates-shallow

Conversation

@stuartmorgan-g
Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g commented Jun 24, 2024

Does a "shallow" Pigeon conversion of the remaining host API calls in the Android implementation. All of the actual method calls are now Pigeon, but for the most part the data structures are not yet converted, and the Pigeon representations of the map objects are instead placeholders that currently just wrap the existing JSON serialization. This is done for a few reasons:

  • Keeps the incremental PR relatively small and easy to understand.
  • Quickly gets us to a state where any new APIs added will automatically use Pigeon, reducing further accumulation of technical debt.
  • Avoids duplication of handling code until [pigeon] Make the codec public flutter#150631 is resolved. As noted in a TODO added in this PR, almost all of the data structures that are passed in these methods are also passed through the PlatformView factory constructor, and Pigeon doesn't yet support using the Pigeon codec in non-Pigeon-generated code, so we would need to have both the structured and JSON handler for all of these objects if we converted them now.

Future PRs will be able to incrementally convert each map object to a structured form. Converting the Flutter APIs (Java->Dart) will also be done in a follow-up, to limit the scope of this PR.

Adds Dart unit tests for each method call, as they were previously not unit tested.

Part of flutter/flutter#117907

Pre-launch Checklist

case "default":
initializeWithRendererRequest(null);
break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the default condition no longer possible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The special "default" value no longer exists, because requesting the default is now expressed as null in the Pigeon API, just as it already was at both the Dart API and Maps SDK API levels.

"Renderer initialization called with invalid renderer type",
null);
initializationResult = null;
MapsInitializer.Renderer rendererType = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: move this to a Convert.toMapRendererType

I will understand if you tell me this is overkill.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

initializationResult.error(
"Unknown renderer type", "Initialized with unknown renderer type", null);
new Messages.FlutterError(
"Unknown renderer type", "Initialized with unknown renderer type", null));
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see the argument for keeping this error the same but consider passing the type instead of null so that if we ever hit this condition we might be able to trace why the type was wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added renderer.name() as the details; we don't like to change errors since it could break people, but adding data that just wasn't there is safe for any but the most contrived case.

@@ -647,42 +1120,88 @@ private PigeonCodec() {}
protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
switch (type) {
case (byte) 129:
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly for future work but consider either extracting these to named constants in this class or putting the byte as a static value on each of the class items then having a list of supported object types that all have a byte identifier and a read/write Value method.

Second pass note: Unless this is generated (which I don't think it is)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This entire file is generated (see comment at the very top). In all other languages we make that clear with a .g. in the file name, but annoyingly Java doesn't allow that since the file name and the class name have to exactly match.

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

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: google_maps_flutter platform-android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants