feat(bt): 批①后台常驻框架实施 — meow_media_app_resident按app会话判活跃+should_keep三参(keepalive||bg_audio&&resident)+background_keepalive声明解析透传+amsd EV BG/FG上报;宿主test_media39/test_bgplay/test_bg_keep19全过,0warning;落盘APP_BACKGROUND_KEEPALIVE_P1;降配(nice)待真机未做

This commit is contained in:
AskaEth committed 2026-09-04 00:39:29 +08:00
1 parent 7e68313981
commit f3ae06d7cd
10 files changed
+330 -30

No files matched your search

+37
View File
@@ -956,6 +956,41 @@ static void handle_out(char **t, int nt)
out_append(pkg, pid, epoch, up, text);
}
/* 批①后台常驻上报(单向 best-effort,launcher → amsd):
* EV BG <app> <pid> → AMS_BG(转后台保活)
* EV FG <app> → AMS_FG(回前台)。旧 launcher 不发、本层不识别也不崩。 */
static void handle_bg(char **t, int nt)
{
if (nt < 2) return;
const char *pkg = t[0];
pid_t pid = (pid_t)atoi(t[1]);
long epoch = (nt > 2) ? atol(t[2]) : (long)time(NULL);
long up = (nt > 3) ? atol(t[3]) : read_uptime_sec();
struct ams_app *a = app_get(pkg);
if (!a) return;
a->state = AMS_BG;
a->pid = pid;
char detail[192];
snprintf(detail, sizeof detail, "pid=%ld", (long)pid);
hist_push(a, "bg", detail, epoch, up);
emit_log("BG %s pid=%ld", pkg, (long)pid);
}
static void handle_fg(char **t, int nt)
{
if (nt < 1) return;
const char *pkg = t[0];
long epoch = (nt > 1) ? atol(t[1]) : (long)time(NULL);
long up = (nt > 2) ? atol(t[2]) : read_uptime_sec();
struct ams_app *a = app_find(pkg);
if (!a) return;
a->state = AMS_FG;
char detail[192];
snprintf(detail, sizeof detail, "bg->fg");
hist_push(a, "fg", detail, epoch, up);
emit_log("FG %s", pkg);
}
/* ---- §6.2 二期:picker 编排(amsd 路由权威) ---- */
static struct ams_picker *picker_find(const char *action)
@@ -1252,6 +1287,8 @@ static int dispatch_line(char *line, char *resp, int rn)
if (!strcmp(tok[0], "LAUNCH")) { handle_launch(tok + 1, nt - 1); }
else if (!strcmp(tok[0], "EXIT")) { handle_exit(tok + 1, nt - 1); }
else if (!strcmp(tok[0], "OUT")) { handle_out(tok + 1, nt - 1); }
else if (!strcmp(tok[0], "BG")) { handle_bg(tok + 1, nt - 1); }
else if (!strcmp(tok[0], "FG")) { handle_fg(tok + 1, nt - 1); }
return 0;
}