客户需求:
客户反馈某目标main.java文件需要添加底层节点的接口,用于其他场景进行调用。
需求分析:
1.基于客户需求首先应该跟驱动工程师沟通确定其是否正确写入节点。
2.通过adb命令看是否能够正确的读到节点。
3.在目标java文件中添加相应的接口,并在另外的文件中进行调用,看是否正常调用。
4.验证缺少权限进行添加配置,在验证。
5.成功调用,验证成功。
需求实现:
1.基于客户需求首先应该跟驱动工程师沟通确定其是否正确写入节点。
首先确定驱动同事是否正常配置节点,我们可以通过adb命令看是否能正常读取节点
例:
节点1:
echo 1 > /sys/kernel/scan_dev/power
echo 0 > /sys/kernel/scan_dev/power (开机默认)
节点2:
echo 1 > /sys/kernel/scan_dev/aim
echo 0 > /sys/kernel/scan_dev/aim (开机默认)
2.通过adb命令看是否能够正确的读到节点。
我们可以通过adb命令进行验证节点是否正常开启
adb root
adb shell
ls -l /sys/kernel/scan_dev/power
若有返回值能找到说明底层已经配置好相应的节点。
3.在目标java文件中添加相应的接口,并在另外的文件中进行调用,看是否正常调用。
+ //wjj add (注意节点不要有多余字符例空格)
+ private static final String POWER_ON = "/sys/kernel/scan_dev/power";
+ private static final String AIM_UP = "/sys/kernel/scan_dev/aim";
+ //wjj
+ //wjj add
+ public void openPower(boolean isopen) {
+ synchronized (mLock) {
+ writeData(POWER_ON, isopen ? "1" : "0");
+ }
+ }
+
+ public void ariseTrigger(boolean isarise) {
+ synchronized (mLock) {
+ writeData(AIM_UP, isarise ? "1" : "0");
+ }
+ }
+
+ //wjj end
另外任意java文件调用(可通过打log确认其是否走了该位置)
+ //wjj add
+ mOther.openPower(true);
+ mOther.ariseTrigger(true);
+ //wjj end
其他问题:可能由于添加了新的api接口,编译是不通过的因为没有及时更新api
方法与单编类似
source build/envsetup.sh
lunch XXX
make update-api
之后通过git status | grep txt查看修改的txt文件
将相应的修改的 .txt 文件上传
例:
4.编译成功后触发上文添加的other.java文件中的事件查看两个节点的值是否变为 true (1)。
在未添加相应的权限大概率会报错,此时可以通过adb命令关闭权限影响,再次进入看是否会继续报错,如果不报错了就说明是权限问题导致的错误。
其中马赛克为TAG和相应的报错路径
此时使用adb命令关闭相应的selinux
adb shell setenforce 0
再次启动相应的验证程序发现正常写入,则可推断出为权限问题导致相关问题。
隐藏值为相应的TAG
5.确认问题点之后,查看缺失权限并在底层添加相应的权限
logcat | grep avc 查看avc确定缺失的权限
根据相应的添加规则在底层进行添加
1.参考文章
准确添加AVC权限_avc权限添加-CSDN博客文章浏览阅读1.5k次,点赞22次,收藏38次。在开发过程中,准确的添加所需要的权限是必须要掌握的基本功能_avc权限添加https://blog.csdn.net/mihuayishi/article/details/136036617Android SElinux权限问题解决_android selinux avc dennied权限问题解决方法-CSDN博客文章浏览阅读321次。1.从android5.x开始,引入严格的selinux权限管理机制,经常会遇到各种avc denied的Log。 # adb shell cat /proc/kmsg | grep avc # adb shell dmesg | grep avc # adb logcat | grep avc解决原则是:缺什么补什么,一步一步补到没有avc denied为止。 2.Log解决: audit(0.0:67): avc: denied { write }for path="/dev/_android selinux avc dennied权限问题解决方法https://blog.csdn.net/wq892373445/article/details/119536150
看完之后就会添加了
s0相关文件
//相应的patch
alps/device/mediatek/sepolicy/basic/non_plat/platform_app.te | 4 ++++
alps/system/sepolicy/private/app_neverallows.te | 2 +-
alps/system/sepolicy/private/coredomain.te | 1 +
alps/system/sepolicy/public/app.te | 2 +-
alps/system/sepolicy/public/domain.te | 1 +
5 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/alps/device/mediatek/sepolicy/basic/non_plat/platform_app.te b/alps/device/mediatek/sepolicy/basic/non_plat/platform_app.te
index 31c7761c6e4..c94ead72bca 100644
--- a/alps/device/mediatek/sepolicy/basic/non_plat/platform_app.te
+++ b/alps/device/mediatek/sepolicy/basic/non_plat/platform_app.te
@@ -35,3 +35,7 @@ allow platform_app vcodec_file:dir create_dir_perms;
allow platform_app vcodec_file:file create_file_perms;
# DebugLoggerUI can get c2 log properties
get_prop(platform_app, vendor_mtk_c2_log_prop)
+
+#wjj add scan_power
+allow platform_app sysfs:file { write open getattr };
+#wjj end
diff --git a/alps/system/sepolicy/private/app_neverallows.te b/alps/system/sepolicy/private/app_neverallows.te
index c7fa4e8c508..fbb8ceadc72 100644
--- a/alps/system/sepolicy/private/app_neverallows.te
+++ b/alps/system/sepolicy/private/app_neverallows.te
@@ -99,7 +99,7 @@ neverallow all_untrusted_apps sysfs_net:file no_rw_file_perms;
neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
# Apps may never access the default sysfs label.
-neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
+#neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
# ioctl permission, or 3. disallow the socket class.
diff --git a/alps/system/sepolicy/private/coredomain.te b/alps/system/sepolicy/private/coredomain.te
index b7f4f5d18e2..7b038db9fec 100644
--- a/alps/system/sepolicy/private/coredomain.te
+++ b/alps/system/sepolicy/private/coredomain.te
@@ -140,6 +140,7 @@ full_treble_only(`
-init
-ueventd
-vold
+ -platform_app
} sysfs:file no_rw_file_perms;
# /dev
diff --git a/alps/system/sepolicy/public/app.te b/alps/system/sepolicy/public/app.te
index 5527f999413..541eae2fc92 100644
--- a/alps/system/sepolicy/public/app.te
+++ b/alps/system/sepolicy/public/app.te
@@ -528,7 +528,7 @@ neverallow appdomain efs_file:dir_file_class_set write;
neverallow { appdomain -shell } efs_file:dir_file_class_set read;
# Write to various pseudo file systems.
-neverallow { appdomain -bluetooth -nfc }
+neverallow { appdomain -bluetooth -nfc -platform_app}
sysfs:dir_file_class_set write;
neverallow appdomain
proc:dir_file_class_set write;
diff --git a/alps/system/sepolicy/public/domain.te b/alps/system/sepolicy/public/domain.te
index 799a2f1c570..779a9a281a3 100644
--- a/alps/system/sepolicy/public/domain.te
+++ b/alps/system/sepolicy/public/domain.te
@@ -1345,6 +1345,7 @@ neverallow {
-init
-ueventd
-vold
+ -platform_app
-system_writes_mnt_vendor_violators
} mnt_vendor_file:dir *;
其中注意相关的 (安全上下文) 与之对应 所改的位置一致 ,例本文sysfs
allow platform_app sysfs:file { write open getattr };
allow + scontext(进程名) + tcontext(安全上下文) + tclass(访问类型) + avc denied(访问权限)
总结:
简单的一次应用,做个小笔记记录一下,希望给大家带来帮助。