From 0dae17339d95aca91a77374c60f2dbc5ea05001d Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 27 Dec 2023 07:28:39 +0000 Subject: [PATCH] qml: add config setting to allow screenshots On Android, we disallow screenshots on screens where the seed is visible. (The seed is extremely sensitive data that should not be stored digitally without significant precautions but it's also cumbersome to write down or memorise, so some people instinctively just try to take a screenshot of it when creating a wallet.) We do this by using the built-in OS mechanism of setting FLAG_SECURE on the window. However, on some devices with custom ROMs (one report from LineageOS, one from /e/OS), unsetting FLAG_SECURE crashes the application for some reason. As a workaround, this commit adds a config setting into the Preferences, to disable this mechanism and just always allow screenshots. (note that you can get into the qml Preferences before creating/opening any wallet) ref https://github.com/spesmilo/electrum/issues/8522 --- electrum/gui/qml/components/Preferences.qml | 19 +++++++++++++++++++ electrum/gui/qml/qeapp.py | 2 ++ electrum/gui/qml/qeconfig.py | 10 ++++++++++ electrum/simple_config.py | 1 + 4 files changed, 32 insertions(+) diff --git a/electrum/gui/qml/components/Preferences.qml b/electrum/gui/qml/components/Preferences.qml index 8804876de..7cfc26512 100644 --- a/electrum/gui/qml/components/Preferences.qml +++ b/electrum/gui/qml/components/Preferences.qml @@ -368,6 +368,24 @@ Pane { wrapMode: Text.Wrap } } + + RowLayout { + Layout.columnSpan: 2 + Layout.fillWidth: true + spacing: 0 + Switch { + id: alwaysAllowScreenshots + onCheckedChanged: { + if (activeFocus) + Config.alwaysAllowScreenshots = checked + } + } + Label { + Layout.fillWidth: true + text: qsTr('Always allow screenshots') + wrapMode: Text.Wrap + } + } } } @@ -392,6 +410,7 @@ Pane { useTrampolineRouting.checked = !Config.useGossip useFallbackAddress.checked = Config.useFallbackAddress enableDebugLogs.checked = Config.enableDebugLogs + alwaysAllowScreenshots.checked = Config.alwaysAllowScreenshots useRecoverableChannels.checked = Config.useRecoverableChannels syncLabels.checked = AppController.isPluginEnabled('labels') } diff --git a/electrum/gui/qml/qeapp.py b/electrum/gui/qml/qeapp.py index 38c892651..c8a7e3847 100644 --- a/electrum/gui/qml/qeapp.py +++ b/electrum/gui/qml/qeapp.py @@ -327,6 +327,8 @@ class QEAppController(BaseCrashReporter, QObject): def secureWindow(self, secure): if not self.isAndroid(): return + if self.config.GUI_QML_ALWAYS_ALLOW_SCREENSHOTS: + return if self._secureWindow != secure: jpythonActivity.setSecureWindow(secure) self._secureWindow = secure diff --git a/electrum/gui/qml/qeconfig.py b/electrum/gui/qml/qeconfig.py index 99ebc1d41..32d4a57cf 100644 --- a/electrum/gui/qml/qeconfig.py +++ b/electrum/gui/qml/qeconfig.py @@ -169,6 +169,16 @@ class QEConfig(AuthMixin, QObject): self.config.GUI_ENABLE_DEBUG_LOGS = enable self.enableDebugLogsChanged.emit() + alwaysAllowScreenshotsChanged = pyqtSignal() + @pyqtProperty(bool, notify=alwaysAllowScreenshotsChanged) + def alwaysAllowScreenshots(self): + return self.config.GUI_QML_ALWAYS_ALLOW_SCREENSHOTS + + @alwaysAllowScreenshots.setter + def alwaysAllowScreenshots(self, enable): + self.config.GUI_QML_ALWAYS_ALLOW_SCREENSHOTS = enable + self.alwaysAllowScreenshotsChanged.emit() + useRecoverableChannelsChanged = pyqtSignal() @pyqtProperty(bool, notify=useRecoverableChannelsChanged) def useRecoverableChannels(self): diff --git a/electrum/simple_config.py b/electrum/simple_config.py index 9396aa468..2ef63943e 100644 --- a/electrum/simple_config.py +++ b/electrum/simple_config.py @@ -1105,6 +1105,7 @@ This will result in longer routes; it might increase your fees and decrease the GUI_QML_USER_KNOWS_PRESS_AND_HOLD = ConfigVar('user_knows_press_and_hold', default=False, type_=bool) GUI_QML_ADDRESS_LIST_SHOW_TYPE = ConfigVar('address_list_show_type', default=1, type_=int) GUI_QML_ADDRESS_LIST_SHOW_USED = ConfigVar('address_list_show_used', default=False, type_=bool) + GUI_QML_ALWAYS_ALLOW_SCREENSHOTS = ConfigVar('android_always_allow_screenshots', default=False, type_=bool) BTC_AMOUNTS_DECIMAL_POINT = ConfigVar('decimal_point', default=DECIMAL_POINT_DEFAULT, type_=int) BTC_AMOUNTS_FORCE_NZEROS_AFTER_DECIMAL_POINT = ConfigVar(