Repository: flutter
Issue: [path_provider] Re-evaluate storage scope of getDownloadsDirectory and similar methods
Labels: p: path_provider,package,team-ecosystem,has reproducible steps,P2,triaged-ecosystem,found in release: 3.24,found in release: 3.26

### What package does this bug report belong to?

path_provider

### What target platforms are you seeing this bug on?

Android, iOS

### Have you already upgraded your packages?

Yes

### Dependency versions

<details><summary>pubspec.lock</summary>

```lock
name: inspectogo
description: "A multiplatform app to manage companies and inspections."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1

environment:
  sdk: '>=3.2.6 <4.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  firebase_core: ^3.0.0
  firebase_auth: ^5.2.0
  cloud_firestore: ^5.4.0
  flutter_riverpod: ^2.4.10
  google_fonts: ^6.1.0
  pin_code_fields: ^8.0.1
  logger: ^2.4.0
  accordion: ^2.6.0
  flutter_lorem: ^2.0.0
  intl_phone_number_input: ^0.7.4
  email_validator: ^3.0.0
  fancy_password_field: ^2.0.7
  flutter_localizations:
    sdk: flutter
  intl: ^0.19.0
  mocktail: ^1.0.4
  google_sign_in: ^6.2.1
  fake_cloud_firestore: ^3.0.2
  im_stepper: ^1.0.1+1
  google_maps_flutter: ^2.7.1
  geocoding: ^3.0.0
  google_maps_flutter_android: ^2.14.5
  google_maps_flutter_platform_interface: ^2.8.0
  throttling: ^2.0.1
  freezed_annotation: ^2.4.4
  json_annotation: ^4.8.1
  fluster: ^1.2.0
  super_context_menu: ^0.8.18
  hold_to_confirm_button: ^0.0.2
  collection: ^1.18.0
  firebase_storage: ^12.2.0
  image_picker: ^1.1.2
  uuid: ^4.5.0
  firebase_performance: ^0.10.0
  path_provider: ^2.1.4
  firebase_analytics: ^11.3.0
  rxdart: ^0.27.7
  firebase_app_check: ^0.3.1
  get_thumbnail_video:
    git:
      url: https://github.com/kdhfred/video_thumbnail
  lazy_load_indexed_stack: ^1.1.0
  firebase_crashlytics: ^4.1.0
  http: ^1.2.2
  shared_preferences: ^2.3.2
  cloud_functions: ^5.1.0
  flutter_widget_from_html: ^0.15.2
  image_picker_platform_interface: ^2.10.0
  image_picker_android: ^0.8.12+4
  image_picker_ios: ^0.8.12
  fast_immutable_collections: ^10.2.4
  go_router: ^14.2.7
  path: ^1.9.0
  flutter_flavorizr: ^2.2.3
  in_app_purchase: ^3.2.0
  crypto: ^3.0.3
  url_launcher: ^6.3.0
  in_app_purchase_android: ^0.3.6+6
  scroll_snap_list: ^0.9.1
  photo_view: ^0.15.0
  image: ^4.2.0
  vector_math: ^2.1.4
  defer_pointer: ^0.0.2
  html: ^0.15.4
  universal_html: ^2.2.4
  open_file_manager: ^1.0.2
  downloadsfolder: ^1.1.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^4.0.0
  custom_lint: ^0.6.4
  riverpod_lint: ^2.3.9
  integration_test:
    sdk: flutter
  freezed: ^2.4.7
  build_runner: ^2.4.12
  json_serializable: ^6.7.1
  cxpress_lint:
    git:
      url: https://github.com/DevXpressInc/cxpress_lint
      ref: ea9ee3556518a4f3765f14901d7d53be72075410
      path: packages/pyramid_lint
  mocktail_image_network: ^1.2.0
  go_router_builder: ^2.7.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:
  generate: true

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

  assets:
    - assets/images/
    - assets/html/fr/
    - assets/html/en/

  shaders:
    - assets/shaders/devxpress-logo.frag

flavorizr:
  app:
    android:
      flavorDimensions: "app"
    ios:
      buildConfiguration:
        debug: "Debug"
        profile: "Profile"
        release: "Release"
  flavors:
    examples:
      app:
        name: "Inspectogo Examples"
      android:
        applicationId: "com.inspectogo.app.examples"
      ios:
       bundleId: "com.inspectogo.app.demo"
    demo:
      app:
        name: "Inspectogo Demo"
      android:
        applicationId: "com.inspectogo.app.demo"
      ios:
        bundleId: "com.inspectogo.app.demo"
        firebase:
          config: "ios/Runner/demo/GoogleService-Info.plist"
      firebase:
        config:
          ios: "ios/Runner/demo/GoogleService-Info.plist"
          android: "android/app/src/demo/google-services.json"
    prod:
      app:
        name: "Inspectogo"
      android:
        applicationId: "com.inspectogo.app"
      ios:
        bundleId: "com.inspectogo.app"
        firebase:
          config: "ios/Runner/prod/GoogleService-Info.plist"
      firebase:
        config:
          ios: "ios/Runner/prod/GoogleService-Info.plist"
          android: "android/app/src/prod/google-services.json"
```

</details>


### Steps to reproduce

Log getDownloadsDirectory() path result on an android emulator or ios emulator

### Expected results

On Android emulator, should return ```/storage/emulated/0/Download```

On IOS emulator, should return ```/Users/{user}/Library/Developer/CoreSimulator/Devices/{device_uid}/data/Containers/Data/Application/{app_uid}/Documents```

### Actual results

On Android emulator, it instead returns ```"/storage/emulated/0/Android/data/{package_name}/files/downloads"```, which doesn't lead to the public downloads folder.

On IOS emulator, it instead returns ``````/Users/{user}/Library/Developer/CoreSimulator/Devices/{device_uid}/data/Containers/Data/Application/{app_uid}/Downloads``````

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:downloadsfolder/downloadsfolder.dart' show getDownloadDirectory;
import 'package:path_provider/path_provider.dart' as pathprovider;

Future(() async {
    final downloadsDir = await getDownloadDirectory();
    final errorDir = await pathprovider.getDownloadsDirectory();

    print('downloadsfolder package: ${downloadsDir.path}');
    print('path_provider package: ${errorDir!.path}');
});
```

</details>


### Screenshots or Videos

_No response_

### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [Version 10.0.22631.4169], locale en-CA)
    • Flutter version 3.24.3 on channel stable at W:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (7 days ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at W:\Android
    • Platform android-35, build-tools 34.0.0
    • ANDROID_HOME = W:\Android
    • Java binary at: W:\Android\AndroidStudio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.5)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.10.35122.118
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2023.1)
    • Android Studio at W:\Android\AndroidStudio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.93.1)
    • VS Code at C:\Users\alexa\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.94.0

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22631.4169]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 128.0.6613.138
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 128.0.2739.42

[√] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>