Android: use empty Intent to clear clipboard data on API < 28

ClipboardManager didn't have any APIs to clear clipboard data before
API level 28.
As a workaround an empty Intent with MIMETYPE_UNKNOWN is created and
inserted into the clipboard for lower API levels.
This makes the QApplication::clipboard()->clear() method work more or
less as expected.
This allows to unblacklist tst_QPlainTextEdit::copyAvailable().

Task-number: QTBUG-87423
Task-number: QTBUG-89402
Pick-to: 6.3 6.2
Change-Id: I454376199cf3b8eed0fa2ecf2f85b87f40892280
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
bb10
Ivan Solovev 2022-03-15 16:24:47 +01:00
parent 9985cc330a
commit 30830e0cba
2 changed files with 10 additions and 7 deletions

View File

@ -1045,9 +1045,16 @@ public class QtNative
private static void clearClipData()
{
if (Build.VERSION.SDK_INT >= 28 && m_clipboardManager != null)
m_clipboardManager.clearPrimaryClip();
m_usePrimaryClip = false;
if (m_clipboardManager != null) {
if (Build.VERSION.SDK_INT >= 28) {
m_clipboardManager.clearPrimaryClip();
} else {
String[] mimeTypes = { ClipDescription.MIMETYPE_UNKNOWN };
ClipData data = new ClipData("", mimeTypes, new ClipData.Item(new Intent()));
m_clipboardManager.setPrimaryClip(data);
}
}
m_usePrimaryClip = false;
}
private static void setClipboardText(String text)
{

View File

@ -1028,10 +1028,6 @@ void tst_QPlainTextEdit::copyAvailable()
#endif
ed->clear();
QApplication::clipboard()->clear();
#ifdef Q_OS_ANDROID
if (QNativeInterface::QAndroidApplication::sdkVersion() < 28)
QEXPECT_FAIL("", "Before Android 9, there's no API to clear the clipboard ", Continue);
#endif
QVERIFY(!ed->canPaste());
QSignalSpy spyCopyAvailabe(ed, SIGNAL(copyAvailable(bool)));