modem: prevent duplicate SIM PIN entry dialog in dual-SIM mode
This commit is contained in:
1 parent
2e2adcc7f2
commit
4aa087f372
6 files changed
+174
-65
No files matched your search
@@ -136,11 +136,12 @@ struct ModemStatusData {
|
||||
|
||||
std::string regStatusLabel() const {
|
||||
if (slots[0].needsPuk() || slots[1].needsPuk() ||
|
||||
mmUnlockRequired == "sim-puk") {
|
||||
(!qmiAvailable && mmUnlockRequired == "sim-puk")) {
|
||||
return "SIM PUK Required";
|
||||
}
|
||||
if (slots[0].needsPin() || slots[1].needsPin() ||
|
||||
mmUnlockRequired == "sim-pin" || mmState == "locked") {
|
||||
(!qmiAvailable &&
|
||||
(mmUnlockRequired == "sim-pin" || mmState == "locked"))) {
|
||||
return "SIM PIN Required";
|
||||
}
|
||||
if (mmRegState == "home" ||
|
||||
@@ -432,13 +433,15 @@ ModemStatusData queryModemAndSimStatus() {
|
||||
actIdx = std::clamp(d.preferredSlot, 1, 2) - 1;
|
||||
}
|
||||
if (actIdx >= 0 && actIdx < 2) {
|
||||
if (d.mmUnlockRequired == "sim-pin" &&
|
||||
d.slots[actIdx].pin1State == "not-initialized") {
|
||||
d.slots[actIdx].state = "present";
|
||||
d.slots[actIdx].pin1State = "enabled-not-verified";
|
||||
} else if (d.mmUnlockRequired == "sim-puk") {
|
||||
d.slots[actIdx].state = "present";
|
||||
d.slots[actIdx].pin1State = "blocked";
|
||||
if (!d.qmiAvailable) {
|
||||
if (d.mmUnlockRequired == "sim-pin" &&
|
||||
d.slots[actIdx].pin1State == "not-initialized") {
|
||||
d.slots[actIdx].state = "present";
|
||||
d.slots[actIdx].pin1State = "enabled-not-verified";
|
||||
} else if (d.mmUnlockRequired == "sim-puk") {
|
||||
d.slots[actIdx].state = "present";
|
||||
d.slots[actIdx].pin1State = "blocked";
|
||||
}
|
||||
}
|
||||
if (d.mmPinRetries >= 0 && d.slots[actIdx].pin1Retries == 0) {
|
||||
d.slots[actIdx].pin1Retries = d.mmPinRetries;
|
||||
@@ -591,6 +594,11 @@ int runModemApp(int argc, char** argv) {
|
||||
int64_t statusBannerUntilMs = 0;
|
||||
|
||||
bool visible = false;
|
||||
bool openedForUnlock = false;
|
||||
int unlockedSlotMask = 0;
|
||||
int64_t lastUnlockSuccessMs = 0;
|
||||
int autoCheckStage = isPreload ? 0 : 2;
|
||||
int64_t nextAutoCheckMs = nowMs() + 2500;
|
||||
int64_t openStartMs = 0;
|
||||
int64_t startupIgnoreUntilMs = 0;
|
||||
int64_t lastRefreshMs = 0;
|
||||
@@ -605,6 +613,19 @@ int runModemApp(int argc, char** argv) {
|
||||
|
||||
auto refreshData = [&](bool reloadLog = false) {
|
||||
status = queryModemAndSimStatus();
|
||||
int64_t now = nowMs();
|
||||
if (lastUnlockSuccessMs > 0 && (now - lastUnlockSuccessMs) < 30000) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
if (unlockedSlotMask & (1 << i)) {
|
||||
if (status.slots[i].pin1State == "enabled-not-verified") {
|
||||
status.slots[i].pin1State = "enabled-verified";
|
||||
}
|
||||
if (status.slots[i].appState.rfind("pin1", 0) == 0) {
|
||||
status.slots[i].appState = "ready";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reloadLog || activeTab == TabId::ModemLog) {
|
||||
book.load();
|
||||
logRows = loadRecentModemLog(book);
|
||||
@@ -612,13 +633,27 @@ int runModemApp(int argc, char** argv) {
|
||||
logRowSel = std::max(0, static_cast<int>(logRows.size()) - 1);
|
||||
}
|
||||
}
|
||||
lastRefreshMs = nowMs();
|
||||
lastRefreshMs = now;
|
||||
if (visible && !isAnotherPluginActive("modem")) {
|
||||
XRaiseWindow(dpy, win);
|
||||
grabPluginKeyboard(dpy, win);
|
||||
}
|
||||
};
|
||||
|
||||
auto anySimNeedsUnlock = [&]() -> bool {
|
||||
if (status.slots[0].needsPin() || status.slots[0].needsPuk() ||
|
||||
status.slots[1].needsPin() || status.slots[1].needsPuk()) {
|
||||
return true;
|
||||
}
|
||||
if (!status.qmiAvailable &&
|
||||
(lastUnlockSuccessMs == 0 || (nowMs() - lastUnlockSuccessMs) >= 30000) &&
|
||||
(status.mmState == "locked" || status.mmUnlockRequired == "sim-pin" ||
|
||||
status.mmUnlockRequired == "sim-puk")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
auto defaultActiveOrPresentSlot = [&]() -> int {
|
||||
if (status.slots[0].needsPin() || status.slots[0].needsPuk()) return 1;
|
||||
if (status.slots[1].needsPin() || status.slots[1].needsPuk()) return 2;
|
||||
@@ -648,7 +683,8 @@ int runModemApp(int argc, char** argv) {
|
||||
inputPin2.clear();
|
||||
inputPin3.clear();
|
||||
modalError.clear();
|
||||
if (s.needsPuk() || status.mmUnlockRequired == "sim-puk") {
|
||||
if (s.needsPuk() ||
|
||||
(!status.qmiAvailable && status.mmUnlockRequired == "sim-puk")) {
|
||||
modal = ModalMode::UnblockPuk;
|
||||
} else {
|
||||
modal = ModalMode::VerifyPin;
|
||||
@@ -662,7 +698,9 @@ int runModemApp(int argc, char** argv) {
|
||||
activeTab = TabId::SimCards;
|
||||
int lockSlot = defaultActiveOrPresentSlot();
|
||||
simRowSel = lockSlot - 1;
|
||||
openPinOrPukModalForSlot(lockSlot);
|
||||
if (anySimNeedsUnlock()) {
|
||||
openPinOrPukModalForSlot(lockSlot);
|
||||
}
|
||||
} else if (a == "info" || a == "status" || a == "radio") {
|
||||
activeTab = TabId::RadioInfo;
|
||||
} else if (a == "log" || a == "logs") {
|
||||
@@ -1261,41 +1299,6 @@ int runModemApp(int argc, char** argv) {
|
||||
grabPluginKeyboard(dpy, win);
|
||||
};
|
||||
|
||||
auto showWindow = [&](const std::string& arg = "") {
|
||||
std::string a = toLowerStr(trimStr(arg));
|
||||
if (visible &&
|
||||
(modal == ModalMode::VerifyPin || modal == ModalMode::UnblockPuk) &&
|
||||
(a == "unlock" || a == "pin" || a == "puk")) {
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("modem");
|
||||
XRaiseWindow(dpy, win);
|
||||
grabKeys();
|
||||
render();
|
||||
return;
|
||||
}
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("modem");
|
||||
if (!visible) {
|
||||
XMapRaised(dpy, win);
|
||||
visible = true;
|
||||
} else {
|
||||
XRaiseWindow(dpy, win);
|
||||
}
|
||||
grabKeys();
|
||||
render();
|
||||
refreshData(true);
|
||||
applyOpenArg(arg);
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("modem");
|
||||
XRaiseWindow(dpy, win);
|
||||
openStartMs = nowMs();
|
||||
startupIgnoreUntilMs = openStartMs + 180;
|
||||
initialSoftkeysReleased = (querySoftkeysDown(dpy) == 0);
|
||||
softkeyPending = 0;
|
||||
grabKeys();
|
||||
render();
|
||||
};
|
||||
|
||||
auto hideWindow = [&]() {
|
||||
if (!visible) return;
|
||||
int xfdLocal = ConnectionNumber(dpy);
|
||||
@@ -1315,10 +1318,65 @@ int runModemApp(int argc, char** argv) {
|
||||
XUnmapWindow(dpy, win);
|
||||
XFlush(dpy);
|
||||
visible = false;
|
||||
openedForUnlock = false;
|
||||
modal = ModalMode::None;
|
||||
::unlink(activePidPath.c_str());
|
||||
};
|
||||
|
||||
auto showWindow = [&](const std::string& arg = "") {
|
||||
std::string a = toLowerStr(trimStr(arg));
|
||||
bool isUnlockReq = (a == "unlock" || a == "pin" || a == "puk");
|
||||
if (isUnlockReq) {
|
||||
autoCheckStage = 2;
|
||||
}
|
||||
if (visible &&
|
||||
(modal == ModalMode::VerifyPin || modal == ModalMode::UnblockPuk) &&
|
||||
isUnlockReq) {
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("modem");
|
||||
XRaiseWindow(dpy, win);
|
||||
grabKeys();
|
||||
render();
|
||||
return;
|
||||
}
|
||||
if (isUnlockReq) {
|
||||
refreshData(false);
|
||||
if (!anySimNeedsUnlock()) {
|
||||
if (visible && openedForUnlock) {
|
||||
hideWindow();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("modem");
|
||||
if (!visible) {
|
||||
openedForUnlock = isUnlockReq;
|
||||
XMapRaised(dpy, win);
|
||||
visible = true;
|
||||
} else {
|
||||
if (!isUnlockReq) {
|
||||
openedForUnlock = false;
|
||||
}
|
||||
XRaiseWindow(dpy, win);
|
||||
}
|
||||
grabKeys();
|
||||
render();
|
||||
if (!isUnlockReq) {
|
||||
refreshData(true);
|
||||
}
|
||||
applyOpenArg(arg);
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("modem");
|
||||
XRaiseWindow(dpy, win);
|
||||
openStartMs = nowMs();
|
||||
startupIgnoreUntilMs = openStartMs + 180;
|
||||
initialSoftkeysReleased = (querySoftkeysDown(dpy) == 0);
|
||||
softkeyPending = 0;
|
||||
grabKeys();
|
||||
render();
|
||||
};
|
||||
|
||||
auto switchSimSlotNow = [&](int slotNum, bool swapGw = false) {
|
||||
slotNum = std::clamp(slotNum, 1, 2);
|
||||
if (swapGw) {
|
||||
@@ -1365,11 +1423,27 @@ int runModemApp(int argc, char** argv) {
|
||||
runCaptureCmd("doas -n /usr/libexec/msm-modem-uim-selection verify-pin " +
|
||||
std::to_string(targetSlot) + " " + shellQuote(inputPin1) +
|
||||
" >/dev/null 2>&1", &rc);
|
||||
if (rc == 0) {
|
||||
unlockedSlotMask |= (1 << (std::clamp(targetSlot, 1, 2) - 1));
|
||||
lastUnlockSuccessMs = nowMs();
|
||||
}
|
||||
refreshData(false);
|
||||
runAsyncCmd("sxmo_hook_statusbar.sh modem >/dev/null 2>&1");
|
||||
if (rc == 0) {
|
||||
modal = ModalMode::None;
|
||||
setBanner("SIM " + std::to_string(targetSlot) + " unlocked");
|
||||
int otherSlot = (targetSlot == 1) ? 2 : 1;
|
||||
const auto& otherSim = status.slots[otherSlot - 1];
|
||||
if (otherSim.needsPin() || otherSim.needsPuk()) {
|
||||
simRowSel = otherSlot - 1;
|
||||
openPinOrPukModalForSlot(otherSlot);
|
||||
setBanner("SIM " + std::to_string(targetSlot) +
|
||||
" unlocked; unlock SIM " + std::to_string(otherSlot));
|
||||
} else {
|
||||
modal = ModalMode::None;
|
||||
setBanner("SIM " + std::to_string(targetSlot) + " unlocked");
|
||||
if (openedForUnlock) {
|
||||
hideWindow();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inputPin1.clear();
|
||||
modalError = "Incorrect PIN";
|
||||
@@ -1401,11 +1475,27 @@ int runModemApp(int argc, char** argv) {
|
||||
runCaptureCmd("doas -n /usr/libexec/msm-modem-uim-selection unblock-puk " +
|
||||
std::to_string(targetSlot) + " " + shellQuote(inputPin1) +
|
||||
" " + shellQuote(inputPin2) + " >/dev/null 2>&1", &rc);
|
||||
if (rc == 0) {
|
||||
unlockedSlotMask |= (1 << (std::clamp(targetSlot, 1, 2) - 1));
|
||||
lastUnlockSuccessMs = nowMs();
|
||||
}
|
||||
refreshData(false);
|
||||
runAsyncCmd("sxmo_hook_statusbar.sh modem >/dev/null 2>&1");
|
||||
if (rc == 0) {
|
||||
modal = ModalMode::None;
|
||||
setBanner("SIM unblocked and new PIN set");
|
||||
int otherSlot = (targetSlot == 1) ? 2 : 1;
|
||||
const auto& otherSim = status.slots[otherSlot - 1];
|
||||
if (otherSim.needsPin() || otherSim.needsPuk()) {
|
||||
simRowSel = otherSlot - 1;
|
||||
openPinOrPukModalForSlot(otherSlot);
|
||||
setBanner("SIM " + std::to_string(targetSlot) +
|
||||
" unblocked; unlock SIM " + std::to_string(otherSlot));
|
||||
} else {
|
||||
modal = ModalMode::None;
|
||||
setBanner("SIM unblocked and new PIN set");
|
||||
if (openedForUnlock) {
|
||||
hideWindow();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wizardStep = 0;
|
||||
inputPin1.clear();
|
||||
@@ -1556,7 +1646,11 @@ int runModemApp(int argc, char** argv) {
|
||||
}
|
||||
switchSimSlotNow(otherGwSlot, true);
|
||||
} else if (row == 4) {
|
||||
openPinOrPukModalForSlot(defaultActiveOrPresentSlot());
|
||||
if (anySimNeedsUnlock()) {
|
||||
openPinOrPukModalForSlot(defaultActiveOrPresentSlot());
|
||||
} else {
|
||||
setBanner("SIM cards are already unlocked");
|
||||
}
|
||||
} else if (row == 5) {
|
||||
targetSlot = defaultActiveOrPresentSlot();
|
||||
wizardStep = 0;
|
||||
@@ -1668,6 +1762,9 @@ int runModemApp(int argc, char** argv) {
|
||||
runAsyncCmd("mmcli -m any --3gpp-ussd-cancel >/dev/null 2>&1");
|
||||
}
|
||||
modal = ModalMode::None;
|
||||
if (openedForUnlock) {
|
||||
hideWindow();
|
||||
}
|
||||
return;
|
||||
}
|
||||
hideWindow();
|
||||
@@ -1744,9 +1841,6 @@ int runModemApp(int argc, char** argv) {
|
||||
}
|
||||
};
|
||||
|
||||
int autoCheckStage = isPreload ? 0 : 2;
|
||||
int64_t nextAutoCheckMs = nowMs() + 2500;
|
||||
|
||||
if (!isPreload) {
|
||||
showWindow(openArg);
|
||||
}
|
||||
@@ -1847,7 +1941,7 @@ int runModemApp(int argc, char** argv) {
|
||||
}
|
||||
if (sym == XK_Return || sym == XK_KP_Enter) {
|
||||
submitModalInput();
|
||||
render();
|
||||
if (visible) render();
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
@@ -2069,7 +2163,7 @@ int runModemApp(int argc, char** argv) {
|
||||
sym == XF86XK_Send || sym == XF86XK_Phone ||
|
||||
sym == XF86XK_PickupPhone) {
|
||||
handleEnterKey();
|
||||
render();
|
||||
if (visible) render();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2088,10 +2182,10 @@ int runModemApp(int argc, char** argv) {
|
||||
sendPluginCommand("xdrawer", "TOGGLE");
|
||||
} else if (pend == 1) {
|
||||
handleLeftSoftkey();
|
||||
render();
|
||||
if (visible) render();
|
||||
} else if (pend == 2) {
|
||||
handleRightSoftkey();
|
||||
render();
|
||||
if (visible) render();
|
||||
}
|
||||
} else {
|
||||
timeoutMs = static_cast<int>(rem);
|
||||
@@ -2134,9 +2228,7 @@ int runModemApp(int argc, char** argv) {
|
||||
++autoCheckStage;
|
||||
nextAutoCheckMs = now + 4500;
|
||||
refreshData(false);
|
||||
if (status.slots[0].needsPin() || status.slots[0].needsPuk() ||
|
||||
status.slots[1].needsPin() || status.slots[1].needsPuk() ||
|
||||
status.mmState == "locked") {
|
||||
if (anySimNeedsUnlock()) {
|
||||
autoCheckStage = 2;
|
||||
showWindow("unlock");
|
||||
} else if ((status.slots[0].state == "present" ||
|
||||
|
||||
Reference in new issue
Block a user