MTK Android 11.0:充电低电指示灯会被未读消息信号灯灭掉,无优先级控制:
1、电池充电、低电状态提示(红绿双色)。(LIGHT_ID_BATTERY)
小于15%时:
A 正在充电 亮红灯。
B 未充电 红灯闪烁 灭2秒 亮0.5秒。
大于15%,小于90%时:
A 正在充电 亮红灯。
B 未充电 灭灯。
大于90%时:
A 正在充电 亮绿灯。
B 未充电 灭灯。
2、未读消息通知灯。(LIGHT_ID_NOTIFICATIONS)
public static final int LIGHT_ID_BACKLIGHT = Type.BACKLIGHT;
public static final int LIGHT_ID_KEYBOARD = Type.KEYBOARD;
public static final int LIGHT_ID_BUTTONS = Type.BUTTONS;
public static final int LIGHT_ID_BATTERY = Type.BATTERY;
public static final int LIGHT_ID_NOTIFICATIONS = Type.NOTIFICATIONS;
public static final int LIGHT_ID_ATTENTION = Type.ATTENTION;
public static final int LIGHT_ID_BLUETOOTH = Type.BLUETOOTH;
public static final int LIGHT_ID_WIFI = Type.WIFI;
3、优先级:
电池充电/低电的优先级 大于 未读消息通知灯。
4、异常现象:在MTK Android 11.0平台上,充电/低电指示灯亮起后,会被后面的未读消息信号灯灭掉,无优先级控制。
5、解决办法:
修改文件:/vendor/mediatek/proprietary/hardware/liblights/aidl/default/Lights.cpp
static int blink_red(int level, int onMS, int offMS)
{
static int preStatus = 0; // 0: off, 1: blink, 2: no blink
int nowStatus;
int i = 0;
int ret = 0;
if(level == 0)
{
nowStatus = 0;
}
else if(onMS && offMS)
{
nowStatus = 1;
}
else
{
nowStatus = 2;
}
if(preStatus == nowStatus)
{
return 0;
}
#ifdef LIGHTS_DBG_ON
ALOGD("blink_red, level=%d, onMS=%d, offMS=%d\n", level, onMS, offMS);
#endif
#if 0 /* Modified start by Eli at 2022-06-14 09:57 */
if(nowStatus == 0)
{
ret = write_int(RED_LED_FILE, 0);
}
else if(nowStatus == 1)
{
//write_int(RED_LED_FILE, level); // default full brightness
ret = write_str(RED_TRIGGER_FILE, "timer");
while(((access(RED_DELAY_OFF_FILE, F_OK) == -1) || (access(RED_DELAY_OFF_FILE, R_OK | W_OK) == -1)) && i < 10)
{
ALOGD("RED_DELAY_OFF_FILE doesn't exist or cannot write!!\n");
led_wait_delay(5);//sleep 5ms for wait kernel LED class create led delay_off/delay_on node of fs
i++;
}
ret = write_int(RED_DELAY_OFF_FILE, offMS);
ret = write_int(RED_DELAY_ON_FILE, onMS);
}
else
{
ret = write_str(RED_TRIGGER_FILE, "none");
ret = write_int(RED_LED_FILE, 255); // default full brightness
}
#else
if(onMS>600)
{
onMS = (onMS-600)/LED_BREATH_MODE_TON_SETP_TIME;
}
else
{
onMS = 0;
}
offMS = offMS/LED_BREATH_MODE_TOFF_SETP_TIME;
if (nowStatus == 0)
{
ret = write_str(RED_TRIGGER_FILE, LED_TRIGGER_CC_MODE);
ret = write_int(RED_LED_FILE, LED_BL_LEVEL_0);
}
else if (nowStatus == 1)
{
ret = write_str(RED_TRIGGER_FILE, LED_TRIGGER_BREATH_MODE);
while (((access(RED_DELAY_OFF_FILE, F_OK) == -1) || (access(RED_DELAY_OFF_FILE, R_OK | W_OK) == -1)) && i < 10)
{
ALOGD("RED_DELAY_OFF_FILE doesn't exist or cannot write!!\n");
led_wait_delay(5);//sleep 5ms for wait kernel LED class create led toff/ton node of fs
i++;
}
//ret = write_int(RED_LED_FILE, LED_BL_LEVEL_4);//delete batteryLed closed by NoticeLed
ret = write_int(RED_DELAY_OFF_FILE, offMS);
ret = write_int(RED_DELAY_ON_FILE, onMS);
ret = write_int(RED_LED_FILE, LED_BL_LEVEL_4);//add batteryLed closed by NoticeLed
}
else
{
ret = write_str(RED_TRIGGER_FILE, LED_TRIGGER_CC_MODE);
ret = write_int(RED_LED_FILE, LED_BL_LEVEL_4); // default full brightness
}
#endif /* #if 0 */
preStatus = nowStatus;
return ret;
}
核心修改如下:
static int handle_speaker_battery_locked(__attribute__((__unused__)) HwLight const *light,
const HwLightState *state)
{
int ret = 0;
//start batteryLed closed by NoticeLed
if(is_lit(&g_battery_state/*state*/))
{
ret = set_speaker_light_locked(light, &g_battery_state/*state*/);
}
//end batteryLed closed by NoticeLed
else
{
/*Turkey workaround: notification and Low battery case, IPO bootup, NLED cannot blink*/
ret = set_speaker_light_locked(&g_battery, &g_battery_state);
ret = set_speaker_light_locked(&g_notification, &g_notification_state);
}
return ret;
}
经过上面这段代码修改后,电池充电/低电的指示灯 不会被 未读消息通知灯灭掉。