contacts, modem: implement direct QRTR QMI UIM SIM phonebook import and export for SIM 1 and SIM 2

This commit is contained in:
Luxferre committed 2026-10-25 15:30:24 +02:00
1 parent ef18a33c9b
commit 7c707844cc
5 files changed
+1095 -173

No files matched your search

+88 -62
View File
@@ -908,34 +908,41 @@ int runContactsApp(int argc, char** argv) {
setStatus("Reading SIM " + std::to_string(slotNum) + " contacts...",
false, 0);
render();
int rc = 0;
std::string out = runCaptureCmd(
"doas -n /usr/libexec/msm-modem-uim-selection sim-contacts-import " +
std::to_string(slotNum) + " 2>&1",
&rc);
if (visible) {
XRaiseWindow(dpy, win);
grabPluginKeyboard(dpy, win);
}
if (out.rfind("ERROR:", 0) == 0) {
std::string err = trimStr(out.substr(6));
setStatus(err.empty() ? "SIM import failed" : err, true);
render();
return;
}
std::vector<std::pair<std::string, std::string>> rows;
std::stringstream ss(out);
std::string line;
while (std::getline(ss, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
std::string qErr;
bool ok = qrtrReadSimContacts(slotNum, rows, qErr);
if (!ok) {
int rc = 0;
std::string out = runCaptureCmd(
"doas -n /usr/libexec/msm-modem-uim-selection sim-contacts-import " +
std::to_string(slotNum) + " 2>&1",
&rc);
if (visible) {
XRaiseWindow(dpy, win);
grabPluginKeyboard(dpy, win);
}
size_t tab = line.find('\t');
if (tab == std::string::npos) continue;
std::string num = trimStr(line.substr(0, tab));
std::string name = trimStr(line.substr(tab + 1));
if (!num.empty()) {
rows.push_back({num, name.empty() ? num : name});
if (out.rfind("ERROR:", 0) == 0) {
std::string err = trimStr(out.substr(6));
setStatus(err.empty() ? (qErr.empty() ? "SIM import failed" : qErr)
: err,
true);
render();
return;
}
std::stringstream ss(out);
std::string line;
while (std::getline(ss, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
size_t tab = line.find('\t');
if (tab == std::string::npos) continue;
std::string num = trimStr(line.substr(0, tab));
std::string name = trimStr(line.substr(tab + 1));
if (!num.empty()) {
rows.push_back({num, name.empty() ? num : name});
}
}
}
if (rows.empty()) {
@@ -954,49 +961,65 @@ int runContactsApp(int argc, char** argv) {
}
render();
} else {
std::string srcFile = getContactsFilePath();
std::string tmpSingle;
std::vector<std::pair<std::string, std::string>> toExport;
if (pendingSimOp == SimOp::ExportSingle) {
if (selected < 0 || selected >= static_cast<int>(filtered.size())) {
return;
}
tmpSingle = "/tmp/sim_single_" + std::to_string(::getpid()) + ".tsv";
std::ofstream tf(tmpSingle, std::ios::trunc);
tf << filtered[selected].number << "\t" << filtered[selected].name
<< "\n";
tf.close();
srcFile = tmpSingle;
} else if (book.savedContacts().empty()) {
setStatus("Phonebook is empty", true);
render();
return;
toExport.push_back({filtered[selected].number, filtered[selected].name});
} else {
if (book.savedContacts().empty()) {
setStatus("Phonebook is empty", true);
render();
return;
}
for (const auto& c : book.savedContacts()) {
toExport.push_back({c.number, c.name});
}
}
setStatus("Writing to SIM " + std::to_string(slotNum) + "...", false, 0);
render();
int rc = 0;
std::string out = runCaptureCmd(
"doas -n /usr/libexec/msm-modem-uim-selection sim-contacts-export " +
std::to_string(slotNum) + " " + shellQuote(srcFile) + " 2>&1",
&rc);
if (visible) {
XRaiseWindow(dpy, win);
grabPluginKeyboard(dpy, win);
}
if (!tmpSingle.empty()) {
::unlink(tmpSingle.c_str());
}
if (out.rfind("ERROR:", 0) == 0) {
std::string err = trimStr(out.substr(6));
setStatus(err.empty() ? "SIM export failed" : err, true);
render();
return;
}
int exported = 0;
std::stringstream ss(out);
std::string line;
while (std::getline(ss, line)) {
if (line.rfind("EXPORTED=", 0) == 0) {
exported = std::atoi(line.c_str() + 9);
std::string qErr;
bool ok = qrtrWriteSimContacts(slotNum, toExport, exported, qErr);
if (!ok && exported <= 0) {
std::string srcFile = getContactsFilePath();
std::string tmpSingle;
if (pendingSimOp == SimOp::ExportSingle) {
tmpSingle = "/tmp/sim_single_" + std::to_string(::getpid()) + ".tsv";
std::ofstream tf(tmpSingle, std::ios::trunc);
tf << toExport[0].first << "\t" << toExport[0].second << "\n";
tf.close();
srcFile = tmpSingle;
}
int rc = 0;
std::string out = runCaptureCmd(
"doas -n /usr/libexec/msm-modem-uim-selection sim-contacts-export " +
std::to_string(slotNum) + " " + shellQuote(srcFile) + " 2>&1",
&rc);
if (visible) {
XRaiseWindow(dpy, win);
grabPluginKeyboard(dpy, win);
}
if (!tmpSingle.empty()) {
::unlink(tmpSingle.c_str());
}
if (out.rfind("ERROR:", 0) == 0) {
std::string err = trimStr(out.substr(6));
setStatus(err.empty() ? (qErr.empty() ? "SIM export failed" : qErr)
: err,
true);
render();
return;
}
std::stringstream ss(out);
std::string line;
while (std::getline(ss, line)) {
if (line.rfind("EXPORTED=", 0) == 0) {
exported = std::atoi(line.c_str() + 9);
}
}
}
if (exported > 0) {
@@ -1008,7 +1031,10 @@ int runContactsApp(int argc, char** argv) {
false);
}
} else {
setStatus("SIM " + std::to_string(slotNum) + " write failed", true);
setStatus(qErr.empty()
? ("SIM " + std::to_string(slotNum) + " write failed")
: qErr,
true);
}
render();
}