Repository: florisboard/florisboard
Issue: Crash when clearing clipboard containing image

#### Short description
I had an image in the clipboard and I cleared the clipboard. The image was from a typical media content URI.
From the crash log, it looks like Florisboard is trying to actually delete the content pointed by the URI, instead of just removing the URI clip from the clipboard. So 1) Florisboard should catch these security exception, but more importantly 2) Florisboard should not try to delete content.

#### Steps to reproduce
1. Get an image in the clipboard
2. In Florisboard, bring up the clipboard
3. click on the clear icon
4. See crash

<!-- Paste the generated crash log below -->
#### Environment information
- FlorisBoard Version: 0.3.12 (43)
- - Device: Samsung SM-G970N
- Android: 11 (cn=R sdk=30)
#### Features enabled
```kt
smartbar = true
suggestions = false
suggestions_clipboard = true
suggestions_next_word = true
glide = true
clipboard_internal = false
clipboard_history = true
```

#### Attached stacktrace files
<details>
<summary>1627824723533.stacktrace</summary>

```
android.app.RecoverableSecurityException: dev.patrickgold.florisboard has no access to content://media/external/images/media/121077
	at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:197)
	at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:194)
	at android.os.Parcel.readParcelable(Parcel.java:3293)
	at android.os.Parcel.createExceptionOrNull(Parcel.java:2380)
	at android.os.Parcel.createException(Parcel.java:2369)
	at android.os.Parcel.readException(Parcel.java:2352)
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
	at android.content.ContentProviderProxy.delete(ContentProviderNative.java:624)
	at android.content.ContentResolver.delete(ContentResolver.java:2299)
	at android.content.ContentResolver.delete(ContentResolver.java:2265)
	at dev.patrickgold.florisboard.ime.clip.provider.ClipboardItem.close(FlorisDatabase.kt:58)
	at dev.patrickgold.florisboard.ime.clip.FlorisClipboardManager.clearHistoryWithAnimation$lambda-4(FlorisClipboardManager.kt:292)
	at dev.patrickgold.florisboard.ime.clip.FlorisClipboardManager.lambda$EGTQORNwlxAgKPqKNzOja-ZeRzc(Unknown Source:0)
	at dev.patrickgold.florisboard.ime.clip.-$$Lambda$FlorisClipboardManager$EGTQORNwlxAgKPqKNzOja-ZeRzc.run(Unknown Source:4)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:246)
	at android.app.ActivityThread.main(ActivityThread.java:8587)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
```
</details>


Changed files:
app/src/main/java/dev/patrickgold/florisboard/ime/clip/FlorisClipboardManager.kt
app/src/main/java/dev/patrickgold/florisboard/ime/clip/provider/FlorisDatabase.kt

diff --git a/app/src/main/java/dev/patrickgold/florisboard/ime/clip/FlorisClipboardManager.kt b/app/src/main/java/dev/patrickgold/florisboard/ime/clip/FlorisClipboardManager.kt
index a5d8664c..f2083ab0 100644
--- a/app/src/main/java/dev/patrickgold/florisboard/ime/clip/FlorisClipboardManager.kt
+++ b/app/src/main/java/dev/patrickgold/florisboard/ime/clip/FlorisClipboardManager.kt
@@ -3,6 +3,7 @@ package dev.patrickgold.florisboard.ime.clip
 import android.content.ClipboardManager
 import android.content.Context
 import android.content.Context.CLIPBOARD_SERVICE
+import dev.patrickgold.florisboard.debug.flogDebug
 import dev.patrickgold.florisboard.ime.clip.provider.*
 import dev.patrickgold.florisboard.ime.core.FlorisBoard
 import dev.patrickgold.florisboard.ime.core.Preferences
@@ -236,7 +237,7 @@ class FlorisClipboardManager private constructor() : ClipboardManager.OnPrimaryC
         } else if (prefs.clipboard.enableHistory) {
             // in the event history is enabled, and it should be updated it is updated
             if (shouldUpdateHistory) {
-                updateHistory(ClipboardItem.fromClipData(systemPrimaryClip, false))
+                updateHistory(ClipboardItem.fromClipData(systemPrimaryClip, true))
             } else {
                 shouldUpdateHistory = true
             }
diff --git a/app/src/main/java/dev/patrickgold/florisboard/ime/clip/provider/FlorisDatabase.kt b/app/src/main/java/dev/patrickgold/florisboard/ime/clip/provider/FlorisDatabase.kt
index 9ae7f464..220bcc1d 100644
--- a/app/src/main/java/dev/patrickgold/florisboard/ime/clip/provider/FlorisDatabase.kt
+++ b/app/src/main/java/dev/patrickgold/florisboard/ime/clip/provider/FlorisDatabase.kt
@@ -22,7 +22,6 @@ enum class ItemType(val value: Int) {
 
 /**
  * Represents an item on the clipboard.
- * The URI stored belongs to FlorisContentProvider, not whatever app copied the image
  *
  * If type == ItemType.IMAGE there must be a uri set
  * if type == ItemType.TEXT there must be a text set