Android 开机动画的启动过程BootAnimation(基于Android10.0.0-r41)

文章目录

Android 开机动画的启动过程BootAnimation(基于Android10.0.0-r41)

1.开机动画的启动过程概述

下面就是BootAnimation的重要部分。

开机动画主要跟三个东西有关系

bootanimation surfaceflinger init

查看下Android.bp编译文件,cc_binary就是我们编译出来的可执行文件

最终的输出路径是在

系统启动的第一个进程是init,init进程会根据init.rc配置启动surfaceflinger进程。就是下面这个.rc进程

但是此时的Bootanim.rc不会启动。是disabled。

一般一个进程启动了,都会有一个对应的main方法。

路径frameworks/native/services/surfaceflinger

c++ 复制代码
int main(int, char**) {
    signal(SIGPIPE, SIG_IGN);

    hardware::configureRpcThreadpool(1 /* maxThreads */,
            false /* callerWillJoin */);

    startGraphicsAllocatorService();

    // When SF is launched in its own process, limit the number of
    // binder threads to 4.
    ProcessState::self()->setThreadPoolMaxThreadCount(4);

    // start the thread pool
    sp<ProcessState> ps(ProcessState::self());
    ps->startThreadPool();

    // instantiate surfaceflinger
    //创建对象
    sp<SurfaceFlinger> flinger = surfaceflinger::createSurfaceFlinger();

    setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);

    set_sched_policy(0, SP_FOREGROUND);

    // Put most SurfaceFlinger threads in the system-background cpuset
    // Keeps us from unnecessarily using big cores
    // Do this after the binder thread pool init
    if (cpusets_enabled()) set_cpuset_policy(0, SP_SYSTEM);

    // initialize before clients can connect
    //执行init方法
    flinger->init();

    // publish surface flinger
    sp<IServiceManager> sm(defaultServiceManager());
    sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false,
                   IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL | IServiceManager::DUMP_FLAG_PROTO);

    startDisplayService(); // dependency on SF getting registered above

    struct sched_param param = {0};
    param.sched_priority = 2;
    if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
        ALOGE("Couldn't set SCHED_FIFO");
    }

    // run surface flinger in this thread
    //执行run方法
    flinger->run();

    return 0;
}

首先进入init方法

开启一个线程,Start()之后这个线程就运行起来了。

线程run起来

bootanim设置属性,控制bootanim的一个服务要启动起来,就是这里设置属性之后就会起来了,就开始播放开机动画。

cpp 复制代码
property_set("service.bootanim.exit", "0");
    // Start BootAnimation if not started
    property_set("ctl.start", "bootanim");

2.为什么设置了属性之后就会播放?

/system/core/init.cpp

启动属性服务

跨进程通信CreateSocket

cpp 复制代码
void StartPropertyService(Epoll* epoll) {
    selinux_callback cb;
    cb.func_audit = SelinuxAuditCallback;
    selinux_set_callback(SELINUX_CB_AUDIT, cb);

    property_set("ro.property_service.version", "2");
	//获取fd
    property_set_fd = CreateSocket(PROP_SERVICE_NAME, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
                                   false, 0666, 0, 0, nullptr);
    if (property_set_fd == -1) {
        PLOG(FATAL) << "start_property_service socket creation failed";
    }
	//监听fd句柄
    listen(property_set_fd, 8);

    if (auto result = epoll->RegisterHandler(property_set_fd, handle_property_set_fd); !result) {
        PLOG(FATAL) << result.error();
    }
}

回调方法handle_property_set_fd,然后调用下面这个方法

然后进到HandleControlMessage,此时我们发现这个方法不知道是哪个头文件引入进来的,所以得搜索一下。

递归搜索当前目录以及子目录。

json 复制代码
grep "HandleControlMessage"  ./ -rn

通过名字查找服务,也就是前面设置的属性值bootanim

找到对应的map,根据msg获取服务的状态是什么样子的,然后根据name名字去找到对应设置的服务。

绘制图像需要依赖surfaceflinger来绘制,所以开机动画是在surfaceflinger之后启动的。

init启动。surfaceflinger进程的init执行,然后StartPropetySetThread线程的启动,然后再通知init进程启动开机动画进程,然后是bootanimation的main方法执行,

相关推荐
zhaotiannuo_19982 小时前
渗透测试之docker
运维·docker·容器
野生的码农3 小时前
码农的妇产科实习记录
android·java·人工智能
王正南3 小时前
kali-linux 虚拟机连接安卓模拟器
android·linux·运维·虚拟机连接模拟器·安卓模拟器,linux虚拟机
撩得Android一次心动3 小时前
Android Jetpack 概述
android·android jetpack
三不原则3 小时前
故障案例:容器启动失败排查(AI运维场景)——从日志分析到根因定位
运维·人工智能·kubernetes
JinBeen3 小时前
sourcetree下码云gitee的ssh经常失效问题
android·gitee·ssh
吳所畏惧3 小时前
Linux环境/麒麟V10SP3下离线安装Redis、修改默认密码并设置Redis开机自启动
linux·运维·服务器·redis·中间件·架构·ssh
yueguangni3 小时前
sysstat 版本 10.1.5 是 CentOS 7 的默认版本,默认情况下确实不显示 %wait 字段。需要升级到新版sysstat
linux·运维·centos
funfan05174 小时前
【运维】MySQL数据库全量备份与恢复实战指南:从入门到精通
运维·数据库·mysql
帅得不敢出门4 小时前
Android各芯片平台日志打开及获取
android