MTK6757 9.0 APK预置vendor/operator/app 无法正常工作
最近在MTK6757 9.0 上实现APK预置时发现,当APK中使用so时预置后无法正常使用.错误信息
04-09 13:33:42.933 3373 3373 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/vendor/operator/app/xxx/xxx.apk"],nativeLibraryDirectories=[/data/app-lib/xxx, /system/fake-libs, /vendor/operator/app/xxx/xxx.apk!/lib/armeabi-v7a, /system/lib]]] couldnt find "lixxx.so" 04-09 13:33:42.933 3373 3373 E AndroidRuntime: at java.lang.Runtime.loadLibrary0(Runtime.java:1013) 04-09 13:33:42.933 3373 3373 E AndroidRuntime: at java.lang.System.loadLibrary(System.java:1669)
经过以下尝试最终解决问题::
1. 尝试将so文件在编译之前拷贝到out下 指定目录/data/app-lib/xxx.编译完成后发现 错误信息一样,问题无法解决.
2. 发现1无法实现后,开始分析PackageManagerService.java系统服务 apk安装相关代码.
public PackageManagerService(Context context, Installer installer, boolean factoryTest, boolean onlyCore) {
发现系统在启动过程中会逐个扫描系统主要目录并尝试安装目录下apk文件scanDirTracedLI.
这时发现没有找到指定目录vendor/operator/app 的扫描,于是尝试添加对次目录扫描
scanDirTracedLI(new File(VENDOR_OPERATOR_DIR), mDefParseFlags | PackageParser.PARSE_IS_SYSTEM_DIR, scanFlags | SCAN_AS_SYSTEM, 0)
编译后刷机发现问题依然没办法解决.在分析系统开机log 后发现问题应该出在其他地方
shirts.xxx: type=1400 audit(0.0:998): avc: denied { open } for path="/data/app-lib/xxx/libxxx.so" dev="dm-2" ino=196611 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0
shirts.xxx: type=1400 audit(0.0:999): avc: denied { read } for name="libxxx.so" dev="dm-1" ino=1344 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:vendor_file:s0 tclass=file permissive=0
3. 在查找了avc: denied { open } 相关的文章后发现问题出在selinux 权限问题上,问题找到方向就好解决.于是开始查找相关selinux权限修改资料学写并尝试修改te文件.
avc: denied { open }--------------------------------------------------缺少什么权限
scontext=u:r:untrusted_app_25:s0:c512,c768 ----------------谁缺少权限 tcontext=u:object_r:system_data_file:s0 ------------------------那个文件缺少权限 tclass=file ----------------------------------------------------------------什么类型的文件 permissive=0
完整意思: untrusted_app_25进程对system_data_file类型的file缺少open权限
avc: denied { read }----------------------------------------------------缺少什么权限
scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:vendor_file:s0 tclass=file permissive=0
完整意思: untrusted_app_25进程对vendor_file类型的file缺少read权限
于是找到相应的te文件进行修改. 由于是9.0 项目所以直接在systemsepolicyprebuiltsapi28.0private 下找到相应的untrusted_app_25.te文件进行修改.由于必须和systemsepolicyprivateuntrusted_app_25.te 文件保持一致,所以做相同修改.
allow untrusted_app_25 system_data_file:file { open }; allow untrusted_app_25 vendor_file:file { read };
兴高采烈的以为己决问题,编译完后发现还是报错,仔细分析后发现修改是有作用的,只是权限还没有赋完整
04-09 13:33:42.923 3373 3373 W shirts.xxx: type=1400 audit(0.0:998): avc: denied { execute} for path="/data/app-lib/xxx/libxxx.so" dev="dm-2" ino=196611 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0
于是在添加对"execute" 权限的增加.
allow untrusted_app_25 system_data_file:file { open execute};
allow untrusted_app_25 vendor_file:file { read };
最终问题解决