参考:[Android L]SEAndroid开放设备文件结点权限(读或写)方法(涵盖常用操作:sys/xxx、proc/xxx、SystemProperties)
http://blog.csdn.net/yelangjueqi/article/details/46761987
HAL:hardware/nubia_hardware/NX541J/breathlight
核心思想是上层打开/sys/class/leds/nubia_led/路径下文件,写入数据即可调试呼吸灯
alps/device/mediatek/common/sepolicy/file.te
type sysfs_breath_leds, fs_type, sysfs_type;
alps/device/mediatek/common/sepolicy/file_contexts
/sys/class/leds/nubia_led(/.*)? u:object_r:sysfs_breath_leds:s0
/sys/class/leds/nubia_led/outn u:object_r:sysfs_breath_leds:s0
/sys/class/leds/nubia_led/grade_parameter u:object_r:sysfs_breath_leds:s0
/sys/class/leds/nubia_led/fade_parameter u:object_r:sysfs_breath_leds:s0
/sys/class/leds/nubia_led/blink_mode u:object_r:sysfs_breath_leds:s0
/sys/devices/soc.4/11008000.i2c/i2c-1/1-0045/leds/nubia_led(/.*)? u:object_r:sysfs_breath_leds:s0
/sys/devices/soc.4/11008000.i2c/i2c-1/1-0045/leds/nubia_led/outn u:object_r:sysfs_breath_leds:s0
/sys/devices/soc.4/11008000.i2c/i2c-1/1-0045/leds/nubia_led/grade_parameter u:object_r:sysfs_breath_leds:s0
/sys/devices/soc.4/11008000.i2c/i2c-1/1-0045/leds/nubia_led/fade_parameter u:object_r:sysfs_breath_leds:s0
/sys/devices/soc.4/11008000.i2c/i2c-1/1-0045/leds/nubia_led/blink_mode u:object_r:sysfs_breath_leds:s0
alps/device/mediatek/common/sepolicy/system_app.te
allow system_app sysfs_breath_leds:dir { search open read write add_name create getattr setattr };
allow system_app sysfs_breath_leds:file { open read write create append unlink ioctl getattr setattr };
allow system_app sysfs_breath_leds:lnk_file { open read write create append unlink ioctl getattr setattr };
allow system_app sysfs_breath_leds:fifo_file { read write open create setattr};
android上层相关代码:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
//blink_mode
//AW_SW_RESET, // 0 soft_reset , all regs revert to default value.
//AW_CONST_ON, // 1 work on a constant lightness.
//AW_CONST_OFF, // 2 darkness is comming
//AW_AUTO_BREATH, // 3 self breathing, used in sences such as missing message.
//AW_STEP_FADE_IN, // 4 fade in means that the lightness is getting stronger.
//AW_STEP_FADE_OUT,
// 5 fade out means that the lightness is getting weaker
//AW_BREATH_ONCE,
// 6 only breath once, touch the home menu for instance.
//AW_RESERVED, // 7 reserverd.
private void turnOnLeds() {
//writeFile("blink_mode","0");
writeFile("outn","1");
writeFile("grade_parameter","200 255");
writeFile("blink_mode","1");
writeFile("outn","0");
//writeFile("grade_parameter","200 255");
writeFile("blink_mode","6");
}
//"/sys/class/leds/nubia_led/blink_mode"
private void turnOffLeds() {
writeFile("blink_mode","0");
}
private void writeFile(String fileName,String writestr){
try{
FileOutputStream mfile = new FileOutputStream("/sys/class/leds/nubia_led/"+fileName);
byte [] bytes = writestr.getBytes();
mfile.write(bytes);
mfile.close();
}
catch (IOException ex) {
Log.w(TAG, "wanglei write File fail: " + ex.toString());
}
}