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

Add support for image insertion on Android #35619

Merged
merged 10 commits into from
Oct 20, 2022

Conversation

tneotia
Copy link
Contributor

@tneotia tneotia commented Aug 23, 2022

This PR adds support for image keyboard support on Android, utilizing the commitContent function.

Partially addresses flutter/flutter#20796. Associated Flutter PR: flutter/flutter#110052.

This is a re-PR of #27763 to clean up the commits.

cc @justinmc and @zlshames

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 [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@tneotia
Copy link
Contributor Author

tneotia commented Aug 23, 2022

I'm also lost on how I can make this test pass. The error isn't helping me much to be honest:

io.flutter.plugin.editing.InputConnectionAdaptorTest > testCommitContent FAILED
    Wanted but not invoked:
    dartExecutor.send(
        <Capturing argument>,
        <Capturing argument>,
        isNull()
    );
    -> at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:223)

    However, there was exactly 1 interaction with this mock:
    dartExecutor.setMessageHandler(
        "flutter/textinput",
        io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler@6030d1b0
    );
    -> at io.flutter.plugin.common.MethodChannel.setMethodCallHandler(MethodChannel.java:149)
        at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:223)
        at io.flutter.plugin.editing.InputConnectionAdaptorTest.testCommitContent(InputConnectionAdaptorTest.java:203)

@chinmaygarde
Copy link
Member

cc @stuartmorgan for finding a reviewer for this.

@stuartmorgan-g
Copy link
Contributor

@GaryQian Could you take a look at this?

@gspencergoog or @dkwingsmt should probably look as well given recent changes to the keyboard system.

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.

Just a few small comments here. I just reviewed the framework PR and this engine one seems fine, though I'm still trying to get it running locally so I can try it out.

Bump @GaryQian @gspencergoog @dkwingsmt for a secondary review.

return false;
}
} else {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

What will this end up looking like in the framework if this isn't supported by the device for some reason? Ideally an app developer would be able to gracefully handle this situation.

Copy link
Contributor Author

@tneotia tneotia Sep 14, 2022

Choose a reason for hiding this comment

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

There's a toast message displayed that "<app> doesn't support image insertion here". It will display this toast any time this function returns false. To my knowledge, it cannot be customized and is an Android framework thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok sounds like that's the same as native so that should be fine 👍

final Map<String, Object> obj = new HashMap<>();
obj.put("mimeType", mimeType);
obj.put("data", data);
obj.put("uri", uri.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all 3 of these parameters guaranteed to be valid at this point, or should there be any checking and error handling 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.

Not sure to be honest. This is why we made the CommittedContent class parameters nullable, just in case something doesn't work correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I guess it will be up to the framework to handle an invalid CommittedContent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, or the developer themselves. They can choose what they want to do if a parameter they need happens to be null.


// Commit the content to the text input channel and release the permission.
textInputChannel.commitContent(mClient, obj);
inputContentInfo.releasePermission();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have to release permission when is is null? You request it in line 508 but only release when successful 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.

Fixed. Good catch :)

@chinmaygarde
Copy link
Member

And JIT release builds are failing on what look to be related errors.

@tneotia
Copy link
Contributor Author

tneotia commented Sep 15, 2022

Think I fixed the JIT builds by merging upstream

@@ -171,6 +174,44 @@ public void testPerformContextMenuAction_paste() {
assertTrue(editable.toString().startsWith(textToBePasted));
}

@Test
public void testCommitContent() throws JSONException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Heads up that this test appears to be failing


io.flutter.plugin.editing.InputConnectionAdaptorTest > testCommitContent FAILED
    Wanted but not invoked:
    dartExecutor.send(
        <Capturing argument>,
        <Capturing argument>,
        isNull()
    );
    -> at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:223)

    However, there was exactly 1 interaction with this mock:
    dartExecutor.setMessageHandler(
        "flutter/textinput",
        io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler@18698c6a
    );
    -> at io.flutter.plugin.common.MethodChannel.setMethodCallHandler(MethodChannel.java:146)
        at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:223)
        at io.flutter.plugin.editing.InputConnectionAdaptorTest.testCommitContent(InputConnectionAdaptorTest.java:203)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm aware of this, the error hasn't really helped me to figure out why its failing. No idea what needs to change to get it to work.

@chinmaygarde
Copy link
Member

@justinmc @GaryQian Are you able to troubleshoot @tneotia s test issue? Perhaps we need to rope in others?

@justinmc
Copy link
Contributor

I tried to look into this but locally I'm always getting a bunch of failures in the java tests, even on main. Maybe something with my setup...

@zanderso
Copy link
Member

From PR review triage: It looks like the next step on this PR is for @tneotia to fix the presubmit test failures, which do appear related to this change.

@chinmaygarde
Copy link
Member

Closing this as stale. Please re-open once progress can be made to patch the presubmit failures.

@tneotia
Copy link
Contributor Author

tneotia commented Oct 6, 2022

I really wish this wouldn't be closed ... I just need a little help getting this test to run. I have no experience writing tests and only have a windows system so I don't even have a great way to run these.

So close to getting this merged yet so far away

@justinmc
Copy link
Contributor

justinmc commented Oct 7, 2022

I really want to see this merged too. I'm going to be out for a week but when I get back I'll try to take a look at the test again if I have time. Not sure what's going on with my engine setup.

@mrorabau
Copy link

mrorabau commented Oct 9, 2022

@chinmaygarde @gspencergoog @dkwingsmt @justinmc @tneotia

I'm sure this will come across as a rant, but it is meant more of a general observation. There are several flutter projects (including the engine itself) that are backed by google where PRs for fixes or enhancements are at least encouraged in the documentation. When suggestions or questions are asked in advance, maintainers (especially google staff) tend to remain somewhat silent or request that a PR just be submitted. When in fact one or more outside contributors attempt to create and submit a PR, if any issues come up (such as with unit tests), there is little-to-no assistance to be found from google maintainers. While I know myself, and I suspect most others appreciate the hard work that the flutter team (including google) puts in to everything, I think providing some minimal dedicated time to assisting free contributions would go a long way to both helping improve the platform and the general flutter community. I would bet a little bit of help would encourage those contributing to learn the specifics of why a PR failed to past tests, and/or how code could better align with the coding style of a particular project and most importantly, encourage contributors to make additional submissions.

Instead, even basic functionality included in other native apps are missing, often for months/years, such as this PR. When the public community attempts to fill in the gaps they are met with a (unintended?) wall of resistance both technically and from the maintainers. I can state that this sentiment is shared with several other OS contributors I've communicated with.

If there is a better way for contributors to request assistance, or if in reality the maintainers do not feel these contributions to be beneficial, I think it would at least be fair to mention this honestly in the documentation so that contributors can reduce wasting time on these efforts, and instead provide submissions to other open source projects.

Thanks for your time, and I hope also that this PR gets re-opened.

@zlshames
Copy link

zlshames commented Oct 9, 2022

@chinmaygarde @gspencergoog @dkwingsmt @justinmc @tneotia

I'm sure this will come across as a rant, but it is meant more of a general observation. There are several flutter projects (including the engine itself) that are backed by google where PRs for fixes or enhancements are at least encouraged in the documentation. When suggestions or questions are asked in advance, maintainers (especially google staff) tend to remain somewhat silent or request that a PR just be submitted. When in fact one or more outside contributors attempt to create and submit a PR, if any issues come up (such as with unit tests), there is little-to-no assistance to be found from google maintainers. While I know myself, and I suspect most others appreciate the hard work that the flutter team (including google) puts in to everything, I think providing some minimal dedicated time to assisting free contributions would go a long way to both helping improve the platform and the general flutter community. I would bet a little bit of help would encourage those contributing to learn the specifics of why a PR failed to past tests, and/or how code could better align with the coding style of a particular project and most importantly, encourage contributors to make additional submissions.

Instead, even basic functionality included in other native apps are missing, often for months/years, such as this PR. When the public community attempts to fill in the gaps they are met with a (unintended?) wall of resistance both technically and from the maintainers. I can state that this sentiment is shared with several other OS contributors I've communicated with.

If there is a better way for contributors to request assistance, or if in reality the maintainers do not feel these contributions to be beneficial, I think it would at least be fair to mention this honestly in the documentation so that contributors can reduce wasting time on these efforts, and instead provide submissions to other open source projects.

Thanks for your time, and I hope also that this PR gets re-opened.

I second this 100%. I know Tanay has worked really hard to get this PR into a state where it can move forward. But he's stuck and any assistance would be greatly appreciated; for a feature that a lot of people are asking for.

This isn't a framework that we created or are super well versed in. So it's already an intimidating codebase and an uphill battle to get it all working between the framework & engine.

ANY guidance on ways to implement things or fix unit tests would go a long way... With just a little effort from the maintainers side

@stuartmorgan-g
Copy link
Contributor

@mrorabau The #hackers channel on the Flutter Discord would be a much better place for a general discussion about code review practice than a specific PR.

(I'd be happy to weigh in there, but not here, as I don't want to drive the discussion here further off of the topic of the PR itself. And others who would certainly have relevant things to say aren't even on this PR.)

@justinmc
Copy link
Contributor

I'm going to try to push a new commit that fixes the test.

@justinmc justinmc reopened this Oct 18, 2022
@justinmc
Copy link
Contributor

@tneotia I don't have permission to push a commit to your branch, but my fix is here: e5ef030

Feel free to make the changes yourself. Or maybe you can allow me to push my commit by checking "Allow edits and access to secrets by maintainers" at the bottom of the right bar of this PR? I'm not sure how that works exactly.

I also merged main in locally, I'm not sure if you'll need to do that or not.

I tested this locally with its corresponding framework PR (flutter/flutter#110052) too, and everything worked great. Super excited for this feature.

@tneotia
Copy link
Contributor Author

tneotia commented Oct 18, 2022

I don't see that button unfortunately, but I will apply your changes in an hour or so. Thank you so, so, SO much for your help on this. Can't wait to get this in a stable flutter release :)

@justinmc
Copy link
Contributor

Sounds good, thank you for your work and persistence!

@tneotia
Copy link
Contributor Author

tneotia commented Oct 19, 2022

Not sure why ci.yaml validation is failing (I merged master), but the test fix is now included here.

@tneotia tneotia requested review from justinmc and removed request for dkwingsmt and gspencergoog October 19, 2022 01:40
@tneotia
Copy link
Contributor Author

tneotia commented Oct 19, 2022

@chinmaygarde @zanderso test failures are fixed and everything seems ready to go here :)

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.

LGTM 👍. I'm glad the test fix worked!

As mentioned elsewhere, I was able to get this code running with the associated framework PR and its example, and it worked great.

This needs one more approval and then we can merge.

Copy link
Contributor

@GaryQian GaryQian left a comment

Choose a reason for hiding this comment

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

LGTM, with a small comment ^^^.

@GaryQian GaryQian added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 20, 2022
@auto-submit auto-submit bot merged commit 4e3a5e3 into flutter:main Oct 20, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants