充电态权威源 mp2731-charger/status(修 battery/status 撒谎恒 Discharging)

真机实测:设备充电中但 battery/status 恒 Discharging;权威源为
mp2731-charger/status(Charging/Full),回退链 fusb302-typec-source/online==1
→ 旧逻辑 battery/status==Charging || ac/online==1。电量仍读 battery/capacity。

- meow_svc_power: battery/status 命令充电判定走权威链(MEOW_PS_DIR 可重定向供宿主自测);
  svc_power_authtest 补 6 用例(mp2731 Charging/Full/Discharging + 两级回退)全 PASS
- SDK meow_ui_sys: 状态栏充电态同权威链
- launcher util.c: 抽 batt_is_charging() 公共判定;meow_sys_light 1s 轻刷补充电态(插拔实时)
- bootmenu 无充电判定(仅读 capacity)/MeowPanel 透传 power 服务:均无需改
- 真机验证(充电窗口):新二进制 battery=88%(Charging),对照固件内旧版 88%(Discharging)
- hello/files/ncm 随 meow_ui.a(af6703f2) 重链已热更到卡(.new+mv,md5 对核一致)

md5: meow_svc_power 39ae3aa2 / meow_launcherd 2aa61780 / hello 2444c151 /
files 691db88b / ncm 89da63ed(仅重链,源码未动)
This commit is contained in:
MeowOS committed 2026-09-01 03:25:01 +08:00
1 parent 793a807ce3
commit f149e24f28
13 files changed
+114 -12

No files matched your search

Binary file not shown.
+27 -4
View File
@@ -57,9 +57,19 @@
#define SETTINGS_FILE "/usr/data/meow/settings.conf"
#define SETTINGS_HDR "# meow-settings 1"
#define VERSION_FILE "/etc/meowos_version"
#define BATT_CAP "/sys/class/power_supply/battery/capacity"
#define BATT_STATUS "/sys/class/power_supply/battery/status"
#define BATT_VOLT "/sys/class/power_supply/battery/voltage_now"
/* sysfs 根可经 MEOW_PS_DIR 覆盖(宿主自测用;生产恒 /sys/class/power_supply) */
#ifndef MEOW_PS_DIR
#define MEOW_PS_DIR "/sys/class/power_supply"
#endif
#define BATT_CAP MEOW_PS_DIR "/battery/capacity"
#define BATT_STATUS MEOW_PS_DIR "/battery/status"
#define BATT_VOLT MEOW_PS_DIR "/battery/voltage_now"
/* 充电态权威源(真机实测 2026-09-01:battery/status 恒 Discharging 撒谎):
* mp2731-charger/status(Charging/Full=充电中)为权威;不可读回退 fusb302-typec-source/online==1
* (USB-C PD 控制器插线检测);再回退旧逻辑 battery/status==Charging || ac/online==1。 */
#define CHG_MP2731_STATUS MEOW_PS_DIR "/mp2731-charger/status"
#define CHG_FUSB302_ONLINE MEOW_PS_DIR "/fusb302-typec-source/online"
#define CHG_AC_ONLINE MEOW_PS_DIR "/ac/online"
#define UPGRADE_FW "/usr/data/mnt/sd_0/r3proii.upt" /* 卡根升级固件(写 mtd5 前完整性校验) */
/* 音量语义(与 launcher MEOW_VOL_DEFAULT/MEOW_VOL_MAX_DEFAULT、SDK MEOW_UI_VOL_* 一致):
@@ -319,11 +329,24 @@ static void cat_b(char *dst, size_t cap, const char *src)
}
/* ---------------- 电池/状态读组(同 util.c/about.c/bootmenu 数据源) ---------------- */
/* 充电态权威判定(见上方 CHG_* 注释):返回写入 st 的状态串(空=无法判定)。 */
static void charging_status_str(char *st, int cap)
{
st[0] = 0;
if (read_file_txt(CHG_MP2731_STATUS, st, cap) > 0 && st[0]) return; /* 权威源直用 */
int on = read_file_int_def(CHG_FUSB302_ONLINE, -1);
if (on >= 0) { snprintf(st, cap, "%s", on == 1 ? "Charging" : "Discharging"); return; }
read_file_txt(BATT_STATUS, st, cap);
if (!strstr(st, "Charging") && !strstr(st, "Full") &&
read_file_int_def(CHG_AC_ONLINE, 0) == 1)
snprintf(st, cap, "Charging");
}
static void battery_fill(char *out, int cap)
{
int pct = read_file_int_def(BATT_CAP, -1);
char st[32] = "";
read_file_txt(BATT_STATUS, st, sizeof st);
charging_status_str(st, sizeof st); /* 权威充电态(battery/status 会撒谎) */
int mv = read_file_int_def(BATT_VOLT, -1) / 1000; /* µV → mV */
if (pct < 0) { snprintf(out, cap, "battery=unknown"); return; }
char one[64];
Binary file not shown.
Binary file not shown.
@@ -9,12 +9,15 @@
* cc -Wall -Wextra -I../meow_launcherd svc_power_authtest.c -o svc_power_authtest && ./svc_power_authtest
*/
#define main meow_svc_power_prod_main_unused
#define MEOW_PS_DIR "/tmp/meow_ps_authtest" /* 充电态判定宿主自测:重定向 sysfs 根 */
#include "meow_svc_power.c"
#undef main
#undef MEOW_PS_DIR
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
static int g_fail = 0;
#define CHECK(cond) do { if (!(cond)) { printf(" FAIL: %s (line %d)\n", #cond, __LINE__); g_fail++; } \
@@ -126,6 +129,49 @@ int main(void)
a.cmd = POWER_SET_DEFAULT_MEOW; CHECK(is_read_level(&a) == 0);
a.cmd = POWER_SET_DEFAULT_HIBY; CHECK(is_read_level(&a) == 0);
/* == 充电态权威源(真机实测 2026-09-01:battery/status 恒 Discharging 撒谎)==
* 在 /tmp 造 power_supply 假节点(MEOW_PS_DIR 已重定向),覆盖判定优先级:
* mp2731-charger/status(权威)→ fusb302-typec-source/online → battery/status|ac/online。 */
printf("== charging_status_str (authoritative mp2731) ==\n");
mkdir("/tmp/meow_ps_authtest", 0755);
mkdir("/tmp/meow_ps_authtest/battery", 0755);
mkdir("/tmp/meow_ps_authtest/mp2731-charger", 0755);
mkdir("/tmp/meow_ps_authtest/fusb302-typec-source", 0755);
mkdir("/tmp/meow_ps_authtest/ac", 0755);
write_file_str("/tmp/meow_ps_authtest/battery/capacity", "72", 0644);
write_file_str("/tmp/meow_ps_authtest/battery/voltage_now", "4150000", 0644);
write_file_str("/tmp/meow_ps_authtest/battery/status", "Discharging", 0644); /* 撒谎节点 */
write_file_str("/tmp/meow_ps_authtest/ac/online", "0", 0644);
char out[64];
/* T1: mp2731=Charging(battery 撒谎 Discharging)→ 充电中 */
write_file_str("/tmp/meow_ps_authtest/mp2731-charger/status", "Charging", 0644);
battery_fill(out, sizeof out);
CHECK(strstr(out, "(Charging)") != NULL);
/* T2: mp2731=Full → 满电 */
write_file_str("/tmp/meow_ps_authtest/mp2731-charger/status", "Full", 0644);
battery_fill(out, sizeof out);
CHECK(strstr(out, "(Full)") != NULL);
/* T3: mp2731=Discharging 且拔线 → 非充电(权威源的放电可信) */
write_file_str("/tmp/meow_ps_authtest/mp2731-charger/status", "Discharging", 0644);
write_file_str("/tmp/meow_ps_authtest/fusb302-typec-source/online", "0", 0644);
battery_fill(out, sizeof out);
CHECK(strstr(out, "(Discharging)") != NULL);
/* T4: mp2731 节点不可读 → 回退 fusb302 online==1 → 充电 */
unlink("/tmp/meow_ps_authtest/mp2731-charger/status");
write_file_str("/tmp/meow_ps_authtest/fusb302-typec-source/online", "1", 0644);
battery_fill(out, sizeof out);
CHECK(strstr(out, "(Charging)") != NULL);
/* T5: 全不可读 → 回退旧逻辑 ac/online==1 → Charging */
unlink("/tmp/meow_ps_authtest/fusb302-typec-source/online");
write_file_str("/tmp/meow_ps_authtest/ac/online", "1", 0644);
battery_fill(out, sizeof out);
CHECK(strstr(out, "(Charging)") != NULL);
/* T6: 全不可读且 ac/online=0、battery=Discharging → Discharging */
write_file_str("/tmp/meow_ps_authtest/ac/online", "0", 0644);
battery_fill(out, sizeof out);
CHECK(strstr(out, "(Discharging)") != NULL);
if (g_fail) { printf("\nAUTH TEST: %d FAIL\n", g_fail); return 1; }
printf("\nAUTH TEST: ALL PASS\n");
return 0;