Skip to content
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

Fixed: Kiwix cannot import ZIM files from the filesystem. #4218

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

MohitMaliFtechiz
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz commented Feb 8, 2025

Fixes #4216

  • On Android 9 (API 28) and below, getExternalFilesDirs correctly returns USB paths. However, on Android 10 (API 29) and above, it returns null for external storage like USB sticks. Previously, we appended /mnt/media_rw/ as a workaround which works in most of the devices, but this was unreliable due to varying mount paths across devices.
  • Android 11 (API 30) introduced the StorageService API, which accurately retrieves mount paths for SD cards, USB sticks, and external hard drives See. We now use this API on Android 10+ while keeping getExternalFilesDirs for Android 9 and below since it is correctly working on those devices. This ensures reliable USB and SD card path detection on modern devices. Additionally, we've added debugging logs to capture errors when opening files in the reader.
  • Displaying a proper error message with the full ZIM path when there is an issue opening the ZIM file or if the selected file is not a valid ZIM file.
  • Refactored CopyMoveFileHandlerTest to align with this change.
  • Updated the string documentation to help translators understand this update.
  • To resolve the lint error, and if the user uses the application in other languages then to avoid crashing the application, all string files have been updated. These files will be automatically updated in the latest TranslateWiki PR.
  • Refactored the deprecated method used in our test cases.

* Displaying a proper error message with the full ZIM path when there is an issue opening the ZIM file or if the selected file is not a valid ZIM file.
* Refactored `CopyMoveFileHandlerTest` to align with this change.
* Updated the documentation to help translators understand this update.
* To resolve the lint error, all string files have been updated. These files will be automatically updated in the latest TranslateWiki PR.
@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as draft February 8, 2025 11:20
Copy link

codecov bot commented Feb 8, 2025

Codecov Report

Attention: Patch coverage is 28.20513% with 28 lines in your changes missing coverage. Please review.

Project coverage is 57.35%. Comparing base (a88884a) to head (452fc10).

Files with missing lines Patch % Lines
...rg/kiwix/kiwixmobile/core/utils/files/FileUtils.kt 43.75% 6 Missing and 3 partials ⚠️
...le/nav/destination/library/LocalLibraryFragment.kt 12.50% 7 Missing ⚠️
...org/kiwix/kiwixmobile/core/reader/ZimFileReader.kt 0.00% 4 Missing ⚠️
.../kiwix/kiwixmobile/core/main/CoreReaderFragment.kt 50.00% 3 Missing ⚠️
...r/fileselectView/effects/OpenFileWithNavigation.kt 0.00% 2 Missing ⚠️
...ile/nav/destination/library/CopyMoveFileHandler.kt 0.00% 1 Missing ⚠️
...bile/nav/destination/reader/KiwixReaderFragment.kt 0.00% 1 Missing ⚠️
...a/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (28.20%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4218      +/-   ##
============================================
+ Coverage     57.18%   57.35%   +0.17%     
- Complexity     1584     1587       +3     
============================================
  Files           316      316              
  Lines         13746    13765      +19     
  Branches       1722     1725       +3     
============================================
+ Hits           7860     7895      +35     
+ Misses         4692     4663      -29     
- Partials       1194     1207      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…d Above.

* The getExternalFilesDirs method only returns the USB path for devices running Android 9 (API 28) and below.
* On Android 10 (API 29) and above, this method returns null when accessing external storage like USB sticks.
* To work around this limitation, we previously appended the /mnt/media_rw/ path manually. While this worked in most cases, it was unreliable across different devices, as the mounted path could vary.
* To ensure accurate retrieval of external storage paths, we have switched to the StorageService API.
* This API, introduced in Android 11 (API 30), directly provides the actual mount paths for all external storage devices, including SD cards, USB sticks, and external hard drives.
* For Android 9 and below, getExternalFilesDirs continues to work as expected, so we use it where applicable.
* This improvement ensures that USB and SD card paths are retrieved correctly on modern Android devices.
* Added debugging logs to capture errors when opening a file in the reader.
* These logs will help us diagnose issues when users share a diagnostic report.
@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review February 11, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kiwix cannot import ZIM files from the filesystem
2 participants