diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index ab049106a1250d..1916de8814b332 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -204,14 +204,29 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) { addItem(new LabelControl(tr("Dongle ID"), getDongleId().value_or(tr("N/A")))); addItem(new LabelControl(tr("Serial"), params.get("HardwareSerial").c_str())); - fleetManagerPin = new LabelControl(tr("Fleet Manager PIN"), pin); + fleetManagerPin = new ButtonControl( + tr(pin_title) + pin, tr("TOGGLE"), + tr("Enable or disable PIN requirement for Fleet Manager access.")); + connect(fleetManagerPin, &ButtonControl::clicked, [=]() { + if (params.getBool("FleetManagerPin")) { + if (ConfirmationDialog::confirm(tr("Are you sure you want to turn off PIN requirement?"), tr("Turn Off"), this)) { + params.remove("FleetManagerPin"); + refreshPin(); + } + } else { + params.putBool("FleetManagerPin", true); + refreshPin(); + } + }); addItem(fleetManagerPin); fs_watch = new QFileSystemWatcher(this); connect(fs_watch, &QFileSystemWatcher::fileChanged, this, &DevicePanel::onPinFileChanged); QString pin_path = "/data/otp/otp.conf"; + QString pin_require = "/data/params/d/FleetManagerPin"; fs_watch->addPath(pin_path); + fs_watch->addPath(pin_require); refreshPin(); // Error Troubleshoot @@ -321,18 +336,24 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) { } void DevicePanel::onPinFileChanged(const QString &file_path) { - if (file_path == "/data/otp/otp.conf") { + if (file_path == "/data/params/d/FleetManagerPin") { + refreshPin(); + } else if (file_path == "/data/otp/otp.conf") { refreshPin(); } } void DevicePanel::refreshPin() { QFile f("/data/otp/otp.conf"); - if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { + QFile require("/data/params/d/FleetManagerPin"); + if (!require.exists()) { + setSpacing(50); + fleetManagerPin->setTitle(QString(pin_title) + "OFF"); + } else if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { pin = f.readAll(); f.close(); setSpacing(50); - fleetManagerPin->setText(pin); + fleetManagerPin->setTitle(QString(pin_title) + pin); } } diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index 91890e3da4ff2a..e7b629a5acf83d 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -54,8 +54,9 @@ private slots: private: Params params; - LabelControl *fleetManagerPin; - QString pin; + ButtonControl *fleetManagerPin; + const char *pin_title = "Fleet Manager PIN: "; + QString pin = "OFF"; QFileSystemWatcher *fs_watch; }; diff --git a/system/fleetmanager/helpers.py b/system/fleetmanager/helpers.py index 998dd8fe6cbff1..fb1c4889f2a824 100644 --- a/system/fleetmanager/helpers.py +++ b/system/fleetmanager/helpers.py @@ -3,6 +3,7 @@ from flask import render_template, request, session from functools import wraps from pathlib import Path +from common.params import Params from system.hardware import PC from system.loggerd.config import ROOT as REALDATA from system.loggerd.uploader import listdir_by_creation @@ -23,7 +24,7 @@ def login_required(f): @wraps(f) def decorated_route(*args, **kwargs): - if not session.get("logged_in"): + if not session.get("logged_in") and Params().get_bool("FleetManagerPin"): session["previous_page"] = request.url return render_template("login.html") return f(*args, **kwargs)