Fix crash on access clipboard on Android

A case where the accessing the clipboard is done when the application
does not have the input focus. Android does not allow access in this
case and returns null on the getPrimaryClip. This happens on some
examples like Analog Clock. Does not happen on autotests.
Fix was adding a test for null.

Fixes: QTBUG-107926
Change-Id: I685594545e5ae8102c257c033fffbcc4f20cef9a
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Samuel Mira 2022-10-25 13:51:02 +03:00
parent 11cc74b066
commit 98a9c38437

View File

@ -1103,8 +1103,10 @@ public class QtNative
if (m_clipboardManager == null)
return false;
ClipData clip = m_clipboardManager.getPrimaryClip();
ClipDescription description = clip.getDescription();
ClipDescription description = m_clipboardManager.getPrimaryClipDescription();
// getPrimaryClipDescription can fail if the app does not have input focus
if (description == null)
return false;
for (int i = 0; i < description.getMimeTypeCount(); ++i) {
String itemMimeType = description.getMimeType(i);