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

Can't choose destination folder for backup [ Play Store Review ] #9

Closed
keshav-space opened this issue Sep 16, 2022 · 7 comments · Fixed by #37
Closed

Can't choose destination folder for backup [ Play Store Review ] #9

keshav-space opened this issue Sep 16, 2022 · 7 comments · Fixed by #37
Labels
Enhancement Enhance existing feature Feedback: Google Play Store Wontfix This will not be worked on
Milestone

Comments

@keshav-space
Copy link
Owner

No description provided.

@keshav-space keshav-space added this to the safe notes 2.0 milestone Sep 16, 2022
keshav-space added a commit that referenced this issue Oct 8, 2022
- fixes #9

Signed-off-by: Keshav Priyadarshi <git@keshav.space>
@thornySoap
Copy link

I still can't on 2.1.0

@keshav-space
Copy link
Owner Author

Android is migrating towards more privacy-friendly Android APIs.

Below is a brief summary of how that impacts storage access

Android >= 11 ( New )

  1. No Storage Permission : Apps can create new files in the download folder without permission
  2. Media and File Permission : Apps can read media and files but can't modify or create files except in app-specific storage space [ moreover, the android will never expose the actual file location rather a cached file location is shared with apps]
  3. All File Permission : When MANAGE_EXTERNAL_STORAGE permission is granted, app can read/modify/create/delete files in external shared storage.

Android < 11 ( Old )

  1. No Storage Permission : App can not access any part of external shared storage
  2. File Permission : App can read, modify, create and delete files in external shared storage.

How Safe Notes will handle the storage access?

These access control will become more stringent in the coming year, something similar to iOS, and that's good for user privacy. Bottom line is that apps should not use All file Permission unless absolutely needed.
Safe Notes will not use All File Permission, this means that users will not be able to choose the location of their choice for backup. Backup will be made inside the Download directory within the Safe Notes folder. [See videos below ]

The new feature is tested on Android 12, 11, 10, 9, 8.1, 8.0 and 7.1

Android 12 Android 12 Android 11 Android 10
Android_12-API_32-Pixel_4.mp4
Android_12-API_31-Pixel_4.mp4
Android_11-API_30-Pixel_4.mp4
Android_10-API_29-Pixel_4.mp4
Android 9 Android 8.1 Android 8.0 Android 7.1
Android_9-API-28-Pixel-4.mp4
Android_8.1-API_27-Pixel-4.mp4
Android_8-API_26-Pixel_4.mp4
Android_7.1-API_25-Pixel_4.mp4

@keshav-space keshav-space added the Wontfix This will not be worked on label Dec 16, 2022
@thornySoap
Copy link

Thanks for the reply, I understand.

I just would like to ask why Safe Notes doesn't use this method used by most modern apps to gain access to a specific directory.

@keshav-space
Copy link
Owner Author

I just would like to ask why Safe Notes doesn't use this method used by most modern apps to gain access to a specific directory.

Safe Notes is already using this for reading import files [ user can pick the import file from anywhere while importing backup]

This permission can't be used to write/modify existing files moreover the new files can only be created in the Download directory or app-specific storage location.

To write a file at an arbitrary [user chosen] location app would require MANAGE_EXTERNAL_STORAGE permission

There is no escape from this.

@thornySoap
Copy link

I am very sorry, I linked the wrong thing. This intent FLAG_GRANT_WRITE_URI_PERMISSION should be the right one (if it's not, I really have to apologize for annoying you without having any idea myself).

You may want to have a look at this notes app:

autoExportLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
            val uri = result.data?.data
            if (result.resultCode == Activity.RESULT_OK && uri != null) {
                val output = try {
                    val cr = context.contentResolver
                    cr.takePersistableUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
                    cr.openOutputStream(uri)
                } catch (e: Exception) {
                    Log.i(TAG, "Data export failed", e)
                    null
                }
                if (output != null) {
                    viewModel.setupAutoExport(output, uri.toString())
                } else {
                    showMessage(R.string.export_fail)
                    autoExportPref.isChecked = false
                }
            }
        }

link to file

fun setupAutoExport(output: OutputStream, uri: String) {
        prefsManager.autoExportUri = uri
        viewModelScope.launch(Dispatchers.IO) {
            val jsonData = jsonManager.exportJsonData()
            try {
                output.use {
                    output.write(jsonData.toByteArray())
                }
                showMessage(R.string.export_success)

                val now = System.currentTimeMillis()
                prefsManager.lastAutoExportTime = now
                _lastAutoExport.postValue(now)
            } catch (e: Exception) {
                showMessage(R.string.export_fail)
            }
        }
    }

link to file

Here is a screen recording:

Screen_Recording_20221218-093546_Files.mp4

@keshav-space
Copy link
Owner Author

This intent FLAG_GRANT_WRITE_URI_PERMISSION should be the right one.

I see you're pointing to the Storage Access Framework and I could have used that, but the only problem I'm having is that the SAF gives you a content URI that doesn't reflect the exact location of the file on the filesystem.

Suppose user creates a backup file at a certain location, the app will receive the content URI of that file.
The app can access and modify the content of that file using content URI, but the app has no clue about where the file is exactly stored, so the app can't show the location of the backup file inside the app.
And this is a problem because, a few months down the line, user will forget where they created the backup file. (happens to me all the time, lol 😆)
Since the app can't show the exact location of the file, user will end up creating a new backup and this will go on.

For an offline app, it's paramount that the user can independently access the backup file.


if it's not, I really have to apologize for annoying you without having any idea myself

Indulgence is much appreciated and always welcome, that's the point of having this open-source. 😊



TL;DR

SAF would work only if there was some way to show the exact location of backup file like this 👇

@thornySoap
Copy link

thornySoap commented Mar 12, 2024

Hello again.
This app (https://github.com/T8RIN/ImageToolbox) allows to pick a location and it is also able to show it.
If there still is interest in working on this app, it may be worth a look.

Screen_Recording_20240312_163203_Image.Toolbox.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Enhance existing feature Feedback: Google Play Store Wontfix This will not be worked on
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants