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

Android SystemServer进程解析

SystemServer进程在android系统中占了举足轻重的地位,系统的所有服务和SystemUI都是由它启动。

一、SystemServer进程主函数流程

1、主函数三部曲

//frameworks/base/services/java/com/android/server/SystemServer.java    /** * The main entry point from zygote. */public static void main(String[] args) {new SystemServer().run();}

SystemServer的入口函数同样是main,调用顺序先是构造函数,再是run,构造函数没有什么重点地方后文dump详细介绍,主要流程主要还是run方法。run里面哦流程其实还是遵循普遍的三部曲:初始化上下文->启动服务->进入loop循环

1)初始化上下文
//frameworks/base/services/java/com/android/server/SystemServer.java    private void run() {TimingsTraceAndSlog t = new TimingsTraceAndSlog();try {t.traceBegin("InitBeforeStartServices");//.....一些属性的初始化....// The system server should never make non-oneway callsBinder.setWarnOnBlocking(true);// The system server should always load safe labelsPackageItemInfo.forceSafeLabels();// Default to FULL within the system server.SQLiteGlobal.sDefaultSyncMode = SQLiteGlobal.SYNC_MODE_FULL;// Deactivate SQLiteCompatibilityWalFlags until settings provider is initializedSQLiteCompatibilityWalFlags.init(null);// Here we go! Slog.i(TAG, "Entered the Android system server!");final long uptimeMillis = SystemClock.elapsedRealtime(); //记录开始启动的时间错,调试系统启动时间的时候需要关注// Mmmmmm... more memory!VMRuntime.getRuntime().clearGrowthLimit();// Some devices rely on runtime fingerprint generation, so make sure we've defined it before booting further.Build.ensureFingerprintProperty();// Within the system server, it is an error to access Environment paths without explicitly specifying a user.Environment.setUserRequired(true);// Within the system server, any incoming Bundles should be defused to avoid throwing BadParcelableException.BaseBundle.setShouldDefuse(true);// Within the system server, when parceling exceptions, include the stack traceParcel.setStackTraceParceling(true);// Ensure binder calls into the system always run at foreground priority.BinderInternal.disableBackgroundScheduling(true);// Increase the number of binder threads in system_serverBinderInternal.setMaxThreads(sMaxBinderThreads);// Prepare the main looper thread (this thread).              android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_FOREGROUND);android.os.Process.setCanSelfBackground(false);Looper.prepareMainLooper();Looper.getMainLooper().setSlowLogThresholdMs(SLOW_DISPATCH_THRESHOLD_MS, SLOW_DELIVERY_THRESHOLD_MS);SystemServiceRegistry.sEnableServiceNotFoundWtf = true;// Initialize native services.System.loadLibrary("android_servers");// Allow heap / perf profiling.initZygoteChildHeapProfiling();// Check whether we failed to shut down last time we tried. This call may not return.performPendingShutdown();// Initialize the system context.createSystemContext();// Call per-process mainline module initialization.ActivityThread.initializeMainlineModules();} finally {t.traceEnd();  // InitBeforeStartServices}
2)启动系统所有服务
//frameworks/base/services/java/com/android/server/SystemServer.java    // Start services.try {t.traceBegin("StartServices");startBootstrapServices(t);   //启动BOOT服务(即没有这些服务系统无法运行)startCoreServices(t);        //启动核心服务startOtherServices(t);       //启动其他服务startApexServices(t);        //启动APEX服务,此服务必现要在前面的所有服务启动之后才能启动,为了防止OTA相关问题// Only update the timeout after starting all the services so that we use// the default timeout to start system server.updateWatchdogTimeout(t);} catch (Throwable ex) {Slog.e("System", "******************************************");Slog.e("System", "************ Failure starting system services", ex);throw ex;} finally {t.traceEnd(); // StartServices}/*** Starts system services defined in apexes.* <p>Apex services must be the last category of services to start. No other service must be* starting after this point. This is to prevent unnecessary stability issues when these apexes* are updated outside of OTA; and to avoid breaking dependencies from system into apexes.*/private void startApexServices(@NonNull TimingsTraceAndSlog t) {t.traceBegin("startApexServices");// TODO(b/192880996): get the list from "android" package, once the manifest entries are migrated to system manifest.List<ApexSystemServiceInfo> services = ApexManager.getInstance().getApexSystemServices();for (ApexSystemServiceInfo info : services) {String name = info.getName();String jarPath = info.getJarPath();t.traceBegin("starting " + name);if (TextUtils.isEmpty(jarPath)) {mSystemServiceManager.startService(name);} else {mSystemServiceManager.startServiceFromJar(name, jarPath);}t.traceEnd();}// make sure no other services are started after this pointmSystemServiceManager.sealStartedServices();t.traceEnd(); // startApexServices}

如上代码大体启动了四类服务:

  • startBootstrapServices:启动一些关键引导服务,这些服务耦合到一起
  • startCoreServices:启动一些关键引导服务,这些服务没有耦合到一起
  • startOtherServices:启动其他一些杂七杂八的服务
  • startApexServices:启动apex类的服务,其实就是mainline那些东西,详情参考请点击我
3)进入loop循环
//frameworks/base/services/java/com/android/server/SystemServer.javaStrictMode.initVmDefaults(null);if (!mRuntimeRestart && !isFirstBootOrUpgrade()) {final long uptimeMillis = SystemClock.elapsedRealtime();final long maxUptimeMillis = 60 * 1000;if (uptimeMillis > maxUptimeMillis) {Slog.wtf(SYSTEM_SERVER_TIMING_TAG, "SystemServer init took too long. uptimeMillis=" + uptimeMillis);}}// Loop forever.Looper.loop();throw new RuntimeException("Main thread loop unexpectedly exited");

和之前讲的binder一样,基本上所有的进程最后都会进入loop进行循环,轮询主线程相关的handle消息和binder消息,如下日志堆栈,表示handle消息处理过程中发生异常:

2、顺序启动服务

二、SystemServer正常启动日志

1、SystemServerTiming日志封装

2、SystemServer启动阶段OnBootPhase

3、SystemServer无法找到服务

4、Slow operation

三、SystemServer dumpsys解读

1、SystemServer的dump

2、其他服务的dump

SystemServer:Runtime restart: falseStart count: 1Runtime start-up time: +8s0msRuntime start-elapsed time: +8s0msSystemServiceManager:Current phase: 1000Current user not set!1 target users: 0(full)172 started services:com.transsion.hubcore.server.TranBootstrapServiceManagerServicecom.android.server.security.FileIntegrityServicecom.android.server.pm.Installercom.android.server.os.DeviceIdentifiersPolicyServicecom.android.server.uri.UriGrantsManagerService.Lifecyclecom.android.server.powerstats.PowerStatsServicecom.android.server.permission.access.AccessCheckingServicecom.android.server.wm.ActivityTaskManagerService.Lifecyclecom.android.server.am.ActivityManagerService.Lifecycle......com.android.server.Watchdog:WatchdogTimeoutMillis=60000SystemServerInitThreadPool:has instance: falsenumber of threads: 8service: java.util.concurrent.ThreadPoolExecutor@7bf04fb[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 351]is shutdown: trueno pending tasksAdServices:mAdServicesModuleName: com.google.android.adservicesmAdServicesModuleVersion: 341131050mHandlerThread: Thread[AdServicesManagerServiceHandler,5,main]mAdServicesPackagesRolledBackFrom: {}mAdServicesPackagesRolledBackTo: {}ShellCmd enabled: falseUserInstanceManagermAdServicesBaseDir: /data/system/adservicesmConsentManagerMapLocked: {}mAppConsentManagerMapLocked: {}mRollbackHandlingManagerMapLocked: {}mBlockedTopicsManagerMapLocked={}TopicsDbHelperCURRENT_DATABASE_VERSION: 1mDbFile: /data/system/adservices_topics.dbmDbVersion: 1

相关文章:

Android SystemServer进程解析

SystemServer进程在android系统中占了举足轻重的地位&#xff0c;系统的所有服务和SystemUI都是由它启动。 一、SystemServer进程主函数流程 1、主函数三部曲 //frameworks/base/services/java/com/android/server/SystemServer.java /** * The main entry point from zy…...

Github主页设置贪吃蛇详细教程

先看最终实现结果&#xff1a; 有条贪吃蛇放在主页还是蛮酷的哈哈哈。接下来我来讲一讲怎么在Github主页添加一条贪吃蛇。 首先要修改自己的Github的主页&#xff0c;我们得有一个特殊的仓库——这个仓库必须与你的Github用户名保持一致&#xff0c;并且需要公开&#xff0c…...

二、实现fastdfs文件上传与延迟删除功能的Spring Boot项目

如何在Spring Boot项目中集成FastDFS实现文件上传功能&#xff0c;并添加支持延迟删除功能的实现。 一、Spring Boot 中集成 fastdfs 使用 1、文件上传功能实现 首先&#xff0c;让我们看一下如何实现文件上传功能的接口方法&#xff1a; RestController public class File…...

Android FrameWork 学习路线

目录 前言 学习路线&#xff1a; 1.基础知识 2、AOSP 源码学习 3. AOSP 源码编译系统 4. Hal与硬件服务 5.基础组件 6. Binder 7. 系统启动过程分析 8. 应用层框架​编辑 9. 显示系统 10. Android 输入系统 11. 系统应用 前言 Android Framework 涉及的行业相当广…...

前端开发者如何打造自己的生态以及ip

作为独立开发者&#xff0c;在公司的岗位上面&#xff0c;经常面对的是页面&#xff0c;但我们不能局限页面&#xff0c;页面是切入点。 1在需求页面的过程中&#xff0c;我们会接触ui&#xff0c;原型&#xff0c;软件&#xff0c;需求&#xff0c; 2在接口对接的过程中&#…...

C语言实现一个两个数加减乘除的答题代码(含文件保存),用户增加,题目增加,题目测试,题目答题等等

目录 1、这是我大一自己写的小代码&#xff0c;现在翻到了就分享出来&#xff0c;高手勿喷。 2、项目运行 3、获取完整源码网址 1、这是我大一自己写的小代码&#xff0c;现在翻到了就分享出来&#xff0c;高手勿喷。 2、项目运行 &#xff08;1&#xff09;测试模块 每次…...

YOLOv9改进策略:注意力机制 | 用于微小目标检测的上下文增强和特征细化网络ContextAggregation,助力小目标检测,暴力涨点

&#x1f4a1;&#x1f4a1;&#x1f4a1;本文改进内容&#xff1a;用于微小目标检测的上下文增强和特征细化网络ContextAggregation&#xff0c;助力小目标检测 yolov9-c-ContextAggregation summary: 971 layers, 51002153 parameters, 51002121 gradients, 238.9 GFLOPs 改…...

基于单片机的老人防丢系统设计

目 录 摘 要 I Abstract II 引 言 3 1 系统总体架构 6 1.1方案设计与选择 6 1.2 系统架构设计 6 1.3 系统器件选择 7 2 系统硬件设计 9 2.1 单片机外围电路设计 9 2.2 LCD1602液晶显示电路设计 12 2.3 短信模块电路设计 14 2.4 GPS模块电路设计 14 2.5 电源与按键控制电路设计…...

从海外开发者大会的亲身体悟聊起,谈谈 AI 与开发者关系的重构 | 编码人声

本期「编码人声」节目中&#xff0c;我们聚焦于「AI 与开发者关系的重构」这一主题&#xff0c;从嘉宾参加海外开发者大会的亲身体验开始分享&#xff0c;聊一聊 AI 技术如何影响开发者社区和生态&#xff0c;以及开发者如何在这一变革中找到新的位置。 我们邀请了开发者社区与…...

HTML_CSS练习:HTML注释

一、代码示例 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>HTML注释</title> </head> <body><marquee loop"1">马龙强<!--下面的输入框是可以滚动的&#x…...

面试官问我Java异步编程用过吗?我直接说了6种方式!

文章目录 线程池 Runnable/Callable线程池 FutureCompletableFuture线程池 Async注解Spring 事件创建事件事件发布者事件监听器调用事件 消息队列生产者消费者 在实际开发中有些耗时操作&#xff0c;或者对主流程不是那么重要的逻辑&#xff0c;可以通过异步的方式去执行&am…...

一维坐标的移动(bfs)

在一个长度为n的坐标轴上&#xff0c;小S想从A点移动B点。 他的移动规则如下&#xff1a; 向前一步&#xff0c;坐标增加1。 向后一步&#xff0c;坐标减少1。 跳跃一步&#xff0c;使得坐标乘2。 小S不能移动到坐标小于0或大于n的位置。 小S想知道从A点移动到B点的最少步数是多…...

面试题 整理

第1题&#xff1a;常见数据类型大小 这边以64位计算机系统&#xff0c;环境而言。 类型 存储大小 值范围 char 1 字节 -128 到 127 或 0 到 255 unsigned char 1 字节 0 到 255 signed char 1 字节 -128 到 127 int 4 字节 -32,768 到 32,767 或 -2,147,483,648…...

苍穹外卖-day08:导入地址簿功能代码(单表crud)、用户下单(业务逻辑)、订单支付(业务逻辑,cpolar软件)

苍穹外卖-day08 课程内容 导入地址簿功能代码用户下单订单支付 功能实现&#xff1a;用户下单、订单支付 用户下单效果图&#xff1a; 订单支付效果图&#xff1a; 1. 导入地址簿功能代码&#xff08;单表crud&#xff09; 1.1 需求分析和设计 1.1.1 产品原型&#xff08…...

Java面试相关问题

一.MySql篇 1优化相关问题 1.1.MySql中如何定位慢查询&#xff1f; 慢查询的概念&#xff1a;在MySQL中&#xff0c;慢查询是指执行时间超过一定阈值的SQL语句。这个阈值是由long_query_time参数设定的&#xff0c;它的默认值是10秒1。也就是说&#xff0c;如果一条SQL语句的执…...

Linux Shell中的循环控制语句

Linux Shell中的循环控制语句 在编写Shell脚本时&#xff0c;循环是一种常用的控制结构&#xff0c;用于重复执行一系列命令。在Shell中&#xff0c;主要有三种循环控制语句&#xff1a;for循环&#xff0c;while循环&#xff0c;和until循环。 1. For循环 for循环是最常见的…...

proto3语言指南

Language Guide (proto3) 本指南介绍了如何使用 protocol buffer 语言来构建protocol buffer数据,包括.proto文件语法以及如何从.proto 文件生成数据访问类。它涵盖了proto3 版本的协议缓冲语言:有关proto2语法的信息,请参阅proto2语言指南。 文章目录 Language Guide (pro…...

解决后端传给前端的日期问题

解决方式&#xff1a; 1). 方式一 在属性上加上注解&#xff0c;对日期进行格式化 但这种方式&#xff0c;需要在每个时间属性上都要加上该注解&#xff0c;使用较麻烦&#xff0c;不能全局处理。 2). 方式二&#xff08;推荐 ) 在WebMvcConfiguration中扩展SpringMVC的消息转…...

MySQL中的索引失效情况介绍

MySQL中的索引是提高查询性能的重要工具。然而&#xff0c;在某些情况下&#xff0c;索引可能无法发挥作用&#xff0c;甚至导致查询性能下降。在本教程中&#xff0c;我们将探讨MySQL中常见的索引失效情况&#xff0c;以及它们的特点和简单的例子。 1. **索引失效的情况** …...

SpringBoot异常:类文件具有错误的版本 61.0, 应为 52.0的解决办法

问题&#xff1a; java: 无法访问org.mybatis.spring.annotation.MapperScan 错误的类文件: /D:/Program Files/apache-maven-3.6.0/repository/org/mybatis/mybatis-spring/3.0.3/mybatis-spring-3.0.3.jar!/org/mybatis/spring/annotation/MapperScan.class 类文件具有错误的…...

从视网膜到脑肿瘤:手把手复现CAS-UNet与DA-TransUNet,搞定医学图像分割的细节与代码

从视网膜到脑肿瘤&#xff1a;手把手复现CAS-UNet与DA-TransUNet&#xff0c;搞定医学图像分割的细节与代码医学图像分割一直是计算机视觉领域最具挑战性的任务之一。不同于自然图像&#xff0c;医学影像往往存在边界模糊、噪声干扰大、目标形态多变等特点。传统的分割方法在这…...

机器学习势函数结合热力学积分:高效精准预测材料高温热力学性质

1. 项目概述与核心价值在材料科学和凝聚态物理领域&#xff0c;准确预测材料的热力学性质——如热容、热膨胀系数和体模量——是理解其相稳定性、设计新型合金和优化材料性能的基石。这些性质直接关联到材料的自由能面&#xff0c;而自由能面的精确计算&#xff0c;尤其是在高温…...

播客主必看的AI语音合成合规红线,版权/声纹/数据跨境三重雷区全解析,错过即违规

更多请点击&#xff1a; https://codechina.net 第一章&#xff1a;AI语音合成在播客制作中的应用 AI语音合成技术正深刻重塑播客内容的生产范式。借助高质量、低延迟、多风格可调的TTS&#xff08;Text-to-Speech&#xff09;引擎&#xff0c;创作者无需专业录音棚、配音演员…...

云服务器Nginx静态网站首屏慢的四层根因与优化方案

1. 为什么明明用了Nginx&#xff0c;静态网站首屏加载却要3秒以上&#xff1f;你有没有遇到过这种情况&#xff1a;在云服务器上用Nginx部署了一个纯HTMLCSSJS的静态站点&#xff0c;连数据库都不用&#xff0c;理论上应该毫秒级响应——结果打开首页&#xff0c;F12 Network面…...

Claude学术写作辅助应用:3天写出SCI初稿?实测7个被顶刊编辑默许的Prompt技巧

更多请点击&#xff1a; https://intelliparadigm.com 第一章&#xff1a;Claude学术写作辅助应用&#xff1a;3天写出SCI初稿&#xff1f;实测7个被顶刊编辑默许的Prompt技巧 为什么Claude比GPT更适配学术写作场景 Claude系列模型&#xff08;尤其是Claude 3.5 Sonnet&#…...

LeetCode 1314:矩阵区域和 | 二维前缀和

LeetCode 1314&#xff1a;矩阵区域和 | 二维前缀和 引言 矩阵区域和&#xff08;Matrix Block Sum&#xff09;是 LeetCode 第 1314 题&#xff0c;难度为 Medium。题目要求计算矩阵中以每个元素为中心、KK 子矩阵区域的元素和。这道题是二维前缀和的经典应用&#xff0c;展…...

从微服务到 Agent 服务:架构思维的迁移

从微服务到 Agent 服务:架构思维的迁移与落地全指南 第一部分:引言与基础 (Introduction & Foundation) 1. 引人注目的标题 (Compelling Title) 副标题:深入解析微服务痛点、Agent服务原理、架构设计迁移路径与企业级生产实践 2. 摘要/引言 (Abstract / Introduction)…...

Windows 11系统级优化:ExplorerPatcher核心技术深度解析与专业修复方案

Windows 11系统级优化&#xff1a;ExplorerPatcher核心技术深度解析与专业修复方案 【免费下载链接】ExplorerPatcher This project aims to enhance the working environment on Windows 项目地址: https://gitcode.com/GitHub_Trending/ex/ExplorerPatcher Windows 11…...

MDK Middleware网络组件的嵌入式安全防护解析

1. MDK Middleware网络组件的安全特性解析在嵌入式系统开发中&#xff0c;网络安全往往是最容易被忽视却又至关重要的环节。作为Keil MDK开发环境的核心组件&#xff0c;Middleware Network为Cortex-M系列微控制器提供了轻量级TCP/IP协议栈实现。不同于桌面级操作系统自带的网络…...

解析美国RTP导热工程塑料在电子散热领域的性能表现与行业应用

美国RTP导热工程塑料通过填充陶瓷、金属等导热介质提升材料热导率&#xff0c;同时保持优异机械性能与绝缘特性&#xff0c;完美适配电子散热场景。行业数据显示其热导率可达1-20 W/(mK)&#xff0c;远超普通塑料0.2W/(mK)水平&#xff0c;成为解决电子设备过热问题的优选方案。…...