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

Storage access issue resolved for all android versions (Including Android 10 and 11 +) #1007

Merged
merged 40 commits into from Nov 19, 2021

Conversation

codegsaini
Copy link
Contributor

@codegsaini codegsaini commented May 20, 2021

Since this app can be considered as Document Management app . It comes under the permitted category to ask new special MANAGE_EXTERNAL_STORAGE permission.

What this special permission do?

  • In simple words, This permission allows app to opt out of scoped storage permanently but android team will be checking regularly if the app should ask this permission or not.
  • This permission is available for android 11 and above so to opt out of scoped storage in android 10/Q, there is a flag in manifest file requestLegacyExternalStorage must be true.

Fixes

Tested on

  • Redmi 6A (API 28) [Physical Device]
  • Pixel 2 (API 29) [Android Emulator]
  • Pixel 2 (API 30) [Android Emulator]

codegsaini and others added 30 commits March 22, 2021 02:44
area:build.gradle
-> Gradle version updated

area:gradle.properties
->replaced android.enableR8=true to android.enabledD8=true

area:gradle\wrapper\gradle-wrapper.properties
->Updated gradle version
->Changed the UI design of navigation drawer
->Changed Navigation Icon
The storage permission was removed by mistake in commit a5b916a and now it is implemented again.
@codegsaini codegsaini changed the base branch from master to PDFOpen September 3, 2021 10:38
@codegsaini codegsaini changed the base branch from PDFOpen to master September 3, 2021 10:38
@Ravipatel401
Copy link

@codegsaini is the issue resolved?

@codegsaini
Copy link
Contributor Author

codegsaini commented Sep 3, 2021

@codegsaini is the issue resolved?

Ravi, before everything, I was resolving some issues with this PR raised by Swati (above commented).

As I have resolved these issues which she raised, Now I am already working on the issue you mentioned. Please be patient, I have to review whole project to regain thinking of it, because I was completely off from this for two and half months. It may take a bit to enter into mainstream. Hope you understood. :)

I'm also curious to resolve your mentioned issue as soon as possible.

@Ravipatel401
Copy link

@codegsaini There's no hurry bro. take your time, 👍

@codegsaini
Copy link
Contributor Author

After trying several times to detect the exact cause (exact line of code) of issue found in (Create Pdf, Add Password, Merge Pdf, Add text, etc) under Android 11, I came to the conclusion that for all of these issues, there is a single code causing the problem and which is -

FileOutputStream("path_of_selected_file")

This method throwing FileNotFoundException with the message "open failed: EPERM (Operation not permitted)" or "open failed: EACCES (Permission denied)" in Android 11.

This exception means that the app don't have permission of the directory chosen through ACTION_OPEN_DOCUMENT_TREE to save the file in it.
But the confusion is that according to ACTION_OPEN_DOCUMENT_TREE documentation the app should have the permission to read and write at this directory.

I'm trying to find the reason for this contrary behaviour related to permission of directory selected by ACTION_OPEN_DOCUMENT_TREE.

I shared this information so that you can also do some research. By the way, I'm still working to find the cause of this behaviour and how to resolve it.

@codegsaini
Copy link
Contributor Author

Resolved the issue of FileOutputStream("FILE_PATH"), Now trying to resolve some other issues which came out in the consequence. Hoping to resolve the issue #1003 soon.

@codegsaini
Copy link
Contributor Author

codegsaini commented Sep 29, 2021

Initial problems

Problem 1 - Unable to read file selected from anywhere to perform any action ( Merge with other file, etc.)
Problem 2 - Unable to write new file in directory provided by ACTION_OPEN_DOCUMENT_TREE

Problem 2 fixed

Problem 1 not fixed

  • Classes like PdfReader("PDF_FILE_PATH") and FileReader("FILE_PATH") throwing exception 'path/of/file/name.pdf not found as file or resource'.
  • So as per my concern, it means that app don't have read permission to read those selected file. Thats why, these (above mentioned) classes are unable to read selected files.

Still working to figure this out...

@codegsaini
Copy link
Contributor Author

codegsaini commented Oct 7, 2021

Issue reference : #1003 #1022 #1028 #1029 are considered to be resolved with this PR. Working on it...

- Using MANAGE_EXTRNAL_STORAGE permission app can access storage as it was allowed before scoped storage policy
- App fall in the category of Document management app, that's why android team will be able to approve this special permission (after providing full explanation of its need)
File changed - PermissionsUtils.java and strings.xml
File changed - MainActivity.java and strings.xml
@codegsaini
Copy link
Contributor Author

codegsaini commented Oct 21, 2021

@Swati4star As per this guidline, at the time of updating app in google play console you will need to provide proper reason why Storage Access Framework is not sufficient for your app, because app is asking special permission (MANAGE_EXTERNAL_STORAGE).

As per my concern the reason you should provide is -

----------YOU CAN COPY PASTE BELOW DESCRIPTION---------------


This app requires MANAGE_ExTERNAL_STORAGE permission for following reasons -

• Document Management App (Introduction)
This app help in managing different type of documents viz. PDF files, Excel sheets, Text Files, etc. Including feature such as Document conversion from one format to other, Adding passwod, Converting Image to PDF files, Converting text files to PDF files, etc.

• Document Conversion (Need broad access of shared storage)
To convert document, app should allow user to pick document present anywhere in shared storage. This can't be done using SAF as it only give access to specific directory URI.

• Preserve History of Converted Document (Need broad access of shared storage)
To save history of every successfully converted document, app should be able to access the path of saved document. The app can save documents at different directory based on the format (viz. PDF, Excel, Text). So, history will contain different paths. This also can't be done with SAF.


----------YOU CAN COPY PASTE ABOVE DESCRIPTION---------------

@codegsaini codegsaini changed the title Scoped storage model implemented to satisfy android's new storage policy. Storage access issue resolved for all android versions (Including Android 10 and 11 +) Oct 21, 2021
@codegsaini
Copy link
Contributor Author

@Swati4star This PR is complete, Please consider reviewing it.

@Ravipatel401
Copy link

@codegsaini Hello,
It seems you have resolved all issues. Can I test it now?

@codegsaini
Copy link
Contributor Author

@codegsaini Hello, It seems you have resolved all issues. Can I test it now?

@Ravipatel401 Yes mentioned issues are resolved. You can test to confirm.

@codegsaini
Copy link
Contributor Author

@Ravipatel401 Is your issue #1003 solved? Please confirm!

@Ravipatel401
Copy link

Ravipatel401 commented Nov 3, 2021 via email

@codegsaini
Copy link
Contributor Author

@Swati4star Once this PR is clear. I would like to work further on this Repo. Please consider reviewing this PR.

@codegsaini
Copy link
Contributor Author

@Ravipatel401 Your review is important as well. Try regenerating issue #1003 . If it is solved then consider submitting your review.

@Swati4star
Copy link
Owner

@codegsaini Sorry for the delay. I was occupied with some work here.

@Swati4star Swati4star merged commit be08fcf into Swati4star:master Nov 19, 2021
@codegsaini
Copy link
Contributor Author

codegsaini commented Nov 19, 2021

@codegsaini Sorry for the delay. I was occupied with some work here.

@Swati4star Not a problem :) Good to hear that you have finished that work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants