Thanks to visit codestin.com
Credit goes to github.com

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

[quick_actions] Extract the Android implementation into a separate package #4698

Merged

Conversation

mvanbeusekom
Copy link
Contributor

@mvanbeusekom mvanbeusekom commented Jan 26, 2022

Moves the native Android implementation from the quick_actions package into its own quick_actions_android package. I also duplicated the method channel implementation as suggested in issue flutter/flutter#94224.

Temporarily marks quick_actions as unpublishable to allow the implementations to be moved, rather than copied and deleted, in order to better preserve git history. A follow-up PR will restore it to publishable form.

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]. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the [CLA].
  • The title of the PR starts with the name of the plugin 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].
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

@@ -15,12 +19,16 @@ flutter:
android:
package: io.flutter.plugins.quickactions
pluginClass: QuickActionsPlugin
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove these two lines.

// 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this file is for native unit tests, in which case it should be a move.

(Actually... is this even used? Java unit tests should be in the main source, not the example, and it looks like we already have that. So this file is likely a mistake. Try making it always fail and see if anything actually fails, and if not—which I expect is the case—you can just remove this, both here and the original.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an interesting one. First of all the test is indeed run and will fail the tree if I force it to fail. Inside this file there is only one test that seems to verify if the QuickActions plugin is part of the engine.getPlugins() collection:

  public void imagePickerPluginIsAdded() {
    final ActivityScenario<QuickActionsTestActivity> scenario =
        ActivityScenario.launch(QuickActionsTestActivity.class);
    scenario.onActivity(
        activity -> {
          assertTrue(activity.engine.getPlugins().has(QuickActionsPlugin.class));
        });
  }

Not sure if this test has a lot of value, I assume that loading the plugin it self is widely tested in the engine code it self, so the only thing it verifies now is that the plugin is added to the pubspec.yaml file (which I this doesn't really need a test).

If this test does have value, it should remain part of the example App since it tests if the plugin is loaded as part of the example App. It doesn't test any logic that is part of the native Java implementation. And doesn't it also make sense to keep the test in both the quick_actions_android and quick_actions example Apps? Both package contain their own example Apps which load the Android plugin in a slightly different way (meaning the registration in the pubspec.yaml is different).

Would like to hear your opinion on this issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I misremembered the file locations for different kinds of tests. This is the harness for running native Android UI (espresso) tests. So we do want this file to exist, but it should be a move since we want native integration tests to only be in the implementation package.

Not sure if this test has a lot of value

It's a placeholder, from the project to make sure we had test harnesses in place for all the kinds of tests we want to be running (so that we'd stop having PRs blocked on tests that couldn't be written without someone first learning how to set up the infrastructure for that kind of test).

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9
Copy link
Contributor

Choose a reason for hiding this comment

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

As with iOS, can we remove this?

icon: 'AppIcon',
),
// NOTE: This second action icon will only work on Android.
// In a real world project keep the same file name for both platforms.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments here as for iOS but reversed.

sdk: flutter
quick_actions_android:
# When depending on this package from a real application you should use:
# quick_actions: ^x.y.z
Copy link
Contributor

Choose a reason for hiding this comment

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

quick_actions_android

integration_test:
sdk: flutter
mockito: ^5.0.0
pedantic: ^1.11.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

sdk: flutter
integration_test:
sdk: flutter
mockito: ^5.0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

I missed this on the iOS side... are we actually using mockito anywhere in this package?

TestWidgetsFlutterBinding.ensureInitialized();

group('$QuickActionsAndroid', () {
final QuickActionsAndroid quickActions = QuickActionsAndroid();
Copy link
Contributor

Choose a reason for hiding this comment

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

I missed this on the iOS side, but probably applies there too: please put this line in each test. Having the object under test be stateful across the tests is an antipattern and leads to a variety of problems (including tests passing when they shouldn't).

group('$QuickActionsAndroid', () {
final QuickActionsAndroid quickActions = QuickActionsAndroid();

final List<MethodCall> log = <MethodCall>[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer making this late and created in setUp instead of being final and cleared in setUp, to reduce statefulness.

# TODO(mvanbeusekom): Remove the exclusion of the quick_actions_android and
# once the native implementation is removed from the
# quick_actions package.
- quick_actions_android
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be necessary now.

Creates a new `quick_actions_android` directory and adds
the following meta-data files:
- `AUTHORS`: copied from the `quick_actions` package and added my name;
- `CHANGELOG.md`: new file adding description for release 0.6.0+9;
- `LICENSE`: copied from the `quick_actions` package;
- `README.md`: new file adding the standard platform implementation
  description;
- `pubspec.yaml`: new file adding package meta-data for the
  `quick_actions_android` package.
A one to one copy of the `quick_actions/android` folder to
`quick_actions_android/` using the following command:
```
cp -R ./quick_actions/android ./quick_actions_android/
```
This commit makes a direct copy of the `quick_actions/example` app to
the  `quick_actions_android` package. After the copy the `example/ios`
folder is removed as it doesn't serve a purpose in the Android specific
package. Commands run where:
```
cp -R ./quick_actions/example ./quick_actions_android/
rm -rf ./quick_actions_android/example/ios
```
This commit updates the example App and integration tests so they directly
use the Android specific quick_actions_android package.
Duplicates the method channel implementation in the platform interface
package into the Android specific package (see issue
flutter/flutter#94224).

Also updated the example project and renamed the channels on native and
Dart side.
Duplicates the method channel implementation tests and update them so
they test the `QuickActionsAndroid` class (see also issue
flutter/flutter#94224).
Exclude the quick_actions_android package from the build all plugins app
CI step as it currently conflicts with the android implementation that
is still part of the quick_actions package.
@mvanbeusekom mvanbeusekom force-pushed the issue/94224_quick_actions_android branch from 6bb9d11 to 104af9c Compare February 8, 2022 13:02
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM once QuickActionsTest.java is converted to a move.

@mvanbeusekom mvanbeusekom force-pushed the issue/94224_quick_actions_android branch from 5e34739 to 7cc4fe4 Compare February 8, 2022 16:32
@mvanbeusekom
Copy link
Contributor Author

LGTM once QuickActionsTest.java is converted to a move.

Done, added waiting for tree to go green label.

@mvanbeusekom mvanbeusekom added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 8, 2022
@fluttergithubbot
Copy link

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite android-platform_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite android-platform_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • This commit is not mergeable and has conflicts. Please rebase your PR and fix all the conflicts.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 8, 2022
@mvanbeusekom mvanbeusekom force-pushed the issue/94224_quick_actions_android branch from 7cc4fe4 to 6a2f1c8 Compare February 9, 2022 07:48
@mvanbeusekom mvanbeusekom force-pushed the issue/94224_quick_actions_android branch from 39938e2 to 5d7671f Compare February 9, 2022 07:59
@mvanbeusekom mvanbeusekom added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 9, 2022
@fluttergithubbot fluttergithubbot merged commit 049ae07 into flutter:main Feb 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: quick_actions platform-android waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants