Skip to content

[image_picker_android] Adds Android 13 photo picker functionality #3267

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

Merged
merged 8 commits into from
Mar 1, 2023

Conversation

FXschwartz
Copy link
Contributor

@FXschwartz FXschwartz commented Feb 22, 2023

NOTE: This PR was moved over from the flutter/plugins repo - flutter/plugins#7043

Description
This PR adds the new Android 13 photo picker functionality to Android devices running SDK version 33 or later as well as bumps the compileSdkVersion from 31 to 33. If an Android device is older, it will use the previous standard image picker. Below are two devices, the left running SDK 30 and the right running SDK 33.

SDK 30 SDK 33
sdk30-photo-picker sdk33-photo-picker

List which issues are fixed by this PR. You must list at least one issue.
Fixes flutter/flutter#104250

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

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.

Comment on lines 166 to 169
verify(mockActivity)
.startActivityForResult(
any(Intent.class),
eq(ImagePickerDelegate.REQUEST_CODE_CHOOSE_IMAGE_FROM_GALLERY_USING_PHOTO_PICKER));
Copy link
Member

Choose a reason for hiding this comment

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

(Continuing from flutter/plugins#7043 (comment) on the pre-migration version of this PR, and from Discord.)

This is checking what "request code" we passed to startActivityForResult. But the request code doesn't have any effect on what UI the system presents to the user, or anything like that — it's a number we make up for our own internal tracking, so that our onActivityResult can know what to do with the result it gets.

The thing that controls whether the system shows the spiffy new photo picker, or does something else, is the "action" in the Intent. So that would be the thing to inspect if writing this style of unit test.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's probably the clearest upstream docs on that — in particular the "Action" subsection: https://developer.android.com/guide/components/intents-filters

Is this something we want want to implement for this PR then? Looks like all the tests currently only check that the intent has the correct tag so I imagine we'd want to refactor those tests to also confirm the correct action.

Copy link
Member

Choose a reason for hiding this comment

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

I imagine we'd want to refactor those tests to also confirm the correct action.

I think that would be a good improvement, but my suggestion for this PR would be to leave the tests for other functionality as they are.

…Contracts to decide which photo_picker should be used based on SDK version instead of handling the checks manually.
@FXschwartz FXschwartz marked this pull request as ready for review February 22, 2023 20:25
@FXschwartz FXschwartz requested a review from gmackall as a code owner February 22, 2023 20:25
@gmackall gmackall requested review from tarrinneal and reidbaker and removed request for gmackall February 23, 2023 19:36
@tarrinneal
Copy link
Contributor

the error causing the failing test:

/imagepicker/ImagePickerDelegate.java:347: Error: Call requires API level 19 (current min is 16): PickMultipleVisualMedia [NewApi]
new ActivityResultContracts.PickMultipleVisualMedia()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@FXschwartz
Copy link
Contributor Author

the error causing the failing test:

/imagepicker/ImagePickerDelegate.java:347: Error: Call requires API level 19 (current min is 16): PickMultipleVisualMedia [NewApi]

Is there any kind of approval process to bump the min SDK or am I good to make that change?

@gnprice
Copy link
Member

gnprice commented Feb 24, 2023

Flutter in general supports API 16, so I imagine folks will want to keep these plugins supporting API 16 too.

It looks like both of these ActivityResultContracts.Pick… classes require API 19. I guess that's because they fall back only as far as Intent.ACTION_OPEN_DOCUMENT, which was new in that version.

I'm a bit surprised that the AndroidX folks didn't add a fallback to Intent.ACTION_GET_CONTENT (what the existing code here has been using) in order to support older versions — I'd thought supporting older Android versions smoothly was a big part of what AndroidX was for — but it seems they didn't.

So I think you'll need to check for API 19, and below that version fall back to the same code that's currently here. Fortunately I don't think that makes things much more complicated; it basically just means adding the same code this version adds, but not deleting the old code. And the old code is pretty short.

@FXschwartz
Copy link
Contributor Author

I'm a bit surprised that the AndroidX folks didn't add a fallback to Intent.ACTION_GET_CONTENT (what the existing code here has been using) in order to support older versions — I'd thought supporting older Android versions smoothly was a big part of what AndroidX was for — but it seems they didn't.

Yeah, it definitely seems odd, especially since they are already doing some SDK checks with the photo picker. I'll implement this change today and ping you for another review!

@reidbaker
Copy link
Contributor

reidbaker commented Feb 27, 2023

Fyi flutter is in the process of bumping support to a min of api 19.
flutter.dev/go/android-ndk-version

FWIW I am waiting on terrinneal to give this a pass before digging in.

@gnprice
Copy link
Member

gnprice commented Feb 27, 2023

Fyi flutter is in the process of bumping support to a min of api 19.
flutter.dev/go/android-ndk-version

Ah, good to know, thanks!

If I owned this code I think I'd want to keep the API 16 support until that process completes and Flutter itself actually does bump the minimum to 19. At least I would in this case, where the cost of continued support is just to keep a few lines of existing code, wrapped in a conditional where it only runs on the old versions. But I wouldn't feel strongly about it.

@FXschwartz
Copy link
Contributor Author

If I owned this code I think I'd want to keep the API 16 support until that process completes and Flutter itself actually does bump the minimum to 19. At least I would in this case, where the cost of continued support is just to keep a few lines of existing code, wrapped in a conditional where it only runs on the old versions. But I wouldn't feel strongly about it.

I agree, I'll continue with the original plan of checking the current API version before deciding what code to run.

@reidbaker Appreciate you bringing that up!

@tarrinneal
Copy link
Contributor

Flutter in general supports API 16, so I imagine folks will want to keep these plugins supporting API 16 too.

We will need to maintain support for API 16 for now. My intention with surfacing that error wasn't to suggest that it needed to be updated in that way. Sorry for the confusion.

I've been digging in to future intent with this plugin moving forward, so it is taking me a little longer than expected to be able to approve this pr. Hoping to be able to move forward with it asap.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

Flutter in general supports API 16, so I imagine folks will want to keep these plugins supporting API 16 too.

We will need to maintain support for API 16 for now. My intention with surfacing that error wasn't to suggest that it needed to be updated in that way. Sorry for the confusion.

…used, otherwise defaults to old Intent.ACTION_GET_CONTENT behavior.
@FXschwartz FXschwartz requested review from tarrinneal and removed request for reidbaker February 28, 2023 20:20
@FXschwartz
Copy link
Contributor Author

Flutter in general supports API 16, so I imagine folks will want to keep these plugins supporting API 16 too.

We will need to maintain support for API 16 for now. My intention with surfacing that error wasn't to suggest that it needed to be updated in that way. Sorry for the confusion.

No apologies necessary, really appreciate the review!

Wrapped functionality in an if statement to check the SDK version. Ready for another review!

@tarrinneal tarrinneal self-requested a review February 28, 2023 20:44
Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

This all seems good to me, thanks for sending this in, and handling all of the revisions as well!

@tarrinneal tarrinneal requested review from gnprice and removed request for gnprice February 28, 2023 20:51
@reidbaker reidbaker added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 28, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 28, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 28, 2023

auto label is removed for flutter/packages, pr: 3267, due to - This commit is not mergeable and has conflicts. Please rebase your PR and fix all the conflicts.

@reidbaker
Copy link
Contributor

I think I fixed the conflicts by removing a version that didnt have a changelog message.

@gnprice
Copy link
Member

gnprice commented Feb 28, 2023

(This looks great to me! Thanks @FXschwartz for all your work on it.)

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 1, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 1, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Mar 1, 2023

auto label is removed for flutter/packages, pr: 3267, due to - The status or check suite repo_checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 1, 2023
@auto-submit auto-submit bot merged commit 7ec6a77 into flutter:main Mar 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 1, 2023
sybrands-place pushed a commit to sybrands-place/packages that referenced this pull request Mar 6, 2023
* main: (3910 commits)
  [various] Align Flutter and Dart SDK constraints (flutter#3349)
  Roll Flutter from c590086 to f2f8005 (14 revisions) (flutter#3373)
  [webview_flutter] Enable warnings-as-errors on Android (flutter#3356)
  [ci] Increase Android platform test sharding (flutter#3365)
  Roll Flutter from f032a4d to c590086 (69 revisions) (flutter#3366)
  [Espresso] Update truth package to 1.1.3 (flutter#3358)
  [google_maps] Relax the Android renderer requset test (flutter#3364)
  [pigeon] Only check generated files on master (flutter#3357)
  [webview]: Bump androidx.webkit:webkit from 1.5.0 to 1.6.0 in /packages/webview_flutter/webview_flutter_android/android (flutter#3243)
  [ci+various] Partially enable javac warning checks (flutter#3293)
  [webview_flutter] Update minimum Flutter version to 3.3 and iOS 11 (flutter#3336)
  [local_auth] Update minimum Flutter version to 3.3 and iOS 11 (flutter#3335)
  [google_sign_in] Update minimum Flutter version to 3.3 and iOS 11 (flutter#3330)
  [google_maps_flutter] Update minimum Flutter version to 3.3 and iOS 11 (flutter#3329)
  [video_player] Update minimum Flutter version to 3.3 and iOS 11 (flutter#3328)
  [file_selector] Update minimum Flutter version to 3.3 and iOS 11 (flutter#3325)
  [go_router_builder] Fix the example for default values in the README (flutter#3231)
  Update annotation and espresso dependencies (flutter#3271)
  [tool] Provide a --base-branch flag (flutter#3322)
  [image_picker_android] Adds Android 13 photo picker functionality (flutter#3267)
  ...
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
…utter#3267)

[image_picker_android] Adds Android 13 photo picker functionality
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: image_picker platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[image_picker] Add support for Android 13's photo picker
4 participants