Fix Bluetooth KeyboardDisplay pairing agent, MGMT flags, and refresh a1120 images
- Switch bananarchy-bt-obex Agent1 from NoInputNoOutput to KeyboardDisplay with /run/bananarchy/bt-obex/pair_{prompt,decision}.tsv and op_done.tsv IPC, auto-confirming Classic Audio headsets while prompting user confirmation, PIN, passkey, or keyboard display codes.
- Enforce bredr on, ssp on, linksec on, bondable on, advertising off, class 2 3, and le on in bananarchy-bt-le-enable.sh alongside PairableTimeout = 0 in main.conf (keeping DiscoverableTimeout = 60 hidden by default) and boot hook sync in sxmo_hook_start.sh.
- Fix root/user daemon UID collisions and sticky-/tmp status/PID writes, separate phones from Classic Audio headsets, increase Pair timeout to 50 s, and add non-blocking --async-ui pairing/connect plus NetModal::BtPairingPrompt in networks.so.
- Extend scripts/test-bluetooth-obex.py, scripts/test-bluetooth-headset.py, scripts/check-rebuild.sh, docs, and rebuild/pin a1120 (cocojamboo) images and archives for nokia-argon, nokia-beatles, nokia-coconut, and nokia-sparkler.
This commit is contained in:
1 parent
36a5f8cb8a
commit
1e1fe7c317
17 files changed
+1387
-326
No files matched your search
@@ -12,6 +12,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <sys/stat.h>
|
||||
#include <cerrno>
|
||||
#include <clocale>
|
||||
|
||||
#ifdef None
|
||||
@@ -44,6 +45,7 @@ enum class NetModal {
|
||||
ObexActions = 6,
|
||||
ObexDirPicker = 7,
|
||||
ObexIncomingPrompt = 8,
|
||||
BtPairingPrompt = 9,
|
||||
};
|
||||
|
||||
constexpr const char* kIconHeadphones = "\xef\x80\xa5"; // U+F025 headphones
|
||||
@@ -201,6 +203,9 @@ void writeSavedBtDiscoverable(bool disc) {
|
||||
constexpr const char* kObexIpcDir = "/run/bananarchy/bt-obex";
|
||||
constexpr const char* kObexPromptPath = "/run/bananarchy/bt-obex/prompt.tsv";
|
||||
constexpr const char* kObexDecisionPath = "/run/bananarchy/bt-obex/decision.tsv";
|
||||
constexpr const char* kPairPromptPath = "/run/bananarchy/bt-obex/pair_prompt.tsv";
|
||||
constexpr const char* kPairDecisionPath = "/run/bananarchy/bt-obex/pair_decision.tsv";
|
||||
constexpr const char* kBtOpDonePath = "/run/bananarchy/bt-obex/op_done.tsv";
|
||||
|
||||
std::string shortenHomePath(const std::string& p) {
|
||||
if (p.empty()) return "~/Downloads";
|
||||
@@ -307,6 +312,54 @@ void writeObexDecision(const std::string& reqId, bool accept, const std::string&
|
||||
::rename(tmpPath.c_str(), kObexDecisionPath);
|
||||
}
|
||||
|
||||
struct BtPairPromptInfo {
|
||||
bool active = false;
|
||||
std::string reqId;
|
||||
std::string mode; // CONFIRM, PIN, PASSKEY, DISPLAY
|
||||
std::string devName;
|
||||
std::string devMac;
|
||||
std::string code;
|
||||
int entered = 0;
|
||||
};
|
||||
|
||||
BtPairPromptInfo readPairPromptFile() {
|
||||
BtPairPromptInfo p;
|
||||
std::ifstream in(kPairPromptPath);
|
||||
std::string line;
|
||||
if (!in.is_open() || !std::getline(in, line)) return p;
|
||||
line = trimStr(line);
|
||||
if (line.empty()) return p;
|
||||
std::vector<std::string> cols;
|
||||
std::stringstream ss(line);
|
||||
std::string c;
|
||||
while (std::getline(ss, c, '\t')) {
|
||||
cols.push_back(c);
|
||||
}
|
||||
if (cols.size() < 4 || cols[0].empty() || cols[1].empty()) return p;
|
||||
p.active = true;
|
||||
p.reqId = cols[0];
|
||||
p.mode = cols[1];
|
||||
p.devName = cols[2];
|
||||
p.devMac = cols[3];
|
||||
if (cols.size() >= 5) p.code = cols[4];
|
||||
if (cols.size() >= 6) p.entered = std::atoi(cols[5].c_str());
|
||||
return p;
|
||||
}
|
||||
|
||||
void writePairDecision(const std::string& reqId, bool accept, const std::string& value) {
|
||||
if (reqId.empty()) return;
|
||||
::mkdir("/run/bananarchy", 0755);
|
||||
::mkdir(kObexIpcDir, 0755);
|
||||
std::string tmpPath = std::string(kPairDecisionPath) + ".tmp";
|
||||
{
|
||||
std::ofstream out(tmpPath, std::ios::trunc);
|
||||
if (out.is_open()) {
|
||||
out << reqId << "\t" << (accept ? "ACCEPT" : "REJECT") << "\t" << value << "\n";
|
||||
}
|
||||
}
|
||||
::rename(tmpPath.c_str(), kPairDecisionPath);
|
||||
}
|
||||
|
||||
bool isLidClosedState() {
|
||||
std::ifstream in("/run/bananarchy/lid-state");
|
||||
std::string line;
|
||||
@@ -778,18 +831,14 @@ std::vector<BtDeviceEntry> queryBtDevices(const std::string& scanRaw = "") {
|
||||
std::string nameLow = toLowerStr(d.name);
|
||||
|
||||
bool hasA2dp = (infoLow.find("0000110b-") != std::string::npos ||
|
||||
infoLow.find("0000110a-") != std::string::npos ||
|
||||
infoLow.find("audio sink") != std::string::npos ||
|
||||
infoLow.find("audio source") != std::string::npos);
|
||||
infoLow.find("audio sink") != std::string::npos);
|
||||
bool hasHfp = (infoLow.find("00001108-") != std::string::npos ||
|
||||
infoLow.find("00001112-") != std::string::npos ||
|
||||
infoLow.find("0000111e-") != std::string::npos ||
|
||||
infoLow.find("0000111f-") != std::string::npos ||
|
||||
infoLow.find("handsfree") != std::string::npos ||
|
||||
infoLow.find("headset") != std::string::npos);
|
||||
infoLow.find("0000111e-") != std::string::npos);
|
||||
bool hasHid = (infoLow.find("00001124-") != std::string::npos ||
|
||||
infoLow.find("00001812-") != std::string::npos ||
|
||||
infoLow.find("human interface device") != std::string::npos);
|
||||
bool isPhoneOrPc = (infoLow.find("icon: phone") != std::string::npos ||
|
||||
infoLow.find("icon: computer") != std::string::npos);
|
||||
|
||||
if (infoLow.find("icon: input-gaming") != std::string::npos ||
|
||||
infoLow.find("icon: input-joystick") != std::string::npos ||
|
||||
@@ -813,6 +862,9 @@ std::vector<BtDeviceEntry> queryBtDevices(const std::string& scanRaw = "") {
|
||||
nameLow.find("trackpad") != std::string::npos) {
|
||||
d.kind = BtDevKind::Mouse;
|
||||
d.profileLabel = "HID Mouse";
|
||||
} else if (isPhoneOrPc) {
|
||||
d.kind = BtDevKind::Phone;
|
||||
d.profileLabel = "OBEX/PAN";
|
||||
} else if (hasPaSink || hasPaSrc || hasA2dp || hasHfp ||
|
||||
infoLow.find("icon: audio-") != std::string::npos) {
|
||||
d.kind = BtDevKind::Audio;
|
||||
@@ -843,10 +895,6 @@ std::vector<BtDeviceEntry> queryBtDevices(const std::string& scanRaw = "") {
|
||||
} else if (hasHid) {
|
||||
d.kind = BtDevKind::Keyboard;
|
||||
d.profileLabel = "HID Input";
|
||||
} else if (infoLow.find("icon: phone") != std::string::npos ||
|
||||
infoLow.find("icon: computer") != std::string::npos) {
|
||||
d.kind = BtDevKind::Phone;
|
||||
d.profileLabel = "OBEX/PAN";
|
||||
}
|
||||
|
||||
size_t batPos = info.find("Battery Percentage:");
|
||||
@@ -1024,6 +1072,13 @@ int runNetworksApp(int argc, char** argv) {
|
||||
int obexPickerSel = 0;
|
||||
bool obexPickerForPrompt = false;
|
||||
|
||||
// Bluetooth pairing confirmation / PIN / passkey prompt state
|
||||
BtPairPromptInfo pairPrompt;
|
||||
int pairPromptSel = 0;
|
||||
std::string pairInput;
|
||||
bool openedForPairPrompt = false;
|
||||
bool pendingDeferredPairPrompt = false;
|
||||
|
||||
// Multi-tap state for text inputs
|
||||
TextMode textMode = TextMode::Lower;
|
||||
int lastTapDigit = -1;
|
||||
@@ -1062,8 +1117,8 @@ int runNetworksApp(int argc, char** argv) {
|
||||
std::string scanRaw;
|
||||
if (btOn) {
|
||||
int obexPid = readIntFile("/tmp/bananarchy_bt_obex.pid");
|
||||
if (obexPid <= 0 || ::kill(obexPid, 0) != 0) {
|
||||
runAsyncCmd("/usr/bin/bananarchy-bt-obex start >/dev/null 2>&1");
|
||||
if (obexPid <= 0 || (::kill(obexPid, 0) != 0 && errno != EPERM)) {
|
||||
runAsyncCmd("doas -n /usr/bin/bananarchy-bt-obex start >/dev/null 2>&1");
|
||||
}
|
||||
btRx = readBtRxStatus();
|
||||
if (forceScan) {
|
||||
@@ -1182,7 +1237,7 @@ int runNetworksApp(int argc, char** argv) {
|
||||
auto applyOpenArg = [&](const std::string& arg) {
|
||||
std::string a = toLowerStr(trimStr(arg));
|
||||
modal = NetModal::None;
|
||||
if (a == "bluetooth" || a == "bt" || a == "obex-prompt") {
|
||||
if (a == "bluetooth" || a == "bt" || a == "obex-prompt" || a == "pair-prompt") {
|
||||
activeTab = NetTab::Bluetooth;
|
||||
} else if (a == "cell" || a == "cellular" || a == "apn" || a == "hotspot") {
|
||||
activeTab = NetTab::Cellular;
|
||||
@@ -1802,6 +1857,101 @@ int runNetworksApp(int argc, char** argv) {
|
||||
drawPango(layoutSmall, fg, 20, ry, 34, pRows[i], kWinWidth - 40);
|
||||
}
|
||||
drawSoftkeyBar("Accept", "Select", "Reject");
|
||||
} else if (modal == NetModal::BtPairingPrompt) {
|
||||
XSetForeground(dpy, gc, pt.spec.bgOverlay);
|
||||
XFillRectangle(dpy, pix, gc, 8, 28, kWinWidth - 16, 232);
|
||||
XSetForeground(dpy, gc, pt.spec.accent);
|
||||
XDrawRectangle(dpy, pix, gc, 8, 28, kWinWidth - 17, 231);
|
||||
|
||||
std::string devLbl = pairPrompt.devName.empty() ? pairPrompt.devMac : pairPrompt.devName;
|
||||
if (pairPrompt.mode == "CONFIRM") {
|
||||
drawPango(layoutMain, &colYellow, 16, 34, 22, "Bluetooth Pairing", kWinWidth - 32);
|
||||
drawPango(layoutSmall, &colLight, 16, 58, 18,
|
||||
tailFitPangoText(layoutSmall, devLbl, kWinWidth - 32), kWinWidth - 32);
|
||||
XSetForeground(dpy, gc, pt.spec.bgInput);
|
||||
XFillRectangle(dpy, pix, gc, 16, 80, kWinWidth - 32, 42);
|
||||
XSetForeground(dpy, gc, pt.spec.border);
|
||||
XDrawRectangle(dpy, pix, gc, 16, 80, kWinWidth - 33, 41);
|
||||
drawPango(layoutMain, &colWhite, 24, 80, 42,
|
||||
"Code: " + (pairPrompt.code.empty() ? std::string("------") : pairPrompt.code),
|
||||
kWinWidth - 48);
|
||||
drawPango(layoutSmall, &colMuted, 16, 124, 18,
|
||||
"Confirm passkey matches", kWinWidth - 32);
|
||||
|
||||
const char* pOpts[2] = {"Accept & Pair", "Reject Pairing"};
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
int ry = 148 + i * 44;
|
||||
bool isSel = (pairPromptSel == i);
|
||||
XSetForeground(dpy, gc, isSel ? pt.spec.selBg : pt.spec.bgButton);
|
||||
XFillRectangle(dpy, pix, gc, 16, ry, kWinWidth - 32, 36);
|
||||
XftColor* fg = isSel ? &colWhite : ((i == 0) ? &colGreen : &colOrange);
|
||||
drawPango(layoutMain, fg, 24, ry, 36, pOpts[i], kWinWidth - 48);
|
||||
}
|
||||
drawSoftkeyBar("Pair", "Select", "Reject");
|
||||
} else if (pairPrompt.mode == "PIN" || pairPrompt.mode == "PASSKEY") {
|
||||
bool isPin = (pairPrompt.mode == "PIN");
|
||||
drawPango(layoutMain, &colYellow, 16, 34, 22,
|
||||
isPin ? "Enter BT PIN" : "Enter Passkey", kWinWidth - 80);
|
||||
if (isPin) {
|
||||
drawPango(layoutSmall, &colBlue, kWinWidth - 58, 36, 20,
|
||||
std::string("[") + textModeLabel() + "]");
|
||||
}
|
||||
drawPango(layoutSmall, &colLight, 16, 58, 18,
|
||||
tailFitPangoText(layoutSmall, devLbl, kWinWidth - 32), kWinWidth - 32);
|
||||
|
||||
XSetForeground(dpy, gc, pt.spec.bgInputFocus);
|
||||
XFillRectangle(dpy, pix, gc, 16, 86, kWinWidth - 32, 34);
|
||||
XSetForeground(dpy, gc, pt.spec.accent);
|
||||
XDrawRectangle(dpy, pix, gc, 16, 86, kWinWidth - 33, 33);
|
||||
drawPango(layoutMain, &colWhite, 22, 86, 34,
|
||||
tailFitPangoText(layoutMain, pairInput + "_", kWinWidth - 44), kWinWidth - 44);
|
||||
|
||||
if (isPin) {
|
||||
if (lastTapDigit >= 0 && lastTapDigit <= 9 && (nowMs() - lastTapMs) <= 850) {
|
||||
const char* seq = (textMode == TextMode::Sym)
|
||||
? kSymTapMap[lastTapDigit]
|
||||
: kMultiTapMap[lastTapDigit];
|
||||
std::string cand = formatMultiTapBar(
|
||||
std::to_string(lastTapDigit) + ":", seq, lastTapCycle,
|
||||
textMode == TextMode::Upper, 6, 19);
|
||||
drawPango(layoutSmall, &colYellow, 16, 130, 18, cand, kWinWidth - 32);
|
||||
} else {
|
||||
drawPango(layoutSmall, &colMuted, 16, 130, 18,
|
||||
"# Input mode (123/abc)", kWinWidth - 32);
|
||||
}
|
||||
drawPango(layoutSmall, &colMuted, 16, 152, 18,
|
||||
"Enter matching PIN on device", kWinWidth - 32);
|
||||
} else {
|
||||
drawPango(layoutSmall, &colMuted, 16, 130, 18,
|
||||
"Type 6-digit passkey shown", kWinWidth - 32);
|
||||
drawPango(layoutSmall, &colMuted, 16, 152, 18,
|
||||
"on the other device", kWinWidth - 32);
|
||||
}
|
||||
drawPango(layoutSmall, &colMuted, 16, 174, 18,
|
||||
"[0-9] Digits [BkSp] Delete", kWinWidth - 32);
|
||||
drawSoftkeyBar("Pair", "Pair", "Reject");
|
||||
} else {
|
||||
drawPango(layoutMain, &colYellow, 16, 34, 22, "Keyboard Pairing", kWinWidth - 32);
|
||||
drawPango(layoutSmall, &colLight, 16, 58, 18,
|
||||
tailFitPangoText(layoutSmall, devLbl, kWinWidth - 32), kWinWidth - 32);
|
||||
XSetForeground(dpy, gc, pt.spec.bgInput);
|
||||
XFillRectangle(dpy, pix, gc, 16, 86, kWinWidth - 32, 44);
|
||||
XSetForeground(dpy, gc, pt.spec.accent);
|
||||
XDrawRectangle(dpy, pix, gc, 16, 86, kWinWidth - 33, 43);
|
||||
drawPango(layoutMain, &colWhite, 22, 86, 44,
|
||||
"Code: " + (pairPrompt.code.empty() ? std::string("------") : pairPrompt.code),
|
||||
kWinWidth - 44);
|
||||
drawPango(layoutSmall, &colLight, 16, 140, 18,
|
||||
"Type this code on device", kWinWidth - 32);
|
||||
drawPango(layoutSmall, &colMuted, 16, 162, 18,
|
||||
"then press Enter to finish", kWinWidth - 32);
|
||||
if (pairPrompt.entered > 0) {
|
||||
drawPango(layoutSmall, &colGreen, 16, 186, 18,
|
||||
"Entered: " + std::to_string(pairPrompt.entered) + " digit(s)",
|
||||
kWinWidth - 32);
|
||||
}
|
||||
drawSoftkeyBar("OK", "OK", "Close");
|
||||
}
|
||||
}
|
||||
|
||||
if (!statusBanner.empty() && nowMs() < statusBannerUntilMs) {
|
||||
@@ -1850,7 +2000,16 @@ int runNetworksApp(int argc, char** argv) {
|
||||
writeObexDecision(obexPrompt.reqId, false, obexPrompt.targetDir);
|
||||
obexPrompt.active = false;
|
||||
}
|
||||
if (modal == NetModal::BtPairingPrompt && pairPrompt.active) {
|
||||
if (pairPrompt.mode == "DISPLAY") {
|
||||
::unlink(kPairPromptPath);
|
||||
} else {
|
||||
writePairDecision(pairPrompt.reqId, false, "");
|
||||
}
|
||||
pairPrompt.active = false;
|
||||
}
|
||||
openedForObexPrompt = false;
|
||||
openedForPairPrompt = false;
|
||||
int xfdLocal = ConnectionNumber(dpy);
|
||||
int64_t drainDeadline = nowMs() + 180;
|
||||
while (nowMs() < drainDeadline && querySoftkeysDown(dpy) != 0) {
|
||||
@@ -1920,6 +2079,67 @@ int runNetworksApp(int argc, char** argv) {
|
||||
render();
|
||||
};
|
||||
|
||||
auto resolvePairPrompt = [&](bool accept) {
|
||||
if (pairPrompt.active) {
|
||||
if (pairPrompt.mode == "DISPLAY") {
|
||||
::unlink(kPairPromptPath);
|
||||
} else {
|
||||
if (accept && (pairPrompt.mode == "PIN" || pairPrompt.mode == "PASSKEY") &&
|
||||
trimStr(pairInput).empty()) {
|
||||
setBanner(pairPrompt.mode == "PIN" ? "Enter PIN first" : "Enter passkey first");
|
||||
render();
|
||||
return;
|
||||
}
|
||||
writePairDecision(pairPrompt.reqId, accept, trimStr(pairInput));
|
||||
}
|
||||
pairPrompt.active = false;
|
||||
}
|
||||
modal = NetModal::None;
|
||||
if (openedForPairPrompt) {
|
||||
openedForPairPrompt = false;
|
||||
hideWindow();
|
||||
} else {
|
||||
refreshCurrentTab(false);
|
||||
if (pairPrompt.mode != "DISPLAY") {
|
||||
setBanner(accept ? "Pairing confirmed..." : "Pairing rejected");
|
||||
}
|
||||
render();
|
||||
}
|
||||
};
|
||||
|
||||
auto tryPresentPairPrompt = [&](bool forceMarkOpened = false) {
|
||||
BtPairPromptInfo p = readPairPromptFile();
|
||||
if (!p.active) {
|
||||
pendingDeferredPairPrompt = false;
|
||||
return;
|
||||
}
|
||||
if (isPhonePasscodeLocked() || isPidFileAlive(getRuntimeFile("xlocker.pid")) ||
|
||||
isCallActiveOrRingingFast() || isLidClosedState()) {
|
||||
pendingDeferredPairPrompt = true;
|
||||
return;
|
||||
}
|
||||
pendingDeferredPairPrompt = false;
|
||||
bool sameReq = (modal == NetModal::BtPairingPrompt && pairPrompt.reqId == p.reqId);
|
||||
bool wasVisible = visible;
|
||||
pairPrompt = p;
|
||||
if (!sameReq) {
|
||||
pairPromptSel = 0;
|
||||
pairInput.clear();
|
||||
textMode = TextMode::Num;
|
||||
lastTapDigit = -1;
|
||||
}
|
||||
if (!wasVisible) {
|
||||
openedForPairPrompt = true;
|
||||
showWindow("bluetooth");
|
||||
} else {
|
||||
if (forceMarkOpened) openedForPairPrompt = true;
|
||||
activeTab = NetTab::Bluetooth;
|
||||
}
|
||||
wakeDisplayForObex(dpy);
|
||||
modal = NetModal::BtPairingPrompt;
|
||||
render();
|
||||
};
|
||||
|
||||
auto connectWifiNow = [&](const std::string& ssid, const std::string& pass) {
|
||||
modal = NetModal::None;
|
||||
setBanner("Connecting to " + ssid + "...");
|
||||
@@ -2061,20 +2281,11 @@ int runNetworksApp(int argc, char** argv) {
|
||||
modal = NetModal::None;
|
||||
int rc = 0;
|
||||
if (act == 0) {
|
||||
setBanner("Connecting " + targetBt.name + "...");
|
||||
setBanner("Connecting " + targetBt.name + "...", 55000);
|
||||
render();
|
||||
runCaptureCmd("/usr/bin/bananarchy-bt-obex connect " +
|
||||
shellQuote(targetBt.mac) + " " +
|
||||
shellQuote(targetBt.name) + " >/dev/null 2>&1", &rc);
|
||||
refreshCurrentTab(false);
|
||||
refreshTargetBtFromList();
|
||||
bool isConn = (rc == 0) || targetBt.connected;
|
||||
if (isConn && targetBt.kind == BtDevKind::Audio) {
|
||||
std::ofstream ofs("/tmp/sxmo_audio_out_device", std::ios::trunc);
|
||||
if (ofs) ofs << "Bluetooth\n";
|
||||
runAsyncCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
}
|
||||
setBanner(isConn ? ("Connected: " + targetBt.name) : "Connect failed");
|
||||
runAsyncCmd("doas -n /usr/bin/bananarchy-bt-obex --async-ui connect " +
|
||||
shellQuote(targetBt.mac) + " " +
|
||||
shellQuote(targetBt.name) + " >/dev/null 2>&1");
|
||||
} else if (act == 1) {
|
||||
setBanner("Disconnecting " + targetBt.name + "...");
|
||||
render();
|
||||
@@ -2087,21 +2298,11 @@ int runNetworksApp(int argc, char** argv) {
|
||||
refreshCurrentTab(false);
|
||||
setBanner("Disconnected " + targetBt.name);
|
||||
} else if (act == 2) {
|
||||
setBanner("Pairing " + targetBt.name + "...");
|
||||
setBanner("Pairing " + targetBt.name + "...", 55000);
|
||||
render();
|
||||
runCaptureCmd("/usr/bin/bananarchy-bt-obex pair " +
|
||||
shellQuote(targetBt.mac) + " " +
|
||||
shellQuote(targetBt.name) + " >/dev/null 2>&1", &rc);
|
||||
refreshCurrentTab(false);
|
||||
refreshTargetBtFromList();
|
||||
bool isPairedOrConn = (rc == 0) || targetBt.connected || targetBt.paired;
|
||||
if (isPairedOrConn && targetBt.kind == BtDevKind::Audio) {
|
||||
std::ofstream ofs("/tmp/sxmo_audio_out_device", std::ios::trunc);
|
||||
if (ofs) ofs << "Bluetooth\n";
|
||||
runAsyncCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
}
|
||||
setBanner(isPairedOrConn ? ("Paired & connected: " + targetBt.name)
|
||||
: ("Pairing failed: " + targetBt.name));
|
||||
runAsyncCmd("doas -n /usr/bin/bananarchy-bt-obex --async-ui pair " +
|
||||
shellQuote(targetBt.mac) + " " +
|
||||
shellQuote(targetBt.name) + " >/dev/null 2>&1");
|
||||
} else if (act == 3) {
|
||||
std::string macU = targetBt.mac;
|
||||
for (char& c : macU) {
|
||||
@@ -2219,6 +2420,14 @@ int runNetworksApp(int argc, char** argv) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (modal == NetModal::BtPairingPrompt) {
|
||||
if (pairPrompt.mode == "CONFIRM") {
|
||||
resolvePairPrompt(pairPromptSel == 0);
|
||||
} else {
|
||||
resolvePairPrompt(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeTab == NetTab::Wifi) {
|
||||
if (wifiRowSel == 0) {
|
||||
@@ -2350,6 +2559,10 @@ int runNetworksApp(int argc, char** argv) {
|
||||
resolveObexPrompt(true);
|
||||
return;
|
||||
}
|
||||
if (modal == NetModal::BtPairingPrompt) {
|
||||
resolvePairPrompt(true);
|
||||
return;
|
||||
}
|
||||
if (modal != NetModal::None) {
|
||||
handleEnterKey();
|
||||
return;
|
||||
@@ -2382,6 +2595,10 @@ int runNetworksApp(int argc, char** argv) {
|
||||
resolveObexPrompt(false);
|
||||
return;
|
||||
}
|
||||
if (modal == NetModal::BtPairingPrompt) {
|
||||
resolvePairPrompt(false);
|
||||
return;
|
||||
}
|
||||
if (modal == NetModal::ObexDirPicker) {
|
||||
modal = obexPickerForPrompt ? NetModal::ObexIncomingPrompt : NetModal::ObexActions;
|
||||
return;
|
||||
@@ -2395,8 +2612,11 @@ int runNetworksApp(int argc, char** argv) {
|
||||
|
||||
if (!isPreload) {
|
||||
showWindow(openArg);
|
||||
if (toLowerStr(trimStr(openArg)) == "obex-prompt") {
|
||||
std::string lowerOpen = toLowerStr(trimStr(openArg));
|
||||
if (lowerOpen == "obex-prompt") {
|
||||
tryPresentObexPrompt(true);
|
||||
} else if (lowerOpen == "pair-prompt") {
|
||||
tryPresentPairPrompt(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2459,6 +2679,8 @@ int runNetworksApp(int argc, char** argv) {
|
||||
if (sym == XF86XK_HangupPhone || sym == XK_Cancel) {
|
||||
if (modal == NetModal::ObexIncomingPrompt) {
|
||||
resolveObexPrompt(false);
|
||||
} else if (modal == NetModal::BtPairingPrompt) {
|
||||
resolvePairPrompt(false);
|
||||
} else {
|
||||
hideWindow();
|
||||
}
|
||||
@@ -2588,6 +2810,45 @@ int runNetworksApp(int argc, char** argv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (modal == NetModal::BtPairingPrompt) {
|
||||
if (pairPrompt.mode == "CONFIRM") {
|
||||
if (sym == XK_Up || sym == XK_KP_Up || sym == XK_Down || sym == XK_KP_Down) {
|
||||
pairPromptSel = (pairPromptSel + 1) % 2;
|
||||
render();
|
||||
} else if (sym == XK_Return || sym == XK_KP_Enter) {
|
||||
handleEnterKey();
|
||||
}
|
||||
} else if (pairPrompt.mode == "PIN" || pairPrompt.mode == "PASSKEY") {
|
||||
if (sym == XK_Return || sym == XK_KP_Enter) {
|
||||
resolvePairPrompt(true);
|
||||
continue;
|
||||
}
|
||||
if (pairPrompt.mode == "PASSKEY") {
|
||||
char kd = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (kd >= '0' && kd <= '9' && pairInput.size() < 6) {
|
||||
pairInput.push_back(kd);
|
||||
render();
|
||||
} else if ((sym == XK_BackSpace || sym == XK_Delete) && !pairInput.empty()) {
|
||||
pairInput.pop_back();
|
||||
render();
|
||||
}
|
||||
} else {
|
||||
if (pairInput.size() < 16 || sym == XK_BackSpace || sym == XK_Delete ||
|
||||
mapDialKey(sym, kc, ev.xkey.state) == '#') {
|
||||
if (handleMultiTapKey(pairInput, sym, kc, ev.xkey.state)) {
|
||||
if (pairInput.size() > 16) pairInput.resize(16);
|
||||
render();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (sym == XK_Return || sym == XK_KP_Enter) {
|
||||
resolvePairPrompt(true);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Main View Tab & Row Navigation
|
||||
char dch = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (dch == '#' && activeTab == NetTab::Bluetooth && btOn) {
|
||||
@@ -2687,7 +2948,8 @@ int runNetworksApp(int argc, char** argv) {
|
||||
}
|
||||
if (lastTapDigit != -1 &&
|
||||
(modal == NetModal::WifiPassword || modal == NetModal::ApnEditor ||
|
||||
modal == NetModal::BtNameEditor)) {
|
||||
modal == NetModal::BtNameEditor ||
|
||||
(modal == NetModal::BtPairingPrompt && pairPrompt.mode == "PIN"))) {
|
||||
int64_t tRem = (lastTapMs + 851) - now;
|
||||
if (tRem <= 0) {
|
||||
lastTapDigit = -1;
|
||||
@@ -2721,6 +2983,36 @@ int runNetworksApp(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (pendingDeferredPairPrompt) {
|
||||
tryPresentPairPrompt();
|
||||
if (pendingDeferredPairPrompt && (timeoutMs < 0 || timeoutMs > 250)) {
|
||||
timeoutMs = 250;
|
||||
}
|
||||
}
|
||||
if (modal == NetModal::BtPairingPrompt) {
|
||||
BtPairPromptInfo curP = readPairPromptFile();
|
||||
if (!curP.active || curP.reqId != pairPrompt.reqId) {
|
||||
if (curP.active && curP.reqId != pairPrompt.reqId) {
|
||||
tryPresentPairPrompt();
|
||||
} else {
|
||||
pairPrompt.active = false;
|
||||
modal = NetModal::None;
|
||||
if (openedForPairPrompt) {
|
||||
openedForPairPrompt = false;
|
||||
hideWindow();
|
||||
} else {
|
||||
refreshCurrentTab(false);
|
||||
if (pairPrompt.mode != "DISPLAY") {
|
||||
setBanner("Pairing ended");
|
||||
}
|
||||
render();
|
||||
}
|
||||
}
|
||||
} else if (timeoutMs < 0 || timeoutMs > 250) {
|
||||
timeoutMs = 250;
|
||||
}
|
||||
}
|
||||
|
||||
struct pollfd pfds[2];
|
||||
pfds[0].fd = xfd;
|
||||
pfds[0].events = POLLIN;
|
||||
@@ -2743,14 +3035,78 @@ int runNetworksApp(int argc, char** argv) {
|
||||
if (visible) render();
|
||||
} else if (cmd.rfind("OBEX_PROMPT", 0) == 0) {
|
||||
tryPresentObexPrompt();
|
||||
} else if (cmd.rfind("PAIR_PROMPT", 0) == 0) {
|
||||
tryPresentPairPrompt();
|
||||
} else if (cmd == "PAIR_CANCEL") {
|
||||
pendingDeferredPairPrompt = false;
|
||||
if (modal == NetModal::BtPairingPrompt) {
|
||||
pairPrompt.active = false;
|
||||
modal = NetModal::None;
|
||||
if (openedForPairPrompt) {
|
||||
openedForPairPrompt = false;
|
||||
hideWindow();
|
||||
} else {
|
||||
refreshCurrentTab(false);
|
||||
setBanner("Pairing cancelled");
|
||||
render();
|
||||
}
|
||||
}
|
||||
} else if (cmd == "BT_OP_DONE") {
|
||||
int opRc = 1;
|
||||
std::string opMode = "pair", opMac, opName;
|
||||
{
|
||||
std::ifstream in(kBtOpDonePath);
|
||||
std::string line;
|
||||
if (in.is_open() && std::getline(in, line)) {
|
||||
std::vector<std::string> cols;
|
||||
std::stringstream ss(line);
|
||||
std::string c;
|
||||
while (std::getline(ss, c, '\t')) cols.push_back(c);
|
||||
if (!cols.empty()) opRc = std::atoi(cols[0].c_str());
|
||||
if (cols.size() >= 2) opMode = cols[1];
|
||||
if (cols.size() >= 3) opMac = cols[2];
|
||||
if (cols.size() >= 4) opName = cols[3];
|
||||
}
|
||||
}
|
||||
::unlink(kBtOpDonePath);
|
||||
if (!opMac.empty()) targetBt.mac = opMac;
|
||||
if (!opName.empty()) targetBt.name = opName;
|
||||
refreshCurrentTab(false);
|
||||
refreshTargetBtFromList();
|
||||
if (opMode == "pair") {
|
||||
bool ok = (opRc == 0) || targetBt.connected || targetBt.paired;
|
||||
if (ok && targetBt.kind == BtDevKind::Audio) {
|
||||
std::ofstream ofs("/tmp/sxmo_audio_out_device", std::ios::trunc);
|
||||
if (ofs) ofs << "Bluetooth\n";
|
||||
runAsyncCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
}
|
||||
if (modal != NetModal::BtPairingPrompt) {
|
||||
setBanner(ok ? ("Paired: " + targetBt.name)
|
||||
: ("Pairing failed: " + targetBt.name));
|
||||
}
|
||||
} else {
|
||||
bool ok = (opRc == 0) || targetBt.connected;
|
||||
if (ok && targetBt.kind == BtDevKind::Audio) {
|
||||
std::ofstream ofs("/tmp/sxmo_audio_out_device", std::ios::trunc);
|
||||
if (ofs) ofs << "Bluetooth\n";
|
||||
runAsyncCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
}
|
||||
if (modal != NetModal::BtPairingPrompt) {
|
||||
setBanner(ok ? ("Connected: " + targetBt.name) : "Connect failed");
|
||||
}
|
||||
}
|
||||
if (visible) render();
|
||||
} else if (cmd == "TOGGLE") {
|
||||
if (visible) hideWindow();
|
||||
else showWindow();
|
||||
} else if (cmd.rfind("OPEN", 0) == 0) {
|
||||
std::string arg = (cmd.size() > 5) ? trimStr(cmd.substr(5)) : "";
|
||||
showWindow(arg);
|
||||
if (toLowerStr(arg) == "obex-prompt") {
|
||||
std::string lowArg = toLowerStr(arg);
|
||||
if (lowArg == "obex-prompt") {
|
||||
tryPresentObexPrompt(true);
|
||||
} else if (lowArg == "pair-prompt") {
|
||||
tryPresentPairPrompt(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user