Skip to content

Commit

Permalink
Fleet Manager: toggle PIN requirement (commaai#160)
Browse files Browse the repository at this point in the history
* Fleet Manager: toggle PIN requirement

* update the entire title

* update the param

* handle conditions

* update on toggle press
  • Loading branch information
sunnyhaibin authored Jun 15, 2023
1 parent f762bd2 commit 6e01328
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
29 changes: 25 additions & 4 deletions selfdrive/ui/qt/offroad/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
5 changes: 3 additions & 2 deletions selfdrive/ui/qt/offroad/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
3 changes: 2 additions & 1 deletion system/fleetmanager/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 6e01328

Please sign in to comment.