Add Dual-SIM Dual Standby (DSDS), outgoing SIM selection, and instant charging icon update
This commit is contained in:
1 parent
5132deb4d8
commit
46f1255905
28 files changed
+2560
-280
No files matched your search
@@ -165,6 +165,7 @@ enum class CallState {
|
||||
Outgoing = 2,
|
||||
Active = 3,
|
||||
Ended = 4,
|
||||
SelectSim = 5,
|
||||
};
|
||||
|
||||
std::string formatTimerSec(int totalSec) {
|
||||
@@ -435,6 +436,8 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
std::string callId;
|
||||
std::string callNumber;
|
||||
std::string contactName;
|
||||
int activeSimSlot = 0;
|
||||
DualSimInfo simInfo = queryDualSimInfo();
|
||||
std::string endReason = "CALL ENDED";
|
||||
std::string statusNotice;
|
||||
int64_t statusNoticeUntilMs = 0;
|
||||
@@ -737,19 +740,27 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
XftColor* stateCol = &colBlue;
|
||||
unsigned long stateAccentPx = theme.spec.accent;
|
||||
|
||||
if (callState == CallState::Incoming) {
|
||||
std::string simTag = (activeSimSlot == 1 || activeSimSlot == 2)
|
||||
? (" [SIM " + std::to_string(activeSimSlot) + "]")
|
||||
: "";
|
||||
if (callState == CallState::SelectSim) {
|
||||
stateIcon = kIconOutCall;
|
||||
stateBadge = "SELECT SIM CARD";
|
||||
stateCol = &colYellow;
|
||||
stateAccentPx = theme.spec.accent;
|
||||
} else if (callState == CallState::Incoming) {
|
||||
stateIcon = ringMuted ? kIconSoundOff : kIconInCall;
|
||||
stateBadge = ringMuted ? "RING SILENCED" : "INCOMING CALL";
|
||||
stateBadge = (ringMuted ? "RING SILENCED" : "INCOMING") + simTag;
|
||||
stateCol = ringMuted ? &colYellow : &colGreen;
|
||||
stateAccentPx = theme.spec.accent;
|
||||
} else if (callState == CallState::Outgoing) {
|
||||
stateIcon = kIconOutCall;
|
||||
stateBadge = "DIALING...";
|
||||
stateBadge = "DIALING" + simTag + "...";
|
||||
stateCol = &colYellow;
|
||||
stateAccentPx = theme.spec.accent;
|
||||
} else if (callState == CallState::Active) {
|
||||
stateIcon = kIconPhone;
|
||||
stateBadge = "IN CALL";
|
||||
stateBadge = "IN CALL" + simTag;
|
||||
stateCol = &colGreen;
|
||||
stateAccentPx = theme.spec.accent;
|
||||
} else if (callState == CallState::Ended) {
|
||||
@@ -760,15 +771,17 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
drawPango(layoutIcon, stateCol, 8, 3, 22, stateIcon);
|
||||
drawPango(layoutSmall, stateCol, 28, 3, 22, stateBadge, 138);
|
||||
drawPango(layoutSmall, stateCol, 28, 3, 22, stateBadge, 148);
|
||||
|
||||
int elapsedSec = 0;
|
||||
if (callState == CallState::Ended) {
|
||||
elapsedSec = lastFinalDurationSec;
|
||||
} else if (callStartMs > 0 && callState != CallState::Idle) {
|
||||
} else if (callStartMs > 0 && callState != CallState::Idle &&
|
||||
callState != CallState::SelectSim) {
|
||||
elapsedSec = static_cast<int>((now - callStartMs) / 1000);
|
||||
}
|
||||
if (callState != CallState::Idle || elapsedSec > 0) {
|
||||
if ((callState != CallState::Idle && callState != CallState::SelectSim) ||
|
||||
elapsedSec > 0) {
|
||||
std::string timerStr = formatTimerSec(elapsedSec);
|
||||
int tw = pangoWidth(layoutMain, timerStr);
|
||||
drawPango(layoutMain,
|
||||
@@ -819,6 +832,9 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
} else if (dtmfMode) {
|
||||
std::string dtmfLabel = "DTMF (0-9/*/#): " + (dtmfSent.empty() ? "_" : dtmfSent);
|
||||
drawPango(layoutSmall, &colYellow, 8, 88, 26, dtmfLabel, 224);
|
||||
} else if (callState == CallState::SelectSim) {
|
||||
drawPango(layoutSmall, &colYellow, 8, 88, 26,
|
||||
"[1/2] Choose SIM [OK/Call] Dial", 224);
|
||||
} else if (callState == CallState::Incoming) {
|
||||
drawPango(layoutSmall, &colLight, 8, 88, 26,
|
||||
"[Call] Answer [*] Mute [End] Reject", 224);
|
||||
@@ -843,7 +859,51 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
XFillRectangle(dpy, pix, gc, 0, kHeaderH - 2, kWinWidth, 2);
|
||||
|
||||
// 2. Body Area (kBodyY..kBodyY+kBodyH)
|
||||
if (callState == CallState::Incoming) {
|
||||
if (callState == CallState::SelectSim) {
|
||||
constexpr int kSimRows = 2;
|
||||
for (int i = 0; i < kSimRows; ++i) {
|
||||
int slotNum = i + 1;
|
||||
int ry = kBodyY + (i * kBodyH) / kSimRows;
|
||||
int nextRy = kBodyY + ((i + 1) * kBodyH) / kSimRows;
|
||||
int rowH = nextRy - ry;
|
||||
bool isSel = (selectedRow == i);
|
||||
bool isPref = (simInfo.preferredSlot == slotNum);
|
||||
|
||||
XSetForeground(dpy, gc,
|
||||
isSel ? theme.spec.selBg
|
||||
: ((i % 2 == 0) ? theme.spec.bgAltEven : theme.spec.bgAltOdd));
|
||||
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH);
|
||||
if (isSel) {
|
||||
XSetForeground(dpy, gc, theme.spec.accent);
|
||||
XFillRectangle(dpy, pix, gc, 0, ry, 4, rowH);
|
||||
}
|
||||
|
||||
std::string op = (slotNum == 1) ? simInfo.slot1Operator : simInfo.slot2Operator;
|
||||
std::string rat = (slotNum == 1) ? simInfo.slot1Rat : simInfo.slot2Rat;
|
||||
std::string msisdn = (slotNum == 1) ? simInfo.slot1Number : simInfo.slot2Number;
|
||||
|
||||
std::string title = "[" + std::to_string(slotNum) + "] SIM " + std::to_string(slotNum);
|
||||
if (!op.empty()) {
|
||||
title += " - " + op;
|
||||
}
|
||||
if (!rat.empty()) {
|
||||
title += " (" + rat + ")";
|
||||
}
|
||||
std::string subLine = msisdn.empty()
|
||||
? (isPref ? "Primary / Default SIM" : "Standby SIM")
|
||||
: msisdn;
|
||||
std::string badge = isPref ? "DEFAULT" : "STANDBY";
|
||||
int bw = pangoWidth(layoutSmall, badge);
|
||||
|
||||
drawPango(layoutIcon, isSel ? &colGreen : &colBlue, 10, ry, rowH, kIconPhone);
|
||||
drawPango(layoutMain, isSel ? &colWhite : &colLight, 34, ry + 12, 24,
|
||||
title, std::max(80, kWinWidth - bw - 48));
|
||||
drawPango(layoutSmall, isSel ? &colYellow : &colMuted, 34, ry + 38, 20,
|
||||
subLine, std::max(80, kWinWidth - 44));
|
||||
drawPango(layoutSmall, isPref ? &colGreen : &colMuted,
|
||||
kWinWidth - bw - 8, ry + 12, 24, badge);
|
||||
}
|
||||
} else if (callState == CallState::Incoming) {
|
||||
struct IncomingAction {
|
||||
const char* icon;
|
||||
const char* title;
|
||||
@@ -977,7 +1037,14 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
XftColor* centerCol = &colGreen;
|
||||
XftColor* rightCol = &colRed;
|
||||
|
||||
if (callState == CallState::Incoming) {
|
||||
if (callState == CallState::SelectSim) {
|
||||
leftLabel = "Dial";
|
||||
centerLabel = (selectedRow == 1) ? "CALL SIM 2" : "CALL SIM 1";
|
||||
rightLabel = "Cancel";
|
||||
leftCol = &colGreen;
|
||||
centerCol = &colGreen;
|
||||
rightCol = &colRed;
|
||||
} else if (callState == CallState::Incoming) {
|
||||
leftLabel = "Accept";
|
||||
centerLabel = "ANSWER";
|
||||
rightLabel = "Reject";
|
||||
@@ -1098,14 +1165,18 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
size_t dot = name.find('.');
|
||||
if (dot != std::string::npos && dot > 0) {
|
||||
std::string candidate = name.substr(0, dot);
|
||||
bool allDigits = true;
|
||||
for (char c : candidate) {
|
||||
if (!std::isdigit(static_cast<unsigned char>(c))) {
|
||||
allDigits = false;
|
||||
break;
|
||||
bool validId = (candidate.rfind("sub1_", 0) == 0 ||
|
||||
candidate.rfind("sub0_", 0) == 0);
|
||||
if (!validId) {
|
||||
validId = !candidate.empty();
|
||||
for (char c : candidate) {
|
||||
if (!std::isdigit(static_cast<unsigned char>(c))) {
|
||||
validId = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allDigits) {
|
||||
if (validId) {
|
||||
::closedir(d);
|
||||
callId = candidate;
|
||||
return callId;
|
||||
@@ -1200,11 +1271,19 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
std::string cid = resolveActiveModemCallId();
|
||||
if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") {
|
||||
char cmd[160];
|
||||
std::snprintf(cmd, sizeof(cmd),
|
||||
"mmcli -m any -o '%s' --send-dtmf='%c' >/dev/null 2>&1",
|
||||
cid.c_str(), ch);
|
||||
runAsyncCmd(cmd);
|
||||
if (cid.rfind("sub", 0) == 0) {
|
||||
char cmd[160];
|
||||
std::snprintf(cmd, sizeof(cmd),
|
||||
"doas -n /usr/libexec/msm-modem-uim-selection call-dtmf '%c' >/dev/null 2>&1",
|
||||
ch);
|
||||
runAsyncCmd(cmd);
|
||||
} else {
|
||||
char cmd[160];
|
||||
std::snprintf(cmd, sizeof(cmd),
|
||||
"mmcli -m any -o '%s' --send-dtmf='%c' >/dev/null 2>&1",
|
||||
cid.c_str(), ch);
|
||||
runAsyncCmd(cmd);
|
||||
}
|
||||
}
|
||||
render();
|
||||
};
|
||||
@@ -1343,7 +1422,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (line == "HANGUP") {
|
||||
if (line == "HANGUP" || line.rfind("HANGUP ", 0) == 0) {
|
||||
if (callState == CallState::Incoming || callState == CallState::Outgoing ||
|
||||
callState == CallState::Active) {
|
||||
hangupCall();
|
||||
@@ -1376,21 +1455,51 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse INCOMING / OUTGOING / ACTIVE / OPEN
|
||||
// Parse PROMPT_SIM / INCOMING / OUTGOING / ACTIVE / OPEN
|
||||
std::istringstream iss(line);
|
||||
std::string verb, arg1, arg2;
|
||||
iss >> verb >> arg1 >> arg2;
|
||||
std::string verb, arg1, arg2, arg3;
|
||||
iss >> verb >> arg1 >> arg2 >> arg3;
|
||||
|
||||
if (verb == "PROMPT_SIM") {
|
||||
simInfo = queryDualSimInfo(true);
|
||||
callId = "-";
|
||||
callNumber.clear();
|
||||
contactName.clear();
|
||||
updateCallerDetails("-", arg1);
|
||||
callState = CallState::SelectSim;
|
||||
selectedRow = (simInfo.preferredSlot == 2) ? 1 : 0;
|
||||
activeSimSlot = 0;
|
||||
writeActiveStateFiles();
|
||||
showWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
if (verb == "OPEN" && !arg1.empty()) {
|
||||
std::string low = toLowerStr(arg1);
|
||||
if (low == "incoming" || low == "outgoing" || low == "active") {
|
||||
verb = (low == "incoming") ? "INCOMING" : ((low == "outgoing") ? "OUTGOING" : "ACTIVE");
|
||||
arg1 = arg2.empty() ? "-" : arg2;
|
||||
arg2.clear();
|
||||
iss >> arg2;
|
||||
arg2 = arg3;
|
||||
arg3.clear();
|
||||
iss >> arg3;
|
||||
}
|
||||
}
|
||||
|
||||
auto parseSimTag = [&](const std::string& cidStr, const std::string& tagStr) {
|
||||
simInfo = queryDualSimInfo();
|
||||
if (tagStr == "SIM1") {
|
||||
activeSimSlot = 1;
|
||||
} else if (tagStr == "SIM2") {
|
||||
activeSimSlot = 2;
|
||||
} else if (cidStr.rfind("sub1_", 0) == 0) {
|
||||
activeSimSlot = (simInfo.secondaryGwSlot > 0) ? simInfo.secondaryGwSlot : 1;
|
||||
} else if (simInfo.dualSimActive) {
|
||||
activeSimSlot = (simInfo.primaryGwSlot > 0) ? simInfo.primaryGwSlot : simInfo.preferredSlot;
|
||||
} else {
|
||||
activeSimSlot = 0;
|
||||
}
|
||||
};
|
||||
|
||||
if (verb == "INCOMING") {
|
||||
callId.clear();
|
||||
callNumber.clear();
|
||||
@@ -1400,6 +1509,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
lastRecordedSec = 0;
|
||||
recordedClipCount = 0;
|
||||
updateCallerDetails(arg1, arg2);
|
||||
parseSimTag(arg1, arg3);
|
||||
callState = CallState::Incoming;
|
||||
callStartMs = nowMs();
|
||||
ringMuted = false;
|
||||
@@ -1418,6 +1528,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
lastRecordedSec = 0;
|
||||
recordedClipCount = 0;
|
||||
updateCallerDetails(arg1, arg2);
|
||||
parseSimTag(arg1, arg3);
|
||||
callState = CallState::Outgoing;
|
||||
callStartMs = nowMs();
|
||||
ringMuted = false;
|
||||
@@ -1434,6 +1545,9 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
bool wasActive = (callState == CallState::Active);
|
||||
bool wasOutgoing = (callState == CallState::Outgoing);
|
||||
updateCallerDetails(arg1, arg2);
|
||||
if (!arg3.empty() || activeSimSlot == 0) {
|
||||
parseSimTag(arg1, arg3);
|
||||
}
|
||||
callState = CallState::Active;
|
||||
if (!wasActive) {
|
||||
callStartMs = nowMs();
|
||||
@@ -1463,6 +1577,16 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
handleFifoCommand(forwardedCmd);
|
||||
}
|
||||
|
||||
auto startDialOnSim = [&](int chosenSim) {
|
||||
std::string num = normalizePhone(callNumber);
|
||||
if (num.empty()) {
|
||||
return;
|
||||
}
|
||||
std::string simStr = (chosenSim == 2) ? "2" : "1";
|
||||
handleFifoCommand("OUTGOING - " + num + " SIM" + simStr);
|
||||
runAsyncArgv("sxmo_modemdial.sh", "--sim", simStr.c_str(), num.c_str());
|
||||
};
|
||||
|
||||
int xfd = ConnectionNumber(dpy);
|
||||
|
||||
while (gRunning) {
|
||||
@@ -1553,8 +1677,9 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Physical Red End / Power button or Escape
|
||||
if (sym == XK_Escape || sym == XF86XK_PowerOff || kc == 124) {
|
||||
// Physical Red End / Power button or Escape / BackSpace in SelectSim
|
||||
if (sym == XK_Escape || sym == XF86XK_PowerOff || kc == 124 ||
|
||||
(callState == CallState::SelectSim && sym == XK_BackSpace)) {
|
||||
writeSoftkeySuppress(nowMs() + 350);
|
||||
if (callState == CallState::Incoming || callState == CallState::Outgoing ||
|
||||
callState == CallState::Active) {
|
||||
@@ -1572,7 +1697,10 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
if (nowMs() < startupIgnoreUntilMs) {
|
||||
continue;
|
||||
}
|
||||
if (callState == CallState::Incoming) {
|
||||
if (callState == CallState::SelectSim) {
|
||||
int chosenSim = (selectedRow == 1) ? 2 : 1;
|
||||
startDialOnSim(chosenSim);
|
||||
} else if (callState == CallState::Incoming) {
|
||||
acceptIncomingCall();
|
||||
} else if (callState == CallState::Ended) {
|
||||
callState = CallState::Idle;
|
||||
@@ -1591,6 +1719,16 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
// Keypad digits 0-9 / * / #
|
||||
char dialCh = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (dialCh != '\0') {
|
||||
if (callState == CallState::SelectSim) {
|
||||
if (dialCh == '1') {
|
||||
selectedRow = 0;
|
||||
startDialOnSim(1);
|
||||
} else if (dialCh == '2') {
|
||||
selectedRow = 1;
|
||||
startDialOnSim(2);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (callState == CallState::Incoming) {
|
||||
if (dialCh == '*' || dialCh == '0') {
|
||||
silenceRing();
|
||||
@@ -1635,14 +1773,18 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
switch (sym) {
|
||||
case XK_Up:
|
||||
case XK_KP_Up: {
|
||||
int maxRows = (callState == CallState::Incoming) ? 3 : 4;
|
||||
int maxRows = (callState == CallState::SelectSim)
|
||||
? 2
|
||||
: ((callState == CallState::Incoming) ? 3 : 4);
|
||||
selectedRow = (selectedRow + maxRows - 1) % maxRows;
|
||||
render();
|
||||
break;
|
||||
}
|
||||
case XK_Down:
|
||||
case XK_KP_Down: {
|
||||
int maxRows = (callState == CallState::Incoming) ? 3 : 4;
|
||||
int maxRows = (callState == CallState::SelectSim)
|
||||
? 2
|
||||
: ((callState == CallState::Incoming) ? 3 : 4);
|
||||
selectedRow = (selectedRow + 1) % maxRows;
|
||||
render();
|
||||
break;
|
||||
@@ -1650,7 +1792,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
case XK_Left:
|
||||
case XK_KP_Left:
|
||||
case XF86XK_AudioLowerVolume:
|
||||
if (callState != CallState::Incoming) {
|
||||
if (callState != CallState::Incoming && callState != CallState::SelectSim) {
|
||||
adjustVolume(-5);
|
||||
selectedRow = 3;
|
||||
render();
|
||||
@@ -1659,7 +1801,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
case XK_Right:
|
||||
case XK_KP_Right:
|
||||
case XF86XK_AudioRaiseVolume:
|
||||
if (callState != CallState::Incoming) {
|
||||
if (callState != CallState::Incoming && callState != CallState::SelectSim) {
|
||||
adjustVolume(+5);
|
||||
selectedRow = 3;
|
||||
render();
|
||||
@@ -1670,7 +1812,10 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
if (nowMs() < startupIgnoreUntilMs) {
|
||||
break;
|
||||
}
|
||||
if (callState == CallState::Incoming) {
|
||||
if (callState == CallState::SelectSim) {
|
||||
int chosenSim = (selectedRow == 1) ? 2 : 1;
|
||||
startDialOnSim(chosenSim);
|
||||
} else if (callState == CallState::Incoming) {
|
||||
if (selectedRow == 0) {
|
||||
acceptIncomingCall();
|
||||
} else if (selectedRow == 1) {
|
||||
@@ -1712,7 +1857,10 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
runAsyncArgv("xdrawer");
|
||||
}
|
||||
} else if (comb == 1) {
|
||||
if (callState == CallState::Incoming) {
|
||||
if (callState == CallState::SelectSim) {
|
||||
int chosenSim = (selectedRow == 1) ? 2 : 1;
|
||||
startDialOnSim(chosenSim);
|
||||
} else if (callState == CallState::Incoming) {
|
||||
acceptIncomingCall();
|
||||
} else if (callState == CallState::Outgoing || callState == CallState::Active) {
|
||||
dtmfMode = !dtmfMode;
|
||||
|
||||
@@ -129,9 +129,13 @@ int dialer_run_main(int argc, char** argv) {
|
||||
Inactive = 0,
|
||||
Imei = 1,
|
||||
Ussd = 2,
|
||||
SelectSim = 3,
|
||||
};
|
||||
DialerModal modal = DialerModal::Inactive;
|
||||
DeviceImeis deviceImeis;
|
||||
DualSimInfo simInfo;
|
||||
int ussdSimSlot = 1;
|
||||
int simPickIdx = 0;
|
||||
std::string ussdCode;
|
||||
std::string ussdResponse;
|
||||
std::string ussdReplyInput;
|
||||
@@ -420,6 +424,38 @@ int dialer_run_main(int argc, char** argv) {
|
||||
centerLabel = "OK";
|
||||
rightLabel = "Close";
|
||||
}
|
||||
} else if (modal == DialerModal::SelectSim) {
|
||||
XSetForeground(dpy, gc, theme.spec.bgOverlay);
|
||||
XFillRectangle(dpy, pix, gc, 12, 34, kWinWidth - 24, 178);
|
||||
XSetForeground(dpy, gc, theme.spec.accent);
|
||||
XDrawRectangle(dpy, pix, gc, 12, 34, kWinWidth - 25, 177);
|
||||
|
||||
drawPango(layoutMain, &colYellow, 20, 40, 24,
|
||||
"Select SIM for " + ussdCode, kWinWidth - 40);
|
||||
XSetForeground(dpy, gc, theme.spec.divider);
|
||||
XFillRectangle(dpy, pix, gc, 18, 66, kWinWidth - 36, 1);
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
int slotNum = i + 1;
|
||||
int ry = 74 + i * 64;
|
||||
bool isSel = (simPickIdx == i);
|
||||
XSetForeground(dpy, gc, isSel ? theme.spec.selBg : theme.spec.bgAltEven);
|
||||
XFillRectangle(dpy, pix, gc, 18, ry, kWinWidth - 36, 56);
|
||||
if (isSel) {
|
||||
XSetForeground(dpy, gc, theme.spec.accent);
|
||||
XFillRectangle(dpy, pix, gc, 18, ry, 4, 56);
|
||||
}
|
||||
std::string lbl = (slotNum == 1) ? simInfo.slot1Label : simInfo.slot2Label;
|
||||
std::string msisdn = (slotNum == 1) ? simInfo.slot1Number : simInfo.slot2Number;
|
||||
drawPango(layoutMain, isSel ? &colWhite : &colLight, 28, ry + 6, 22,
|
||||
"[" + std::to_string(slotNum) + "] " + lbl, kWinWidth - 54);
|
||||
drawPango(layoutSmall, isSel ? &colYellow : &colMuted, 28, ry + 30, 18,
|
||||
msisdn.empty() ? ((simInfo.preferredSlot == slotNum) ? "Default SIM" : "Standby SIM") : msisdn,
|
||||
kWinWidth - 54);
|
||||
}
|
||||
leftLabel = "Send";
|
||||
centerLabel = (simPickIdx == 1) ? "SIM 2" : "SIM 1";
|
||||
rightLabel = "Cancel";
|
||||
}
|
||||
|
||||
drawPango(layoutMain, &colLight, 6, sbY + 1, kSoftbarH - 1, leftLabel);
|
||||
@@ -456,16 +492,31 @@ int dialer_run_main(int argc, char** argv) {
|
||||
render();
|
||||
};
|
||||
|
||||
auto executeUssd = [&](const std::string& codeOrReply, bool isReply) {
|
||||
auto executeUssd = [&](const std::string& codeOrReply, bool isReply,
|
||||
int chosenSim = 0) {
|
||||
if (chosenSim == 1 || chosenSim == 2) {
|
||||
ussdSimSlot = chosenSim;
|
||||
} else if (!isReply) {
|
||||
simInfo = queryDualSimInfo(true);
|
||||
if (simInfo.dualSimActive) {
|
||||
ussdCode = codeOrReply;
|
||||
simPickIdx = (simInfo.preferredSlot == 2) ? 1 : 0;
|
||||
modal = DialerModal::SelectSim;
|
||||
render();
|
||||
return;
|
||||
}
|
||||
ussdSimSlot = (simInfo.primaryGwSlot == 2) ? 2 : 1;
|
||||
}
|
||||
modal = DialerModal::Ussd;
|
||||
if (!isReply || isUssdCode(codeOrReply)) {
|
||||
ussdCode = codeOrReply;
|
||||
}
|
||||
ussdScrollLine = 0;
|
||||
ussdResponse = "Sending USSD " + codeOrReply + "...";
|
||||
ussdResponse = "Sending USSD " + codeOrReply + " [SIM " +
|
||||
std::to_string(ussdSimSlot) + "]...";
|
||||
ussdReplyInput.clear();
|
||||
render();
|
||||
ussdResponse = sendModemUssd(codeOrReply, isReply, &ussdSessionActive);
|
||||
ussdResponse = sendModemUssd(codeOrReply, isReply, &ussdSessionActive, ussdSimSlot);
|
||||
if (visible) {
|
||||
XRaiseWindow(dpy, win);
|
||||
grabPluginKeyboard(dpy, win);
|
||||
@@ -682,6 +733,27 @@ int dialer_run_main(int argc, char** argv) {
|
||||
|
||||
char dialCh = mapDialKey(sym, ev.xkey.keycode, ev.xkey.state);
|
||||
|
||||
if (modal == DialerModal::SelectSim) {
|
||||
if (dialCh == '1') {
|
||||
simPickIdx = 0;
|
||||
executeUssd(ussdCode, false, 1);
|
||||
} else if (dialCh == '2') {
|
||||
simPickIdx = 1;
|
||||
executeUssd(ussdCode, false, 2);
|
||||
} else if (sym == XK_Up || sym == XK_KP_Up || sym == XK_Down || sym == XK_KP_Down) {
|
||||
simPickIdx = 1 - simPickIdx;
|
||||
render();
|
||||
} else if (sym == XK_Return || sym == XK_KP_Enter ||
|
||||
sym == XF86XK_Phone || sym == XF86XK_PickupPhone ||
|
||||
sym == XF86XK_Send) {
|
||||
executeUssd(ussdCode, false, (simPickIdx == 1) ? 2 : 1);
|
||||
} else if (sym == XK_Escape || sym == XK_BackSpace) {
|
||||
modal = DialerModal::Inactive;
|
||||
render();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (modal == DialerModal::Imei) {
|
||||
if (sym == XK_Return || sym == XK_KP_Enter || sym == XK_Escape ||
|
||||
sym == XK_BackSpace || sym == XF86XK_Phone ||
|
||||
@@ -846,8 +918,8 @@ int dialer_run_main(int argc, char** argv) {
|
||||
executeUssd(target, false);
|
||||
} else {
|
||||
writeSoftkeySuppress(nowMs() + 350);
|
||||
hideWindow(true);
|
||||
placePhoneCall(target);
|
||||
hideWindow(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -869,7 +941,9 @@ int dialer_run_main(int argc, char** argv) {
|
||||
runAsyncArgv("xdrawer");
|
||||
}
|
||||
} else if (comb == 1) {
|
||||
if (modal == DialerModal::Imei) {
|
||||
if (modal == DialerModal::SelectSim) {
|
||||
executeUssd(ussdCode, false, (simPickIdx == 1) ? 2 : 1);
|
||||
} else if (modal == DialerModal::Imei) {
|
||||
modal = DialerModal::Inactive;
|
||||
render();
|
||||
} else if (modal == DialerModal::Ussd) {
|
||||
@@ -900,7 +974,10 @@ int dialer_run_main(int argc, char** argv) {
|
||||
render();
|
||||
}
|
||||
} else if (comb == 2) {
|
||||
if (modal == DialerModal::Imei) {
|
||||
if (modal == DialerModal::SelectSim) {
|
||||
modal = DialerModal::Inactive;
|
||||
render();
|
||||
} else if (modal == DialerModal::Imei) {
|
||||
modal = DialerModal::Inactive;
|
||||
render();
|
||||
} else if (modal == DialerModal::Ussd) {
|
||||
|
||||
@@ -56,8 +56,14 @@ struct SimSlotInfo {
|
||||
std::string upinState = "not-initialized";
|
||||
int upinRetries = 0;
|
||||
int upukRetries = 0;
|
||||
std::string regState;
|
||||
std::string operatorName;
|
||||
std::string rat;
|
||||
std::string phoneNumber;
|
||||
int rssi = 0;
|
||||
|
||||
bool isActiveProvisioned = false;
|
||||
bool isSecondaryProvisioned = false;
|
||||
bool isPreferred = false;
|
||||
|
||||
bool needsPin() const {
|
||||
@@ -84,6 +90,8 @@ struct ModemStatusData {
|
||||
bool qmiAvailable = false;
|
||||
int preferredSlot = 1;
|
||||
int primaryGwSlot = 0;
|
||||
int secondaryGwSlot = 0;
|
||||
bool dualSimActive = false;
|
||||
SimSlotInfo slots[2];
|
||||
|
||||
bool mmPresent = false;
|
||||
@@ -261,6 +269,10 @@ ModemStatusData queryModemAndSimStatus() {
|
||||
if (!uimKv["PRIMARY_GW_SLOT"].empty()) {
|
||||
d.primaryGwSlot = std::atoi(uimKv["PRIMARY_GW_SLOT"].c_str());
|
||||
}
|
||||
if (!uimKv["SECONDARY_GW_SLOT"].empty()) {
|
||||
d.secondaryGwSlot = std::atoi(uimKv["SECONDARY_GW_SLOT"].c_str());
|
||||
}
|
||||
d.dualSimActive = (uimKv["DUAL_SIM_ACTIVE"] == "1");
|
||||
d.nasRegState = uimKv["NAS_REG_STATE"];
|
||||
d.nasOperator = uimKv["NAS_OPERATOR"];
|
||||
d.nasMcc = uimKv["NAS_MCC"];
|
||||
@@ -291,7 +303,15 @@ ModemStatusData queryModemAndSimStatus() {
|
||||
if (!uimKv[pfx + "UPUK_RETRIES"].empty()) {
|
||||
s.upukRetries = std::atoi(uimKv[pfx + "UPUK_RETRIES"].c_str());
|
||||
}
|
||||
s.regState = uimKv[pfx + "REG_STATE"];
|
||||
s.operatorName = uimKv[pfx + "OPERATOR"];
|
||||
s.rat = uimKv[pfx + "RAT"];
|
||||
s.phoneNumber = uimKv[pfx + "NUMBER"];
|
||||
if (!uimKv[pfx + "RSSI"].empty()) {
|
||||
s.rssi = std::atoi(uimKv[pfx + "RSSI"].c_str());
|
||||
}
|
||||
s.isActiveProvisioned = (d.primaryGwSlot == (i + 1));
|
||||
s.isSecondaryProvisioned = (d.secondaryGwSlot == (i + 1));
|
||||
s.isPreferred = (d.preferredSlot == (i + 1));
|
||||
}
|
||||
|
||||
@@ -740,8 +760,13 @@ int runModemApp(int argc, char** argv) {
|
||||
10, cardY + 2, 22, kIconSim);
|
||||
|
||||
std::string title = "SIM Slot " + std::to_string(s.slotNum);
|
||||
if (s.isActiveProvisioned) {
|
||||
if (status.dualSimActive &&
|
||||
(s.isActiveProvisioned || s.isSecondaryProvisioned)) {
|
||||
title += s.isPreferred ? " [ACTIVE / DEFAULT]" : " [ACTIVE / DSDS]";
|
||||
} else if (s.isActiveProvisioned) {
|
||||
title += " [ACTIVE]";
|
||||
} else if (s.isSecondaryProvisioned) {
|
||||
title += " [DSDS STANDBY]";
|
||||
} else if (s.isPreferred) {
|
||||
title += " [PREF]";
|
||||
}
|
||||
@@ -759,20 +784,40 @@ int runModemApp(int argc, char** argv) {
|
||||
line2Col = &colOrange;
|
||||
} else if (s.isActiveProvisioned) {
|
||||
std::string reg = status.regStatusLabel();
|
||||
if (!status.operatorName.empty()) {
|
||||
reg += " - " + status.operatorName;
|
||||
std::string op = !s.operatorName.empty() ? s.operatorName : status.operatorName;
|
||||
std::string rat = !s.rat.empty() ? s.rat : status.accessTech;
|
||||
if (!op.empty()) {
|
||||
reg += " - " + op;
|
||||
}
|
||||
if (!status.accessTech.empty()) {
|
||||
reg += " [" + status.accessTech + "]";
|
||||
if (!rat.empty()) {
|
||||
reg += " [" + rat + "]";
|
||||
}
|
||||
line2 = reg;
|
||||
if (status.isNetworkRegistered()) {
|
||||
if (status.isNetworkRegistered() || s.regState == "registered") {
|
||||
line2Col = &colGreen;
|
||||
} else if (status.isNetworkSearching()) {
|
||||
} else if (status.isNetworkSearching() || s.regState == "searching") {
|
||||
line2Col = &colOrange;
|
||||
} else {
|
||||
line2Col = &colRed;
|
||||
}
|
||||
} else if (s.isSecondaryProvisioned || s.regState == "registered" ||
|
||||
s.regState == "searching") {
|
||||
if (s.regState == "registered") {
|
||||
line2 = "Registered (DSDS)";
|
||||
if (!s.operatorName.empty()) {
|
||||
line2 += " - " + s.operatorName;
|
||||
}
|
||||
if (!s.rat.empty()) {
|
||||
line2 += " [" + s.rat + "]";
|
||||
}
|
||||
line2Col = &colGreen;
|
||||
} else if (s.regState == "searching") {
|
||||
line2 = "Searching Network (DSDS)...";
|
||||
line2Col = &colOrange;
|
||||
} else {
|
||||
line2 = "Active Standby (" + s.appType + ")";
|
||||
line2Col = &colBlue;
|
||||
}
|
||||
} else if (status.primaryGwSlot == 0) {
|
||||
line2 = "Present (Unactivated - Press Select)";
|
||||
line2Col = &colOrange;
|
||||
@@ -796,8 +841,11 @@ int runModemApp(int argc, char** argv) {
|
||||
else if (pState == "blocked") pState = "PUK Req";
|
||||
line3 = pState + " (PIN:" + std::to_string(s.pin1Retries) +
|
||||
" PUK:" + std::to_string(s.puk1Retries) + ")";
|
||||
if (s.isActiveProvisioned && !status.ownNumber.empty()) {
|
||||
line3 += " " + status.ownNumber;
|
||||
std::string numStr = !s.phoneNumber.empty()
|
||||
? s.phoneNumber
|
||||
: (s.isActiveProvisioned ? status.ownNumber : "");
|
||||
if (!numStr.empty()) {
|
||||
line3 += " " + numStr;
|
||||
}
|
||||
} else {
|
||||
line3 = "Insert nano-SIM & restart/switch";
|
||||
@@ -820,7 +868,9 @@ int runModemApp(int argc, char** argv) {
|
||||
std::string(kIconRefresh) +
|
||||
(status.primaryGwSlot == 0
|
||||
? (" Activate SIM " + std::to_string(otherSlot))
|
||||
: (" Switch Active to SIM " + std::to_string(otherSlot))),
|
||||
: (status.dualSimActive
|
||||
? (" Set Default SIM to Slot " + std::to_string(otherSlot))
|
||||
: (" Switch Active to SIM " + std::to_string(otherSlot)))),
|
||||
std::string(kIconUnlock) + " Unlock SIM (PIN / PUK)",
|
||||
std::string(kIconLock) + " Enable / Disable SIM PIN",
|
||||
std::string(kIconKey) + " Change SIM PIN Code",
|
||||
@@ -1043,7 +1093,7 @@ int runModemApp(int argc, char** argv) {
|
||||
drawPango(layoutMain, &colYellow, 20, 48, 24, hdr, kWinWidth - 40);
|
||||
|
||||
const char* actLabels[5] = {
|
||||
"Set as Active SIM Slot",
|
||||
"Set as Default / Primary SIM",
|
||||
"Unlock SIM (Enter PIN)",
|
||||
"Unblock SIM (Enter PUK)",
|
||||
"Enable / Disable SIM PIN",
|
||||
@@ -1457,7 +1507,8 @@ int runModemApp(int argc, char** argv) {
|
||||
const auto& s = status.slots[row];
|
||||
if (s.needsPin() || s.needsPuk()) {
|
||||
openPinOrPukModalForSlot(sNum);
|
||||
} else if (s.state == "present" && !s.isActiveProvisioned) {
|
||||
} else if (s.state == "present" && !s.isActiveProvisioned &&
|
||||
!s.isSecondaryProvisioned) {
|
||||
switchSimSlotNow(sNum);
|
||||
} else {
|
||||
targetSlot = sNum;
|
||||
|
||||
@@ -1421,15 +1421,314 @@ inline bool clearCallLogFile(const std::string& logPath) {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void placePhoneCall(const std::string& rawNumber) {
|
||||
struct DualSimInfo {
|
||||
bool dualSimActive = false;
|
||||
bool slot1Present = false;
|
||||
bool slot2Present = false;
|
||||
int preferredSlot = 1;
|
||||
int primaryGwSlot = 1;
|
||||
int secondaryGwSlot = 0;
|
||||
std::string slot1Operator;
|
||||
std::string slot2Operator;
|
||||
std::string slot1Number;
|
||||
std::string slot2Number;
|
||||
std::string slot1Rat;
|
||||
std::string slot2Rat;
|
||||
std::string slot1Label;
|
||||
std::string slot2Label;
|
||||
std::string slot1Short;
|
||||
std::string slot2Short;
|
||||
};
|
||||
|
||||
inline DualSimInfo queryDualSimInfo(bool forceRefresh = false) {
|
||||
static DualSimInfo cached;
|
||||
static int64_t lastQueryMs = 0;
|
||||
int64_t now = nowMs();
|
||||
if (!forceRefresh && lastQueryMs > 0 && (now - lastQueryMs) < 3000) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
DualSimInfo info;
|
||||
{
|
||||
std::ifstream conf("/etc/conf.d/msm-modem-uim-selection");
|
||||
std::string line;
|
||||
while (std::getline(conf, line)) {
|
||||
if (line.rfind("preferred_sim_slot=", 0) == 0) {
|
||||
int v = std::atoi(line.c_str() + 19);
|
||||
if (v == 1 || v == 2) info.preferredSlot = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constexpr int kAfQipcrtr = 42;
|
||||
constexpr uint32_t kQrtrPortCtrl = 0xfffffffeu;
|
||||
constexpr uint32_t kQrtrTypeNewServer = 4;
|
||||
constexpr uint32_t kQrtrTypeNewLookup = 10;
|
||||
constexpr uint32_t kQmiServiceDms = 2;
|
||||
constexpr uint32_t kQmiServiceNas = 3;
|
||||
constexpr uint32_t kQmiServiceUim = 11;
|
||||
|
||||
struct SockAddrQrtr {
|
||||
unsigned short sq_family;
|
||||
uint32_t sq_node;
|
||||
uint32_t sq_port;
|
||||
};
|
||||
struct QrtrCtrlPkt {
|
||||
uint32_t cmd;
|
||||
uint32_t service;
|
||||
uint32_t instance;
|
||||
uint32_t node;
|
||||
uint32_t port;
|
||||
} __attribute__((packed));
|
||||
|
||||
auto lookupService = [&](uint32_t sid, uint32_t& outNode, uint32_t& outPort) -> bool {
|
||||
int fd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0) return false;
|
||||
SockAddrQrtr localSq {};
|
||||
socklen_t sl = sizeof(localSq);
|
||||
if (::getsockname(fd, reinterpret_cast<struct sockaddr*>(&localSq), &sl) < 0) {
|
||||
::close(fd);
|
||||
return false;
|
||||
}
|
||||
SockAddrQrtr ctrlSq { kAfQipcrtr, localSq.sq_node, kQrtrPortCtrl };
|
||||
QrtrCtrlPkt lookup { kQrtrTypeNewLookup, sid, 0, 0, 0 };
|
||||
if (::sendto(fd, &lookup, sizeof(lookup), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&ctrlSq),
|
||||
sizeof(ctrlSq)) < 0) {
|
||||
::close(fd);
|
||||
return false;
|
||||
}
|
||||
bool found = false;
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
struct pollfd pfd { fd, POLLIN, 0 };
|
||||
if (::poll(&pfd, 1, 40) <= 0) break;
|
||||
QrtrCtrlPkt pkt {};
|
||||
ssize_t n = ::recv(fd, &pkt, sizeof(pkt), 0);
|
||||
if (n >= static_cast<ssize_t>(sizeof(pkt)) && pkt.cmd == kQrtrTypeNewServer) {
|
||||
if (pkt.service == sid && pkt.port != 0) {
|
||||
outNode = pkt.node;
|
||||
outPort = pkt.port;
|
||||
found = true;
|
||||
}
|
||||
if (pkt.service == 0 && pkt.node == 0 && pkt.port == 0) break;
|
||||
}
|
||||
}
|
||||
::close(fd);
|
||||
return found;
|
||||
};
|
||||
|
||||
uint32_t uimNode = 0, uimPort = 0;
|
||||
if (lookupService(kQmiServiceUim, uimNode, uimPort)) {
|
||||
int sfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (sfd >= 0) {
|
||||
SockAddrQrtr uimSq { kAfQipcrtr, uimNode, uimPort };
|
||||
uint8_t req[7] = { 0x00, 0x01, 0x00, 0x2F, 0x00, 0x00, 0x00 };
|
||||
if (::sendto(sfd, req, sizeof(req), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&uimSq),
|
||||
sizeof(uimSq)) >= 0) {
|
||||
struct pollfd pfd { sfd, POLLIN, 0 };
|
||||
if (::poll(&pfd, 1, 60) > 0) {
|
||||
uint8_t buf[1024];
|
||||
ssize_t rlen = ::recv(sfd, buf, sizeof(buf), 0);
|
||||
if (rlen >= 7 && buf[0] == 0x02 && buf[3] == 0x2F) {
|
||||
size_t pos = 7;
|
||||
while (pos + 3 <= static_cast<size_t>(rlen)) {
|
||||
uint8_t tt = buf[pos];
|
||||
uint16_t tl = static_cast<uint16_t>(buf[pos + 1]) |
|
||||
(static_cast<uint16_t>(buf[pos + 2]) << 8);
|
||||
pos += 3;
|
||||
if (pos + tl > static_cast<size_t>(rlen)) break;
|
||||
if (tt == 0x10 && tl >= 9) {
|
||||
const uint8_t* p = buf + pos;
|
||||
uint16_t gwPri = static_cast<uint16_t>(p[0]) | (static_cast<uint16_t>(p[1]) << 8);
|
||||
uint16_t gwSec = static_cast<uint16_t>(p[4]) | (static_cast<uint16_t>(p[5]) << 8);
|
||||
if (gwPri != 0xFFFF) info.primaryGwSlot = ((gwPri >> 8) & 0xFF) + 1;
|
||||
if (gwSec != 0xFFFF) info.secondaryGwSlot = ((gwSec >> 8) & 0xFF) + 1;
|
||||
uint8_t numSlots = p[8];
|
||||
size_t off = 9;
|
||||
for (uint8_t s = 0; s < numSlots && s < 2; ++s) {
|
||||
if (off + 6 > tl) break;
|
||||
uint8_t cstate = p[off];
|
||||
if (s == 0) info.slot1Present = (cstate == 1);
|
||||
if (s == 1) info.slot2Present = (cstate == 1);
|
||||
uint8_t numApps = p[off + 5];
|
||||
off += 6;
|
||||
for (uint8_t a = 0; a < numApps; ++a) {
|
||||
if (off + 7 > tl) break;
|
||||
uint8_t aidLen = p[off + 6];
|
||||
if (off + 14 + aidLen > tl) break;
|
||||
off += 14 + aidLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
pos += tl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
::close(sfd);
|
||||
}
|
||||
}
|
||||
|
||||
info.dualSimActive = info.slot1Present && info.slot2Present &&
|
||||
(info.primaryGwSlot == 1 || info.primaryGwSlot == 2) &&
|
||||
(info.secondaryGwSlot == 1 || info.secondaryGwSlot == 2);
|
||||
|
||||
uint32_t nasNode = 0, nasPort = 0;
|
||||
uint32_t dmsNode = 0, dmsPort = 0;
|
||||
bool hasNas = lookupService(kQmiServiceNas, nasNode, nasPort);
|
||||
bool hasDms = lookupService(kQmiServiceDms, dmsNode, dmsPort);
|
||||
|
||||
auto querySubMeta = [&](int slot, int sub, std::string& outOp,
|
||||
std::string& outRat, std::string& outNum) {
|
||||
if (sub < 0) return;
|
||||
if (hasNas) {
|
||||
int sfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (sfd >= 0) {
|
||||
SockAddrQrtr nasSq { kAfQipcrtr, nasNode, nasPort };
|
||||
uint8_t bindReq[11] = {
|
||||
0x00, 0x01, 0x00, 0x45, 0x00, 0x04, 0x00,
|
||||
0x01, 0x01, 0x00, static_cast<uint8_t>(sub)
|
||||
};
|
||||
::sendto(sfd, bindReq, sizeof(bindReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&nasSq), sizeof(nasSq));
|
||||
struct pollfd pfd { sfd, POLLIN, 0 };
|
||||
if (::poll(&pfd, 1, 40) > 0) {
|
||||
uint8_t tmp[256];
|
||||
::recv(sfd, tmp, sizeof(tmp), 0);
|
||||
}
|
||||
uint8_t ssReq[7] = { 0x00, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00 };
|
||||
::sendto(sfd, ssReq, sizeof(ssReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&nasSq), sizeof(nasSq));
|
||||
if (::poll(&pfd, 1, 50) > 0) {
|
||||
uint8_t buf[1024];
|
||||
ssize_t rlen = ::recv(sfd, buf, sizeof(buf), 0);
|
||||
if (rlen >= 7 && buf[0] == 0x02 && buf[3] == 0x24) {
|
||||
size_t pos = 7;
|
||||
while (pos + 3 <= static_cast<size_t>(rlen)) {
|
||||
uint8_t tt = buf[pos];
|
||||
uint16_t tl = static_cast<uint16_t>(buf[pos + 1]) |
|
||||
(static_cast<uint16_t>(buf[pos + 2]) << 8);
|
||||
pos += 3;
|
||||
if (pos + tl > static_cast<size_t>(rlen)) break;
|
||||
if (tt == 0x01 && tl >= 5 && buf[pos + 3] >= 1) {
|
||||
uint8_t rb = buf[pos + 4];
|
||||
if (rb == 8) outRat = "4G";
|
||||
else if (rb == 5) outRat = "3G";
|
||||
else if (rb == 4) outRat = "2G";
|
||||
} else if (tt == 0x12 && tl >= 5) {
|
||||
uint8_t dlen = buf[pos + 4];
|
||||
if (5 + dlen <= tl && dlen > 0) {
|
||||
outOp.assign(reinterpret_cast<const char*>(buf + pos + 5), dlen);
|
||||
outOp = trimStr(outOp);
|
||||
}
|
||||
}
|
||||
pos += tl;
|
||||
}
|
||||
}
|
||||
}
|
||||
::close(sfd);
|
||||
}
|
||||
}
|
||||
if (hasDms) {
|
||||
int sfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (sfd >= 0) {
|
||||
SockAddrQrtr dmsSq { kAfQipcrtr, dmsNode, dmsPort };
|
||||
uint8_t bindReq[11] = {
|
||||
0x00, 0x01, 0x00, 0x54, 0x00, 0x04, 0x00,
|
||||
0x01, 0x01, 0x00, static_cast<uint8_t>(sub)
|
||||
};
|
||||
::sendto(sfd, bindReq, sizeof(bindReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&dmsSq), sizeof(dmsSq));
|
||||
struct pollfd pfd { sfd, POLLIN, 0 };
|
||||
if (::poll(&pfd, 1, 40) > 0) {
|
||||
uint8_t tmp[256];
|
||||
::recv(sfd, tmp, sizeof(tmp), 0);
|
||||
}
|
||||
uint8_t msReq[7] = { 0x00, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00 };
|
||||
::sendto(sfd, msReq, sizeof(msReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&dmsSq), sizeof(dmsSq));
|
||||
if (::poll(&pfd, 1, 50) > 0) {
|
||||
uint8_t buf[512];
|
||||
ssize_t rlen = ::recv(sfd, buf, sizeof(buf), 0);
|
||||
if (rlen >= 7 && buf[0] == 0x02 && buf[3] == 0x24) {
|
||||
size_t pos = 7;
|
||||
while (pos + 3 <= static_cast<size_t>(rlen)) {
|
||||
uint8_t tt = buf[pos];
|
||||
uint16_t tl = static_cast<uint16_t>(buf[pos + 1]) |
|
||||
(static_cast<uint16_t>(buf[pos + 2]) << 8);
|
||||
pos += 3;
|
||||
if (pos + tl > static_cast<size_t>(rlen)) break;
|
||||
if (tt == 0x01 && tl > 0) {
|
||||
std::string raw(reinterpret_cast<const char*>(buf + pos), tl);
|
||||
raw = trimStr(raw);
|
||||
if (!raw.empty()) {
|
||||
outNum = (raw.front() == '+') ? raw : ("+" + raw);
|
||||
}
|
||||
}
|
||||
pos += tl;
|
||||
}
|
||||
}
|
||||
}
|
||||
::close(sfd);
|
||||
}
|
||||
}
|
||||
(void)slot;
|
||||
};
|
||||
|
||||
int sub1 = (info.primaryGwSlot == 1) ? 0 : ((info.secondaryGwSlot == 1) ? 1 : -1);
|
||||
int sub2 = (info.primaryGwSlot == 2) ? 0 : ((info.secondaryGwSlot == 2) ? 1 : -1);
|
||||
querySubMeta(1, sub1, info.slot1Operator, info.slot1Rat, info.slot1Number);
|
||||
querySubMeta(2, sub2, info.slot2Operator, info.slot2Rat, info.slot2Number);
|
||||
|
||||
auto formatSlotStrings = [](int s, const std::string& op, const std::string& rat,
|
||||
const std::string& num, std::string& outLabel,
|
||||
std::string& outShort) {
|
||||
std::string base = "SIM " + std::to_string(s);
|
||||
outShort = op.empty() ? base : (base + " (" + op + ")");
|
||||
outLabel = base;
|
||||
if (!op.empty()) {
|
||||
outLabel += ": " + op;
|
||||
}
|
||||
if (!rat.empty()) {
|
||||
outLabel += " [" + rat + "]";
|
||||
}
|
||||
if (!num.empty()) {
|
||||
outLabel += " " + num;
|
||||
}
|
||||
};
|
||||
|
||||
formatSlotStrings(1, info.slot1Operator, info.slot1Rat, info.slot1Number,
|
||||
info.slot1Label, info.slot1Short);
|
||||
formatSlotStrings(2, info.slot2Operator, info.slot2Rat, info.slot2Number,
|
||||
info.slot2Label, info.slot2Short);
|
||||
|
||||
cached = info;
|
||||
lastQueryMs = now;
|
||||
return info;
|
||||
}
|
||||
|
||||
inline void placePhoneCall(const std::string& rawNumber, int simSlot = 0) {
|
||||
std::string num = normalizePhone(rawNumber);
|
||||
if (num.empty()) {
|
||||
return;
|
||||
}
|
||||
if (!sendPluginCommand("callscreen", "OUTGOING - " + num)) {
|
||||
if (simSlot == 0) {
|
||||
DualSimInfo dsi = queryDualSimInfo();
|
||||
if (dsi.dualSimActive) {
|
||||
if (!sendPluginCommand("callscreen", "PROMPT_SIM " + num)) {
|
||||
runAsyncArgv("sxmo_modemdial.sh", num.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
simSlot = (dsi.primaryGwSlot == 2) ? 2 : 1;
|
||||
}
|
||||
std::string simTag = "SIM" + std::to_string(simSlot);
|
||||
if (!sendPluginCommand("callscreen", "OUTGOING - " + num + " " + simTag)) {
|
||||
runAsyncArgv("xcallscreen", "outgoing", "-", num.c_str());
|
||||
}
|
||||
runAsyncArgv("sxmo_modemdial.sh", num.c_str());
|
||||
std::string simStr = std::to_string(simSlot);
|
||||
runAsyncArgv("sxmo_modemdial.sh", "--sim", simStr.c_str(), num.c_str());
|
||||
}
|
||||
|
||||
inline void closeOtherPlugins(const char* selfPluginName) {
|
||||
@@ -1940,11 +2239,11 @@ inline bool queryQrtrDmsImeis(DeviceImeis& out) {
|
||||
dmsSq.sq_node = dmsNode;
|
||||
dmsSq.sq_port = dmsPort;
|
||||
|
||||
// 1. QMI_DMS_BIND_SUBSCRIPTION (0x0057), TLV 0x01 = uint32_t(subType)
|
||||
// 1. QMI_DMS_BIND_SUBSCRIPTION (0x0054), TLV 0x01 = uint32_t(subType)
|
||||
if (subType > 0) {
|
||||
uint8_t bindReq[14] = {
|
||||
0x00, 0x01, 0x00, // flags=0 (req), txn_id=1
|
||||
0x57, 0x00, // msg_id = 0x0057
|
||||
0x54, 0x00, // msg_id = 0x0054
|
||||
0x07, 0x00, // tlv_len = 7
|
||||
0x01, 0x04, 0x00, // TLV 0x01, len 4
|
||||
static_cast<uint8_t>(subType & 0xFF), 0x00, 0x00, 0x00
|
||||
@@ -2049,16 +2348,20 @@ inline bool isUssdCode(const std::string& code) {
|
||||
|
||||
inline std::string sendModemUssd(const std::string& input,
|
||||
bool isReply = false,
|
||||
bool* outSessionActive = nullptr) {
|
||||
bool* outSessionActive = nullptr,
|
||||
int simSlot = 0) {
|
||||
if (outSessionActive) *outSessionActive = false;
|
||||
std::string clean = trimStr(input);
|
||||
if (clean.empty()) return "Empty USSD request.";
|
||||
|
||||
int rc = 0;
|
||||
std::string mode = (isReply && !isUssdCode(clean)) ? "respond" : "initiate";
|
||||
std::string simArg = (simSlot == 1 || simSlot == 2)
|
||||
? ("--sim " + std::to_string(simSlot) + " ")
|
||||
: "";
|
||||
std::string cmd =
|
||||
"doas -n /usr/libexec/msm-modem-uim-selection ussd " + mode + " " +
|
||||
shellQuote(clean) + " 2>&1";
|
||||
simArg + shellQuote(clean) + " 2>&1";
|
||||
|
||||
std::string out = trimStr(runCaptureCmd(cmd, &rc));
|
||||
if (out.empty()) {
|
||||
|
||||
+104
-13
@@ -30,6 +30,7 @@ enum class ViewMode {
|
||||
ConfirmDelete = 5,
|
||||
Blocklist = 6,
|
||||
AddBlock = 7,
|
||||
SelectSim = 8,
|
||||
};
|
||||
|
||||
enum class TextCaseMode {
|
||||
@@ -169,6 +170,8 @@ int runSmsApp(int argc, char** argv) {
|
||||
int selectedPicker = 0;
|
||||
int confirmSelected = 0;
|
||||
int blockSelected = 0;
|
||||
int simPickIdx = 0;
|
||||
DualSimInfo simInfo;
|
||||
std::string addBlockInput;
|
||||
|
||||
std::string activeNumber;
|
||||
@@ -341,13 +344,26 @@ int runSmsApp(int argc, char** argv) {
|
||||
};
|
||||
|
||||
auto startAsyncSendSms = [&](const std::string& rawRecipient,
|
||||
const std::string& body) {
|
||||
const std::string& body,
|
||||
int chosenSim = 0) {
|
||||
std::string recipient = normalizePhone(rawRecipient);
|
||||
if (recipient.empty() || trimStr(body).empty()) {
|
||||
statusBanner = "Set recipient and message";
|
||||
statusBannerUntilMs = nowMs() + 2000;
|
||||
return;
|
||||
}
|
||||
if (chosenSim == 0) {
|
||||
simInfo = queryDualSimInfo(false);
|
||||
if (simInfo.dualSimActive) {
|
||||
simPickIdx = (simInfo.preferredSlot == 2) ? 1 : 0;
|
||||
mode = ViewMode::SelectSim;
|
||||
return;
|
||||
}
|
||||
chosenSim = simInfo.preferredSlot;
|
||||
}
|
||||
if (chosenSim != 1 && chosenSim != 2) {
|
||||
chosenSim = 1;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(sendMutex);
|
||||
if (sendingInProgress) {
|
||||
@@ -356,12 +372,13 @@ int runSmsApp(int argc, char** argv) {
|
||||
sendingInProgress = true;
|
||||
}
|
||||
saveSmsDraft(recipient, body);
|
||||
statusBanner = "Sending SMS to " + recipient + "...";
|
||||
statusBanner = "Sending SMS (SIM " + std::to_string(chosenSim) + ") to " +
|
||||
recipient + "...";
|
||||
statusBannerUntilMs = nowMs() + 15000;
|
||||
|
||||
int writePipe = notifyPipe[1];
|
||||
std::thread([recipient, body, writePipe, &sendMutex, &sendingInProgress,
|
||||
&statusBanner, &statusBannerUntilMs]() {
|
||||
std::thread([recipient, body, chosenSim, writePipe, &sendMutex,
|
||||
&sendingInProgress, &statusBanner, &statusBannerUntilMs]() {
|
||||
std::string draftPath =
|
||||
getModemLogDirPath() + "/" + recipient + "/draft.txt";
|
||||
ContactBook::ensureParentDir(draftPath);
|
||||
@@ -370,6 +387,7 @@ int runSmsApp(int argc, char** argv) {
|
||||
out << body << "\n";
|
||||
}
|
||||
|
||||
std::string simStr = std::to_string(chosenSim);
|
||||
int rc = -1;
|
||||
pid_t pid = ::fork();
|
||||
if (pid == 0) {
|
||||
@@ -381,11 +399,11 @@ int runSmsApp(int argc, char** argv) {
|
||||
if (nullfd > 2) ::close(nullfd);
|
||||
}
|
||||
execlp("sxmo_modemsendsms.sh", "sxmo_modemsendsms.sh",
|
||||
recipient.c_str(), "-f", draftPath.c_str(),
|
||||
static_cast<char*>(nullptr));
|
||||
"--sim", simStr.c_str(), recipient.c_str(), "-f",
|
||||
draftPath.c_str(), static_cast<char*>(nullptr));
|
||||
execl("/usr/bin/sxmo_modemsendsms.sh", "sxmo_modemsendsms.sh",
|
||||
recipient.c_str(), "-f", draftPath.c_str(),
|
||||
static_cast<char*>(nullptr));
|
||||
"--sim", simStr.c_str(), recipient.c_str(), "-f",
|
||||
draftPath.c_str(), static_cast<char*>(nullptr));
|
||||
_exit(127);
|
||||
} else if (pid > 0) {
|
||||
int status = 0;
|
||||
@@ -411,12 +429,13 @@ int runSmsApp(int argc, char** argv) {
|
||||
ContactBook::ensureParentDir(smsPath);
|
||||
std::ofstream smsOut(smsPath, std::ios::app);
|
||||
if (smsOut.is_open()) {
|
||||
smsOut << "Sent at " << tbuf << ":\n" << body << "\n\n";
|
||||
smsOut << "Sent at " << tbuf << " [SIM " << chosenSim << "]:\n"
|
||||
<< body << "\n\n";
|
||||
}
|
||||
std::ofstream logOut(getModemLogFilePath(), std::ios::app);
|
||||
if (logOut.is_open()) {
|
||||
logOut << tbuf << "\tsent_txt\t" << recipient << "\t"
|
||||
<< body.size() << " chars\n";
|
||||
logOut << tbuf << "\tsent_txt\t" << recipient << "\t[SIM "
|
||||
<< chosenSim << "] " << body.size() << " chars\n";
|
||||
}
|
||||
removeSmsDraft(recipient);
|
||||
}
|
||||
@@ -424,7 +443,9 @@ int runSmsApp(int argc, char** argv) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(sendMutex);
|
||||
sendingInProgress = false;
|
||||
statusBanner = (rc == 0) ? "SMS Sent!" : "Saved to Sent (modem offline)";
|
||||
statusBanner = (rc == 0)
|
||||
? ("SMS Sent (SIM " + std::to_string(chosenSim) + ")!")
|
||||
: "Saved to Sent (modem offline)";
|
||||
statusBannerUntilMs = nowMs() + 2200;
|
||||
}
|
||||
if (writePipe >= 0) {
|
||||
@@ -944,6 +965,48 @@ int runSmsApp(int argc, char** argv) {
|
||||
i == 0 ? "No, Keep Thread" : "Yes, Delete Thread", 184);
|
||||
}
|
||||
drawSoftkeyBar("Select", "Confirm", "Cancel");
|
||||
|
||||
} else if (mode == ViewMode::SelectSim) {
|
||||
XSetForeground(dpy, gc, pt.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 36);
|
||||
drawPango(layoutIcon, &colYellow, 8, 0, 36, kIconSim);
|
||||
drawPango(layoutMain, &colWhite, 30, 0, 36, "Select SIM for SMS", 200);
|
||||
|
||||
std::string cname = book.resolveName(composeRecipient);
|
||||
std::string toLine =
|
||||
"To: " + (cname.empty() ? composeRecipient : cname);
|
||||
drawPango(layoutSmall, &colLight, 12, 44, 22, toLine, 216);
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
int ry = 74 + i * 74;
|
||||
bool isSel = (simPickIdx == i);
|
||||
XSetForeground(dpy, gc, isSel ? pt.spec.selBg : pt.spec.bgAltEven);
|
||||
XFillRectangle(dpy, pix, gc, 10, ry, kWinWidth - 20, 64);
|
||||
XSetForeground(dpy, gc, isSel ? pt.spec.accent : pt.spec.border);
|
||||
XDrawRectangle(dpy, pix, gc, 10, ry, kWinWidth - 21, 63);
|
||||
|
||||
std::string op = (i == 0) ? simInfo.slot1Operator : simInfo.slot2Operator;
|
||||
std::string rat = (i == 0) ? simInfo.slot1Rat : simInfo.slot2Rat;
|
||||
std::string num = (i == 0) ? simInfo.slot1Number : simInfo.slot2Number;
|
||||
if (op.empty()) op = "SIM " + std::to_string(i + 1);
|
||||
std::string title = "[" + std::to_string(i + 1) + "] SIM " +
|
||||
std::to_string(i + 1) + " - " + op;
|
||||
if (!rat.empty()) title += " [" + rat + "]";
|
||||
std::string sub = num.empty() ? "Ready" : num;
|
||||
if (simInfo.preferredSlot == (i + 1)) {
|
||||
sub += " (Default)";
|
||||
}
|
||||
|
||||
drawPango(layoutIcon, isSel ? &colYellow : &colGreen, 18, ry + 8, 22,
|
||||
kIconSim);
|
||||
drawPango(layoutMain, &colWhite, 40, ry + 8, 22, title, kWinWidth - 54);
|
||||
drawPango(layoutSmall, isSel ? &colLight : &colMuted, 40, ry + 34, 18,
|
||||
sub, kWinWidth - 54);
|
||||
}
|
||||
|
||||
drawPango(layoutSmall, &colMuted, 12, 230, 20,
|
||||
"Press 1 or 2, or Up/Down + Send", 216);
|
||||
drawSoftkeyBar("Send", "Select", "Back");
|
||||
}
|
||||
|
||||
int64_t tNow = nowMs();
|
||||
@@ -1257,6 +1320,14 @@ int runSmsApp(int argc, char** argv) {
|
||||
} else {
|
||||
mode = prevMode;
|
||||
}
|
||||
} else if (mode == ViewMode::SelectSim) {
|
||||
if (isLeft) {
|
||||
mode = ViewMode::Compose;
|
||||
startAsyncSendSms(composeRecipient, composeText,
|
||||
(simPickIdx == 1) ? 2 : 1);
|
||||
} else {
|
||||
mode = ViewMode::Compose;
|
||||
}
|
||||
}
|
||||
drawUI();
|
||||
};
|
||||
@@ -1348,7 +1419,12 @@ int runSmsApp(int argc, char** argv) {
|
||||
(kc == 177 || sym == XF86XK_PickupPhone || sym == XF86XK_Phone ||
|
||||
sym == _EVDEVK(0x1bd) || sym == _EVDEVK(0x0a9));
|
||||
if (isCallKey) {
|
||||
if (mode == ViewMode::Compose) {
|
||||
if (mode == ViewMode::SelectSim) {
|
||||
mode = ViewMode::Compose;
|
||||
startAsyncSendSms(composeRecipient, composeText,
|
||||
(simPickIdx == 1) ? 2 : 1);
|
||||
drawUI();
|
||||
} else if (mode == ViewMode::Compose) {
|
||||
startAsyncSendSms(composeRecipient, composeText);
|
||||
drawUI();
|
||||
} else if (mode == ViewMode::ThreadView && !activeNumber.empty()) {
|
||||
@@ -1590,6 +1666,21 @@ int runSmsApp(int argc, char** argv) {
|
||||
} else if (sym == XK_Return || sym == XK_KP_Enter) {
|
||||
handleSoftkeyAction(true);
|
||||
}
|
||||
} else if (mode == ViewMode::SelectSim) {
|
||||
char d = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (d == '1') {
|
||||
simPickIdx = 0;
|
||||
handleSoftkeyAction(true);
|
||||
} else if (d == '2') {
|
||||
simPickIdx = 1;
|
||||
handleSoftkeyAction(true);
|
||||
} else if (sym == XK_Up || sym == XK_Down || sym == XK_KP_Up ||
|
||||
sym == XK_KP_Down) {
|
||||
simPickIdx = 1 - simPickIdx;
|
||||
drawUI();
|
||||
} else if (sym == XK_Return || sym == XK_KP_Enter) {
|
||||
handleSoftkeyAction(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user