diff options
author | Sergei Kozelko <KozelkoS@yandex.ru> | 2022-10-15 11:09:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-15 11:09:09 +0000 |
commit | 297c20f5d34a49816fc2e954c156d0d3c49f19c9 (patch) | |
tree | 62b4a0a4e2da28abc9b5b0a5b1f99aedfb1ee805 | |
parent | 48dcf2293cabf19578a35269e890125838efa8c2 (diff) | |
download | infinity-for-reddit-297c20f5d34a49816fc2e954c156d0d3c49f19c9.tar infinity-for-reddit-297c20f5d34a49816fc2e954c156d0d3c49f19c9.tar.gz infinity-for-reddit-297c20f5d34a49816fc2e954c156d0d3c49f19c9.tar.bz2 infinity-for-reddit-297c20f5d34a49816fc2e954c156d0d3c49f19c9.tar.lz infinity-for-reddit-297c20f5d34a49816fc2e954c156d0d3c49f19c9.tar.xz infinity-for-reddit-297c20f5d34a49816fc2e954c156d0d3c49f19c9.tar.zst infinity-for-reddit-297c20f5d34a49816fc2e954c156d0d3c49f19c9.zip |
Fix duplicate download folders by persisting read permission (#1164)
* Persist read permission
ACTION_OPEN_DOCUMENT_TREE grants both read and write permissions, but they are
granted only until device reboot unless app persists them.
Once read permission is lost, app cannot check if folders exist in DownloadMediaService.
But it can still create new folders because it has write permission. This results
in duplicate folders.
* Remove unnecessary FLAG_GRANT_WRITE_URI_PERMISSION
This flag is ignored when used with ACTION_OPEN_DOCUMENT_TREE
Diffstat (limited to '')
2 files changed, 8 insertions, 9 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java index 359a95ff..9f9534fb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java @@ -276,7 +276,6 @@ public class AdvancedPreferenceFragment extends CustomFontPreferenceFragmentComp if (backupSettingsPreference != null) { backupSettingsPreference.setOnPreferenceClickListener(preference -> { Intent intent = new Intent(ACTION_OPEN_DOCUMENT_TREE); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivityForResult(intent, SELECT_BACKUP_SETTINGS_DIRECTORY_REQUEST_CODE); return true; }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java index 8c717c5c..d036d8a6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java @@ -50,7 +50,6 @@ public class DownloadLocationPreferenceFragment extends CustomFontPreferenceFrag nsfwDownloadLocationPreference.setOnPreferenceClickListener(preference -> { Intent intent = new Intent(ACTION_OPEN_DOCUMENT_TREE); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivityForResult(intent, NSFW_DOWNLOAD_LOCATION_REQUEST_CODE); return true; }); @@ -63,7 +62,6 @@ public class DownloadLocationPreferenceFragment extends CustomFontPreferenceFrag imageDownloadLocationPreference.setOnPreferenceClickListener(preference -> { Intent intent = new Intent(ACTION_OPEN_DOCUMENT_TREE); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivityForResult(intent, IMAGE_DOWNLOAD_LOCATION_REQUEST_CODE); return true; }); @@ -77,7 +75,6 @@ public class DownloadLocationPreferenceFragment extends CustomFontPreferenceFrag gifDownloadLocationPreference.setOnPreferenceClickListener(preference -> { Intent intent = new Intent(ACTION_OPEN_DOCUMENT_TREE); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivityForResult(intent, GIF_DOWNLOAD_LOCATION_REQUEST_CODE); return true; }); @@ -91,7 +88,6 @@ public class DownloadLocationPreferenceFragment extends CustomFontPreferenceFrag videoDownloadLocationPreference.setOnPreferenceClickListener(preference -> { Intent intent = new Intent(ACTION_OPEN_DOCUMENT_TREE); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivityForResult(intent, VIDEO_DOWNLOAD_LOCATION_REQUEST_CODE); return true; }); @@ -103,25 +99,29 @@ public class DownloadLocationPreferenceFragment extends CustomFontPreferenceFrag super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK && data != null && data.getData() != null) { if (requestCode == IMAGE_DOWNLOAD_LOCATION_REQUEST_CODE) { - activity.getContentResolver().takePersistableUriPermission(data.getData(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + activity.getContentResolver().takePersistableUriPermission(data.getData(), + Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); sharedPreferences.edit().putString(SharedPreferencesUtils.IMAGE_DOWNLOAD_LOCATION, data.getDataString()).apply(); if (imageDownloadLocationPreference != null) { imageDownloadLocationPreference.setSummary(data.getDataString()); } } else if (requestCode == GIF_DOWNLOAD_LOCATION_REQUEST_CODE) { - activity.getContentResolver().takePersistableUriPermission(data.getData(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + activity.getContentResolver().takePersistableUriPermission(data.getData(), + Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); sharedPreferences.edit().putString(SharedPreferencesUtils.GIF_DOWNLOAD_LOCATION, data.getDataString()).apply(); if (gifDownloadLocationPreference != null) { gifDownloadLocationPreference.setSummary(data.getDataString()); } } else if (requestCode == VIDEO_DOWNLOAD_LOCATION_REQUEST_CODE) { - activity.getContentResolver().takePersistableUriPermission(data.getData(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + activity.getContentResolver().takePersistableUriPermission(data.getData(), + Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); sharedPreferences.edit().putString(SharedPreferencesUtils.VIDEO_DOWNLOAD_LOCATION, data.getDataString()).apply(); if (videoDownloadLocationPreference != null) { videoDownloadLocationPreference.setSummary(data.getDataString()); } } else if (requestCode == NSFW_DOWNLOAD_LOCATION_REQUEST_CODE) { - activity.getContentResolver().takePersistableUriPermission(data.getData(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + activity.getContentResolver().takePersistableUriPermission(data.getData(), + Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); sharedPreferences.edit().putString(SharedPreferencesUtils.NSFW_DOWNLOAD_LOCATION, data.getDataString()).apply(); if (nsfwDownloadLocationPreference != null) { nsfwDownloadLocationPreference.setSummary(data.getDataString()); |