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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2018-06-28 06:42:13 -07:00
parent bcde65b152
commit e79d177c71

View file

@ -347,8 +347,22 @@ void QMLManager::copyAppLogToClipboard()
copyString += in.readAll(); copyString += in.readAll();
} }
LOG_STP_CLIPBOARD(&copyString); LOG_STP_CLIPBOARD(&copyString);
copyString += "---------- finish ----------\n"; 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 // and copy to clipboard
QApplication::clipboard()->setText(copyString, QClipboard::Clipboard); QApplication::clipboard()->setText(copyString, QClipboard::Clipboard);
} }