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

[path_provider] Android implementation of getDownloadsDirectory #4559

Closed
wants to merge 5 commits into from

Conversation

guillermin
Copy link

@guillermin guillermin commented Nov 30, 2021

This PR adds an Android implementation for the getDownloadsDirectory method in the path_provider interface, returning the public Android downloads directory path.

Resolves issue flutter/flutter#93198: [path_provider] getDownloadsDirectory() doesn't work for iOS and Android.

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

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.

Making the change this way adds complexity, and a breaking change we don't want. The better option is to:

  1. Wait until 2.8 or later is on stable
  2. Switch Android to Dart+internal-method-channel implementation (see [path_provider] Switch macOS to an internal method channel #4547)
  3. Make getDownloadsDirectory redirect at the Dart level to getExternalStorageDirectories (which despite the legacy name no longer calls that Android method) with the downloads directory constant.

@@ -242,6 +256,10 @@ private String getPathProviderStorageDirectory() {
return dir.getAbsolutePath();
}

private String getPathProviderDownloadsDirectory() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is deprecated; we deliberately do not use it for that reason.

@@ -84,8 +84,8 @@ class MethodChannelPathProvider extends PathProviderPlatform {

@override
Future<String?> getDownloadsPath() {
if (!_platform.isMacOS) {
throw UnsupportedError('Functionality only available on macOS');
if (_platform.isIOS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually a breaking change. These packages aren't atomic, and the layering here is problematic (these checks should really never have been in the platform interface), so it would be possible to have a version of the Android package that doesn't support it, but the new version of the platform interface that removed the check, and as a result get a different error type.

@stuartmorgan-g
Copy link
Contributor

stuartmorgan-g commented Dec 14, 2021

2.8 has been released to stable, so this could proceed as described above.

Also, you'll need to fix your commits to use the same email address as the one you used to sign the CLA (which appears to be the one associated with your GitHub account).

@guillermin
Copy link
Author

guillermin commented Dec 15, 2021

2.8 has been released to stable, so this could proceed as described above.

Also, you'll need to fix your commits to use the same email address as the one you used to sign the CLA (which appears to be the one associated with your GitHub account).

I created a new PR (from a new GitHub account) focusing only on switching Android to an internal method channel: #4617

I just copied the same steps you did on your MacOS PR (except for the directory creation part). What else do you think it would need? Perhaps @gaaclarke could review the TODO that he left in for when flutter/engine#29147 was in stable (which I believe it is).

Just wanted you to know I'm on it and if anybody is interested in participating they can do so through #4617 instead of creating a new PR.

@stuartmorgan-g
Copy link
Contributor

I just copied the same steps you did on your MacOS PR (except for the directory creation part). What else do you think it would need?

Probably nothing; I'll take a look.

Perhaps @gaaclarke could review the TODO that he left in for when flutter/engine#29147 was in stable (which I believe it is).

That's unrelated to the Dart side of the method channel, so would be best handled in a different PR.

@godofredoc godofredoc changed the base branch from master to main January 6, 2022 22:37
@stuartmorgan-g
Copy link
Contributor

Are you planning on updating this to do step 3 of #4559 (review)?

@stuartmorgan-g
Copy link
Contributor

Thank you for your contribution. I'm going to close this PR for now since there are outstanding comments, just to get this off our PR review queue. Please don't hesitate to submit a new PR if you have the time to address the review comments. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants