Fix background call hangup and end calls on screen lock or lid close
This commit is contained in:
1 parent
c7cdde6734
commit
0c352f0a10
55 files changed
+391
-120
No files matched your search
@@ -452,6 +452,22 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
int selectedRow = 0;
|
||||
|
||||
auto hasBtAudioCard = []() -> bool {
|
||||
bool hciConnected = false;
|
||||
DIR* bd = ::opendir("/sys/class/bluetooth");
|
||||
if (bd) {
|
||||
struct dirent* ent;
|
||||
while ((ent = ::readdir(bd)) != nullptr) {
|
||||
if (std::strncmp(ent->d_name, "hci", 3) == 0 &&
|
||||
std::strchr(ent->d_name, ':') != nullptr) {
|
||||
hciConnected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
::closedir(bd);
|
||||
}
|
||||
if (!hciConnected) {
|
||||
return false;
|
||||
}
|
||||
FILE* fp = ::popen("pactl list short cards 2>/dev/null", "r");
|
||||
if (!fp) return false;
|
||||
char line[256];
|
||||
@@ -1421,7 +1437,35 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
render();
|
||||
};
|
||||
|
||||
auto hangupCall = [&]() {
|
||||
int missingModemPolls = 0;
|
||||
|
||||
auto resetToIdleAndClose = [&]() {
|
||||
stopRecording();
|
||||
if (micMuted) {
|
||||
setMicMuted(false);
|
||||
}
|
||||
stopRingingJobs();
|
||||
btAudioOn = false;
|
||||
dtmfMode = false;
|
||||
ringMuted = false;
|
||||
sipZrtpSas.clear();
|
||||
callState = CallState::Idle;
|
||||
callId.clear();
|
||||
callNumber.clear();
|
||||
contactName.clear();
|
||||
endedAtMs = 0;
|
||||
missingModemPolls = 0;
|
||||
writeActiveStateFiles();
|
||||
hideWindow(false);
|
||||
runAsyncCmd("sxmo_jobs.sh stop ringing >/dev/null 2>&1; "
|
||||
"pkill -TERM -f sxmo_hook_ring.sh >/dev/null 2>&1; "
|
||||
"pkill -TERM -f 'pw-play.*ring' >/dev/null 2>&1; "
|
||||
"pkill -TERM -f 'mpv.*ring' >/dev/null 2>&1; "
|
||||
"pkill -TERM -x sxmo_vibrate >/dev/null 2>&1; "
|
||||
"sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1");
|
||||
};
|
||||
|
||||
auto hangupCall = [&](bool closeImmediately = false) {
|
||||
std::string cid = resolveActiveModemCallId();
|
||||
bool wasIncoming = (callState == CallState::Incoming);
|
||||
stopRingingJobs();
|
||||
@@ -1432,9 +1476,16 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
} else if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") {
|
||||
runAsyncArgv("sxmo_modemcall.sh", "hangup", cid.c_str());
|
||||
} else {
|
||||
runAsyncCmd("mmcli -m any --voice-hangup-all >/dev/null 2>&1");
|
||||
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) {
|
||||
resetToIdleAndClose();
|
||||
} else {
|
||||
transitionToEnded(wasIncoming ? "CALL REJECTED" : "CALL ENDED");
|
||||
}
|
||||
transitionToEnded(wasIncoming ? "CALL REJECTED" : "CALL ENDED");
|
||||
};
|
||||
|
||||
auto sendDtmfTone = [&](char ch) {
|
||||
@@ -1527,6 +1578,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
SockAddrQrtr vSq { kAfQipcrtr, vNode, vPort };
|
||||
bool gotValidReply = false;
|
||||
for (int sub : {1, 0}) {
|
||||
int sfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (sfd < 0) continue;
|
||||
@@ -1537,21 +1589,35 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
::sendto(sfd, bindReq, sizeof(bindReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&vSq), sizeof(vSq));
|
||||
struct pollfd pfd { sfd, POLLIN, 0 };
|
||||
if (::poll(&pfd, 1, 40) > 0) {
|
||||
uint8_t tmp[256];
|
||||
::recv(sfd, tmp, sizeof(tmp), 0);
|
||||
int64_t bindDeadline = nowMs() + 150;
|
||||
while (nowMs() < bindDeadline) {
|
||||
int waitMs = static_cast<int>(std::max<int64_t>(5, 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));
|
||||
if (::poll(&pfd, 1, 50) > 0) {
|
||||
int64_t infoDeadline = nowMs() + 200;
|
||||
while (nowMs() < infoDeadline) {
|
||||
int waitMs = static_cast<int>(std::max<int64_t>(5, 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[3] == 0x2F) {
|
||||
const uint8_t* rawCi = nullptr;
|
||||
uint16_t lenCi = 0;
|
||||
const uint8_t* rawNum = nullptr;
|
||||
uint16_t lenNum = 0;
|
||||
if (rlen >= 7 && buf[0] == 0x02 && buf[1] == 0x02 && buf[2] == 0x00 &&
|
||||
buf[3] == 0x2F && buf[4] == 0x00) {
|
||||
gotValidReply = true;
|
||||
const uint8_t* rawCi01 = nullptr;
|
||||
uint16_t lenCi01 = 0;
|
||||
const uint8_t* rawCi10 = nullptr;
|
||||
uint16_t lenCi10 = 0;
|
||||
const uint8_t* rawNum11 = nullptr;
|
||||
uint16_t lenNum11 = 0;
|
||||
size_t pos = 7;
|
||||
while (pos + 3 <= static_cast<size_t>(rlen)) {
|
||||
uint8_t tt = buf[pos];
|
||||
@@ -1559,15 +1625,22 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
(static_cast<uint16_t>(buf[pos + 2]) << 8);
|
||||
pos += 3;
|
||||
if (pos + tl > static_cast<size_t>(rlen)) break;
|
||||
if (tt == 0x10) {
|
||||
rawCi = buf + pos;
|
||||
lenCi = tl;
|
||||
if (tt == 0x01) {
|
||||
rawCi01 = buf + pos;
|
||||
lenCi01 = tl;
|
||||
} else if (tt == 0x10) {
|
||||
rawCi10 = buf + pos;
|
||||
lenCi10 = tl;
|
||||
} else if (tt == 0x11) {
|
||||
rawNum = buf + pos;
|
||||
lenNum = tl;
|
||||
rawNum11 = buf + pos;
|
||||
lenNum11 = tl;
|
||||
}
|
||||
pos += tl;
|
||||
}
|
||||
const uint8_t* rawCi = rawCi01 ? rawCi01 : rawCi10;
|
||||
uint16_t lenCi = rawCi01 ? lenCi01 : lenCi10;
|
||||
const uint8_t* rawNum = rawCi01 ? rawCi10 : rawNum11;
|
||||
uint16_t lenNum = rawCi01 ? lenCi10 : lenNum11;
|
||||
if (rawCi && lenCi >= 1) {
|
||||
uint8_t cnt = rawCi[0];
|
||||
size_t off = 1;
|
||||
@@ -1608,11 +1681,12 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
::close(sfd);
|
||||
}
|
||||
return true;
|
||||
return gotValidReply;
|
||||
};
|
||||
|
||||
auto syncModemCalls = [&]() {
|
||||
@@ -1625,55 +1699,59 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
std::string foundNum;
|
||||
bool sawTerminated = false;
|
||||
|
||||
FILE* fp = ::popen("mmcli -m any --voice-list-calls -a 2>/dev/null", "r");
|
||||
if (fp) {
|
||||
char line[512];
|
||||
while (std::fgets(line, sizeof(line), fp)) {
|
||||
std::string s(line);
|
||||
if (s.find("No calls") != std::string::npos) {
|
||||
continue;
|
||||
if (callId.rfind("sub", 0) != 0) {
|
||||
FILE* fp = ::popen("mmcli -m any --voice-list-calls -a 2>/dev/null", "r");
|
||||
if (fp) {
|
||||
char line[512];
|
||||
while (std::fgets(line, sizeof(line), fp)) {
|
||||
std::string s(line);
|
||||
if (s.find("No calls") != std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
if (s.find("terminated") != std::string::npos) {
|
||||
sawTerminated = true;
|
||||
continue;
|
||||
}
|
||||
size_t callPos = s.find("/Call/");
|
||||
if (callPos == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
size_t idStart = callPos + 6;
|
||||
size_t idEnd = idStart;
|
||||
while (idEnd < s.size() && std::isdigit(static_cast<unsigned char>(s[idEnd]))) {
|
||||
++idEnd;
|
||||
}
|
||||
if (idEnd == idStart) {
|
||||
continue;
|
||||
}
|
||||
foundId = s.substr(idStart, idEnd - idStart);
|
||||
if (s.find("incoming") != std::string::npos) {
|
||||
foundDir = "incoming";
|
||||
} else if (s.find("outgoing") != std::string::npos) {
|
||||
foundDir = "outgoing";
|
||||
}
|
||||
size_t lp = s.find('(');
|
||||
size_t rp = s.find(')', lp == std::string::npos ? 0 : lp);
|
||||
if (lp != std::string::npos && rp != std::string::npos && rp > lp + 1) {
|
||||
foundState = s.substr(lp + 1, rp - lp - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (s.find("terminated") != std::string::npos) {
|
||||
sawTerminated = true;
|
||||
continue;
|
||||
}
|
||||
size_t callPos = s.find("/Call/");
|
||||
if (callPos == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
size_t idStart = callPos + 6;
|
||||
size_t idEnd = idStart;
|
||||
while (idEnd < s.size() && std::isdigit(static_cast<unsigned char>(s[idEnd]))) {
|
||||
++idEnd;
|
||||
}
|
||||
if (idEnd == idStart) {
|
||||
continue;
|
||||
}
|
||||
foundId = s.substr(idStart, idEnd - idStart);
|
||||
if (s.find("incoming") != std::string::npos) {
|
||||
foundDir = "incoming";
|
||||
} else if (s.find("outgoing") != std::string::npos) {
|
||||
foundDir = "outgoing";
|
||||
}
|
||||
size_t lp = s.find('(');
|
||||
size_t rp = s.find(')', lp == std::string::npos ? 0 : lp);
|
||||
if (lp != std::string::npos && rp != std::string::npos && rp > lp + 1) {
|
||||
foundState = s.substr(lp + 1, rp - lp - 1);
|
||||
}
|
||||
break;
|
||||
::pclose(fp);
|
||||
}
|
||||
::pclose(fp);
|
||||
}
|
||||
|
||||
if (sawTerminated) {
|
||||
runAsyncCmd("sxmo_modem.sh checkforfinishedcalls >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
bool qmiOk = true;
|
||||
if (foundId.empty()) {
|
||||
queryQmiVoiceCalls(foundId, foundDir, foundState, foundNum, sawTerminated);
|
||||
qmiOk = queryQmiVoiceCalls(foundId, foundDir, foundState, foundNum, sawTerminated);
|
||||
}
|
||||
|
||||
if (!foundId.empty()) {
|
||||
missingModemPolls = 0;
|
||||
if (callId.empty() || callId == "-") {
|
||||
callId = foundId;
|
||||
}
|
||||
@@ -1725,6 +1803,10 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
sawTerminated ||
|
||||
(callState == CallState::Outgoing &&
|
||||
((!callId.empty() && callId != "-") || nowMs() - callStartMs > 3500))) {
|
||||
if (!sawTerminated && (!qmiOk || ++missingModemPolls < 2)) {
|
||||
return;
|
||||
}
|
||||
missingModemPolls = 0;
|
||||
std::string callsDir = getRuntimeFile("sxmo_calls");
|
||||
DIR* d = ::opendir(callsDir.c_str());
|
||||
if (d) {
|
||||
@@ -1754,6 +1836,14 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
return;
|
||||
}
|
||||
if (line == "CLOSE") {
|
||||
if (callState == CallState::SelectSim || callState == CallState::Ended) {
|
||||
callState = CallState::Idle;
|
||||
callId.clear();
|
||||
callNumber.clear();
|
||||
contactName.clear();
|
||||
endedAtMs = 0;
|
||||
writeActiveStateFiles();
|
||||
}
|
||||
hideWindow(false);
|
||||
return;
|
||||
}
|
||||
@@ -1770,13 +1860,12 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (line == "HANGUP_CLOSE" || line.rfind("HANGUP_CLOSE ", 0) == 0) {
|
||||
hangupCall(true);
|
||||
return;
|
||||
}
|
||||
if (line == "HANGUP" || line.rfind("HANGUP ", 0) == 0) {
|
||||
if (callState == CallState::Incoming || callState == CallState::Outgoing ||
|
||||
callState == CallState::Active) {
|
||||
hangupCall();
|
||||
} else {
|
||||
hideWindow(false);
|
||||
}
|
||||
hangupCall(!visible);
|
||||
return;
|
||||
}
|
||||
if (line == "MUTE_RING") {
|
||||
@@ -1816,6 +1905,11 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
iss >> verb >> arg1 >> arg2 >> arg3;
|
||||
|
||||
if (verb == "PROMPT_SIM") {
|
||||
if (callState == CallState::Incoming || callState == CallState::Outgoing ||
|
||||
callState == CallState::Active) {
|
||||
showWindow();
|
||||
return;
|
||||
}
|
||||
simInfo = queryDualSimInfo(true);
|
||||
callId = "-";
|
||||
callNumber.clear();
|
||||
@@ -1857,7 +1951,9 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
activeSimSlot = 4;
|
||||
return;
|
||||
}
|
||||
simInfo = queryDualSimInfo();
|
||||
if (!simInfo.slot1Present && !simInfo.slot2Present) {
|
||||
simInfo = queryDualSimInfo();
|
||||
}
|
||||
if (tagStr == "SIM1") {
|
||||
activeSimSlot = 1;
|
||||
} else if (tagStr == "SIM2") {
|
||||
@@ -1883,6 +1979,8 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
parseSimTag(arg1, arg3);
|
||||
callState = CallState::Incoming;
|
||||
callStartMs = nowMs();
|
||||
lastModemPollMs = callStartMs;
|
||||
missingModemPolls = 0;
|
||||
ringMuted = false;
|
||||
speakerOn = false;
|
||||
dtmfMode = false;
|
||||
@@ -1902,6 +2000,8 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
parseSimTag(arg1, arg3);
|
||||
callState = CallState::Outgoing;
|
||||
callStartMs = nowMs();
|
||||
lastModemPollMs = callStartMs;
|
||||
missingModemPolls = 0;
|
||||
ringMuted = false;
|
||||
speakerOn = false;
|
||||
btAudioOn = hasBtAudioCard();
|
||||
@@ -1921,8 +2021,10 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
parseSimTag(arg1, arg3);
|
||||
}
|
||||
callState = CallState::Active;
|
||||
lastModemPollMs = nowMs();
|
||||
missingModemPolls = 0;
|
||||
if (!wasActive) {
|
||||
callStartMs = nowMs();
|
||||
callStartMs = lastModemPollMs;
|
||||
if (!wasOutgoing) {
|
||||
speakerOn = false;
|
||||
btAudioOn = hasBtAudioCard();
|
||||
@@ -2009,6 +2111,14 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
} else if (ev.type == VisibilityNotify &&
|
||||
ev.xvisibility.state != VisibilityUnobscured) {
|
||||
if (isAnotherPluginActive("callscreen")) {
|
||||
if (callState == CallState::SelectSim || callState == CallState::Ended) {
|
||||
callState = CallState::Idle;
|
||||
callId.clear();
|
||||
callNumber.clear();
|
||||
contactName.clear();
|
||||
endedAtMs = 0;
|
||||
writeActiveStateFiles();
|
||||
}
|
||||
hideWindow(false);
|
||||
} else {
|
||||
XRaiseWindow(dpy, win);
|
||||
|
||||
Reference in new issue
Block a user