Clipboard Manager & History
Relevant source files
The following files were used as context for generating this wiki page:
- app/src/main/kotlin/dev/patrickgold/florisboard/ime/clipboard/provider/ClipboardDatabase.kt
- app/src/main/res/values/strings.xml
- app/src/main/kotlin/dev/patrickgold/florisboard/lib/devtools/Devtools.kt
- app/src/main/AndroidManifest.xml
- app/src/main/kotlin/dev/patrickgold/florisboard/app/ext/ExtensionEditScreen.kt
The Clipboard Manager is a central module in Ownkey Keyboard designed to store, manage, and retrieve snippets of text and media (images/videos) copied by the user. It extends basic system clipboard functionality by providing a persistent history, pinning capabilities, and advanced privacy controls, such as sensitive content detection and automatic cleanup.
The system is built upon a Room-based database architecture that segregates clipboard metadata from physical file references. It supports synchronization with the Android system clipboard while offering an "internal clipboard" mode for enhanced privacy, ensuring that copied data remains within the application context when configured by the user.
Sources: app/src/main/res/values/strings.xml:655-660, app/src/main/kotlin/dev/patrickgold/florisboard/ime/clipboard/provider/ClipboardDatabase.kt:33-40
Architecture and Data Models
The clipboard system is structured around the ClipboardHistoryDatabase, which manages ClipboardItem entities. This database tracks the type of content, its source, and its persistence state (pinned vs. unpinned).
Clipboard Item Structure
Each entry in the clipboard history is represented by a ClipboardItem data class. This class differentiates between text-based clips and media-based clips using a URI reference.
| Field | Type | Description |
|---|---|---|
id | Long | Primary key, auto-generated. |
type | ItemType | Enum: TEXT, IMAGE, or VIDEO. |
text | String? | The text content (null for media items). |
uri | Uri? | Reference to the file in ClipboardMediaProvider. |
creationTimestampMs | Long | System time when the item was copied. |
isPinned | Boolean | If true, the item is excluded from automatic cleanup. |
isSensitive | Boolean | Flag for sensitive data (e.g., passwords). |
isRemoteDevice | Boolean | Indicates if the clip originated from a synchronized remote device. |
Sources: app/src/main/kotlin/dev/patrickgold/florisboard/ime/clipboard/provider/ClipboardDatabase.kt:53-73
Database Components
The system utilizes two primary tables to manage history and file metadata:
- clipboard_history: Stores the metadata and text content for all clips.
- clipboard_files: Manages metadata for physical media files (images/videos) stored by the provider.
The diagram shows the relationship between the Room database definitions and their respective entity models.
Sources: app/src/main/kotlin/dev/patrickgold/florisboard/ime/clipboard/provider/ClipboardDatabase.kt:33-34, app/src/main/kotlin/dev/patrickgold/florisboard/ime/clipboard/provider/ClipboardDatabase.kt:230-235
Data Flow and Content Management
The clipboard system manages the lifecycle of a clip from the moment it is detected in the system or internal clipboard until it is pasted or deleted.
Clip Creation Logic
When content is added, the system determines the ItemType based on MIME types. If the content is an image or video, the ClipboardMediaProvider clones the URI to ensure Ownkey Keyboard maintains access even if the original source file is removed.
Flow of content from a copy event to database persistence.
Sources: app/src/main/kotlin/dev/patrickgold/florisboard/ime/clipboard/provider/ClipboardDatabase.kt:94-118
Sensitive Content Handling
The system respects Android's sensitive content flags (EXTRA_IS_SENSITIVE). Sensitive items are masked in the UI with a placeholder string and can be configured for aggressive automatic cleanup.
Sources: app/src/main/kotlin/dev/patrickgold/florisboard/ime/clipboard/provider/ClipboardDatabase.kt:133-145, app/src/main/res/values/strings.xml:678-679
Configuration and Preferences
Users can customize the behavior of the clipboard manager through various settings located in the application's preference model.
| Preference Label | Summary / Effect |
|---|---|
Use internal clipboard | If enabled, prevents copied data from being shared with the system clipboard. |
Sync from system | Automatically imports system clipboard changes into Ownkey history. |
Clean up old items | Deletes unpinned items after a specified duration. |
Auto clean sensitive | Specifically targets items flagged as sensitive for immediate/timed deletion. |
Limit history size | Sets the maximum number of items stored in the database. |
Clear primary clip affects history | If enabled, clearing the current active clip also removes it from history if unpinned. |
Sources: app/src/main/res/values/strings.xml:670-686
Integration with System Components
ClipboardMediaProvider
The ClipboardMediaProvider is a specialized ContentProvider defined in the AndroidManifest.xml. It manages the actual file data for images and videos, allowing the keyboard to "paste" media into compatible applications via URIs.
Sources: app/src/main/AndroidManifest.xml:135-140, app/src/main/kotlin/dev/patrickgold/florisboard/ime/clipboard/provider/ClipboardDatabase.kt:105-110
Devtools Integration
For debugging, the Devtools module provides an overlay to show the current "primary clip" metadata. This allows developers to verify the contents and flags (like sensitivity) of the active clipboard item in real-time.
Sources: app/src/main/kotlin/dev/patrickgold/florisboard/lib/devtools/Devtools.kt:105, app/src/main/res/values/strings.xml:691-692
Summary
The Clipboard Manager & History system provides a robust framework for managing user-copied content with a focus on persistence and privacy. By utilizing a dual-database approach for history and media files, and integrating strictly with Android's sensitivity and synchronization APIs, the module ensures that users have quick access to their data while maintaining control over its exposure and lifecycle. Reiterations of key features include pinning for long-term storage and internal-only clipboard modes for high-security environments.