Skip to content

Commit

Permalink
Improve logic for revoking grants when moving and removing documents
Browse files Browse the repository at this point in the history
The DocumentsProvider base class already has a method for doing this.
The previous revokeGrants() method did not properly revoke grants for
tree URIs. This also fixes grants being revoked twice when a client app
calls deleteDocument().

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Jan 18, 2025
1 parent 9556d2c commit b21d1b7
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions app/src/main/java/com/chiller3/rsaf/rclone/RcloneProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,6 @@ class RcloneProvider : DocumentsProvider(), SharedPreferences.OnSharedPreference
context!!.contentResolver.notifyChange(uri, null)
}

private fun revokeGrants(documentId: String) {
val uri = DocumentsContract.buildDocumentUri(BuildConfig.DOCUMENTS_AUTHORITY, documentId)
context!!.revokeUriPermission(
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION and Intent.FLAG_GRANT_WRITE_URI_PERMISSION,
)
}

override fun onCreate(): Boolean {
val context = context!!

Expand Down Expand Up @@ -764,8 +756,6 @@ class RcloneProvider : DocumentsProvider(), SharedPreferences.OnSharedPreference
throw error.toException("rbDocRemove")
}

revokeGrants(documentId)

val (parent, _) = splitPath(documentId)
notifyChildrenChanged(parent)
}
Expand All @@ -779,6 +769,7 @@ class RcloneProvider : DocumentsProvider(), SharedPreferences.OnSharedPreference
}

deleteDocument(documentId)
revokeDocumentPermission(documentId)
}

/**
Expand Down Expand Up @@ -842,7 +833,7 @@ class RcloneProvider : DocumentsProvider(), SharedPreferences.OnSharedPreference
waitUntilUploadsDone(sourceDocumentId)

return copyOrMove(sourceDocumentId, targetParentDocumentId, false).also {
revokeGrants(sourceDocumentId)
revokeDocumentPermission(sourceDocumentId)
}
}

Expand Down

0 comments on commit b21d1b7

Please sign in to comment.