Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
fix(path_provider_tvos): surface the tvOS sandbox write restrictions#6
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 101 additions & 5 deletions
106 packages/path_provider_tvos/test/path_provider_tvos_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,111 @@ | ||
| // Copyright 2026 The FlutterTV Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
| // | ||
| // Generated on 2026-05-18 by `flutter-tvos plugin port`. | ||
| // Source plugin: path_provider_foundation | ||
| import 'dart:io' show Directory; | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:path_provider/path_provider.dart'; | ||
| import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; | ||
| import 'package:path_provider_tvos/path_provider_tvos.dart'; | ||
| void main() { | ||
| test('package compiles and exposes PathProviderTvos', () { | ||
| expect(PathProviderTvos, isNotNull); | ||
| TestWidgetsFlutterBinding.ensureInitialized(); | ||
| const channel = MethodChannel('plugins.flutter.io/path_provider'); | ||
| final messenger = | ||
| TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger; | ||
| late List<String> log; | ||
| /// Answers the native side with [responses], recording every method name. | ||
| /// A missing key answers null, which is what the tvOS plugin returns for a | ||
| /// directory the sandbox will not give us. | ||
| void mockNative(Map<String, String?> responses) { | ||
| messenger.setMockMethodCallHandler(channel, (MethodCall call) async { | ||
| log.add(call.method); | ||
| return responses[call.method]; | ||
| }); | ||
| } | ||
| setUp(() { | ||
| log = <String>[]; | ||
| PathProviderTvos.registerWith(); | ||
| }); | ||
| tearDown(() => messenger.setMockMethodCallHandler(channel, null)); | ||
| test('registerWith installs itself as the platform implementation', () { | ||
| expect(PathProviderPlatform.instance, isA<PathProviderTvos>()); | ||
| }); | ||
| group('method-channel contract', () { | ||
| test('each getter invokes the matching native method', () async { | ||
| mockNative(<String, String?>{ | ||
| 'getTemporaryDirectory': '/tmp', | ||
| 'getApplicationSupportDirectory': '/support', | ||
| 'getLibraryDirectory': '/library', | ||
| 'getApplicationDocumentsDirectory': '/documents', | ||
| 'getApplicationCacheDirectory': '/caches', | ||
| }); | ||
| final tvos = PathProviderTvos(); | ||
| expect(await tvos.getTemporaryPath(), '/tmp'); | ||
| expect(await tvos.getApplicationSupportPath(), '/support'); | ||
| expect(await tvos.getLibraryPath(), '/library'); | ||
| expect(await tvos.getApplicationDocumentsPath(), '/documents'); | ||
| expect(await tvos.getApplicationCachePath(), '/caches'); | ||
| expect(log, <String>[ | ||
| 'getTemporaryDirectory', | ||
| 'getApplicationSupportDirectory', | ||
| 'getLibraryDirectory', | ||
| 'getApplicationDocumentsDirectory', | ||
| 'getApplicationCacheDirectory', | ||
| ]); | ||
| }); | ||
| test('downloads resolves to null without touching the channel', () async { | ||
| mockNative(<String, String?>{}); | ||
| expect(await PathProviderTvos().getDownloadsPath(), isNull); | ||
| expect(log, isEmpty); | ||
| }); | ||
| test('Android-only APIs throw UnsupportedError', () async { | ||
| final tvos = PathProviderTvos(); | ||
| expect(tvos.getExternalStoragePath, throwsUnsupportedError); | ||
| expect(tvos.getExternalCachePaths, throwsUnsupportedError); | ||
| expect(tvos.getExternalStoragePaths, throwsUnsupportedError); | ||
| }); | ||
| }); | ||
| group('directories the tvOS sandbox refuses', () { | ||
| // The native side returns nil for Application Support because tvOS will not | ||
| // let us create it (measured on a physical Apple TV). Returning a path that | ||
| // does not exist is what this replaced: the caller used to find out only at | ||
| // its first write, as an errno naming nothing. | ||
| test('a null Application Support surfaces as an exception, not a path', | ||
| () async { | ||
| mockNative(<String, String?>{'getApplicationSupportDirectory': null}); | ||
| expect(await PathProviderTvos().getApplicationSupportPath(), isNull); | ||
| await expectLater( | ||
| getApplicationSupportDirectory(), | ||
| throwsA(isA<MissingPlatformDirectoryException>()), | ||
| ); | ||
| }); | ||
| test('Documents is still returned — it exists and reads work', () async { | ||
| mockNative(<String, String?>{ | ||
| 'getApplicationDocumentsDirectory': '/documents', | ||
| }); | ||
| // Deliberately NOT null: nil'ing this would break iOS parity and any app | ||
| // reading pre-populated data. Writes fail on device; the plugin logs a | ||
| // one-time warning and the README says so. | ||
| expect(await getApplicationDocumentsDirectory(), | ||
| isA<Directory>().having((Directory d) => d.path, 'path', '/documents')); | ||
| }); | ||
| }); | ||
| } |
67 changes: 56 additions & 11 deletions
67 packages/path_provider_tvos/tvos/Classes/PathProviderPlugin.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth deciding explicitly — the PR title says "stop returning directories tvOS cannot write", but
Documents(writes denied per your own table) is still returned here. So the most common path_provider usage —getApplicationDocumentsDirectory()+ write a file — still fails silently at the first write with the same unhelpful errno this PR fixes for App Support. It's only mitigated by docs ("usegetApplicationCacheDirectoryinstead").Keeping the path is defensible:
Documentsexists and reads work (some apps read pre-populated data), nil'ing it would break iOS parity and readers, and writability can depend on entitlements — so returning it lets apps that can write still work, whereas App Support genuinely can't be created. That asymmetry is reasonable.But the silent-write-failure the PR sets out to kill still lives for the more common directory. Cheap way to make it loud without breaking parity or readers: a one-time
NSLogwhengetApplicationDocumentsDirectoryis called on tvOS ("Documents is not writable on a real Apple TV; use the cache directory"). Either add that, or soften the title to reflect that Documents is a docs-only mitigation. Your call — not a blocker.