Fix lid wake blanking, passcode lag, idle drain, zero-log privacy default, and replace Conky with native dwm clock
This commit is contained in:
1 parent
11ec778c2f
commit
1d71bc81d8
42 files changed
+732
-267
No files matched your search
@@ -75,6 +75,7 @@ struct EngStatus {
|
||||
int cpuMaxMhz = 1094;
|
||||
bool diagActive = false;
|
||||
std::string usbPid = "18d1:d001";
|
||||
bool extLogging = false;
|
||||
};
|
||||
|
||||
// Calculate 15th Luhn check digit from the first 14 digits (Wallace calcIMEIChecksum)
|
||||
@@ -254,6 +255,7 @@ EngStatus queryEngStatus() {
|
||||
else if (k == "CPU_MAX_MHZ") st.cpuMaxMhz = std::atoi(v.c_str());
|
||||
else if (k == "DIAG_ACTIVE") st.diagActive = (v == "1");
|
||||
else if (k == "USB_PID") st.usbPid = v;
|
||||
else if (k == "EXT_LOGGING") st.extLogging = (v == "1");
|
||||
}
|
||||
if (st.imei1.empty() || st.imei2.empty()) {
|
||||
DeviceImeis devIm = queryDeviceImeis();
|
||||
@@ -410,6 +412,14 @@ int engmenu_run_main(int argc, char** argv) {
|
||||
rows.push_back({"7", "7: Edit Bluetooth MAC", bmacSub,
|
||||
isRfnv ? "persist" : "NV 447", 2});
|
||||
|
||||
// 8. [8] Extended logging (privacy)
|
||||
std::string logSub = status.extLogging
|
||||
? "RAM logs active in /tmp"
|
||||
: "Disabled (zero idle logs)";
|
||||
rows.push_back({"8", "8: Extended Logging", logSub,
|
||||
status.extLogging ? "ON" : "OFF",
|
||||
status.extLogging ? 2 : 1});
|
||||
|
||||
return rows;
|
||||
};
|
||||
|
||||
@@ -478,6 +488,12 @@ int engmenu_run_main(int argc, char** argv) {
|
||||
editBuf = generateRandomMac();
|
||||
lastHexKey = -1;
|
||||
modal = EngModal::EditBtMac;
|
||||
} else if (idx == 7) {
|
||||
// 8: Extended Logging
|
||||
std::string res = runEngCtlCapture({"logging", "toggle"});
|
||||
refreshStatus();
|
||||
showToast(status.extLogging ? "Extended logging enabled (/tmp)"
|
||||
: "Extended logging disabled & purged");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -716,7 +732,7 @@ int engmenu_run_main(int argc, char** argv) {
|
||||
std::string lskLabel = "Select";
|
||||
if (selIdx == 0 || selIdx == 1 || selIdx == 2 || selIdx == 5 || selIdx == 6) {
|
||||
lskLabel = "Edit";
|
||||
} else if (selIdx == 3 || selIdx == 4) {
|
||||
} else if (selIdx == 3 || selIdx == 4 || selIdx == 7) {
|
||||
lskLabel = "Toggle";
|
||||
}
|
||||
neo.drawSoftbar(lskLabel, "Run", "Close", &theme.colYellow);
|
||||
@@ -1000,7 +1016,7 @@ int engmenu_run_main(int argc, char** argv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
constexpr int kNumItems = 7;
|
||||
constexpr int kNumItems = 8;
|
||||
if (sym == XK_Up || sym == XK_KP_Up) {
|
||||
selIdx = (selIdx > 0) ? (selIdx - 1) : (kNumItems - 1);
|
||||
render();
|
||||
@@ -1019,8 +1035,8 @@ int engmenu_run_main(int argc, char** argv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Direct hotkeys 1..7
|
||||
if (dch >= '1' && dch <= '7') {
|
||||
// Direct hotkeys 1..8
|
||||
if (dch >= '1' && dch <= '8') {
|
||||
selIdx = dch - '1';
|
||||
triggerRowAction(selIdx);
|
||||
render();
|
||||
|
||||
+331
-121
@@ -178,12 +178,38 @@ enum class VerifyResult {
|
||||
|
||||
class PasscodeVerifier {
|
||||
public:
|
||||
PasscodeVerifier() {
|
||||
struct timespec ts {};
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
sessionSalt_ = (static_cast<uint64_t>(ts.tv_sec) << 32) ^
|
||||
static_cast<uint64_t>(ts.tv_nsec) ^
|
||||
(static_cast<uint64_t>(::getpid()) * 0x9e3779b97f4a7c15ULL);
|
||||
int ufd = ::open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||
if (ufd >= 0) {
|
||||
uint64_t rnd = 0;
|
||||
if (::read(ufd, &rnd, sizeof(rnd)) == static_cast<ssize_t>(sizeof(rnd))) {
|
||||
sessionSalt_ ^= rnd;
|
||||
}
|
||||
::close(ufd);
|
||||
}
|
||||
}
|
||||
|
||||
void clearSessionCache() {
|
||||
hasVerifiedNormal_ = false;
|
||||
verifiedNormalLen_ = 0;
|
||||
verifiedNormalDigest_ = 0;
|
||||
hasVerifiedDuress_ = false;
|
||||
verifiedDuressLen_ = 0;
|
||||
verifiedDuressDigest_ = 0;
|
||||
}
|
||||
|
||||
void forceRefresh() {
|
||||
shadowMtime_ = 0;
|
||||
shadowSize_ = 0;
|
||||
duressMtime_ = -1;
|
||||
cachedHash_.clear();
|
||||
cachedDuressHash_.clear();
|
||||
clearSessionCache();
|
||||
refreshIfNeeded();
|
||||
}
|
||||
|
||||
@@ -202,6 +228,7 @@ class PasscodeVerifier {
|
||||
shadowSize_ = st.st_size;
|
||||
duressMtime_ = curDuressMtime;
|
||||
}
|
||||
clearSessionCache();
|
||||
int pipefd[2];
|
||||
if (::pipe(pipefd) != 0) {
|
||||
return;
|
||||
@@ -258,19 +285,57 @@ class PasscodeVerifier {
|
||||
}
|
||||
}
|
||||
|
||||
VerifyResult verify(const std::string& candidate) {
|
||||
VerifyResult verifyFast(const std::string& candidate) {
|
||||
if (candidate.empty()) {
|
||||
return VerifyResult::Invalid;
|
||||
}
|
||||
refreshIfNeeded();
|
||||
uint64_t dig = computeSessionDigest(candidate);
|
||||
if (hasVerifiedNormal_ && candidate.size() == verifiedNormalLen_ &&
|
||||
dig == verifiedNormalDigest_) {
|
||||
return VerifyResult::NormalUser;
|
||||
}
|
||||
if (hasVerifiedDuress_ && candidate.size() == verifiedDuressLen_ &&
|
||||
dig == verifiedDuressDigest_) {
|
||||
return VerifyResult::DuressUser;
|
||||
}
|
||||
return VerifyResult::Invalid;
|
||||
}
|
||||
|
||||
bool canSkipAutoVerifyLength(size_t len) const {
|
||||
if (hasVerifiedNormal_ && cachedDuressHash_.empty()) {
|
||||
return len != verifiedNormalLen_;
|
||||
}
|
||||
if (hasVerifiedNormal_ && hasVerifiedDuress_) {
|
||||
return len != verifiedNormalLen_ && len != verifiedDuressLen_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
VerifyResult verify(const std::string& candidate) {
|
||||
if (candidate.empty()) {
|
||||
return VerifyResult::Invalid;
|
||||
}
|
||||
VerifyResult fast = verifyFast(candidate);
|
||||
if (fast != VerifyResult::Invalid) {
|
||||
return fast;
|
||||
}
|
||||
writeSysfsStr("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor",
|
||||
"schedutil");
|
||||
if (!cachedHash_.empty()) {
|
||||
char* res = ::crypt(candidate.c_str(), cachedHash_.c_str());
|
||||
if (res && constantTimeEq(res, cachedHash_)) {
|
||||
hasVerifiedNormal_ = true;
|
||||
verifiedNormalLen_ = candidate.size();
|
||||
verifiedNormalDigest_ = computeSessionDigest(candidate);
|
||||
return VerifyResult::NormalUser;
|
||||
}
|
||||
if (!cachedDuressHash_.empty()) {
|
||||
char* dres = ::crypt(candidate.c_str(), cachedDuressHash_.c_str());
|
||||
if (dres && constantTimeEq(dres, cachedDuressHash_)) {
|
||||
hasVerifiedDuress_ = true;
|
||||
verifiedDuressLen_ = candidate.size();
|
||||
verifiedDuressDigest_ = computeSessionDigest(candidate);
|
||||
return VerifyResult::DuressUser;
|
||||
}
|
||||
}
|
||||
@@ -309,9 +374,15 @@ class PasscodeVerifier {
|
||||
if (pid > 0 && ::waitpid(pid, &status, 0) > 0 && WIFEXITED(status)) {
|
||||
int code = WEXITSTATUS(status);
|
||||
if (code == 0) {
|
||||
hasVerifiedNormal_ = true;
|
||||
verifiedNormalLen_ = candidate.size();
|
||||
verifiedNormalDigest_ = computeSessionDigest(candidate);
|
||||
return VerifyResult::NormalUser;
|
||||
}
|
||||
if (code == 10) {
|
||||
hasVerifiedDuress_ = true;
|
||||
verifiedDuressLen_ = candidate.size();
|
||||
verifiedDuressDigest_ = computeSessionDigest(candidate);
|
||||
return VerifyResult::DuressUser;
|
||||
}
|
||||
}
|
||||
@@ -319,11 +390,31 @@ class PasscodeVerifier {
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t computeSessionDigest(const std::string& s) const {
|
||||
uint64_t h = 0xcbf29ce484222325ULL ^ sessionSalt_;
|
||||
for (unsigned char c : s) {
|
||||
h ^= static_cast<uint64_t>(c);
|
||||
h *= 0x100000001b3ULL;
|
||||
h ^= (h >> 32);
|
||||
}
|
||||
h ^= static_cast<uint64_t>(s.size()) * 0x9e3779b97f4a7c15ULL;
|
||||
h = (h ^ (h >> 30)) * 0xbf58476d1ce4e5b9ULL;
|
||||
h = (h ^ (h >> 27)) * 0x94d049bb133111ebULL;
|
||||
return h ^ (h >> 31);
|
||||
}
|
||||
|
||||
std::string cachedHash_;
|
||||
std::string cachedDuressHash_;
|
||||
time_t shadowMtime_ = 0;
|
||||
off_t shadowSize_ = 0;
|
||||
time_t duressMtime_ = -1;
|
||||
uint64_t sessionSalt_ = 0;
|
||||
bool hasVerifiedNormal_ = false;
|
||||
size_t verifiedNormalLen_ = 0;
|
||||
uint64_t verifiedNormalDigest_ = 0;
|
||||
bool hasVerifiedDuress_ = false;
|
||||
size_t verifiedDuressLen_ = 0;
|
||||
uint64_t verifiedDuressDigest_ = 0;
|
||||
};
|
||||
|
||||
int countNotifFiles() {
|
||||
@@ -436,6 +527,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
constexpr int64_t kLockerIdleBlankMs = 30000;
|
||||
bool visible = false;
|
||||
bool grabHeld = false;
|
||||
bool wasScreenBlanked = isScreenBlanked();
|
||||
std::string passcode;
|
||||
std::string statusMsg;
|
||||
bool statusIsError = false;
|
||||
@@ -444,8 +536,37 @@ int locker_run_main(int argc, char** argv) {
|
||||
int64_t statusClearAtMs = 0;
|
||||
int64_t lockActivatedMs = 0;
|
||||
int64_t lastActivityMs = 0;
|
||||
int64_t autoVerifyAtMs = 0;
|
||||
int lastRenderedMin = -1;
|
||||
|
||||
int cachedPctVal = -1;
|
||||
bool cachedIsCharging = false;
|
||||
int cachedNotifCount = 0;
|
||||
int64_t lastStatusPollMs = 0;
|
||||
|
||||
auto refreshStatusCache = [&](bool force) {
|
||||
int64_t now = nowMs();
|
||||
if (!force && lastStatusPollMs > 0 && (now - lastStatusPollMs) < 10000) {
|
||||
return;
|
||||
}
|
||||
lastStatusPollMs = now;
|
||||
std::string cap = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/capacity");
|
||||
if (cap.empty()) {
|
||||
cap = readSmallFileTrimmed("/sys/class/power_supply/battery/capacity");
|
||||
}
|
||||
std::string batStatus = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/status");
|
||||
if (batStatus.empty()) {
|
||||
batStatus = readSmallFileTrimmed("/sys/class/power_supply/battery/status");
|
||||
}
|
||||
std::string chgrOnline = readSmallFileTrimmed("/sys/class/power_supply/pm8916-lbc-chgr/online");
|
||||
cachedPctVal = cap.empty() ? -1 : std::clamp(std::atoi(cap.c_str()), 0, 100);
|
||||
cachedIsCharging = (batStatus == "Charging" || batStatus == "Full" || chgrOnline == "1");
|
||||
if (chgrOnline == "0") {
|
||||
cachedIsCharging = false;
|
||||
}
|
||||
cachedNotifCount = countNotifFiles();
|
||||
};
|
||||
|
||||
auto isCallScreenVisible = [&]() -> bool {
|
||||
return isPidFileAlive(getRuntimeFile("xcallscreen.pid"));
|
||||
};
|
||||
@@ -458,13 +579,13 @@ int locker_run_main(int argc, char** argv) {
|
||||
XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
|
||||
XFlush(dpy);
|
||||
grabHeld = false;
|
||||
for (int attempt = 0; attempt < 15; ++attempt) {
|
||||
for (int attempt = 0; attempt < 3; ++attempt) {
|
||||
if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync,
|
||||
CurrentTime) == GrabSuccess) {
|
||||
grabHeld = true;
|
||||
break;
|
||||
}
|
||||
::usleep(10000);
|
||||
::usleep(3000);
|
||||
}
|
||||
XGrabPointer(dpy, win, True, ButtonPressMask | ButtonReleaseMask,
|
||||
GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
||||
@@ -499,6 +620,8 @@ int locker_run_main(int argc, char** argv) {
|
||||
statusClearAtMs = 0;
|
||||
}
|
||||
|
||||
refreshStatusCache(false);
|
||||
|
||||
// Background fill
|
||||
XSetForeground(dpy, gc, theme.spec.bgMain);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kScreenWidth, kScreenHeight);
|
||||
@@ -512,20 +635,8 @@ int locker_run_main(int argc, char** argv) {
|
||||
neo.drawPango(layoutIcon, &theme.colYellow, 8, 0, 24, kIconLock);
|
||||
neo.drawPango(layoutSmall, &theme.colLight, 26, 0, 24, "Locked");
|
||||
|
||||
std::string cap = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/capacity");
|
||||
if (cap.empty()) {
|
||||
cap = readSmallFileTrimmed("/sys/class/power_supply/battery/capacity");
|
||||
}
|
||||
std::string batStatus = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/status");
|
||||
if (batStatus.empty()) {
|
||||
batStatus = readSmallFileTrimmed("/sys/class/power_supply/battery/status");
|
||||
}
|
||||
std::string chgrOnline = readSmallFileTrimmed("/sys/class/power_supply/pm8916-lbc-chgr/online");
|
||||
int pctVal = cap.empty() ? -1 : std::clamp(std::atoi(cap.c_str()), 0, 100);
|
||||
bool isCharging = (batStatus == "Charging" || batStatus == "Full" || chgrOnline == "1");
|
||||
if (chgrOnline == "0") {
|
||||
isCharging = false;
|
||||
}
|
||||
int pctVal = cachedPctVal;
|
||||
bool isCharging = cachedIsCharging;
|
||||
if (pctVal >= 0) {
|
||||
std::string batText = std::string(pickBatteryIcon(pctVal, isCharging)) +
|
||||
" " + std::to_string(pctVal) + "%";
|
||||
@@ -557,7 +668,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
kScreenWidth, 1);
|
||||
|
||||
// Notification badge (count only, no private content exposed on lockscreen)
|
||||
int notifCount = countNotifFiles();
|
||||
int notifCount = cachedNotifCount;
|
||||
if (notifCount > 0) {
|
||||
std::string nstr = std::string(kIconBell) + " " +
|
||||
std::to_string(notifCount) +
|
||||
@@ -642,9 +753,6 @@ int locker_run_main(int argc, char** argv) {
|
||||
passcode.empty() ? "Sleep" : "Clear",
|
||||
&theme.colYellow);
|
||||
|
||||
if (!grabHeld && !isCallScreenVisible()) {
|
||||
grabLockerInput();
|
||||
}
|
||||
neo.present();
|
||||
};
|
||||
|
||||
@@ -664,6 +772,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
statusIsError = false;
|
||||
failedAttempts = 0;
|
||||
cooldownUntilMs = 0;
|
||||
autoVerifyAtMs = 0;
|
||||
::unlink(kLockFlagPath);
|
||||
::unlink(activePidPath.c_str());
|
||||
releaseLockerGrab();
|
||||
@@ -675,6 +784,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
writeSoftkeySuppress(nowMs() + 350);
|
||||
setSxmoStateFile("unlock");
|
||||
wakeScreenBacklight();
|
||||
wasScreenBlanked = false;
|
||||
runAsyncCmd("sxmo_hook_unlock.sh >/dev/null 2>&1");
|
||||
};
|
||||
|
||||
@@ -693,6 +803,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
verifier.refreshIfNeeded();
|
||||
int64_t now = nowMs();
|
||||
lastActivityMs = now;
|
||||
autoVerifyAtMs = 0;
|
||||
if (!alreadyVisible || blankDisplay) {
|
||||
passcode.clear();
|
||||
statusMsg.clear();
|
||||
@@ -709,14 +820,18 @@ int locker_run_main(int argc, char** argv) {
|
||||
if (blankDisplay) {
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
wasScreenBlanked = true;
|
||||
} else {
|
||||
setSxmoStateFile("lock");
|
||||
wakeScreenBacklight();
|
||||
wasScreenBlanked = false;
|
||||
refreshStatusCache(true);
|
||||
render();
|
||||
}
|
||||
};
|
||||
|
||||
auto submitPasscode = [&](bool explicitSubmit) {
|
||||
autoVerifyAtMs = 0;
|
||||
int64_t now = nowMs();
|
||||
if (cooldownUntilMs > now) {
|
||||
render();
|
||||
@@ -757,6 +872,119 @@ int locker_run_main(int argc, char** argv) {
|
||||
}
|
||||
};
|
||||
|
||||
auto handleKeyInput = [&](unsigned int kc, unsigned int state, KeySym sym) {
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
int64_t now = nowMs();
|
||||
lastActivityMs = now;
|
||||
if (isScreenBlanked()) {
|
||||
setSxmoStateFile("lock");
|
||||
wakeScreenBacklight();
|
||||
wasScreenBlanked = false;
|
||||
lockActivatedMs = now;
|
||||
refreshStatusCache(true);
|
||||
render();
|
||||
return;
|
||||
}
|
||||
if (now - lockActivatedMs < 80) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Power / End Call / Sleep button blanks the screen while remaining locked
|
||||
if (kc == 124 || sym == XF86XK_PowerOff || sym == XF86XK_Sleep ||
|
||||
sym == XF86XK_Standby || sym == XF86XK_Suspend ||
|
||||
sym == XF86XK_HangupPhone || sym == XK_Cancel ||
|
||||
sym == _EVDEVK(0x74) || sym == _EVDEVK(0x8e) ||
|
||||
sym == XK_Escape) {
|
||||
if (isCallActiveOrRingingFast() || isCallScreenVisible()) {
|
||||
sendPluginCommand("callscreen", "HANGUP_CLOSE");
|
||||
::unlink("/tmp/sxmo_call_ringing");
|
||||
::unlink("/tmp/sxmo_active_call");
|
||||
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
|
||||
}
|
||||
passcode.clear();
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
autoVerifyAtMs = 0;
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
wasScreenBlanked = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Left softkey: explicit Unlock attempt
|
||||
if (isLeftSoftkey(sym, kc)) {
|
||||
submitPasscode(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Right softkey: Clear last digit, or blank screen if empty
|
||||
if (isRightSoftkey(sym, kc)) {
|
||||
autoVerifyAtMs = 0;
|
||||
if (!passcode.empty()) {
|
||||
passcode.pop_back();
|
||||
render();
|
||||
} else {
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
wasScreenBlanked = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Backspace / Left arrow: delete last digit
|
||||
if (sym == XK_BackSpace || sym == XK_Delete ||
|
||||
sym == XK_Left || sym == XK_KP_Left) {
|
||||
autoVerifyAtMs = 0;
|
||||
if (!passcode.empty()) {
|
||||
passcode.pop_back();
|
||||
render();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Enter / Center OK / Call / Pound (#): explicit Unlock attempt
|
||||
if (sym == XK_Return || sym == XK_KP_Enter ||
|
||||
sym == XF86XK_Phone || sym == XF86XK_PickupPhone ||
|
||||
sym == XF86XK_Send || isPoundKey(sym, kc)) {
|
||||
submitPasscode(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Numeric digits 0-9
|
||||
char ch = mapDialKey(sym, kc, state);
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
if (cooldownUntilMs > now) {
|
||||
render();
|
||||
return;
|
||||
}
|
||||
if (passcode.size() < 32) {
|
||||
passcode.push_back(ch);
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
render();
|
||||
if (passcode.size() >= 4) {
|
||||
VerifyResult fastRes = verifier.verifyFast(passcode);
|
||||
if (fastRes == VerifyResult::NormalUser ||
|
||||
fastRes == VerifyResult::DuressUser) {
|
||||
autoVerifyAtMs = 0;
|
||||
unlockPhone(fastRes == VerifyResult::DuressUser);
|
||||
return;
|
||||
}
|
||||
if (!verifier.canSkipAutoVerifyLength(passcode.size())) {
|
||||
autoVerifyAtMs = nowMs() + 220;
|
||||
} else {
|
||||
autoVerifyAtMs = 0;
|
||||
}
|
||||
} else {
|
||||
autoVerifyAtMs = 0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if (!isPreload) {
|
||||
lockPhone(initCmd == "LOCK_BLANK");
|
||||
} else if (::access(kLockFlagPath, F_OK) == 0) {
|
||||
@@ -767,6 +995,16 @@ int locker_run_main(int argc, char** argv) {
|
||||
bool callWasActive = false;
|
||||
|
||||
while (gRunning) {
|
||||
bool blankNow = isScreenBlanked();
|
||||
if (wasScreenBlanked && !blankNow) {
|
||||
wasScreenBlanked = false;
|
||||
int64_t now = nowMs();
|
||||
lastActivityMs = now;
|
||||
refreshStatusCache(true);
|
||||
} else if (blankNow) {
|
||||
wasScreenBlanked = true;
|
||||
}
|
||||
|
||||
if (fifoFd >= 0) {
|
||||
for (const std::string& cmd : readFifoLines(fifoFd)) {
|
||||
if (cmd == "NOP") {
|
||||
@@ -801,16 +1039,37 @@ int locker_run_main(int argc, char** argv) {
|
||||
if (!visible) {
|
||||
lockPhone(false);
|
||||
} else {
|
||||
closeOtherOverlays();
|
||||
bool wasBlank = wasScreenBlanked || isScreenBlanked();
|
||||
if (wasBlank) {
|
||||
closeOtherOverlays();
|
||||
}
|
||||
setSxmoStateFile("lock");
|
||||
wakeScreenBacklight();
|
||||
wasScreenBlanked = false;
|
||||
lastActivityMs = nowMs();
|
||||
grabLockerInput();
|
||||
if (wasBlank) {
|
||||
refreshStatusCache(true);
|
||||
}
|
||||
if (!grabHeld) {
|
||||
grabLockerInput();
|
||||
}
|
||||
render();
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (cmd.rfind("KEY ", 0) == 0) {
|
||||
unsigned int kc = 0;
|
||||
unsigned int st = 0;
|
||||
if (std::sscanf(cmd.c_str() + 4, "%u %u", &kc, &st) >= 1 && kc > 0) {
|
||||
if (!grabHeld && visible && !isCallScreenVisible()) {
|
||||
grabLockerInput();
|
||||
}
|
||||
KeySym sym = XKeycodeToKeysym(dpy, static_cast<KeyCode>(kc), 0);
|
||||
handleKeyInput(kc, st, sym);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (cmd.rfind("VERIFY ", 0) == 0) {
|
||||
std::string code = trimStr(cmd.substr(7));
|
||||
VerifyResult vres =
|
||||
@@ -852,7 +1111,7 @@ int locker_run_main(int argc, char** argv) {
|
||||
} else if (!callNow && callWasActive) {
|
||||
grabLockerInput();
|
||||
render();
|
||||
} else if (!callNow && !grabHeld) {
|
||||
} else if (!callNow && !grabHeld && !isScreenBlanked()) {
|
||||
grabLockerInput();
|
||||
}
|
||||
callWasActive = callNow;
|
||||
@@ -862,112 +1121,46 @@ int locker_run_main(int argc, char** argv) {
|
||||
XEvent ev;
|
||||
XNextEvent(dpy, &ev);
|
||||
if (ev.type == Expose) {
|
||||
if (visible && ev.xexpose.count == 0) {
|
||||
if (visible && ev.xexpose.count == 0 && !isScreenBlanked()) {
|
||||
render();
|
||||
}
|
||||
} else if (ev.type == VisibilityNotify || ev.type == FocusOut ||
|
||||
ev.type == UnmapNotify) {
|
||||
} else if (ev.type == UnmapNotify) {
|
||||
if (visible && ::access(kLockFlagPath, F_OK) == 0 &&
|
||||
!isCallScreenVisible()) {
|
||||
if (ev.type == UnmapNotify) {
|
||||
XMapRaised(dpy, win);
|
||||
}
|
||||
XMapRaised(dpy, win);
|
||||
grabLockerInput();
|
||||
if (!isScreenBlanked()) {
|
||||
render();
|
||||
}
|
||||
}
|
||||
} else if (ev.type == VisibilityNotify) {
|
||||
if (visible && ev.xvisibility.state != VisibilityUnobscured &&
|
||||
::access(kLockFlagPath, F_OK) == 0 && !isCallScreenVisible() &&
|
||||
!isScreenBlanked()) {
|
||||
XRaiseWindow(dpy, win);
|
||||
if (!grabHeld) {
|
||||
grabLockerInput();
|
||||
}
|
||||
render();
|
||||
}
|
||||
} else if (ev.type == FocusOut) {
|
||||
if (visible && ::access(kLockFlagPath, F_OK) == 0 &&
|
||||
!isCallScreenVisible() && !isScreenBlanked() &&
|
||||
ev.xfocus.mode == NotifyNormal) {
|
||||
grabLockerInput();
|
||||
}
|
||||
} else if (ev.type == KeyPress) {
|
||||
if (!visible) {
|
||||
continue;
|
||||
}
|
||||
int64_t now = nowMs();
|
||||
lastActivityMs = now;
|
||||
if (isScreenBlanked()) {
|
||||
setSxmoStateFile("lock");
|
||||
wakeScreenBacklight();
|
||||
lockActivatedMs = now;
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (now - lockActivatedMs < 180) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned int kc = ev.xkey.keycode;
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||
handleKeyInput(ev.xkey.keycode, ev.xkey.state, sym);
|
||||
}
|
||||
}
|
||||
|
||||
// Power / End Call / Sleep button blanks the screen while remaining locked
|
||||
if (kc == 124 || sym == XF86XK_PowerOff || sym == XF86XK_Sleep ||
|
||||
sym == XF86XK_Standby || sym == XF86XK_Suspend ||
|
||||
sym == XF86XK_HangupPhone || sym == XK_Cancel ||
|
||||
sym == _EVDEVK(0x74) || sym == _EVDEVK(0x8e) ||
|
||||
sym == XK_Escape) {
|
||||
if (isCallActiveOrRingingFast() || isCallScreenVisible()) {
|
||||
sendPluginCommand("callscreen", "HANGUP_CLOSE");
|
||||
::unlink("/tmp/sxmo_call_ringing");
|
||||
::unlink("/tmp/sxmo_active_call");
|
||||
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
|
||||
}
|
||||
passcode.clear();
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Left softkey: explicit Unlock attempt
|
||||
if (isLeftSoftkey(sym, kc)) {
|
||||
submitPasscode(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Right softkey: Clear last digit, or blank screen if empty
|
||||
if (isRightSoftkey(sym, kc)) {
|
||||
if (!passcode.empty()) {
|
||||
passcode.pop_back();
|
||||
render();
|
||||
} else {
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Backspace / Left arrow: delete last digit
|
||||
if (sym == XK_BackSpace || sym == XK_Delete ||
|
||||
sym == XK_Left || sym == XK_KP_Left) {
|
||||
if (!passcode.empty()) {
|
||||
passcode.pop_back();
|
||||
render();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Enter / Center OK / Call / Pound (#): explicit Unlock attempt
|
||||
if (sym == XK_Return || sym == XK_KP_Enter ||
|
||||
sym == XF86XK_Phone || sym == XF86XK_PickupPhone ||
|
||||
sym == XF86XK_Send || isPoundKey(sym, kc)) {
|
||||
submitPasscode(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Numeric digits 0-9
|
||||
char ch = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
if (cooldownUntilMs > now) {
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (passcode.size() < 32) {
|
||||
passcode.push_back(ch);
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
render();
|
||||
if (passcode.size() >= 4) {
|
||||
submitPasscode(false);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
if (visible && autoVerifyAtMs > 0 && !isScreenBlanked()) {
|
||||
int64_t now = nowMs();
|
||||
if (now >= autoVerifyAtMs) {
|
||||
autoVerifyAtMs = 0;
|
||||
if (passcode.size() >= 4) {
|
||||
submitPasscode(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -981,8 +1174,10 @@ int locker_run_main(int argc, char** argv) {
|
||||
passcode.clear();
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
autoVerifyAtMs = 0;
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
wasScreenBlanked = true;
|
||||
} else {
|
||||
if (!isCallScreenVisible() && !grabHeld) {
|
||||
grabLockerInput();
|
||||
@@ -993,6 +1188,9 @@ int locker_run_main(int argc, char** argv) {
|
||||
int curMin = tmNow.tm_hour * 60 + tmNow.tm_min;
|
||||
if (curMin != lastRenderedMin || cooldownUntilMs > now ||
|
||||
(statusClearAtMs > 0 && now >= statusClearAtMs)) {
|
||||
if (curMin != lastRenderedMin) {
|
||||
refreshStatusCache(true);
|
||||
}
|
||||
render();
|
||||
}
|
||||
}
|
||||
@@ -1019,6 +1217,12 @@ int locker_run_main(int argc, char** argv) {
|
||||
if (idleRemMs < timeoutMs) {
|
||||
timeoutMs = static_cast<int>(idleRemMs);
|
||||
}
|
||||
if (autoVerifyAtMs > 0) {
|
||||
int64_t autoRem = std::max<int64_t>(10, autoVerifyAtMs - now);
|
||||
if (autoRem < timeoutMs) {
|
||||
timeoutMs = static_cast<int>(autoRem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct pollfd pfds[2] {};
|
||||
@@ -1026,7 +1230,13 @@ int locker_run_main(int argc, char** argv) {
|
||||
pfds[0].events = POLLIN;
|
||||
pfds[1].fd = fifoFd;
|
||||
pfds[1].events = POLLIN;
|
||||
::poll(pfds, (fifoFd >= 0) ? 2 : 1, timeoutMs);
|
||||
int pr = ::poll(pfds, (fifoFd >= 0) ? 2 : 1, timeoutMs);
|
||||
if (pr < 0 && errno != EINTR) {
|
||||
break;
|
||||
}
|
||||
if (pfds[0].revents & (POLLHUP | POLLERR | POLLNVAL)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_object_unref(layoutClock);
|
||||
|
||||
Reference in new issue
Block a user