这两天遇到个奇怪的问题,手机电量低于15%的时候,只会弹出低电量的提示框,低电量指示灯并没有闪烁。
查看log
01-01 00:02:36.294016 1253 1286 D lights : set_led_state colorRGB=FFFF0000, onMS=125, offMS=2875
01-01 00:02:36.294087 1253 1286 D lights : blink_red, level=255, onMS=125, offMS=2875
01-01 00:02:36.294147 1253 1286 D lights : write timer to /sys/class/leds/red/trigger
01-01 00:02:36.295306 1253 1286 D lights : write_str open fd=149
01-01 00:02:36.306318 1253 1286 D lights : write timer to /sys/class/leds/red/trigger amt = 5
01-01 00:02:36.308148 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.313706 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.319396 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.324970 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.330605 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.336586 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.342146 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.348308 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.353941 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.359572 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!!
01-01 00:02:36.365457 1253 1286 D lights : RED_DELAY_OFF_FILE doesn't exist or cannot write!! i=10
01-01 00:02:36.365742 1253 1286 D lights : write_int open fd=-1
01-01 00:02:36.366032 1253 1286 D lights : write_int open fd=-1
可以看到是因为write_str(RED_TRIGGER_FILE, “timer”); 之后,并没有生成delay_on和delay_off两个文件。
手动用echo测试
先echo timer >> /sys/class/leds/red/trigger 测试,可以生成 delay_on和delay_off两个文件,然后
echo 200 >> /sys/class/leds/red/delay_off
echo 200 >> /sys/class/leds/red/delay_on 这样设置一下时间,指示灯就可以闪烁。
write_int open fd=-1 返回-1 ,意味着没有权限,这两个文件是动态注册权限的,所以看ueventd.mt6735.rc文件,找到下面两句
/sys/devices/platform/leds-mt65xx/leds/red delay_on 0664 system system
/sys/devices/platform/leds-mt65xx/leds/red delay_off 0664 system system
通过adb连接设备,发现leds-mt65xx的路径不对,实际上在
/sys/devices/leds-mt65xx,尝试修改上面两句为
/sys/devices/leds-mt65xx/leds/red delay_on 0664 system system
/sys/devices/leds-mt65xx/leds/red delay_off 0664 system system
重新编译下载,问题解决。