Fix instant QMI call hangup, eliminate post-call dialer/callscreen popups and desktop clock flicker
This commit is contained in:
1 parent
1d71bc81d8
commit
c9c870c3bb
27 files changed
+867
-308
No files matched your search
@@ -484,6 +484,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
|
||||
int64_t callStartMs = 0;
|
||||
int64_t endedAtMs = 0;
|
||||
int64_t lastHangupMs = 0;
|
||||
int lastFinalDurationSec = 0;
|
||||
int64_t lastModemPollMs = 0;
|
||||
|
||||
@@ -860,7 +861,9 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
if (callState == CallState::Incoming) {
|
||||
writeIntFile("/tmp/sxmo_call_ringing", 1);
|
||||
writeIntFile("/tmp/sxmo_active_call", 1);
|
||||
} else if (callState == CallState::Outgoing || callState == CallState::Active) {
|
||||
} else if (callState == CallState::SelectSim ||
|
||||
callState == CallState::Outgoing ||
|
||||
callState == CallState::Active) {
|
||||
::unlink("/tmp/sxmo_call_ringing");
|
||||
writeIntFile("/tmp/sxmo_active_call", 2);
|
||||
} else {
|
||||
@@ -1422,6 +1425,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
endReason = reason.empty() ? "CALL ENDED" : reason;
|
||||
callState = CallState::Ended;
|
||||
callId.clear();
|
||||
endedAtMs = nowMs();
|
||||
dtmfMode = false;
|
||||
ringMuted = false;
|
||||
@@ -1465,7 +1469,168 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
"sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1");
|
||||
};
|
||||
|
||||
auto hangupQmiVoiceCallsNow = [&]() {
|
||||
constexpr int kAfQipcrtr = 42;
|
||||
constexpr uint32_t kQrtrPortCtrl = 0xfffffffeu;
|
||||
constexpr uint32_t kQrtrTypeNewServer = 4;
|
||||
constexpr uint32_t kQrtrTypeNewLookup = 10;
|
||||
constexpr uint32_t kQmiServiceVoice = 9;
|
||||
|
||||
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));
|
||||
|
||||
int lfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (lfd < 0) {
|
||||
return;
|
||||
}
|
||||
SockAddrQrtr localSq {};
|
||||
socklen_t sl = sizeof(localSq);
|
||||
if (::getsockname(lfd, reinterpret_cast<struct sockaddr*>(&localSq), &sl) < 0) {
|
||||
::close(lfd);
|
||||
return;
|
||||
}
|
||||
SockAddrQrtr ctrlSq { kAfQipcrtr, localSq.sq_node, kQrtrPortCtrl };
|
||||
QrtrCtrlPkt lookup { kQrtrTypeNewLookup, kQmiServiceVoice, 0, 0, 0 };
|
||||
if (::sendto(lfd, &lookup, sizeof(lookup), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&ctrlSq),
|
||||
sizeof(ctrlSq)) < 0) {
|
||||
::close(lfd);
|
||||
return;
|
||||
}
|
||||
uint32_t vNode = 0, vPort = 0;
|
||||
bool foundSrv = false;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
struct pollfd pfd { lfd, POLLIN, 0 };
|
||||
if (::poll(&pfd, 1, 30) <= 0) break;
|
||||
QrtrCtrlPkt pkt {};
|
||||
ssize_t n = ::recv(lfd, &pkt, sizeof(pkt), 0);
|
||||
if (n >= static_cast<ssize_t>(sizeof(pkt)) && pkt.cmd == kQrtrTypeNewServer) {
|
||||
if (pkt.service == kQmiServiceVoice && pkt.port != 0) {
|
||||
vNode = pkt.node;
|
||||
vPort = pkt.port;
|
||||
foundSrv = true;
|
||||
break;
|
||||
}
|
||||
if (pkt.service == 0 && pkt.node == 0 && pkt.port == 0) break;
|
||||
}
|
||||
}
|
||||
::close(lfd);
|
||||
if (!foundSrv) {
|
||||
return;
|
||||
}
|
||||
|
||||
SockAddrQrtr vSq { kAfQipcrtr, vNode, vPort };
|
||||
for (int sub : {1, 0}) {
|
||||
int sfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (sfd < 0) continue;
|
||||
uint8_t bindReq[11] = {
|
||||
0x00, 0x01, 0x00, 0x44, 0x00, 0x04, 0x00,
|
||||
0x01, 0x01, 0x00, static_cast<uint8_t>(sub)
|
||||
};
|
||||
::sendto(sfd, bindReq, sizeof(bindReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&vSq), sizeof(vSq));
|
||||
struct pollfd pfd { sfd, POLLIN, 0 };
|
||||
int64_t bindDeadline = nowMs() + 60;
|
||||
while (nowMs() < bindDeadline) {
|
||||
int waitMs = static_cast<int>(std::max<int64_t>(2, bindDeadline - nowMs()));
|
||||
if (::poll(&pfd, 1, waitMs) <= 0) break;
|
||||
uint8_t tmp[512];
|
||||
ssize_t rlen = ::recv(sfd, tmp, sizeof(tmp), 0);
|
||||
if (rlen >= 7 && tmp[0] == 0x02 && tmp[1] == 0x01 && tmp[2] == 0x00 &&
|
||||
tmp[3] == 0x44 && tmp[4] == 0x00) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t infoReq[7] = { 0x00, 0x02, 0x00, 0x2F, 0x00, 0x00, 0x00 };
|
||||
::sendto(sfd, infoReq, sizeof(infoReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&vSq), sizeof(vSq));
|
||||
std::vector<uint8_t> cidsToHangup;
|
||||
int64_t infoDeadline = nowMs() + 80;
|
||||
while (nowMs() < infoDeadline) {
|
||||
int waitMs = static_cast<int>(std::max<int64_t>(2, infoDeadline - nowMs()));
|
||||
if (::poll(&pfd, 1, waitMs) <= 0) break;
|
||||
uint8_t buf[1024];
|
||||
ssize_t rlen = ::recv(sfd, buf, sizeof(buf), 0);
|
||||
if (rlen >= 7 && buf[0] == 0x02 && buf[1] == 0x02 && buf[2] == 0x00 &&
|
||||
buf[3] == 0x2F && buf[4] == 0x00) {
|
||||
const uint8_t* rawCi01 = nullptr;
|
||||
uint16_t lenCi01 = 0;
|
||||
const uint8_t* rawCi10 = nullptr;
|
||||
uint16_t lenCi10 = 0;
|
||||
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) {
|
||||
rawCi01 = buf + pos;
|
||||
lenCi01 = tl;
|
||||
} else if (tt == 0x10) {
|
||||
rawCi10 = buf + pos;
|
||||
lenCi10 = tl;
|
||||
}
|
||||
pos += tl;
|
||||
}
|
||||
const uint8_t* rawCi = rawCi01 ? rawCi01 : rawCi10;
|
||||
uint16_t lenCi = rawCi01 ? lenCi01 : lenCi10;
|
||||
if (rawCi && lenCi >= 1) {
|
||||
uint8_t cnt = rawCi[0];
|
||||
size_t off = 1;
|
||||
for (uint8_t i = 0; i < cnt && off + 7 <= lenCi; ++i, off += 7) {
|
||||
uint8_t cid = rawCi[off];
|
||||
uint8_t cstate = rawCi[off + 1];
|
||||
if (cstate != 8 && cstate != 9 && cid > 0) {
|
||||
cidsToHangup.push_back(cid);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cidsToHangup.empty()) {
|
||||
cidsToHangup.push_back(1);
|
||||
}
|
||||
uint8_t txn = 3;
|
||||
for (uint8_t cid : cidsToHangup) {
|
||||
uint8_t endReq[11] = {
|
||||
0x00, txn, 0x00, 0x21, 0x00, 0x04, 0x00,
|
||||
0x01, 0x01, 0x00, cid
|
||||
};
|
||||
::sendto(sfd, endReq, sizeof(endReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&vSq), sizeof(vSq));
|
||||
int64_t endDeadline = nowMs() + 50;
|
||||
while (nowMs() < endDeadline) {
|
||||
int waitMs = static_cast<int>(std::max<int64_t>(2, endDeadline - nowMs()));
|
||||
if (::poll(&pfd, 1, waitMs) <= 0) break;
|
||||
uint8_t tmp[512];
|
||||
ssize_t rlen = ::recv(sfd, tmp, sizeof(tmp), 0);
|
||||
if (rlen >= 7 && tmp[0] == 0x02 && tmp[1] == txn && tmp[2] == 0x00 &&
|
||||
tmp[3] == 0x21 && tmp[4] == 0x00) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
++txn;
|
||||
}
|
||||
::close(sfd);
|
||||
}
|
||||
};
|
||||
|
||||
auto hangupCall = [&](bool closeImmediately = false) {
|
||||
lastHangupMs = nowMs();
|
||||
writeIntFile("/tmp/sxmo_hangup_requested", 1);
|
||||
std::string cid = resolveActiveModemCallId();
|
||||
bool wasIncoming = (callState == CallState::Incoming);
|
||||
stopRingingJobs();
|
||||
@@ -1473,12 +1638,34 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
sendPluginCommand("sip", "CALL_HANGUP " + cid);
|
||||
} else if (cid.rfind("tox:", 0) == 0 || activeSimSlot == 4) {
|
||||
sendPluginCommand("tox", "CALL_HANGUP " + cid);
|
||||
} else if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") {
|
||||
runAsyncArgv("sxmo_modemcall.sh", "hangup", cid.c_str());
|
||||
} else {
|
||||
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
|
||||
sendPluginCommand("sip", "CALL_HANGUP");
|
||||
sendPluginCommand("tox", "CALL_HANGUP");
|
||||
hangupQmiVoiceCallsNow();
|
||||
std::string callsDir = getRuntimeFile("sxmo_calls");
|
||||
DIR* d = ::opendir(callsDir.c_str());
|
||||
if (d) {
|
||||
struct dirent* ent;
|
||||
while ((ent = ::readdir(d)) != nullptr) {
|
||||
if (ent->d_name[0] != '.' && ent->d_name[0] != '\0') {
|
||||
std::string fn(ent->d_name);
|
||||
if (fn.rfind("sub", 0) == 0 ||
|
||||
fn.find(".ringing-in") != std::string::npos ||
|
||||
fn.find(".dialing") != std::string::npos ||
|
||||
fn.find(".ringing-out") != std::string::npos ||
|
||||
fn.find(".active") != std::string::npos) {
|
||||
std::string fpPath = callsDir + "/" + fn;
|
||||
::unlink(fpPath.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
::closedir(d);
|
||||
}
|
||||
if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") {
|
||||
runAsyncArgv("sxmo_modemcall.sh", "hangup", cid.c_str());
|
||||
} else {
|
||||
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
|
||||
sendPluginCommand("sip", "CALL_HANGUP");
|
||||
sendPluginCommand("tox", "CALL_HANGUP");
|
||||
}
|
||||
}
|
||||
if (closeImmediately || !visible || callState == CallState::Idle ||
|
||||
callState == CallState::SelectSim || callState == CallState::Ended) {
|
||||
@@ -1660,7 +1847,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
else if (cstate == 6) st = "held";
|
||||
if (!st.empty() && outId.empty()) {
|
||||
outId = (sub == 1) ? ("sub1_" + std::to_string(cid))
|
||||
: std::to_string(cid);
|
||||
: ("sub0_" + std::to_string(cid));
|
||||
outState = st;
|
||||
outDir = (cdir == 2) ? "incoming" : "outgoing";
|
||||
if (rawNum && lenNum >= 1) {
|
||||
@@ -1693,13 +1880,17 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
if (callId == "sim" || callId == "test" || isVoipCallId(callId)) {
|
||||
return;
|
||||
}
|
||||
if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 &&
|
||||
::access("/tmp/sxmo_hangup_requested", F_OK) == 0) {
|
||||
return;
|
||||
}
|
||||
std::string foundId;
|
||||
std::string foundDir;
|
||||
std::string foundState;
|
||||
std::string foundNum;
|
||||
bool sawTerminated = false;
|
||||
|
||||
if (callId.rfind("sub", 0) != 0) {
|
||||
if (callId.rfind("sub1_", 0) != 0) {
|
||||
FILE* fp = ::popen("mmcli -m any --voice-list-calls -a 2>/dev/null", "r");
|
||||
if (fp) {
|
||||
char line[512];
|
||||
@@ -1891,9 +2082,9 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
if (line == "ENDED" || line.rfind("ENDED ", 0) == 0) {
|
||||
std::string reason = (line.size() > 6) ? trimStr(line.substr(6)) : "CALL ENDED";
|
||||
sipZrtpSas.clear();
|
||||
if (callState != CallState::Idle) {
|
||||
if (callState != CallState::Idle && callState != CallState::Ended) {
|
||||
transitionToEnded(reason);
|
||||
} else {
|
||||
} else if (callState == CallState::Idle) {
|
||||
hideWindow(false);
|
||||
}
|
||||
return;
|
||||
@@ -1904,13 +2095,46 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
std::string verb, arg1, arg2, arg3;
|
||||
iss >> verb >> arg1 >> arg2 >> arg3;
|
||||
|
||||
if (verb == "PROMPT_SIM") {
|
||||
if (verb == "DIAL" || verb == "PROMPT_SIM") {
|
||||
if (callState == CallState::Incoming || callState == CallState::Outgoing ||
|
||||
callState == CallState::Active) {
|
||||
showWindow();
|
||||
return;
|
||||
}
|
||||
simInfo = queryDualSimInfo(true);
|
||||
lastHangupMs = 0;
|
||||
::unlink("/tmp/sxmo_hangup_requested");
|
||||
if (!simInfo.slot1Present && !simInfo.slot2Present) {
|
||||
simInfo = queryDualSimInfo(false);
|
||||
}
|
||||
if (verb == "DIAL" && !simInfo.dualSimActive) {
|
||||
int slot = (simInfo.primaryGwSlot == 2) ? 2 : 1;
|
||||
std::string simStr = std::to_string(slot);
|
||||
std::string num = normalizePhone(arg1);
|
||||
if (!num.empty()) {
|
||||
callId.clear();
|
||||
callNumber.clear();
|
||||
contactName.clear();
|
||||
updateCallerDetails("-", num);
|
||||
activeSimSlot = slot;
|
||||
callState = CallState::Outgoing;
|
||||
callStartMs = nowMs();
|
||||
lastModemPollMs = callStartMs;
|
||||
missingModemPolls = 0;
|
||||
ringMuted = false;
|
||||
speakerOn = false;
|
||||
btAudioOn = hasBtAudioCard();
|
||||
dtmfMode = false;
|
||||
dtmfSent.clear();
|
||||
selectedRow = 0;
|
||||
setSpeakerRoute(false, btAudioOn);
|
||||
statusNotice.clear();
|
||||
statusNoticeUntilMs = 0;
|
||||
writeActiveStateFiles();
|
||||
showWindow();
|
||||
runAsyncArgv("sxmo_modemdial.sh", "--sim", simStr.c_str(), num.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
callId = "-";
|
||||
callNumber.clear();
|
||||
contactName.clear();
|
||||
@@ -1920,6 +2144,11 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
activeSimSlot = 0;
|
||||
writeActiveStateFiles();
|
||||
showWindow();
|
||||
if (simInfo.slot1Operator.empty() && simInfo.slot2Operator.empty()) {
|
||||
simInfo = queryDualSimInfo(true);
|
||||
selectedRow = (simInfo.preferredSlot == 2) ? 1 : 0;
|
||||
render();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1968,6 +2197,8 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
};
|
||||
|
||||
if (verb == "INCOMING") {
|
||||
lastHangupMs = 0;
|
||||
::unlink("/tmp/sxmo_hangup_requested");
|
||||
callId.clear();
|
||||
callNumber.clear();
|
||||
contactName.clear();
|
||||
@@ -1989,31 +2220,46 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
writeActiveStateFiles();
|
||||
showWindow();
|
||||
} else if (verb == "OUTGOING") {
|
||||
callId.clear();
|
||||
callNumber.clear();
|
||||
contactName.clear();
|
||||
recordFileName.clear();
|
||||
recordFilePath.clear();
|
||||
lastRecordedSec = 0;
|
||||
recordedClipCount = 0;
|
||||
if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 &&
|
||||
::access("/tmp/sxmo_hangup_requested", F_OK) == 0) {
|
||||
return;
|
||||
}
|
||||
lastHangupMs = 0;
|
||||
bool alreadyOutgoing = (callState == CallState::Outgoing);
|
||||
if (!alreadyOutgoing) {
|
||||
callId.clear();
|
||||
callNumber.clear();
|
||||
contactName.clear();
|
||||
recordFileName.clear();
|
||||
recordFilePath.clear();
|
||||
lastRecordedSec = 0;
|
||||
recordedClipCount = 0;
|
||||
}
|
||||
updateCallerDetails(arg1, arg2);
|
||||
parseSimTag(arg1, arg3);
|
||||
callState = CallState::Outgoing;
|
||||
callStartMs = nowMs();
|
||||
lastModemPollMs = callStartMs;
|
||||
if (!alreadyOutgoing) {
|
||||
callStartMs = nowMs();
|
||||
ringMuted = false;
|
||||
speakerOn = false;
|
||||
btAudioOn = hasBtAudioCard();
|
||||
dtmfMode = false;
|
||||
dtmfSent.clear();
|
||||
selectedRow = 0;
|
||||
setSpeakerRoute(false, btAudioOn);
|
||||
statusNotice.clear();
|
||||
statusNoticeUntilMs = 0;
|
||||
}
|
||||
lastModemPollMs = nowMs();
|
||||
missingModemPolls = 0;
|
||||
ringMuted = false;
|
||||
speakerOn = false;
|
||||
btAudioOn = hasBtAudioCard();
|
||||
dtmfMode = false;
|
||||
dtmfSent.clear();
|
||||
selectedRow = 0;
|
||||
setSpeakerRoute(false, btAudioOn);
|
||||
statusNotice.clear();
|
||||
statusNoticeUntilMs = 0;
|
||||
writeActiveStateFiles();
|
||||
showWindow();
|
||||
} else if (verb == "ACTIVE") {
|
||||
if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 &&
|
||||
::access("/tmp/sxmo_hangup_requested", F_OK) == 0) {
|
||||
return;
|
||||
}
|
||||
lastHangupMs = 0;
|
||||
bool wasActive = (callState == CallState::Active);
|
||||
bool wasOutgoing = (callState == CallState::Outgoing);
|
||||
updateCallerDetails(arg1, arg2);
|
||||
@@ -2044,7 +2290,9 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
if (callState == CallState::Idle || callState == CallState::Ended) {
|
||||
syncModemCalls();
|
||||
}
|
||||
showWindow();
|
||||
if (callState != CallState::Idle || !arg1.empty()) {
|
||||
showWindow();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2057,6 +2305,8 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
if (num.empty()) {
|
||||
return;
|
||||
}
|
||||
lastHangupMs = 0;
|
||||
::unlink("/tmp/sxmo_hangup_requested");
|
||||
std::string simStr = (chosenSim == 2) ? "2" : "1";
|
||||
handleFifoCommand("OUTGOING - " + num + " SIM" + simStr);
|
||||
runAsyncArgv("sxmo_modemdial.sh", "--sim", simStr.c_str(), num.c_str());
|
||||
@@ -2120,10 +2370,6 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
writeActiveStateFiles();
|
||||
}
|
||||
hideWindow(false);
|
||||
} else {
|
||||
XRaiseWindow(dpy, win);
|
||||
grabPluginKeyboard(dpy, win);
|
||||
render();
|
||||
}
|
||||
} else if (ev.type == KeyRelease) {
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||
@@ -2374,16 +2620,22 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (visible && (callState != CallState::Idle || checkRecordingAlive())) {
|
||||
static int64_t lastTimerRenderMs = 0;
|
||||
bool hasLiveTimer = (callState == CallState::Outgoing ||
|
||||
callState == CallState::Active ||
|
||||
checkRecordingAlive());
|
||||
if (visible && hasLiveTimer && nowMs() - lastTimerRenderMs >= 250) {
|
||||
lastTimerRenderMs = nowMs();
|
||||
render();
|
||||
}
|
||||
|
||||
int timeoutMs = -1;
|
||||
if (visible || callState != CallState::Idle || checkRecordingAlive()) {
|
||||
if (softkeyDeadlineMs > 0) {
|
||||
timeoutMs = static_cast<int>(std::max<int64_t>(5, softkeyDeadlineMs - nowMs()));
|
||||
} else if (callState == CallState::Ended && endedAtMs > 0) {
|
||||
timeoutMs = static_cast<int>(std::max<int64_t>(10, 1300 - (nowMs() - endedAtMs)));
|
||||
} else if (hasLiveTimer || callState == CallState::Incoming) {
|
||||
timeoutMs = 250;
|
||||
if (softkeyDeadlineMs > 0) {
|
||||
timeoutMs = static_cast<int>(std::max<int64_t>(5, softkeyDeadlineMs - nowMs()));
|
||||
}
|
||||
}
|
||||
|
||||
struct pollfd pfds[2] {};
|
||||
|
||||
Reference in new issue
Block a user