[network/kdeconnect-android] src/main/java/org/kde/kdeconnect/plugins/share: Fix SecurityException for some files sent via SendFileActivity
Manuel Mike <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 14c65432dcbaabc796af4fe449756e6adb7c0d28 by Manuel Mike.
Committed on 07/08/2026 at 13:23.
Pushed by albertvaka into branch 'master'.
Fix SecurityException for some files sent via SendFileActivity
ACTION_GET_CONTENT grants read permission on the returned URIs only for
the lifetime of the receiving activity. SendFileActivity dispatched the
actual reading (SharePlugin.sendUriList -> FilesHelper.uriToNetworkPacket
-> ContentResolver.openInputStream) to a background thread but called
finish() immediately afterwards without waiting for it, so the activity
could be torn down -- and the URI grants revoked -- before all the
selected files had been opened. Any URI opened after that point failed
with "SecurityException: ... requires ACTION_OPEN_DOCUMENT", so multi-file
sends would silently drop a subset of the selection.
finish() is now deferred until sendUriList() has returned, keeping the
activity (and its URI grants) alive for the whole synchronous read loop
while still keeping that work off the main thread.
BUG: 523973
M +14 -6 src/main/java/org/kde/kdeconnect/plugins/share/SendFileActivity.java
https://invent.kde.org/network/kdeconnect-android/-/commit/14c65432dcbaabc796af4fe449756e6adb7c0d28
diff --git a/src/main/java/org/kde/kdeconnect/plugins/share/SendFileActivity.java b/src/main/java/org/kde/kdeconnect/plugins/share/SendFileActivity.java
index 62d195bf3..a7227fb74 100644
--- a/src/main/java/org/kde/kdeconnect/plugins/share/SendFileActivity.java
+++ b/src/main/java/org/kde/kdeconnect/plugins/share/SendFileActivity.java
@@ -68,18 +68,26 @@ public class SendFileActivity extends AppCompatActivity {
if (uris.isEmpty()) {
Log.w("SendFileActivity", "No files to send?");
+ finish();
} else {
ThreadHelper.execute(() -> {
- SharePlugin plugin = KdeConnect.getInstance().getDevicePlugin(mDeviceId, SharePlugin.class);
- if (plugin == null) {
- finish();
- return;
+ try {
+ SharePlugin plugin = KdeConnect.getInstance().getDevicePlugin(mDeviceId, SharePlugin.class);
+ if (plugin != null) {
+ plugin.sendUriList(uris);
+ }
+ } finally {
+ // The read permissions ACTION_GET_CONTENT grants for these URIs are tied to
+ // this activity's lifetime, so we can't finish() until sendUriList() has opened
+ // all of them -- otherwise any URI not yet opened throws a SecurityException
+ // ("... requires that you obtain access using ACTION_OPEN_DOCUMENT").
+ runOnUiThread(this::finish);
}
- plugin.sendUriList(uris);
});
}
+ } else {
+ finish();
}
- finish();
break;
default:
super.onActivityResult(requestCode, resultCode, data);