Skip to content

Check Storage Permission Before Upload #15240

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

Merged
merged 15 commits into from
Aug 15, 2025

Conversation

alperozturk96
Copy link
Collaborator

@alperozturk96 alperozturk96 commented Jul 23, 2025

  • Tests written, or not not needed

Issue

Previously granted MANAGE_EXTERNAL_STORAGE or Only Media Access permission can be revoked if the app hasn't been used for a few months (e.g. if user not opens the app just using the app for auto upload) or after a system upgrade.

Screenshot 2025-07-23 at 13 35 00

Some other OS implementations may handle this differently, so we need to cover this edge case as well.
Also, it seems that some users have experienced this issue before and resolved it by re-granting the permission.

#15218 (comment)
#15039 (comment)

Changes

Image 1

Notes

PermissionUtil.requestExternalStoragePermission cannot be used to display the same permission dialog that appears at the beginning of the application, as it depends on AppCompatActivity. Therefore, we inform the user and provide them with the option to choose between the standard app permission or full file access.

@ZetaTom

Additionally, instead of handling the error after a failed upload, we proactively check for the necessary permissions before initiating the upload. This approach prevents unnecessary calls and simplifies the logic flow.

All files access action

Image 1

App permissions action

We cannot redirect to the directly to the storage permission page. There is no intent action for that.

Image 2

@alperozturk96 alperozturk96 added 3. to review ux-enhancement Improvements that refine user interactions, accessibility, or overall usability labels Jul 23, 2025
@alperozturk96 alperozturk96 force-pushed the check-manage-all-files-permission branch from 38a609b to 92df4ea Compare July 29, 2025 11:50
ZetaTom

This comment was marked as resolved.

@alperozturk96

This comment was marked as resolved.

@alperozturk96
Copy link
Collaborator Author

alperozturk96 commented Aug 7, 2025

Looks like full file access permission fixed the issue, please read the issue and comments.

#15039 (comment)
#15039 (comment)
#15039 (comment)
#15039 (comment)
#15039 (comment)

@alperozturk96 alperozturk96 force-pushed the check-manage-all-files-permission branch from 92df4ea to d446815 Compare August 7, 2025 11:11
@alperozturk96 alperozturk96 changed the title Check Storage Permission Before Auto Upload Check Storage Permission Before Upload Aug 7, 2025
@alperozturk96 alperozturk96 force-pushed the check-manage-all-files-permission branch from d83b4f9 to b7be9b8 Compare August 8, 2025 07:16
@alperozturk96
Copy link
Collaborator Author

/backport to stable-3.32

if (!localFile.canRead()) {
Log_OC.e(TAG, "Upload cancelled for " + getStoragePath() + ": file is not readable or inaccessible.");
UploadFileOperationExtensionsKt.showStoragePermissionNotification(this);
missingPermissionThrown.set(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is set for one operation, but what if we have multiple runs?
E.g. user uploads 5x, one after the other?

Then it is always being reset and the user will receive 5x the "error" message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's using same notification id also I added check for active notification thus it will only display one notification.

Screen.Recording.2025-08-14.at.09.08.55.mov

Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
… "missingPermissionThrown" in one thread may not yield the value of the most recent write from another thread

Signed-off-by: alperozturk <alper_ozturk@proton.me>
@alperozturk96 alperozturk96 force-pushed the check-manage-all-files-permission branch from f79c579 to 95375f8 Compare August 14, 2025 06:58
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Copy link

Codacy

Lint

TypemasterPR
Warnings4848
Errors1111

SpotBugs

CategoryBaseNew
Bad practice6060
Correctness6262
Dodgy code296296
Experimental11
Internationalization77
Malicious code vulnerability22
Multithreaded correctness3535
Performance5050
Security1818
Total531531

Copy link

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/15240.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

.addAction(appPermissionsAction)
.setAutoCancel(true)

notificationManager.notify(MISSING_FILE_PERMISSION_NOTIFICATION_ID, notificationBuilder.build())

Check failure

Code scanning / CodeQL

Use of implicit PendingIntents High

An implicit Intent is created
and sent to an unspecified third party through a PendingIntent.

Copilot Autofix

AI 3 days ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Copy link
Collaborator Author

@alperozturk96 alperozturk96 Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/nextcloud/android/security/code-scanning/246

Screenshot 2025-08-14 at 11 08 46

Already immutable and has specific action.

private fun getActionPendingIntent(context: Context, actionType: UploadFileBroadcastReceiverActions): PendingIntent {
    val intent = Intent(context, UploadFileBroadcastReceiver::class.java).apply {
        action = "com.owncloud.android.ACTION_UPLOAD_FILE_PERMISSION"
        putExtra(UploadFileBroadcastReceiver.ACTION_TYPE, actionType)
    }

    return PendingIntent.getBroadcast(
        context,
        actionType.ordinal,
        intent,
        PendingIntent.FLAG_IMMUTABLE
    )
}

@tobiasKaminsky tobiasKaminsky merged commit f75e8f1 into master Aug 15, 2025
17 of 20 checks passed
@tobiasKaminsky tobiasKaminsky deleted the check-manage-all-files-permission branch August 15, 2025 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review ux-enhancement Improvements that refine user interactions, accessibility, or overall usability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android application should detect when "all files access" is not "allowed"
3 participants