Fix mobile data static IP bearer, call recording, earpiece audio, and ringtone/vibration
This commit is contained in:
1 parent
21dfb187be
commit
a8a28fa685
23 files changed
+624
-212
No files matched your search
+107
-26
@@ -2,6 +2,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <glob.h>
|
||||
#include <linux/input.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -9,17 +10,42 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int read_configured_level(void) {
|
||||
char path[512];
|
||||
static volatile sig_atomic_t g_stop = 0;
|
||||
|
||||
static void handle_signal(int sig) {
|
||||
(void)sig;
|
||||
g_stop = 1;
|
||||
}
|
||||
|
||||
static void get_sxmo_config_dir(char* out, size_t out_sz) {
|
||||
const char* cfg = getenv("XDG_CONFIG_HOME");
|
||||
const char* home = getenv("HOME");
|
||||
if (cfg && *cfg) {
|
||||
snprintf(path, sizeof(path), "%s/sxmo/ringsettings", cfg);
|
||||
snprintf(out, out_sz, "%s/sxmo", cfg);
|
||||
} else if (home && *home) {
|
||||
snprintf(path, sizeof(path), "%s/.config/sxmo/ringsettings", home);
|
||||
snprintf(out, out_sz, "%s/.config/sxmo", home);
|
||||
} else {
|
||||
snprintf(path, sizeof(path), "/home/user/.config/sxmo/ringsettings");
|
||||
snprintf(out, out_sz, "/home/user/.config/sxmo");
|
||||
}
|
||||
}
|
||||
|
||||
static int is_vibrate_muted(void) {
|
||||
const char* force = getenv("SXMO_VIBRATE_FORCE");
|
||||
if (force && *force == '1') {
|
||||
return 0;
|
||||
}
|
||||
char dir[448];
|
||||
char path[512];
|
||||
get_sxmo_config_dir(dir, sizeof(dir));
|
||||
snprintf(path, sizeof(path), "%s/.novibrate", dir);
|
||||
return access(path, F_OK) == 0;
|
||||
}
|
||||
|
||||
static int read_configured_level(void) {
|
||||
char dir[448];
|
||||
char path[512];
|
||||
get_sxmo_config_dir(dir, sizeof(dir));
|
||||
snprintf(path, sizeof(path), "%s/ringsettings", dir);
|
||||
|
||||
FILE* fp = fopen(path, "r");
|
||||
if (!fp) return 0;
|
||||
@@ -32,24 +58,45 @@ static int read_configured_level(void) {
|
||||
if (strncmp(p, "SXMO_VIBRATE_STRENGTH=", 22) == 0) {
|
||||
int v = atoi(p + 22);
|
||||
if (v >= 1 && v <= 3) level = v;
|
||||
else if (v > 3 && v <= 16000) level = 1;
|
||||
else if (v > 16000 && v <= 45000) level = 2;
|
||||
else if (v > 45000) level = 3;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return level;
|
||||
}
|
||||
|
||||
static int resolve_magnitude(int raw_arg, int has_arg) {
|
||||
static int resolve_level_and_magnitude(int raw_arg, int has_arg, int* level_out) {
|
||||
int val = raw_arg;
|
||||
if (!has_arg || (val == 1 && !getenv("SXMO_VIBRATE_STRENGTH"))) {
|
||||
const char* env_str = getenv("SXMO_VIBRATE_STRENGTH");
|
||||
if (!has_arg || (val == 1 && (!env_str || !*env_str))) {
|
||||
int cfg = read_configured_level();
|
||||
if (cfg >= 1 && cfg <= 3) val = cfg;
|
||||
if (cfg >= 1 && cfg <= 3) {
|
||||
val = cfg;
|
||||
} else if (env_str && *env_str) {
|
||||
int ev = atoi(env_str);
|
||||
if (ev >= 1) val = ev;
|
||||
} else if (!has_arg) {
|
||||
val = 2;
|
||||
}
|
||||
}
|
||||
if (val <= 1) return 8000;
|
||||
if (val == 2) return 32000;
|
||||
if (val == 3) return 65535;
|
||||
if (val < 256) return val * 257;
|
||||
if (val > 65535) return 65535;
|
||||
return val;
|
||||
|
||||
int level = 2;
|
||||
int mag = 32000;
|
||||
if (val <= 1 || (val >= 256 && val <= 16000)) {
|
||||
level = 1;
|
||||
mag = 14000;
|
||||
} else if (val == 2 || (val > 16000 && val <= 45000)) {
|
||||
level = 2;
|
||||
mag = 32000;
|
||||
} else {
|
||||
level = 3;
|
||||
mag = 65535;
|
||||
}
|
||||
|
||||
if (level_out) *level_out = level;
|
||||
return mag;
|
||||
}
|
||||
|
||||
static int open_vibrator_device(void) {
|
||||
@@ -77,6 +124,15 @@ static int open_vibrator_device(void) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void sleep_ms_interruptible(long ms) {
|
||||
if (ms <= 0 || g_stop) return;
|
||||
struct timespec req;
|
||||
req.tv_sec = ms / 1000;
|
||||
req.tv_nsec = (ms % 1000) * 1000000L;
|
||||
while (!g_stop && nanosleep(&req, &req) == -1 && errno == EINTR) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2 || argc > 3) {
|
||||
fprintf(stderr, "Usage: sxmo_vibrate duration_ms [strength_number]\n");
|
||||
@@ -91,6 +147,10 @@ int main(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (is_vibrate_muted()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int raw_strength = 2;
|
||||
int has_strength = 0;
|
||||
if (argc == 3) {
|
||||
@@ -103,7 +163,16 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
int magnitude = resolve_magnitude(raw_strength, has_strength);
|
||||
int level = 2;
|
||||
int magnitude = resolve_level_and_magnitude(raw_strength, has_strength, &level);
|
||||
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = handle_signal;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaction(SIGINT, &sa, NULL);
|
||||
sigaction(SIGTERM, &sa, NULL);
|
||||
sigaction(SIGHUP, &sa, NULL);
|
||||
|
||||
int fd = open_vibrator_device();
|
||||
if (fd < 0) {
|
||||
@@ -128,18 +197,30 @@ int main(int argc, char** argv) {
|
||||
memset(&play, 0, sizeof(play));
|
||||
play.type = EV_FF;
|
||||
play.code = (unsigned short)effect.id;
|
||||
play.value = 3;
|
||||
|
||||
if (write(fd, &play, sizeof(play)) < 0) {
|
||||
ioctl(fd, EVIOCRMFF, effect.id);
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct timespec req;
|
||||
req.tv_sec = duration_ms / 1000;
|
||||
req.tv_nsec = (duration_ms % 1000) * 1000000L;
|
||||
while (nanosleep(&req, &req) == -1 && errno == EINTR) {
|
||||
if (level >= 3 || duration_ms <= 90) {
|
||||
long actual_ms = (level == 1 && duration_ms > 55) ? 55 : duration_ms;
|
||||
play.value = 1;
|
||||
if (write(fd, &play, sizeof(play)) >= 0) {
|
||||
sleep_ms_interruptible(actual_ms);
|
||||
}
|
||||
} else {
|
||||
long on_ms = (level == 1) ? 75 : 160;
|
||||
long off_ms = (level == 1) ? 125 : 80;
|
||||
long rem = duration_ms;
|
||||
while (rem > 0 && !g_stop) {
|
||||
long cur_on = (rem < on_ms) ? rem : on_ms;
|
||||
play.value = 1;
|
||||
if (write(fd, &play, sizeof(play)) < 0) break;
|
||||
sleep_ms_interruptible(cur_on);
|
||||
rem -= cur_on;
|
||||
play.value = 0;
|
||||
(void)write(fd, &play, sizeof(play));
|
||||
if (rem <= 0 || g_stop) break;
|
||||
long cur_off = (rem < off_ms) ? rem : off_ms;
|
||||
sleep_ms_interruptible(cur_off);
|
||||
rem -= cur_off;
|
||||
}
|
||||
}
|
||||
|
||||
play.value = 0;
|
||||
|
||||
Reference in new issue
Block a user