Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

Converts from direct use of method channels to using Pigeon.

Adds unit testing of the actual implementation logic. The previous unit tests only covered the intermediate class that converted method calls/arguments into Java calls, which has been removed since that's now handled by Pigeon.

Part of flutter/flutter#117915

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

context,
intent -> {
ComponentName componentName = intent.resolveActivity(context.getPackageManager());
return componentName == null ? null : componentName.toShortString();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was able to narrow the code that's not being unit tested from "all of UrlLauncher" to just these two lines (which come from the old canLaunch). I spent some time looking at this, and didn't see how to mock enough of context to make intent.resolveActivity return a dummy ComponentName, so I just extracted this one small piece into something tests could replace.

NO_ACTIVITY,
/** No Activity found that can handle given intent. */
ACTIVITY_NOT_FOUND,
private static @NonNull Bundle extractBundle(Map<String, String> headersMap) {
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, and the strings in the error in ensureActivity, are the surviving code from MethodCallHandlerImpl.

Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

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

This LGTM, though I haven't reviewed any conversions to pigeon before. In your opinion is this a change that it would be good for me to find a second reviewer on, or is the perceived risk low?

@stuartmorgan-g
Copy link
Collaborator Author

The pigeon surface here is quite small, so between that and the expanded native unit testing I think the risk is pretty low.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label May 25, 2023
@auto-submit auto-submit bot merged commit e14d0d5 into flutter:main May 25, 2023
@bparrishMines
Copy link
Contributor

@stuartmorgan This is causing a failure on main:

Analyzing url_launcher_android...

   info - test/url_launcher_android_test.dart:89:7 - Missing an 'await' for the 'Future' computed by this expression. Try adding an 'await' or wrapping the expression un 'unawaited'. - unawaited_futures
   info - test/url_launcher_android_test.dart:104:7 - Missing an 'await' for the 'Future' computed by this expression. Try adding an 'await' or wrapping the expression un 'unawaited'. - unawaited_futures
   info - test/url_launcher_android_test.dart:170:7 - Missing an 'await' for the 'Future' computed by this expression. Try adding an 'await' or wrapping the expression un 'unawaited'. - unawaited_futures
   info - test/url_launcher_android_test.dart:185:7 - Missing an 'await' for the 'Future' computed by this expression. Try adding an 'await' or wrapping the expression un 'unawaited'. - unawaited_futures

@bparrishMines
Copy link
Contributor

#4086

stuartmorgan-g pushed a commit that referenced this pull request May 25, 2023
Fixes `unawaited_futures` lint errors from
#4045.

This only updates the tests, so no version bump.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [x] I signed the [CLA].
- [x] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated `pubspec.yaml` with an appropriate new version according
to the [pub versioning philosophy], or this PR is [exempt from version
changes].
- [ ] I updated `CHANGELOG.md` to add a description of the change,
[following repository CHANGELOG style].
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[relevant style guides]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[pub versioning philosophy]: https://dart.dev/tools/pub/versioning
[exempt from version changes]:
https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#version-and-changelog-updates
[following repository CHANGELOG style]:
https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changelog-style
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
@stuartmorgan-g stuartmorgan-g deleted the url-launcher-android-pigeon branch May 25, 2023 22:35
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 26, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 26, 2023
flutter/packages@995bfc5...9f8dcc5

2023-05-25 [email protected] Append $flutter/osx sdk property to existing platforms/targets relying on xcode (flutter/packages#4074)
2023-05-25 [email protected] [url_launcher_android] Fix `unawaited_futures` lint errors (flutter/packages#4086)
2023-05-25 [email protected] [url_launcher] Convert Android to Pigeon (flutter/packages#4045)
2023-05-25 [email protected] [multiple packages] Update collection-fors to prefer final (as per updated `prefer_final_in_for_each`) (flutter/packages#4073)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@rafaelmeteoro
Copy link

I catch an error on build android:

/opt/flutter_3.3.0/.pub-cache/hosted/pub.dartlang.org/url_launcher_android-6.0.35/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncher.java:66: error: cannot find symbol01:34
    if (BuildConfig.DEBUG) {
        ^
  symbol:   variable BuildConfig01:34
  location: class UrlLauncher

anyone else with this?

@bparrishMines
Copy link
Contributor

@rafaelmeteoro Could you open a new issue with an explanation of when you are seeing this error? https://github.com/flutter/flutter/issues/new/choose

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: url_launcher platform-android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants