installd守护进程

news/2025/5/24 1:02:50

installd守护进程

android11-release
PackageManagerServie 服务负责应用的安装、卸载等相关工作,而真正干活的还是 installd。

installd 启动

Android系统启动 查看 init 进程system/core/init/init.cpp中SecondStageMain,最终在 LoadBootScripts 解析 rc 文件,其中解析 installd.rc,调用到installd.cpp主函数。InstalldNativeService::start()将该服务发布到 native 层的 ServiceManager 中。

frameworks/native/cmds/installd/installd.rc
service installd /system/bin/installdclass main
frameworks/native/cmds/installd/installd.cpp
namespace android {
namespace installd {
//... ...
static int installd_main(const int argc ATTRIBUTE_UNUSED, char *argv[]) {//... ...if ((ret = InstalldNativeService::start()) != android::OK) {SLOGE("Unable to start InstalldNativeService: %d", ret);exit(1);}//... ...return 0;
}}  // namespace installd
}  // namespace androidint main(const int argc, char *argv[]) {return android::installd::installd_main(argc, argv);
}

InstalldNativeService

frameworks/native/cmds/installd/InstalldNativeService.h
frameworks/native/cmds/installd/InstalldNativeService.cpp

InstalldNativeService 继承 BinderService(Binder通信,之前socket),BinderService::publish() 将"installd"服务添加到ServiceManager中
在这里插入图片描述

status_t InstalldNativeService::start() {IPCThreadState::self()->disableBackgroundScheduling(true);status_t ret = BinderService<InstalldNativeService>::publish();if (ret != android::OK) {return ret;}sp<ProcessState> ps(ProcessState::self());ps->startThreadPool();ps->giveThreadPoolName();sAppDataIsolationEnabled = android::base::GetBoolProperty(kAppDataIsolationEnabledProperty, true);return android::OK;
}
frameworks/native/libs/binder/include/binder/BinderService.h

在这里插入图片描述

Installer.java 连接 “installd” 服务

SystemServer 中 startBootstrapServices 启动 Installer 连接 “installd” 服务
在这里插入图片描述
在这里插入图片描述

installd_main 其他函数

回到 installd 查看其他函数

initialize_globals()

在这里插入图片描述

frameworks/native/cmds/installd/globals.h
frameworks/native/cmds/installd/globals.cpp

获取相关目录:/data//system/data/app//data/app-private//data/app-ephemeral//data/app-lib//data/app-lib//mnt/asec/data/media//mnt/expand//data/misc/profiles/data/app-staging//system/app//system/app-private//vendor/app//oem/app/

bool init_globals_from_data_and_root(const char* data, const char* root) {// Get the android data directory.android_data_dir = ensure_trailing_slash(data);// Get the android root directory.android_root_dir = ensure_trailing_slash(root);// Get the android app directory.android_app_dir = android_data_dir + APP_SUBDIR;// Get the android protected app directory.android_app_private_dir = android_data_dir + PRIVATE_APP_SUBDIR;// Get the android ephemeral app directory.android_app_ephemeral_dir = android_data_dir + EPHEMERAL_APP_SUBDIR;// Get the android app native library directory.android_app_lib_dir = android_data_dir + APP_LIB_SUBDIR;// Get the sd-card ASEC mount point.android_asec_dir = ensure_trailing_slash(getenv(ASEC_MOUNTPOINT_ENV_NAME));// Get the android media directory.android_media_dir = android_data_dir + MEDIA_SUBDIR;// Get the android external app directory.android_mnt_expand_dir = "/mnt/expand/";// Get the android profiles directory.android_profiles_dir = android_data_dir + PROFILES_SUBDIR;// Get the android session staging directory.android_staging_dir = android_data_dir + STAGING_SUBDIR;// Take note of the system and vendor directories.android_system_dirs.clear();android_system_dirs.push_back(android_root_dir + APP_SUBDIR);android_system_dirs.push_back(android_root_dir + PRIV_APP_SUBDIR);android_system_dirs.push_back("/vendor/app/");android_system_dirs.push_back("/oem/app/");return true;
}

initialize_directories()

  • 读取当前文件系统版本
  • 处理升级路径
static int initialize_directories() {int res = -1;// Read current filesystem layout version to handle upgrade pathschar version_path[PATH_MAX];snprintf(version_path, PATH_MAX, "%smisc/installd/layout_version", android_data_dir.c_str());int oldVersion;if (fs_read_atomic_int(version_path, &oldVersion) == -1) {oldVersion = 0;}int version = oldVersion;if (version < 2) {SLOGD("Assuming that device has multi-user storage layout; upgrade no longer supported");version = 2;}if (ensure_config_user_dirs(0) == -1) {SLOGE("Failed to setup misc for user 0");goto fail;}if (version == 2) {SLOGD("Upgrading to /data/misc/user directories");char misc_dir[PATH_MAX];snprintf(misc_dir, PATH_MAX, "%smisc", android_data_dir.c_str());char keychain_added_dir[PATH_MAX];snprintf(keychain_added_dir, PATH_MAX, "%s/keychain/cacerts-added", misc_dir);char keychain_removed_dir[PATH_MAX];snprintf(keychain_removed_dir, PATH_MAX, "%s/keychain/cacerts-removed", misc_dir);DIR *dir;struct dirent *dirent;dir = opendir("/data/user");if (dir != nullptr) {while ((dirent = readdir(dir))) {const char *name = dirent->d_name;// skip "." and ".."if (name[0] == '.') {if (name[1] == 0) continue;if ((name[1] == '.') && (name[2] == 0)) continue;}uint32_t user_id = std::stoi(name);// /data/misc/user/<user_id>if (ensure_config_user_dirs(user_id) == -1) {goto fail;}char misc_added_dir[PATH_MAX];snprintf(misc_added_dir, PATH_MAX, "%s/user/%s/cacerts-added", misc_dir, name);char misc_removed_dir[PATH_MAX];snprintf(misc_removed_dir, PATH_MAX, "%s/user/%s/cacerts-removed", misc_dir, name);uid_t uid = multiuser_get_uid(user_id, AID_SYSTEM);gid_t gid = uid;if (access(keychain_added_dir, F_OK) == 0) {if (copy_dir_files(keychain_added_dir, misc_added_dir, uid, gid) != 0) {SLOGE("Some files failed to copy");}}if (access(keychain_removed_dir, F_OK) == 0) {if (copy_dir_files(keychain_removed_dir, misc_removed_dir, uid, gid) != 0) {SLOGE("Some files failed to copy");}}}closedir(dir);if (access(keychain_added_dir, F_OK) == 0) {delete_dir_contents(keychain_added_dir, 1, nullptr);}if (access(keychain_removed_dir, F_OK) == 0) {delete_dir_contents(keychain_removed_dir, 1, nullptr);}}version = 3;}// Persist layout version if changedif (version != oldVersion) {if (fs_write_atomic_int(version_path, version) == -1) {SLOGE("Failed to save version to %s: %s", version_path, strerror(errno));goto fail;}}// Success!res = 0;fail:return res;
}

https://dhexx.cn/news/show-591706.html

相关文章

Java设计模式(十一) 享元模式

2019独角兽企业重金招聘Python工程师标准>>> 原创文章&#xff0c;同步发自作者个人博客&#xff0c;http://www.jasongj.com/design_pattern/flyweight/。转载请注明出处 享元模式介绍 享元模式适用场景 面向对象技术可以很好的解决一些灵活性或可扩展性问题&#…

JavaFx:添加顶部菜单 Microsoft Ribbon For JavaFX

JavaFx:添加顶部菜单 Microsoft Ribbon For JavaFX Microsoft Ribbon For JavaFX&#xff1a;Ribbon control for Java, implemented using JavaFX, based on the Microsoft Ribbon. Github FXRibbon FXRibbon-master 导入运行 运行ChangeAccentColorSample&#xff1a;更多内…

JavaFX:Robot高DPI截图

JavaFX:Robot高DPI截图 使用JDK中 java.awt.*&#xff1a;Robot、Rectangle JavaFX:截图功能 createScreenCapture 图片模糊 Iamge : (665.0,230.0) createMultiResolutionScreenCapture MultiResolutionImage mrImage robot.createMultiResolutionScreenCapture(rec); …

JavaFx:快捷键

JavaFx&#xff1a;快捷键 KeyCombination.html KeyCode.html 设置方式参考&#xff1a;JavaFX 设置快捷键、JavaFx&#xff1a;11、设置快捷键、JavaFX学习&#xff1a;快捷键 快捷键CTRL C KeyCombination ctrl_c new KeyCodeCombination(KeyCode.C, KeyCombination.CO…

Windows NTFS权限设置小结

在实际工作中经常会碰到NTFS文件夹权限设置的问题&#xff0c;比如&#xff1a;即使你赋予某用户full control并向子文件夹继承仍会出现access denied的情况&#xff0c;如下图&#xff1a;出现此情况的原因是由于赋权用户(如域管理员、本地管理员)没有某些子文件夹的full cont…

JavaFX: 多语言适配

JavaFX: 多语言适配 JDK国际化&#xff1a;ResourceBundle.html 其他资源&#xff1a;TornadoFX编程指南&#xff0c;第10章&#xff0c;FXML和国际化、JavaFX的ResourceBundle使用 创建Resource Bundle资源 ResourceBundle获取资源 public class ResourceBundleUtil {priva…

一组Linux Shell Scripting小练习

原创作品&#xff0c;允许转载&#xff0c;转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://dgd2010.blog.51cto.com/1539422/1718284 # Linux shell将字符串分割成数组 12result$(facter | awk /ipaddress/ && !/ipaddres…

PackageManagerService启动

PackageManagerService启动 android11-release SystemServer 启动 PackageManagerService 在 startBootstrapServices 中启动 PackageManagerService PackageManagerService.main() 过程主要是创建PKMS服务&#xff0c;并注册到ServiceManagerInstaller 连接 “installd” …

L2权重衰减就是L2正则化 的 代码实现

本文以Paddle为例&#xff0c;torch操作也差不多 我在5年前管这个限制参数过大的东西叫正则化&#xff0c;结果现在叫权重衰减了hhh 有点儿跟不上潮流了&#xff0c;我还以以为这个权重衰减是每次迭代给权重乘以一个0.99999&#xff0c;让他进行衰减呢(这样操作也衰减的太快了…

【转载】 HDU 动态规划46题【只提供思路与状态转移方程】

1.Robberies 连接 &#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总的概率以为是抢N家银行的概率之和… 把状态转移方程写成了f[j]max{f[j],f[j-q[i].v]q…