Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture and API reference

This chapter is for developers integrating or changing the Android client. The KyDrive server source defines the API; the Android app does not define a separate wire protocol.

Layout

PathResponsibility
app/src/main/java/org/kysecurity/drive/core/Portable wire models, request signing, file operations, transfer and certificate policy; no Android imports
MainActivity.kt, Rows.ktFiles/Shared navigation, item actions and system file pickers
Session.kt, DeviceSigningKey.kt, DeviceTls.ktAndroid storage, Keystore and platform TLS adapters
OpenProvider.ktRead-only proxy file descriptors for external viewers; not a DocumentsProvider
lock/, SecureActivity.kt, UnlockActivity.ktPIN/biometric policy and protected-screen lifecycle
Work.ktProcess-owned background transfers and user-facing error mapping
app/src/test/, app/src/androidTest/JVM tests, fuzz seeds, TLS fixtures and device lifecycle/transport tests

Linking input and output

The QR payload is kydrive://link?srv=<encoded-origin>&code=<code>. srv must be a bare HTTPS origin with a hostname, optional port, no user information, query or fragment. code is exactly 43 base64url characters. Duplicate/unknown parameters, malformed escapes and unsupported origins are refused before a network request.

POST /api/devices/token sends form fields grant=qr, code, name, platform=android and publicKey (standard-base64 SPKI DER). The response supplies a kyd_ token, user_id and user. GET /api/drive/device must identify the same account before the session is saved. DELETE /api/devices/self revokes the current phone.

Never log or place the device token in a URL. The app sends it as Authorization: Bearer …; request signatures are separate headers. The signature golden vector in app/src/test/resources/device-signing-v1.json is shared with the server.

File operations

OperationRequestResult used by the client
Visible workspacesGET /api/drive/workspacesArray with workspace ID, name, kind, role and head
Ensure personal workspacePOST /api/drive/personal-workspaceWorkspace ID, followed by a workspace reload
Folder/file listingGET /api/drive/workspaces/{id}/folders and /filesArrays; ?trash=true selects trash
Direct sharesGET /api/drive/shared-with-meShared item kind, IDs, workspace name and role
Shared folder childrenGET /api/drive/folders/{id}/childrenfolders and files arrays
File metadataGET /api/drive/files/{id}Revision, size, SHA-256 digest and modification time
New folderPOST /api/drive/workspaces/{id}/foldersNew folder metadata
RenamePUT /api/drive/files/{id}/location or /folders/{id}/locationUpdated item; files include an expected revision
Trash/restorePUT /api/drive/files/{id}/trash or /folders/{id}/trashChange confirmation; the client reloads
Download/openGET /api/drive/files/{id}/downloadFile bytes; range opens require 206 and bind the listed digest with If-Range
UploadPOST /api/drive/workspaces/{id}/upload-sessions, then PUT /api/drive/upload-sessions/{id} and POST …/completeSession ID, accepted offset and completed file metadata

Names from the server are display values, not local paths. API JSON responses are bounded; malformed JSON becomes an I/O failure. Non-success replies expose a status, structured error code and optional wipe field internally. Raw server error text is not displayed verbatim to users.

401 with device_revoked wipes regardless of its wipe boolean. Ordinary 401 marks the account signed out. Other status codes map to the messages in Troubleshooting.

Change the wire contract

Read the server’s current API and both repositories’ AGENTS.md files before changing a request. Put server changes in a separate server PR. Update the shared signature vector and interoperability tests when its format changes. Bump the real-server CI pin when a client needs newer routes; a local test against a different server is not evidence that the pinned CI integration ran.