From e79d177c7150166851e1e8152ecdd1908e1bcacf Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 28 Jun 2018 06:42:13 -0700 Subject: Android: limit the amount of data copied to clipboard The clipboard fails if we attempt to copy more than 1MB of data. But the data buffer used is shared between all transactions 'in flight' and we cannot tell what else is currently using that buffer. Limiting ourselves to 500k of text for the logfiles seems reasonable and hopefully makes it more likely that the transaction will succeed (sadly, Qt doesn't tell us if it failed). Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'mobile-widgets') diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index a3a4fffad..5269be9fe 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -347,8 +347,22 @@ void QMLManager::copyAppLogToClipboard() copyString += in.readAll(); } LOG_STP_CLIPBOARD(©String); + copyString += "---------- finish ----------\n"; +#if defined(Q_OS_ANDROID) + // on Android, the clipboard is effectively limited in size, but there is no + // predefined hard limit. All remote procedure calls use a shared Binder + // transaction buffer that is limited to 1MB. To work around this let's truncate + // the log once it is more than half a million characters. Qt doesn't tell us if + // the clipboard transaction fails, hopefully this will typically leave enough + // margin of error. + if (copyString.size() > 500000) { + copyString.truncate(500000); + copyString += "\n\n---------- truncated ----------\n"; + } +#endif + // and copy to clipboard QApplication::clipboard()->setText(copyString, QClipboard::Clipboard); } -- cgit v1.2.3-70-g09d2