Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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));
}


}
2 changes: 2 additions & 0 deletions electrum/gui/qml/qeqrscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down