Add NeoUI passcode configurator, duress mode profile, and Bluetooth OBEX UI
This commit is contained in:
1 parent
51a1a91d42
commit
62ac46e498
100 files changed
+2736
-240
No files matched your search
@@ -295,11 +295,14 @@ struct FileStamp {
|
||||
time_t sec = -1;
|
||||
long nsec = -1;
|
||||
off_t size = -1;
|
||||
std::string lastPath;
|
||||
|
||||
bool checkAndUpdate(const std::string& path) {
|
||||
bool pathChanged = (path != lastPath);
|
||||
lastPath = path;
|
||||
struct stat st {};
|
||||
if (::stat(path.c_str(), &st) != 0) {
|
||||
if (sec != 0 || size != 0) {
|
||||
if (pathChanged || sec != 0 || size != 0) {
|
||||
sec = 0;
|
||||
nsec = 0;
|
||||
size = 0;
|
||||
@@ -307,8 +310,8 @@ struct FileStamp {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (st.st_mtim.tv_sec != sec || st.st_mtim.tv_nsec != nsec ||
|
||||
st.st_size != size) {
|
||||
if (pathChanged || st.st_mtim.tv_sec != sec ||
|
||||
st.st_mtim.tv_nsec != nsec || st.st_size != size) {
|
||||
sec = st.st_mtim.tv_sec;
|
||||
nsec = st.st_mtim.tv_nsec;
|
||||
size = st.st_size;
|
||||
@@ -514,7 +517,17 @@ inline bool isPoundKey(KeySym sym, unsigned int keycode) {
|
||||
sym == XK_KP_Divide || static_cast<uint32_t>(sym) == 0x1008ffab;
|
||||
}
|
||||
|
||||
constexpr const char* kDuressModeFlagPath = "/tmp/bananarchy_duress_mode";
|
||||
constexpr const char* kDuressHomeDirPath = "/tmp/duress_home";
|
||||
|
||||
inline bool isDuressMode() {
|
||||
return ::access(kDuressModeFlagPath, F_OK) == 0;
|
||||
}
|
||||
|
||||
inline std::string getHomeDir() {
|
||||
if (isDuressMode()) {
|
||||
return kDuressHomeDirPath;
|
||||
}
|
||||
return getHomeDirPath();
|
||||
}
|
||||
|
||||
@@ -587,6 +600,9 @@ inline std::string toT9Digits(const std::string& name) {
|
||||
}
|
||||
|
||||
inline std::string getContactsFilePath() {
|
||||
if (isDuressMode()) {
|
||||
return std::string(kDuressHomeDirPath) + "/.config/sxmo/contacts.tsv";
|
||||
}
|
||||
const char* env = std::getenv("SXMO_CONTACTFILE");
|
||||
if (env && env[0]) {
|
||||
return env;
|
||||
@@ -601,6 +617,10 @@ inline std::string getContactsFilePath() {
|
||||
}
|
||||
|
||||
inline std::string getModemLogFilePath() {
|
||||
if (isDuressMode()) {
|
||||
return std::string(kDuressHomeDirPath) +
|
||||
"/.local/share/sxmo/modem/modemlog.tsv";
|
||||
}
|
||||
const char* env = std::getenv("SXMO_LOGDIR");
|
||||
if (env && env[0]) {
|
||||
return std::string(env) + "/modemlog.tsv";
|
||||
@@ -993,6 +1013,9 @@ class ContactBook {
|
||||
};
|
||||
|
||||
inline std::string getBlockFilePath() {
|
||||
if (isDuressMode()) {
|
||||
return std::string(kDuressHomeDirPath) + "/.config/sxmo/block.tsv";
|
||||
}
|
||||
const char* env = std::getenv("SXMO_BLOCKFILE");
|
||||
if (env && env[0]) {
|
||||
return env;
|
||||
@@ -1007,6 +1030,9 @@ inline std::string getBlockFilePath() {
|
||||
}
|
||||
|
||||
inline std::string getBlockDirPath() {
|
||||
if (isDuressMode()) {
|
||||
return std::string(kDuressHomeDirPath) + "/.local/share/sxmo/block";
|
||||
}
|
||||
const char* env = std::getenv("SXMO_BLOCKDIR");
|
||||
if (env && env[0]) {
|
||||
return env;
|
||||
@@ -1767,6 +1793,10 @@ inline DualSimInfo queryDualSimInfo(bool forceRefresh = false) {
|
||||
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);
|
||||
if (isDuressMode()) {
|
||||
info.slot1Number.clear();
|
||||
info.slot2Number.clear();
|
||||
}
|
||||
|
||||
auto formatSlotStrings = [](int s, const std::string& op, const std::string& rat,
|
||||
const std::string& num, std::string& outLabel,
|
||||
@@ -1842,6 +1872,8 @@ inline void closeOtherPlugins(const char* selfPluginName) {
|
||||
{"xtox.pid", "tox"},
|
||||
{"xsmallweb.pid", "smallweb"},
|
||||
{"xgps.pid", "gps"},
|
||||
{"xpasscode.pid", "passcode"},
|
||||
{"xengmenu.pid", "engmenu"},
|
||||
};
|
||||
for (const auto& p : kAllPlugins) {
|
||||
if (selfPluginName && std::strcmp(p.name, selfPluginName) == 0) {
|
||||
@@ -1884,6 +1916,8 @@ inline bool isAnotherPluginActive(const char* selfPluginName) {
|
||||
{"xtox.pid", "tox"},
|
||||
{"xsmallweb.pid", "smallweb"},
|
||||
{"xgps.pid", "gps"},
|
||||
{"xpasscode.pid", "passcode"},
|
||||
{"xengmenu.pid", "engmenu"},
|
||||
};
|
||||
for (const auto& p : kAllPlugins) {
|
||||
if (selfPluginName && std::strcmp(p.name, selfPluginName) == 0) {
|
||||
@@ -1935,6 +1969,8 @@ inline void broadcastThemeReload(const char* selfPluginName = nullptr) {
|
||||
"tox",
|
||||
"smallweb",
|
||||
"gps",
|
||||
"passcode",
|
||||
"engmenu",
|
||||
};
|
||||
for (const char* name : kPlugins) {
|
||||
if (selfPluginName && std::strcmp(name, selfPluginName) == 0) {
|
||||
@@ -1947,10 +1983,13 @@ inline void broadcastThemeReload(const char* selfPluginName = nullptr) {
|
||||
::close(fd);
|
||||
}
|
||||
}
|
||||
runAsyncCmd("pkill -USR1 -x st >/dev/null 2>&1");
|
||||
runAsyncCmd("pkill -USR1 -x st >/dev/null 2>&1; /usr/bin/bananarchy-sync-dunst-theme >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
inline std::string getModemLogDirPath() {
|
||||
if (isDuressMode()) {
|
||||
return std::string(kDuressHomeDirPath) + "/.local/share/sxmo/modem";
|
||||
}
|
||||
const char* env = std::getenv("SXMO_LOGDIR");
|
||||
if (env && env[0]) {
|
||||
return env;
|
||||
@@ -2411,8 +2450,111 @@ inline bool queryQrtrDmsImeis(DeviceImeis& out) {
|
||||
return !out.imei1.empty() || !out.imei2.empty();
|
||||
}
|
||||
|
||||
inline std::string generateRandomImeiFromTac(const std::string& rawTac) {
|
||||
std::string tac;
|
||||
for (char c : rawTac) {
|
||||
if (c >= '0' && c <= '9' && tac.size() < 8) {
|
||||
tac.push_back(c);
|
||||
}
|
||||
}
|
||||
while (tac.size() < 8) {
|
||||
tac += "35829909"[tac.size()];
|
||||
}
|
||||
unsigned char rnd[6] = {0, 0, 0, 0, 0, 0};
|
||||
int ufd = ::open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||
if (ufd >= 0) {
|
||||
(void)::read(ufd, rnd, sizeof(rnd));
|
||||
::close(ufd);
|
||||
}
|
||||
std::string body = tac;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
body.push_back(static_cast<char>('0' + (rnd[i] % 10)));
|
||||
}
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 14; ++i) {
|
||||
int d = body[i] - '0';
|
||||
if ((i % 2) == 1) {
|
||||
d *= 2;
|
||||
if (d >= 10) {
|
||||
d = (d / 10) + (d % 10);
|
||||
}
|
||||
}
|
||||
sum += d;
|
||||
}
|
||||
int check = (10 - (sum % 10)) % 10;
|
||||
body.push_back(static_cast<char>('0' + check));
|
||||
return body;
|
||||
}
|
||||
|
||||
inline DeviceImeis queryDeviceImeis() {
|
||||
static DeviceImeis cached;
|
||||
static DeviceImeis cachedDuress;
|
||||
|
||||
if (isDuressMode()) {
|
||||
if (!cachedDuress.imei1.empty() && !cachedDuress.imei2.empty()) {
|
||||
return cachedDuress;
|
||||
}
|
||||
const char* kDuressImeiFile = "/tmp/bananarchy_duress_imei";
|
||||
{
|
||||
std::ifstream in(kDuressImeiFile);
|
||||
std::string line;
|
||||
while (std::getline(in, line)) {
|
||||
if (line.rfind("IMEI1=", 0) == 0) {
|
||||
cachedDuress.imei1 = trimStr(line.substr(6));
|
||||
} else if (line.rfind("IMEI2=", 0) == 0) {
|
||||
cachedDuress.imei2 = trimStr(line.substr(6));
|
||||
} else if (line.rfind("IMEI_SV=", 0) == 0) {
|
||||
cachedDuress.imeiSv = trimStr(line.substr(8));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cachedDuress.imei1.empty() && !cachedDuress.imei2.empty()) {
|
||||
return cachedDuress;
|
||||
}
|
||||
|
||||
std::string tac1 = "35829909";
|
||||
std::string tac2 = "35829909";
|
||||
{
|
||||
std::ifstream tin("/tmp/bananarchy_real_tac");
|
||||
std::string tline;
|
||||
if (std::getline(tin, tline) && tline.size() >= 8) {
|
||||
tac1 = tline.substr(0, 8);
|
||||
tac2 = tac1;
|
||||
}
|
||||
if (std::getline(tin, tline) && tline.size() >= 8) {
|
||||
tac2 = tline.substr(0, 8);
|
||||
}
|
||||
}
|
||||
if (!cached.imei1.empty() && cached.imei1.size() >= 8) {
|
||||
tac1 = cached.imei1.substr(0, 8);
|
||||
tac2 = (!cached.imei2.empty() && cached.imei2.size() >= 8)
|
||||
? cached.imei2.substr(0, 8)
|
||||
: tac1;
|
||||
} else if (::access("/tmp/bananarchy_real_tac", F_OK) != 0) {
|
||||
DeviceImeis realTmp;
|
||||
queryQrtrDmsImeis(realTmp);
|
||||
if (realTmp.imei1.size() >= 8) {
|
||||
tac1 = realTmp.imei1.substr(0, 8);
|
||||
tac2 = (realTmp.imei2.size() >= 8) ? realTmp.imei2.substr(0, 8) : tac1;
|
||||
}
|
||||
}
|
||||
|
||||
cachedDuress.imei1 = generateRandomImeiFromTac(tac1);
|
||||
cachedDuress.imei2 = generateRandomImeiFromTac(tac2);
|
||||
while (cachedDuress.imei2 == cachedDuress.imei1) {
|
||||
cachedDuress.imei2 = generateRandomImeiFromTac(tac2);
|
||||
}
|
||||
cachedDuress.imeiSv = "01";
|
||||
|
||||
std::ofstream out(kDuressImeiFile, std::ios::trunc);
|
||||
if (out.is_open()) {
|
||||
out << "IMEI1=" << cachedDuress.imei1 << "\n"
|
||||
<< "IMEI2=" << cachedDuress.imei2 << "\n"
|
||||
<< "IMEI_SV=" << cachedDuress.imeiSv << "\n";
|
||||
}
|
||||
return cachedDuress;
|
||||
}
|
||||
|
||||
if (!cached.imei1.empty() && !cached.imei2.empty()) {
|
||||
return cached;
|
||||
}
|
||||
@@ -2441,6 +2583,16 @@ inline DeviceImeis queryDeviceImeis() {
|
||||
}
|
||||
if (!res.imei1.empty()) {
|
||||
cached = res;
|
||||
if (res.imei1.size() >= 8 &&
|
||||
::access("/tmp/bananarchy_real_tac", F_OK) != 0) {
|
||||
std::ofstream tout("/tmp/bananarchy_real_tac", std::ios::trunc);
|
||||
if (tout.is_open()) {
|
||||
tout << res.imei1.substr(0, 8) << "\n"
|
||||
<< ((res.imei2.size() >= 8) ? res.imei2.substr(0, 8)
|
||||
: res.imei1.substr(0, 8))
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -3007,6 +3159,10 @@ inline bool qrtrReadSimContacts(
|
||||
std::string& outErr) {
|
||||
outContacts.clear();
|
||||
outErr.clear();
|
||||
if (isDuressMode()) {
|
||||
outErr = "SIM phonebook empty";
|
||||
return false;
|
||||
}
|
||||
|
||||
int sfd = -1;
|
||||
uint32_t uimNode = 0, uimPort = 0;
|
||||
@@ -3045,6 +3201,10 @@ inline bool qrtrWriteSimContacts(
|
||||
int& outExported, std::string& outErr) {
|
||||
outExported = 0;
|
||||
outErr.clear();
|
||||
if (isDuressMode()) {
|
||||
outErr = "SIM phonebook unavailable";
|
||||
return false;
|
||||
}
|
||||
if (contactsToWrite.empty()) {
|
||||
outErr = "No contacts to export";
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user