当前位置: 首页 > 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 类文件具有错误的…...

大数据零基础学习day1之环境准备和大数据初步理解

学习大数据会使用到多台Linux服务器。 一、环境准备 1、VMware 基于VMware构建Linux虚拟机 是大数据从业者或者IT从业者的必备技能之一也是成本低廉的方案 所以VMware虚拟机方案是必须要学习的。 &#xff08;1&#xff09;设置网关 打开VMware虚拟机&#xff0c;点击编辑…...

Java - Mysql数据类型对应

Mysql数据类型java数据类型备注整型INT/INTEGERint / java.lang.Integer–BIGINTlong/java.lang.Long–––浮点型FLOATfloat/java.lang.FloatDOUBLEdouble/java.lang.Double–DECIMAL/NUMERICjava.math.BigDecimal字符串型CHARjava.lang.String固定长度字符串VARCHARjava.lang…...

MySQL 8.0 OCP 英文题库解析(十三)

Oracle 为庆祝 MySQL 30 周年&#xff0c;截止到 2025.07.31 之前。所有人均可以免费考取原价245美元的MySQL OCP 认证。 从今天开始&#xff0c;将英文题库免费公布出来&#xff0c;并进行解析&#xff0c;帮助大家在一个月之内轻松通过OCP认证。 本期公布试题111~120 试题1…...

SpringTask-03.入门案例

一.入门案例 启动类&#xff1a; package com.sky;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCach…...

全志A40i android7.1 调试信息打印串口由uart0改为uart3

一&#xff0c;概述 1. 目的 将调试信息打印串口由uart0改为uart3。 2. 版本信息 Uboot版本&#xff1a;2014.07&#xff1b; Kernel版本&#xff1a;Linux-3.10&#xff1b; 二&#xff0c;Uboot 1. sys_config.fex改动 使能uart3(TX:PH00 RX:PH01)&#xff0c;并让boo…...

如何在网页里填写 PDF 表格?

有时候&#xff0c;你可能希望用户能在你的网站上填写 PDF 表单。然而&#xff0c;这件事并不简单&#xff0c;因为 PDF 并不是一种原生的网页格式。虽然浏览器可以显示 PDF 文件&#xff0c;但原生并不支持编辑或填写它们。更糟的是&#xff0c;如果你想收集表单数据&#xff…...

docker 部署发现spring.profiles.active 问题

报错&#xff1a; org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property spring.profiles.active imported from location class path resource [application-test.yml] is invalid in a profile specific resource [origin: class path re…...

HarmonyOS运动开发:如何用mpchart绘制运动配速图表

##鸿蒙核心技术##运动开发##Sensor Service Kit&#xff08;传感器服务&#xff09;# 前言 在运动类应用中&#xff0c;运动数据的可视化是提升用户体验的重要环节。通过直观的图表展示运动过程中的关键数据&#xff0c;如配速、距离、卡路里消耗等&#xff0c;用户可以更清晰…...

AI+无人机如何守护濒危物种?YOLOv8实现95%精准识别

【导读】 野生动物监测在理解和保护生态系统中发挥着至关重要的作用。然而&#xff0c;传统的野生动物观察方法往往耗时耗力、成本高昂且范围有限。无人机的出现为野生动物监测提供了有前景的替代方案&#xff0c;能够实现大范围覆盖并远程采集数据。尽管具备这些优势&#xf…...

并发编程 - go版

1.并发编程基础概念 进程和线程 A. 进程是程序在操作系统中的一次执行过程&#xff0c;系统进行资源分配和调度的一个独立单位。B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位。C.一个进程可以创建和撤销多个线程;同一个进程中…...