Android SystemServer学习

Android平台实现开机调试system_process 提供一种在Android平台开机调试system_process的方法 阅读详情

Linux内核启动后,Android系统启动有4个步骤;

(1)init进程启动

(2)Native服务启动

(3)System Server及Java服务启动

(4)Home启动


Init进程启动后,将根据init.rc及initXXX.rc的内容执行一系列的命令,包括创建mount目录,安装文件系统,设置属性,启动adb,systemserver,mediaserver


system/core/rootdir/init.rc 内容如下:

# setup the global environment                 //设置环境变量
    export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
    export LD_LIBRARY_PATH /vendor/lib:/system/lib
...
    # Filesystem image public mount points.    //mount文件系统
    mkdir /mnt/obb 0700 root system
    mount tmpfs tmpfs /mnt/obb mode=0755,gid=1000
...

# Define the oom_adj values for the classes of processes that can be
# killed by the kernel.  These are used in ActivityManagerService.
    setprop ro.FOREGROUND_APP_ADJ 0
... 

service servicemanager /system/bin/servicemanager           //在其他服务启动前必须启动ServiceManager
    class pre_zygote_services
    user system
    group system
    critical
    onrestart restart zygote
    onrestart restart media

service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server   //启动SystemServer
    class zygote_services
    socket zygote stream 666
    onrestart write /sys/android_power/request_state wake
    onrestart write /sys/power/state on
    onrestart restart media
    onrestart restart netd

service media /system/bin/mediaserver    //启动mediaserver,启动多媒体相关的camera/playback等服务
    class zygote_services
    user media
    group system audio camera graphics inet net_bt net_bt_admin net_raw mot_drm input mot_tpapi mot_secclkd mot_pwric mot_caif
    ioprio rt 4

代码中service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server将启动systemserver。



具体调用路径如下:


app_process主入口函数,启动system server时命令行为app_process -Xzygote /system/bin --zygote --start-system-server。

frameworks/base/cmds/app_process/app_main.cpp

int main(int argc, const char* const argv[])
{
...
    // Next arg is startup classname or "--zygote"
    if (i < argc) {
        arg = argv[i++];
        if (0 == strcmp("--zygote", arg)) { //命令行必须含 --zygote
            bool startSystemServer = (i < argc) ? 
                    strcmp(argv[i], "--start-system-server") == 0 : false; //命令行是否含--start-system-server
            setArgv0(argv0, "zygote");
            set_process_name("zygote");
            runtime.start("com.android.internal.os.ZygoteInit",
                startSystemServer);          //此处启动systemserver
        } else {
...
}

启动ZygoteInit进程,以后所有的java进程均须通过此进程fork而成。


frameworks/base/core/jni/AndroidRuntime.cpp

void AndroidRuntime::start(const char* className, const bool startSystemServer)
{
...
    /* start the virtual machine */
    if (startVm(&mJavaVM, &env) != 0)
        goto bail;

    /*
     * Register android functions.
     */
    if (startReg(env) < 0) {
        LOGE("Unable to register all android natives\n");
        goto bail;
    }
...
    if (startClass == NULL) {
        LOGE("JavaVM unable to locate class '%s'\n", slashClassName);
        /* keep going */
    } else {
        startMeth = env->GetStaticMethodID(startClass, "main",
            "([Ljava/lang/String;)V");
        if (startMeth == NULL) {
            LOGE("JavaVM unable to find main() in '%s'\n", className);
            /* keep going */
        } else {
            env->CallStaticVoidMethod(startClass, startMeth, strArray); //调用com.android.internal.os.ZygoteInit的main()方法
        }
    }

bail:
    free(slashClassName);
}


ZygoteInit进程入口函数:

frameworks/base/core/java/com/android/internal/os/ZygoteInit.java

    public static void main(String argv[]) {
        try {
            VMRuntime.getRuntime().setMinimumHeapSize(5 * 1024 * 1024);
...            registerZygoteSocket();
...            preloadClasses();
...            preloadResources();
            // Do an initial gc to clean up after startup
            gc();
...
            if (argv[1].equals("true")) { //只支持true参数
                startSystemServer();       //此处启动systemserver
            }
...
            if (ZYGOTE_FORK_MODE) { //目前为false
                runForkMode();
            } else {
                runSelectLoopMode(); //将在Loop中顺序处理以后的For请求
            }

            closeServerSocket();
        } catch (MethodAndArgsCaller caller) {
            caller.run();
        } catch (RuntimeException ex) {
            Log.e(TAG, "Zygote died with exception", ex);
            closeServerSocket();
            throw ex;
        }
    }
启动system server。
    private static boolean startSystemServer()
            throws MethodAndArgsCaller, RuntimeException {
        /* Hardcoded command line to start the system server */
        String args[] = {
            "--setuid=1000",
            "--setgi
Android Framework学习八:SystemServer及startService原理 Android 系统中 SystemServer 启动流程如下: 首先由 untimeInit.applicationInit() 准备反射所需 Method,加载 libandroid_servers.so 动态库。接着创建系统上下文,实例化 SystemServiceManager 管理服务。 服务启动分三步:startBootstrapServices(t) 启动引导服务,如 ATM 等,通过反射创建服务并执行 onStart();startCoreServices(t) 启动核心服务,像电池服务; 阅读详情

相关推荐

启动SystemServer的进程:启动各种系统服务

首先是一个知识清单:(对于现在的Android及移动互联网来说,我们需要掌握的技术)泛型原理丶反射原理丶Java虚拟机原理丶线程池原理丶注解原理丶注解原理丶序列化Activity知识体系(Activity的生命周期丶Activity的任务栈丶Activity的启动模式丶View源码丶Fragment内核相关丶service原理等)代码框架结构优化(数据结构丶排序算法丶设计模式)APP性能优化(用户体验优化丶适配丶代码调优)热修复丶热升级丶Hook技术丶IOC架构设计。

2401_84121485的博客 1082

Halcon Socket TCP通讯:从算子调用到工业视觉系统集成

本文详细介绍了Halcon Socket TCP通讯在工业视觉系统中的应用与优化技巧。从基础算子调用到高并发处理,再到与PLC、机器人及MES系统的集成实战,提供了全面的解决方案和性能优化建议,帮助开发者高效实现工业视觉系统的通讯需求。

weixin_33502772的博客 253

FANUC机器人PROFINET通讯方式组态

6 然后对模块进行命名及更改IP地址,点击“Network Detection”,进行扫描,会生成下图,双击商科模块会生成下边的对话框,对模块进行命名及更改IP地址,在“Permanent Name”处点对勾,完成后点击“Apply Name及Apply”进行命名。此处注意,上图左上在线在不了,网络扫描处上面也灰色的,扫描不了。5双击abcc-prt-2-port RT(FW1.13),生成下面图标,在右边点击1、2把原来内容删掉,从新在左侧加载 ,使1、2是输出,3、4为输入,完成后点击OK。

dxs93的博客 8458

ROS——无人机ROS仿真包 rotors_simulator 编译教程

文章目录 安装wstool sudo apt install python3-wstool 创建ROS工程 $ mkdir -p ~/UAV/src $ cd ~/UAV/src $ catkin_init_workspace # initialize your catkin workspace $ wstool init 下载源码 git clone git@github.com:ethz-asl/rotors_simulator.git 源码链接: https://github.com/eth

漫长IT路 5873

从AD到HFSS:Gerber文件驱动的PCB三维电磁仿真全流程解析

本文详细解析了从AD到HFSS的Gerber文件驱动的PCB三维电磁仿真全流程,重点介绍了Gerber文件作为桥梁的重要性、AD端Gerber文件导出实战指南、HFSS 3D Layout导入技巧及高级问题排查方法。通过实际案例和技巧分享,帮助工程师高效完成PCB电磁仿真,提升设计验证效率。

weixin_33735077的博客 266

jeecg-boot getDictItemsByTable接口存在SQL注入漏洞CVE-2024-48307

微信公众号搜索:南风漏洞复现文库该文章 南风漏洞复现文库 公众号首发JeecgBoot 是一款开源的的低代码开发平台。

nnn2188185的博客 337

【深度学习】最强算法之:残差网络(ResNet)

一篇掌握深度学习算法之:残差网络

商务合作 | 面试培训 | 职场规划 ==>主页扫码 7843

深入解析 Multi-Agent 协同决策机制与架构设计

让我们从一些基础定义开始,为后续的讨论建立共同的语言。在计算机科学和人工智能领域,智能体(Agent)是指一个能够感知环境、做出决策并执行动作的实体。智能体是任何可以通过传感器感知环境,并通过执行器作用于该环境的事物。atπstat​πst​sts_tst​是时刻ttt的环境状态(或智能体的观测)π\piπ是智能体的策略(Policy),即从状态到动作的映射ata_tat​是智能体在时刻ttt选择执行的动作多智能体系统(MAS)

AI天才研究院 545

第4.4节:保护轴承与安全系统

飞轮储能系统的保护轴承是磁悬浮失效时的最后安全屏障,其设计需满足非干涉性、高可靠性和有限寿命承载原则。转子跌落过程包括自由下落、碰撞、进动和滑行减速等复杂非线性阶段,产生远超常规工况的冲击载荷。保护轴承需具备极限冲击容量、高温耐受性和抗卡死能力。系统采用多层级安全架构,结合故障诊断与健康管理,通过监测振动、电流等参数实现预测性维护。安全停机序列有序结合主动制动与被动摩擦制动,确保系统在极端工况下的安全。保护轴承类型多样,需根据系统规模与可靠性要求合理选择。

技术工作者 240

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

上一篇: Binder学习三 MediaServer -- 实例
下一篇: ubuntu下执行cts
cloudwu007
博客等级 码龄18年 42粉丝 28原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值