I am working on an Android app and would like to implement a restricted clipboard functionality similar to the Intune Mobile App Management (MAM) feature. The goal is to allow users to perform clipboard operations (cut/copy/paste) within the app and with a few whitelisted apps, while preventing the copying of data/text from the app and pasting it outside the app, and vice versa.
After researching potential solutions, I have encountered some limitations with the options I explored:
Cleaning up clipboard when the app goes to the background:
- If the app crashes, it won't have an opportunity to clean up the clipboard.
- Sharing data with whitelisted apps is not possible.
- When the app goes to the background and is brought back, clipboard data will not be available.
- Other apps listening to clipboard change events may still receive the data.
Saving data in encrypted form:
- This approach adds a layer of security, but the data still needs to be cleaned up.
- If the app crashes, it won't have time to clean up the data.
- Other apps listening to clipboard change events may access the data before encryption.
Utilizing ClipData.Item URI:
This solution can work for custom copy and paste actions triggered by button clicks but does not override the OS-level copy-paste behavior. Users can still copy text to the clipboard by long-pressing.
It does not prevent other apps from accessing the clipboard data.
Considering these limitations, I am seeking suggestions on how to intercept app-wide copying to the clipboard in order to implement an app-only clipboard. The aim is to provide a secure clipboard that ensures the contents are kept within the app only.
I appreciate any insights or alternative approaches to achieve this functionality. Thank you.