在Andorid8.x系统之前,Android系统的服务不是在SystemServer.java中启动,就在init进程初始化xxx.xxx.rc中启动。
而Android8.x开始,会发现像/vendor/etc/init/android.hardware.*@2.0-service.rc这种类型的服务和初始化不知道在什么地方加载起来,本文主要这个这种情况进行分析和优化。
本文转自:https://blog.csdn.net/touxiong/article/details/80537777
优化开机速度--抓log发现很多用不着的service
[ 22.577559] c3 init: Parsing directory /vendor/etc/init...
[ 22.583263] c3 init: Parsing file /vendor/etc/init/android.hardware.audio@2.0-service.rc...
[ 22.592402] c3 init: Parsing file /vendor/etc/init/android.hardware.biometrics.fingerprint@2.1-service.rc...
[ 22.603000] c3 init: Parsing file /vendor/etc/init/android.hardware.bluetooth@1.0-service.rc...
[ 22.612471] c3 init: Parsing file /vendor/etc/init/android.hardware.camera.provider@2.4-service.rc...
[ 22.622456] c3 init: Parsing file /vendor/etc/init/android.hardware.cas@1.0-service.rc...
[ 22.631375] c3 init: Parsing file /vendor/etc/init/android.hardware.configstore@1.0-service.rc...
[ 22.640973] c3 init: Parsing file /vendor/etc/init/android.hardware.drm@1.0-service.rc...
[ 22.650100] c3 init: Parsing file /vendor/etc/init/android.hardware.dumpstate@1.0-service.rc...
[ 22.659732] c3 init: Parsing file /vendor/etc/init/android.hardware.gatekeeper@1.0-service.rc...
[ 22.669427] c3 init: Parsing file /vendor/etc/init/android.hardware.gnss@1.0-service.rc...
[ 22.678653] c3 init: Parsing file /vendor/etc/init/android.hardware.graphics.allocator@2.0-service.rc...
[ 22.689081] c3 init: Parsing file /vendor/etc/init/android.hardware.graphics.composer@2.1-service.rc...
[ 22.699269] c3 init: Parsing file /vendor/etc/init/android.hardware.health@1.0-service.rc...
[ 22.708675] c3 init: Parsing file /vendor/etc/init/android.hardware.keymaster@3.0-service.rc...
[ 22.718172] c3 init: Parsing file /vendor/etc/init/android.hardware.light@2.0-service.rc...
[ 22.727480] c3 init: Parsing file /vendor/etc/init/android.hardware.media.omx@1.0-service.rc...
[ 22.737140] c3 init: Parsing file /vendor/etc/init/android.hardware.memtrack@1.0-service.rc...
[ 22.746312] c3 init: Parsing file /vendor/etc/init/android.hardware.sensors@1.0-service.rc...
[ 22.755606] c3 init: Parsing file /vendor/etc/init/android.hardware.usb@1.1-service.rc...
[ 22.764512] c3 init: Parsing file /vendor/etc/init/android.hardware.vibrator@1.0-service.rc...
[ 22.773805] c3 init: Parsing file /vendor/etc/init/android.hardware.wifi@1.0-service.rc..
想着以前都是在init.rc中把这些脚本import解析执行,搜了一大圈没找到,又去SystemServer.java中找,也没找到,回过头分析log,“Parsing directory” 找到
./core/init/init_parser.cpp: LOG(INFO) <<"Parsing directory " <./core/init/init_parser.cpp
bool Parser::ParseConfig(const std::string& path) {if (is_dir(path.c_str())) {return ParseConfigDir(path);}return ParseConfigFile(path);
}
继续搜索
std::string bootscript &#61; GetProperty("ro.boot.init_rc", "");if (bootscript.empty()) {parser.ParseConfig("/init.rc");parser.set_is_system_etc_init_loaded(parser.ParseConfig("/system/etc/init"));parser.set_is_vendor_etc_init_loaded(parser.ParseConfig("/vendor/etc/init"));parser.set_is_odm_etc_init_loaded(parser.ParseConfig("/odm/etc/init"));} else {parser.ParseConfig(bootscript);parser.set_is_system_etc_init_loaded(true);parser.set_is_vendor_etc_init_loaded(true);parser.set_is_odm_etc_init_loaded(true);
static void import_late(const std::vector& args, size_t start_index, size_t end_index) {Parser& parser &#61; Parser::GetInstance();if (end_index <&#61; start_index) {// Fallbacks for partitions on which early mount isn&#39;t enabled.if (!parser.is_system_etc_init_loaded()) {parser.ParseConfig("/system/etc/init");parser.set_is_system_etc_init_loaded(true);}if (!parser.is_vendor_etc_init_loaded()) {parser.ParseConfig("/vendor/etc/init");parser.set_is_vendor_etc_init_loaded(true);}if (!parser.is_odm_etc_init_loaded()) {parser.ParseConfig("/odm/etc/init");parser.set_is_odm_etc_init_loaded(true);}
那请问 /vendor/etc/init 是在上面蓝色还是红色出解析的呢&#xff1f;
接口和软件包
HIDL 是围绕接口进行编译的&#xff0c;接口是面向对象的语言使用的一种用来定义行为的抽象类型。每个接口都是软件包的一部分。
软件包
软件包名称可以具有子级&#xff0c;例如 package.subpackage。已发布的 HIDL 软件包的根目录是 hardware/interfaces 或 vendor/vendorName&#xff08;例如 Pixel 设备为 vendor/google&#xff09;。软件包名称在根目录下形成一个或多个子目录&#xff1b;定义软件包的所有文件都位于同一目录下。例如&#xff0c;package android.hardware.example.extension.light&#64;2.0 可以在 hardware/interfaces/example/extension/light/2.0 下找到。
下表列出了软件包前缀和位置&#xff1a;
软件包 | 位置 |
android.hardware.* | hardware/interfaces/* |
android.frameworks.* | frameworks/hardware/interfaces/* |
android.system.* | system/hardware/interfaces/* |
android.hidl.* | system/libhidl/transport/* |
软件包目录中包含扩展名为 .hal
的文件。每个文件均必须包含一个指定文件所属的软件包和版本的 package
语句。文件 types.hal
&#xff08;如果存在&#xff09;并不定义接口&#xff0c;而是定义软件包中每个接口可以访问的数据类型.
现在删除部分serveice:
hidl-gen工具
在Treble架构中&#xff0c;经常会提到HIDL&#xff0c;首先介绍和HIDL相关的一个工具hidl-gen,系统定义的所有的.hal接口&#xff0c;都是通过hidl-gen工具转换成对应的代码。比如hardware/interfaces/power/1.0/IPower.hal&#xff0c;会通过hidl-gen转换成out/soong/.intermediates/hardware/interfaces/power/1.0/android.hardware.power&#64;1.0_genc&#43;&#43;/gen/android/hardware/power/1.0/PowerAll.cpp文件&#xff0c;为了深入了解&#xff0c;介绍相关原理,首先分析hidl-gen。
hidl-gen
源码路径&#xff1a;system/tools/hidl&#xff0c;是在ubuntu上可执行的二进制文件。
使用方法&#xff1a;hidl-gen -o output-path -L language (-r interface-root) fqname
列子&#xff1a;
hidl-gen -Lmakefile -r android.hardware:hardware/interfaces -r android.hidl:system/libhidl/transpor
diff --git a/update-base-files.sh b/update-base-files.sh
index 1eb6b51..b5b1a99 100755
--- a/update-base-files.sh
&#43;&#43;&#43; b/update-base-files.sh
&#64;&#64; -22,9 &#43;22,9 &#64;&#64; options&#61;"-Lexport-header \hidl-gen $options \-o hardware/libhardware/include/hardware/sensors-base.h \android.hardware.sensors&#64;1.0
-hidl-gen $options \
- -o hardware/libhardware/include/hardware/nfc-base.h \
- android.hardware.nfc&#64;1.0
&#43;#hidl-gen $options \
&#43;# -o hardware/libhardware/include/hardware/nfc-base.h \
&#43;# android.hardware.nfc&#64;1.0hidl-gen $options \-o hardware/libhardware/include/hardware/gnss-base.h \android.hardware.gnss&#64;1.0
参考&#xff1a;https://source.android.com/devices/architecture/hidl/interfaces
https://blog.csdn.net/xiaosayidao/article/details/75577940