鸿蒙OS投票机制

(基于openharmony5.0)

投票机制

param get | grep ohos.boot.time
投票机制参数图

只有当所有的投票完成,开机动画才会退出,整理需要投票的系统应用(三方应用不参与投票)如下图所示:

以进程foundation为例:

foundation\systemabilitymgr\safwk\etc\profile\foundation.cfg

复制代码
"bootevents": [
    "bootevent.wms.fullscreen.ready",
    "bootevent.appfwk.ready",
    "bootevent.lockscreen.ready",
    "bootevent.wms.ready"
],

可以看到foundation进程有4个投票事件,会在相应的时机,代码中调用SystemWriteParam()方法进行投票。如果有需要投票的地方没有投,会导致开机动画不会退出,开机动画退出会检测bootevent.boot.completed事件。

base\startup\init\services\modules\bootevent\bootevent.c

复制代码
#define BOOT_EVENT_BOOT_COMPLETED "bootevent.boot.completed"

...

static int BootEventParaFireByName(const char *paramName)
{
    BOOT_EVENT_PARAM_ITEM *found = NULL;

    char *bootEventValue = strrchr(paramName, '.');
    INIT_CHECK(bootEventValue != NULL, return 0);
    bootEventValue[0] = '\0';

    WriteBooteventSysParam(paramName);

    found = (BOOT_EVENT_PARAM_ITEM *)OH_ListFind(&bootEventList, (void *)paramName, BootEventParaListCompareProc);
    if (found == NULL) {
        return 0;
    }

    // Already fired
    if (found->timestamp[BOOTEVENT_READY].tv_sec > 0) {
        return 0;
    }
    INIT_CHECK_RETURN_VALUE(clock_gettime(CLOCK_MONOTONIC,
        &(found->timestamp[BOOTEVENT_READY])) == 0, 0);

    g_bootEventNum--;
    SetServiceBooteventHookMgr(NULL, paramName, 2); // 2: bootevent service has ready
    // Check if all boot event params are fired
    if (g_bootEventNum > 0) {
        return 0;
    }
    // All parameters are fired, set boot completed now ...
    INIT_LOGI("All boot events are fired, boot complete now ...");
    //所有投票事件都已经完成
    SystemWriteParam(BOOT_EVENT_BOOT_COMPLETED, "true");
    SaveServiceBootEvent();
    // report complete event
    ReportSysEvent();
    BootCompleteClearAll();
#ifndef STARTUP_INIT_TEST
    HookMgrExecute(GetBootStageHookMgr(), INIT_BOOT_COMPLETE, NULL, NULL);
#endif
    RemoveCmdExecutor("bootevent", -1);
    return 1;
}
相关推荐
xmdy586624 分钟前
Flutter+开源鸿蒙实战|校园易生活Day7 个人中心完善+我的发布/收藏+退出登录+主题切换+全局UI美化(项目闭环)
flutter·开源·harmonyos
求学中--26 分钟前
鸿蒙网络请求从入门到精通:HttpURLConnection+第三方库,GET/POST/文件上传全覆盖
开发语言·php·harmonyos
13509729421 小时前
Harmony OS 多功能录音小工具
harmonyos
13509729421 小时前
Harmony OS 定位功能开发实战
harmonyos
13509729421 小时前
Harmony OS 打造多功能录音与发音应用(音视频开发)
harmonyos
13509729421 小时前
Harmony OS 截图保存功能详解
harmonyos
前端不太难2 小时前
鸿蒙 App 的 Task + State 双核心架构
架构·状态模式·harmonyos
木斯佳2 小时前
HarmonyOS 实战(源码教学篇):从一次语音识别率排查,讲透音频采集、PCM 与 ASR 同源校验
音视频·语音识别·harmonyos
Mr. zhihao3 小时前
从救火到防火:解读华为的确定性运维方法论,以及AI扮演的真正角色
运维·人工智能·华为
干词3 小时前
干词入选华为应用首页“精选推荐”鸿蒙/安卓/双端支持!
华为·harmonyos·雅思·背单词·四六级·干词·精选推荐