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
parent
9985cc330a
commit
30830e0cba
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue