Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Add support for text processing actions #44579

Merged
merged 7 commits into from Oct 11, 2023

Conversation

bleroux
Copy link
Contributor

@bleroux bleroux commented Aug 10, 2023

Description

This Android related PR adds a channel buffer and a plugin to interact with Android 'process text' feature. It makes it possible to query text processing actions and to run those actions (for instance 'calling' Google translate).
Text actions that outputs a processed text are supported.

The implementation is based on the great sample provided by @gualse , see flutter/flutter#107603 (comment).

In order to return a non empty list of text actions, the implementation will require adding a section to the Android manifest file (see flutter/flutter#107603 (comment)).
Adding this section automatically to new or existing Flutter apps is not part of this PR but will be tackled in a future PR.

Related Issue

Android engine side for flutter/flutter#139361

Tests

Adds 3 tests.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

This approach LGTM. I think it's good to keep this separate in its own method channel.
CC @camsim99 in case you have any quick thoughts from the Android side of things.

Comment on lines +103 to +118
infos = packageManager.queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(0));
} else {
infos = packageManager.queryIntentActivities(intent, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between the calls in these two versions? I'm just wondering if it's anything we should be documenting or anything like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous version is deprecated, the new one allow using 'long' values instead of 'int' for the previous one.
I will probabl add a comment above the call to the old one to mention it is deprecated.

Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

The approach looks good to me! Just a question on some constructor logic.

this.processTextChannel = processTextChannel;
this.packageManager = processTextChannel.packageManager;

this.cacheResolveInfos();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we can do this elsewhere because this will happen immediately when a ProcessTextPlugin is created, and that will happen regardless of whether or not this functionality is used. Would it make sense to be part of queryTextActions() or processTextAction(...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good point, I will try lazy loading instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@bleroux bleroux changed the title WIP - [Android] Add support for text processing actions [Android] Add support for text processing actions Oct 3, 2023
@bleroux bleroux marked this pull request as ready for review October 3, 2023 07:40
@bleroux bleroux force-pushed the android_process_text branch 7 times, most recently from c8bb275 to 6a4274b Compare October 4, 2023 06:06
@bleroux bleroux requested a review from camsim99 October 4, 2023 13:12
@bleroux bleroux force-pushed the android_process_text branch 3 times, most recently from 08753a2 to 641c524 Compare October 10, 2023 12:42
Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

Looks good, just some nits!

@Override
public Map<String, String> queryTextActions() {
if (resolveInfosById == null) {
resolveInfosById = new HashMap<String, ResolveInfo>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can this happen in cacheResolveInfos versus here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, great suggestion, and doing so we can remove the resolveInfosById.clear()call your mention below.

infos = packageManager.queryIntentActivities(intent, 0);
}

resolveInfosById.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ever called where resolveInfosById wouldn't be an empty array? Wondering if we need this call.

@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 11, 2023
@auto-submit auto-submit bot merged commit d93fe23 into flutter:main Oct 11, 2023
25 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 11, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 11, 2023
…136346)

flutter/engine@cb0dabd...d93fe23

2023-10-11 leroux_bruno@yahoo.fr [Android] Add support for text processing actions (flutter/engine#44579)
2023-10-11 skia-flutter-autoroll@skia.org Roll Skia from 4935bed4260d to 11e41e0e2f9f (3 revisions) (flutter/engine#46759)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jsimmons@google.com,rmistry@google.com,zra@google.com 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://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gmackall pushed a commit to gmackall/engine that referenced this pull request Oct 11, 2023
auto-submit bot pushed a commit that referenced this pull request Oct 11, 2023
…46788)

This reverts commit d93fe23.

This change is causing integration tests to fail on attempts to roll the latest master version of flutter into the packages repo.

See a sample failure here: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8767521956894285553/+/u/Run_package_tests/native_integration_tests/stdout

The root cause seems to be that we are getting request codes in `onActivityResult` that we never added to the `requestsByCode` map, so the call to remove returns null (and we then call success getting a NPE).

More info: 
1. There is a [discussion in discord here](https://discord.com/channels/608014603317936148/1161718667566919761/1161721935927980052)
2. And the failure can be reproduced by running `dart run script/tool/bin/flutter_plugin_tools.dart native-test --android --packages file_selector` from the root of the packages repo (with a flutter checkout that contains these changes).

cc @bleroux 

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
@bleroux bleroux deleted the android_process_text branch October 12, 2023 06:51
auto-submit bot pushed a commit that referenced this pull request Oct 16, 2023
## Description

This is a reland of #44579 which was reverted in #46788.

This reland adds a check into `onActivityResult` in order to return early if the result is related to an unknown request code (aka the result is related to a request sent by another plugin).
It also adds one test that simulates receiving such an unknown request code.

## Related Issue

Android engine side for flutter/flutter#107603

## Tests

Adds 4 tests.
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
## Description

This Android related PR adds a channel buffer and a plugin to interact with Android 'process text' feature. It makes it possible to query text processing actions and to run those actions (for instance 'calling' Google translate).
Text actions that outputs a processed text are supported.

The implementation is based on the great sample provided by @gualse , see flutter/flutter#107603 (comment). 

In order to return a non empty list of text actions, the implementation will require adding a section to the Android manifest file (see flutter/flutter#107603 (comment)).
Adding this section automatically to new or existing Flutter apps is not part of this PR but will be tackled in a future PR.

## Related Issue

Android engine side for flutter/flutter#107603

## Tests

Adds 3 tests.
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
…46788)

This reverts commit d93fe23.

This change is causing integration tests to fail on attempts to roll the latest master version of flutter into the packages repo.

See a sample failure here: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8767521956894285553/+/u/Run_package_tests/native_integration_tests/stdout

The root cause seems to be that we are getting request codes in `onActivityResult` that we never added to the `requestsByCode` map, so the call to remove returns null (and we then call success getting a NPE).

More info: 
1. There is a [discussion in discord here](https://discord.com/channels/608014603317936148/1161718667566919761/1161721935927980052)
2. And the failure can be reproduced by running `dart run script/tool/bin/flutter_plugin_tools.dart native-test --android --packages file_selector` from the root of the packages repo (with a flutter checkout that contains these changes).

cc @bleroux 

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
## Description

This is a reland of #44579 which was reverted in #46788.

This reland adds a check into `onActivityResult` in order to return early if the result is related to an unknown request code (aka the result is related to a request sent by another plugin).
It also adds one test that simulates receiving such an unknown request code.

## Related Issue

Android engine side for flutter/flutter#107603

## Tests

Adds 4 tests.
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 26, 2023
## Description

This PR adds `ProcessTextService` on the framework side to communicate with the engine to query and run text processing actions (on the engine side, only Android is supported currently, see flutter/engine#44579).

## Related Issue

Non-UI framework side for #107603

## Tests

Adds 3 tests.
fluttermirroringbot pushed a commit to flutter/flutter that referenced this pull request Nov 16, 2023
…7207)

## Description

This PR adds a new section to the Android manifest file.
This section is required for flutter/engine#44579 (because it uses `PackageManager.queryIntentActivities` API ), see:

1. https://developer.android.com/training/package-visibility?hl=en
2. https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT
3. https://developer.android.com/reference/android/content/pm/PackageManager?hl=en#queryIntentActivities(android.content.Intent,%20android.content.pm.PackageManager.ResolveInfoFlags)

## Related Issue

Android manifest update for #107603

## Tests

This PR updates the integration tests and examples Android manifest files, this will help catch error or warning related to this change.
Markzipan pushed a commit to Markzipan/flutter that referenced this pull request Nov 27, 2023
…tter#137207)

## Description

This PR adds a new section to the Android manifest file.
This section is required for flutter/engine#44579 (because it uses `PackageManager.queryIntentActivities` API ), see:

1. https://developer.android.com/training/package-visibility?hl=en
2. https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT
3. https://developer.android.com/reference/android/content/pm/PackageManager?hl=en#queryIntentActivities(android.content.Intent,%20android.content.pm.PackageManager.ResolveInfoFlags)

## Related Issue

Android manifest update for flutter#107603

## Tests

This PR updates the integration tests and examples Android manifest files, this will help catch error or warning related to this change.
iska9der added a commit to iska9der/flabr that referenced this pull request Dec 12, 2023
Используется, например, для обработки текста при выделении.
Пока никакого эффекта, но заработает как только
релизнут flutter со следующим PR:
flutter/engine#44579
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 platform-android
Projects
None yet
3 participants