添加
设备节点读写方法
private static final String path = "/sys/charge_led_gpio/charge_led_gpio";
private void open() {
try {
setNodeString(path,String.valueOf(1));
} catch (Exception e) {
e.printStackTrace();
}
}
private void close() {
try {
setNodeString(path,String.valueOf(0));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 读取设备节点
*/
public static String getNodeString(String path) {
String prop = "waiting";// 默认值
try {
BufferedReader reader = new BufferedReader(new FileReader(path));
prop = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return prop;
}
/**
* 改写节点
*/
public static boolean setNodeString(String path,String value){
try {
BufferedWriter bufWriter = null;
bufWriter = new BufferedWriter(new FileWriter(path));
bufWriter.write(value); // 写入数据
bufWriter.close();
Log.e("fht","改写节点成功!");
} catch (IOException e) {
e.printStackTrace();
Log.e("fht","改写节点失败!");
return false;
}
return true;
}
AndroidManifest.xml添加
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="android.uid.system"
生成signed 在Ubuntu下执行
keytool-importkeypair工具下载
https://download.csdn.net/download/ruidongren/87818572
-master$ ./keytool-importkeypair -k demo.jks -p 123456 -pk8 platform.pk8 -cert platform.x509.pem -alias demo
platform.pk8
platform.x509.pem
两个文件获取路径
Android系统源码:build/target/product/security
Android studio添加signed
系统文件中添加文件节点权限
+++ b/code/device/rockchip/rk356x/init.rk356x.rc
@@ -6,6 +6,7 @@ on property:sys.boot_completed=1
chmod 0664 /sys/class/devfreq/ff400000.gpu/governor
chmod 0664 /sys/class/devfreq/ff400000.gpu/min_freq
chmod 0664 /sys/class/devfreq/ff400000.gpu/max_freq
+ chmod 0666 /sys/charge_led_gpio/charge_led_gpio
diff --git a/code/device/rockchip/common/sepolicy/vendor/file.te b/code/device/rockchip/common/sepolicy/vendor/file.te
index b31ba824b3..2e3f9fcf1f 100755
--- a/code/device/rockchip/common/sepolicy/vendor/file.te
+++ b/code/device/rockchip/common/sepolicy/vendor/file.te
@@ -13,3 +13,4 @@ type fuseblk, sdcard_type, fs_type, mlstrustedobject;
type debugfs_sw_sync, fs_type, debugfs_type;
type sysfs_dmc, fs_type, sysfs_type;
type sysfs_mmc, fs_type, sysfs_type;
+type sysfs_led, fs_type, sysfs_type;
diff --git a/code/device/rockchip/common/sepolicy/vendor/file_contexts b/code/device/rockchip/common/sepolicy/vendor/file_contexts
old mode 100644
new mode 100755
index e940f91bc6..a7df50ccbb
--- a/code/device/rockchip/common/sepolicy/vendor/file_contexts
+++ b/code/device/rockchip/common/sepolicy/vendor/file_contexts
@@ -240,3 +240,5 @@
# vibrator aidl
/(vendor|system/vendor)/bin/hw/android\.hardware\.vibrator-service\.rockchip u:object_r:hal_vibrator_default_exec:s0
+
+/sys/charge_led_gpio/charge_led_gpio u:object_r:sysfs_led:s0
diff --git a/code/device/rockchip/common/sepolicy/vendor/priv_app.te b/code/device/rockchip/common/sepolicy/vendor/priv_app.te
old mode 100644
new mode 100755
index b9340820d9..bff49982ca
--- a/code/device/rockchip/common/sepolicy/vendor/priv_app.te
+++ b/code/device/rockchip/common/sepolicy/vendor/priv_app.te
@@ -12,3 +12,5 @@ allow priv_app vr_manager_service:service_manager find;
binder_call(priv_app, zygote)
rw_rockchip_graphic_device(priv_app)
+
+allow system_app sysfs_led:file rw_file_perms;
diff --git a/code/device/rockchip/common/sepolicy/vendor/system_app.te b/code/device/rockchip/common/sepolicy/vendor/system_app.te
old mode 100644
new mode 100755
index 3de70f7831..cbeb2ecffe
--- a/code/device/rockchip/common/sepolicy/vendor/system_app.te
+++ b/code/device/rockchip/common/sepolicy/vendor/system_app.te
@@ -51,3 +51,5 @@ allow system_app proc_pagetypeinfo:file r_file_perms;
allow system_app mnt_sdcard_file:lnk_file r_file_perms;
allow system_app mnt_pass_through_file:dir r_file_perms;
+
+allow system_app sysfs_led:file rw_file_perms;
+allow system_app sysfs_led:file { read getattr open write };