当前位置: 首页 > news >正文

android 14 apexd分析(1)apexd bootstrap

Apex的由来,我们都知道普通的apk我们可以通过应用商店playstore等进行更新,apex的引入是google希望也能通过playstore更新bin文件.so etc配置文件等类型文件. 这些文件的安装实际通过apexd来进行,现在我们来解析一下apexd, apexd的启动分为两个阶段,bootstrap和普通apexd启动,下面分析apexd bootstrap

1. rc文件启动
/system/core/rootdir/init.rc#80

 本阶段启动三个bootstrap apex,分别为com.android.i18n,com.android.runtime com.android.tzdata,在bootstrap 阶段主要就是提供 critical shared libraries


77     # Run apexd-bootstrap so that APEXes that provide critical libraries
78     # become available. Note that this is executed as exec_start to ensure that
79     # the libraries are available to the processes started after this statement.
80     exec_start apexd-bootstrap    
2. main函数
/system/apex/apexd/apexd_main.cpp#118
int main(int /*argc*/, char** argv) {
...
118    android::apex::SetConfig(android::apex::kDefaultConfig); → 全局config
...
151    if (has_subcommand) {
152      return HandleSubcommand(argv);    →  这里走 apexd --bootstrap
153    }

全局config 就是这些常量:

61  static const ApexdConfig kDefaultConfig = {
62      kApexStatusSysprop,       →    kApexStatusSysprop = "apexd.status" apex的状态
63      kApexPackageBuiltinDirs,   →  所有apex文件所在的目录data、product、system、system_ext、vendor
64      kActiveApexPackagesDataDir,   →  kActiveApexPackagesDataDir = "/data/apex/active"
65      kApexDecompressedDir,         →    kApexDecompressedDir = "/data/apex/decompressed";
66      kOtaReservedDir,             →        kOtaReservedDir = "/data/apex/ota_reserved";
67      kApexHashTreeDir,           →   kApexHashTreeDir = "/data/apex/hashtree";
68      kStagedSessionsDir,        →   StagedSessionsDir = "/data/app-staging"
69      kMetadataSepolicyStagedDir,  →  kMetadataSepolicyStagedDir = "/metadata/sepolicy/staged";
70      kVmPayloadMetadataPartitionProp,  →  kVmPayloadMetadataPartitionProp = "apexd.payload_metadata.path"
71      "u:object_r:staging_data_file",  → staging_data_file的 file contexts
72  };
3. OnBootstrap()
 
/system/apex/apexd/apexd_main.cpp#38
36  int HandleSubcommand(char** argv) {
37    if (strcmp("--bootstrap", argv[1]) == 0) {
38      SetDefaultTag("apexd-bootstrap");
39      LOG(INFO) << "Bootstrap subcommand detected";
40      return android::apex::OnBootstrap();
41    }/system/apex/apexd/apexd.cpp#2566
2566  int OnBootstrap() {
2567    ATRACE_NAME("OnBootstrap");
2568    auto time_started = boot_clock::now();
2569  
2570    ApexFileRepository& instance = ApexFileRepository::GetInstance(); → 创建个实例 啥也没做
2571    Result<void> status =
2572        instance.AddPreInstalledApex(gConfig->apex_built_in_dirs);  →  3.1 scan kApexPackageBuiltinDirs下的所有apex, 详见3.1.1
2573    if (!status.ok()) {
2574      LOG(ERROR) << "Failed to collect APEX keys : " << status.error();
2575      return 1;
2576    }
2577  
2578    const auto& pre_installed_apexes = instance.GetPreInstalledApexFiles(); → 从全局变量中得到 pre_installed_store_
2579    int loop_device_cnt = pre_installed_apexes.size();
2580    // Find all bootstrap apexes
2581    std::vector<ApexFileRef> bootstrap_apexes;
2582    for (const auto& apex : pre_installed_apexes) {      →  遍历 所有apexfile
2583      if (IsBootstrapApex(apex.get())) {      →    判断是否是bootstrap apex,有三个com.android.i18n com.android.runtime com.android.tzdata
2584        LOG(INFO) << "Found bootstrap APEX " << apex.get().GetPath();
2585        bootstrap_apexes.push_back(apex);
2586        loop_device_cnt++;
2587      }
2588      if (apex.get().GetManifest().providesharedapexlibs()) {
2589        LOG(INFO) << "Found sharedlibs APEX " << apex.get().GetPath();
2590        // Sharedlis APEX might be mounted 2 times:
2591        //   * Pre-installed sharedlibs APEX will be mounted in OnStart
2592        //   * Updated sharedlibs APEX (if it exists) will be mounted in OnStart
2593        //
2594        // We already counted a loop device for one of these 2 mounts, need to add
2595        // 1 more.
2596        loop_device_cnt++;
2597      }
259
http://www.lryc.cn/news/331012.html

相关文章:

  • C++ 中的 vector 的模拟实现【代码纯享】
  • UE4 方块排序动画
  • 网络与并发编程(一)
  • 超详细工具Navicat安装教程
  • RN在android/ios手机剪切图片的操作
  • C语言 | Leetcode C语言题解之第6题Z字形变换
  • C 回调函数的两种使用方法
  • 医院云HIS系统源码,二级医院、专科医院his系统源码,经扩展后能够应用于医联体/医共体
  • NineData云原生智能数据管理平台新功能发布|2024年3月版
  • java Web 疫苗预约管理系统用eclipse定制开发mysql数据库BS模式java编程jdbc
  • Qt5.14.2 揭秘Qt日志神器高效诊断程序潜在隐疾
  • Mac上设置环境变量PATH
  • Redis 全景图(1)--- 关于 Redis 的6大模块
  • Lambda表达式,Stream流
  • Apache Hive的基本使用语法(一)
  • Python爬虫详解:原理、常用库与实战案例
  • 搭建跨境电商电商独立站如何接入1688平台API接口|通过1688API接口采集商品通过链接搜索商品下单
  • 【GlobalMapper精品教程】073:像素到点(Pixels-to-Points)从无人机图像轻松生成点云
  • 论文复现1:Mobilealoha
  • pycharm复习
  • 【SQLSERVER】批量导出所有作业或链接脚本
  • 函数参数缺省和内联函数【C++】
  • javaWeb城市公交查询系统的设计与实现
  • 企业案例:金蝶云星空对接旺店通·企业版
  • wpsword求和操作教程
  • Android 手机部署whisper 模型
  • 通信术语:初学者入门指南(二)
  • Java中使用MQTT客户端库实现TLS/SSL加密通信的示例
  • 【m122】webrtc的比较
  • axios发送get请求但参数中有数组导致请求路径多出了“[]“的处理办法