Skip to content

Commit 545798d

Browse files
committed
android: inhibit screenshotting SimpleScannerActivity the same way as PythonActivity
1 parent 4622390 commit 545798d

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

electrum/gui/qml/java_classes/org/electrum/qr/SimpleScannerActivity.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import android.content.pm.PackageManager;
1414
import android.view.View;
1515
import android.view.ViewGroup;
16+
import android.view.Window;
1617
import android.view.WindowInsets;
18+
import android.view.WindowManager;
1719
import android.widget.Button;
1820
import android.widget.TextView;
1921
import android.widget.Toast;
@@ -48,6 +50,10 @@ public void onCreate(Bundle savedInstanceState) {
4850
TextView hintTextView = (TextView) findViewById(R.id.hint);
4951
hintTextView.setText(text);
5052

53+
// secure this window
54+
boolean secure = !intent.getBooleanExtra("allow_screenshots", false);
55+
setSecureWindow(secure);
56+
5157
// bind "paste" button
5258
Button btn = (Button) findViewById(R.id.paste_btn);
5359
btn.setOnClickListener(new View.OnClickListener() {
@@ -209,4 +215,43 @@ private void setupEdgeToEdge() {
209215
return insets;
210216
});
211217
}
218+
219+
public void setSecureWindow(boolean secure) {
220+
runOnUiThread(new Runnable() {
221+
private Activity mActivity;
222+
private boolean mEnable;
223+
224+
public Runnable _initialize(Activity activity, boolean enable) {
225+
this.mActivity = activity;
226+
this.mEnable = enable;
227+
return this;
228+
}
229+
230+
@Override
231+
public void run() {
232+
Window window = this.mActivity.getWindow();
233+
234+
if ( !((window.getAttributes().flags & WindowManager.LayoutParams.FLAG_SECURE) != 0) ^ mEnable)
235+
return; // no change needed
236+
237+
if (mEnable) {
238+
Log.v(TAG, "Setting Secure Window");
239+
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
240+
} else {
241+
Log.v(TAG, "UnSetting Secure Window");
242+
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
243+
// The below forces a redraw of the window/view, which is needed on some phones
244+
// to actually clear the flag. However on some other phones, it crashes the app...
245+
// see https://github.com/spesmilo/electrum/issues/8522
246+
/*if (ViewCompat.isAttachedToWindow(window.getDecorView())) {
247+
WindowManager wm = this.mActivity.getWindowManager();
248+
wm.removeViewImmediate(window.getDecorView());
249+
wm.addView(window.getDecorView(), window.getAttributes());
250+
}*/
251+
}
252+
}
253+
}._initialize(this, secure));
254+
}
255+
256+
212257
}

electrum/gui/qml/qeqrscanner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from PyQt6.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, Qt
44
from PyQt6.QtGui import QGuiApplication
55

6+
from electrum.gui.qml.qeconfig import QEConfig
67
from electrum.gui.qml.qetypes import QEBytes
78
from electrum.util import send_exception_to_crash_reporter
89
from electrum.logging import get_logger
@@ -54,6 +55,7 @@ def open(self):
5455
jSimpleScannerActivity = autoclass("org.electrum.qr.SimpleScannerActivity")
5556
intent = jIntent(jpythonActivity, jSimpleScannerActivity)
5657
intent.putExtra(jIntent.EXTRA_TEXT, jString(self._hint))
58+
intent.putExtra('allow_screenshots', QEConfig.instance.config.GUI_QML_ALWAYS_ALLOW_SCREENSHOTS)
5759

5860
activity.bind(on_activity_result=self.on_qr_activity_result)
5961
jpythonActivity.startActivityForResult(intent, self.REQUEST_CODE_SIMPLE_SCANNER_ACTIVITY)

0 commit comments

Comments
 (0)