一、开发环境
系统版本:OpenHarmony 4.0.10.13
设备平台:rk3588
SDK版本:fullSDK 4.0.10.13
二、背景
使用自研应用作为默认Launcher,或者说使特定应用默认开机自启作为Home应用。
三、分析过程
通过分析原生Launcher启动流程可知:
AMS启动根据应用优先级启动应用,通常是OOBE或Launcher
foundation/ability/ability_runtime/services/abilitymgr/src/ability_manager_service.cpp
void AbilityManagerService::StartUserApps(int32_t userId, bool isBoot)
{
HILOG_INFO("StartUserApps, userId:%{public}d, currentUserId:%{public}d", userId, GetUserId());
if (currentMissionListManager_ && currentMissionListManager_->IsStarted()) {
HILOG_INFO("missionListManager ResumeManager");
currentMissionListManager_->ResumeManager();
}
//启动优先级最高的应用
StartHighestPriorityAbility(userId, isBoot);
}
...
void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isBoot)
{
...
/* Query the highest priority ability or extension ability, and start it. usually, it is OOBE or launcher */
Want want;
want.AddEntity(HIGHEST_PRIORITY_ABILITY_ENTITY);
AppExecFwk::AbilityInfo abilityInfo;
AppExecFwk::ExtensionAbilityInfo extensionAbilityInfo;
int attemptNums = 0;
//ImplicitQueryInfoByPriority查询应用ability和extensionAbility配置中的优先级
while (!IN_PROCESS_CALL(bms->ImplicitQueryInfoByPriority(want,
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, userId,
abilityInfo, extensionAbilityInfo))) {
HILOG_INFO("Waiting query highest priority ability info completed.");
++attemptNums;
if (!isBoot && attemptNums > SWITCH_ACCOUNT_TRY) {
HILOG_ERROR("Query highest priority ability failed.");
return;
}
AbilityRequest abilityRequest;
ComponentRequest componentRequest = initComponentRequest();
if (!IsComponentInterceptionStart(want, componentRequest, abilityRequest)) {
return;
}
usleep(REPOLL_TIME_MICRO_SECONDS);
}
...
//启动查询到的最高优先级应用
/* note: OOBE APP need disable itself, otherwise, it will be started when restart system everytime */
(void)StartAbility(abilityWant, userId, DEFAULT_INVAL_VALUE);
}
至此我们了解到应用优先级取决于应用ability和extensionAbility 优先级配置
查看官方资料
module.json5配置文件
查看launcher module.json5配置文件
"extensionAbilities": [
{
"priority": 2, //优先级设定为2
"skills": [ //接受home Want的特征标签
{
"entities": [
"entity.system.home",
"flag.home.intent.from.system"
],
"actions": [
"action.system.home",
"com.ohos.action.main",
"action.form.publish"
]
}
],
"exported": false, //本组件不可被其他应用调研
"name": "com.ohos.launcher.MainAbility&#