Skip to content

Commit

Permalink
Fixed, can not open ZIM files from phone storage via the file picker …
Browse files Browse the repository at this point in the history
…in Android 13.

* Improved the permission request scenario for 'MANAGE_EXTERNAL_STORAGE' in Android 13. In the non-play store variant, we were not prompting users to grant this permission, and they were unaware that it was necessary to access the ZIM files in their storage. To resolve this issue, we now request this permission.
  • Loading branch information
MohitMaliDeveloper committed Oct 31, 2023
1 parent 89acaf1 commit 528ca4d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/detekt_baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ID>MagicNumber:ZimManageViewModel.kt$ZimManageViewModel$5</ID>
<ID>MagicNumber:ZimManageViewModel.kt$ZimManageViewModel$500</ID>
<ID>MagicNumber:LocalFileTransferFragment.kt$LocalFileTransferFragment$500</ID>
<ID>NestedBlockDepth:LocalLibraryFragment.kt$LocalLibraryFragment$private fun checkPermissions()</ID>
<ID>NestedBlockDepth:LocalLibraryFragment.kt$LocalLibraryFragment$private fun checkManageExternalStoragePermission()</ID>
<ID>NestedBlockDepth:PeerGroupHandshake.kt$PeerGroupHandshake$private fun readHandshakeAndExchangeMetaData(): InetAddress?</ID>
<ID>NestedBlockDepth:ReceiverHandShake.kt$ReceiverHandShake$override fun exchangeFileTransferMetadata(inputStream: InputStream, outputStream: OutputStream)</ID>
<ID>PackageNaming:AvailableSpaceCalculator.kt$package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,33 +430,37 @@ class LocalLibraryFragment : BaseFragment() {
)
)
} else {
requestFileSystemCheck()
checkManageExternalStoragePermission()

Check warning on line 433 in app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt#L433

Added line #L433 was not covered by tests
}
} else {
if (sharedPreferenceUtil.isPlayStoreBuild) {
requestFileSystemCheck()
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
// We already have permission!!
requestFileSystemCheck()
} else {
if (sharedPreferenceUtil.manageExternalFilesPermissionDialog) {
// We should only ask for first time, If the users wants to revoke settings
// then they can directly toggle this feature from settings screen
sharedPreferenceUtil.manageExternalFilesPermissionDialog = false
// Show Dialog and Go to settings to give permission
dialogShower.show(
KiwixDialog.ManageExternalFilesPermissionDialog,
{
this.activity?.let(FragmentActivity::navigateToSettings)
}
)
}
}
} else {
checkManageExternalStoragePermission()
}
}

private fun checkManageExternalStoragePermission() {
if (sharedPreferenceUtil.isPlayStoreBuild) {
requestFileSystemCheck()

Check warning on line 442 in app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt#L442

Added line #L442 was not covered by tests
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
// We already have permission!!
requestFileSystemCheck()
} else {
if (sharedPreferenceUtil.manageExternalFilesPermissionDialog) {
// We should only ask for first time, If the users wants to revoke settings
// then they can directly toggle this feature from settings screen
sharedPreferenceUtil.manageExternalFilesPermissionDialog = false

Check warning on line 452 in app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt#L452

Added line #L452 was not covered by tests
// Show Dialog and Go to settings to give permission
dialogShower.show(
KiwixDialog.ManageExternalFilesPermissionDialog,
{

Check warning on line 456 in app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt#L454-L456

Added lines #L454 - L456 were not covered by tests
this.activity?.let(FragmentActivity::navigateToSettings)
}

Check warning on line 458 in app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt#L458

Added line #L458 was not covered by tests
)
}
}
} else {
requestFileSystemCheck()
}
}
}
Expand Down

0 comments on commit 528ca4d

Please sign in to comment.