fix: replace hardcoded android storage path with path_provider#1039
fix: replace hardcoded android storage path with path_provider#1039vibhutomer wants to merge 1 commit into
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe ChangesAndroid Scoped Storage Path Resolution
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/utils/file_storage.dart (1)
17-21: ⚡ Quick winRemove unnecessary
Permission.storagerequest for app-specific external directory.Since
getExternalStorageDirectory()(line 31) returns the app-specific external directory (Android/data/<package>/files), the runtimePermission.storagerequest at lines 17-21 is unnecessary on Android 10–14. Modern scoped storage allows your app to read/write its own app-specific files without broad storage permissions.Suggested removal
static Future<String> getExternalDocumentPath() async { - // To check whether permission is given for this app or not. - var status = await Permission.storage.status; - if (!status.isGranted) { - // If not we will ask for permission first - await Permission.storage.request(); - } Directory directory = Directory("");🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/utils/file_storage.dart` around lines 17 - 21, Remove the unnecessary runtime storage permission check/request: delete the Permission.storage.status + Permission.storage.request() block (references: Permission.storage) since you are using getExternalStorageDirectory() for app-specific external storage (getExternalStorageDirectory()). After removal, ensure code still handles platform differences (no-op on Android 10–14 scoped storage) and remove any now-unused imports (e.g., permission_handler/Permission) if applicable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/utils/file_storage.dart`:
- Around line 17-21: Remove the unnecessary runtime storage permission
check/request: delete the Permission.storage.status +
Permission.storage.request() block (references: Permission.storage) since you
are using getExternalStorageDirectory() for app-specific external storage
(getExternalStorageDirectory()). After removal, ensure code still handles
platform differences (no-op on Android 10–14 scoped storage) and remove any
now-unused imports (e.g., permission_handler/Permission) if applicable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: bb3537b6-73bd-450a-b3d1-c75ef1ee52d8
📒 Files selected for processing (1)
lib/utils/file_storage.dart
Signed-off-by: vibhutomer <vibhutomer25@gmail.com>
df39ff8 to
a006063
Compare
Description
This PR resolves a critical issue where the application crashes or silently fails on modern Android devices (API 29+) due to Scoped Storage restrictions.
Previously, the app attempted to write directly to a hardcoded
/storage/emulated/0/Downloadpath. On Android 10 and above, this throws aFileSystemException(Permission Denied) unless the app possesses legacy flags or broadMANAGE_EXTERNAL_STORAGEpermissions.Changes Made
/storage/emulated/0/Downloadpath in theFileStorage.getExternalDocumentPath()method.getExternalStorageDirectory()from thepath_providerpackage to dynamically fetch the correct, OS-approved external storage path.getApplicationDocumentsDirectory()in the event that external storage resolves tonull(which can occur on specific custom ROMs or locked enterprise devices).Related Issue
Closes #1038
Type of Change
Checklist
Summary by CodeRabbit