diff --git a/electrum/gui/qml/java_classes/org/electrum/qr/SimpleScannerActivity.java b/electrum/gui/qml/java_classes/org/electrum/qr/SimpleScannerActivity.java index 476c375c42ed..8f809efaf5aa 100644 --- a/electrum/gui/qml/java_classes/org/electrum/qr/SimpleScannerActivity.java +++ b/electrum/gui/qml/java_classes/org/electrum/qr/SimpleScannerActivity.java @@ -13,7 +13,9 @@ import android.content.pm.PackageManager; import android.view.View; import android.view.ViewGroup; +import android.view.Window; import android.view.WindowInsets; +import android.view.WindowManager; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; @@ -48,6 +50,10 @@ public void onCreate(Bundle savedInstanceState) { TextView hintTextView = (TextView) findViewById(R.id.hint); hintTextView.setText(text); + // secure this window + boolean secure = !intent.getBooleanExtra("allow_screenshots", false); + setSecureWindow(secure); + // bind "paste" button Button btn = (Button) findViewById(R.id.paste_btn); btn.setOnClickListener(new View.OnClickListener() { @@ -209,4 +215,43 @@ private void setupEdgeToEdge() { return insets; }); } + + public void setSecureWindow(boolean secure) { + runOnUiThread(new Runnable() { + private Activity mActivity; + private boolean mEnable; + + public Runnable _initialize(Activity activity, boolean enable) { + this.mActivity = activity; + this.mEnable = enable; + return this; + } + + @Override + public void run() { + Window window = this.mActivity.getWindow(); + + if ( !((window.getAttributes().flags & WindowManager.LayoutParams.FLAG_SECURE) != 0) ^ mEnable) + return; // no change needed + + if (mEnable) { + Log.v(TAG, "Setting Secure Window"); + window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + } else { + Log.v(TAG, "UnSetting Secure Window"); + window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + // The below forces a redraw of the window/view, which is needed on some phones + // to actually clear the flag. However on some other phones, it crashes the app... + // see https://github.com/spesmilo/electrum/issues/8522 + /*if (ViewCompat.isAttachedToWindow(window.getDecorView())) { + WindowManager wm = this.mActivity.getWindowManager(); + wm.removeViewImmediate(window.getDecorView()); + wm.addView(window.getDecorView(), window.getAttributes()); + }*/ + } + } + }._initialize(this, secure)); + } + + } diff --git a/electrum/gui/qml/qeqrscanner.py b/electrum/gui/qml/qeqrscanner.py index be93bbf1f288..01b65324a58b 100644 --- a/electrum/gui/qml/qeqrscanner.py +++ b/electrum/gui/qml/qeqrscanner.py @@ -3,6 +3,7 @@ from PyQt6.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, Qt from PyQt6.QtGui import QGuiApplication +from electrum.gui.qml.qeconfig import QEConfig from electrum.gui.qml.qetypes import QEBytes from electrum.util import send_exception_to_crash_reporter from electrum.logging import get_logger @@ -54,6 +55,7 @@ def open(self): jSimpleScannerActivity = autoclass("org.electrum.qr.SimpleScannerActivity") intent = jIntent(jpythonActivity, jSimpleScannerActivity) intent.putExtra(jIntent.EXTRA_TEXT, jString(self._hint)) + intent.putExtra('allow_screenshots', QEConfig.instance.config.GUI_QML_ALWAYS_ALLOW_SCREENSHOTS) activity.bind(on_activity_result=self.on_qr_activity_result) jpythonActivity.startActivityForResult(intent, self.REQUEST_CODE_SIMPLE_SCANNER_ACTIVITY)