1:修改 install_list.json

修改 install_list.json(源码路径:/product/preinstall-config/install_list.json,设备路径:/system/etc/app/install_list.json)
使Launcher应用hap(Launcher.hap、Launcher_Settings.hap)所在路径被包含在列表app_dir所示路径内:

{
+   "app_dir" : "/system/app/com.my.launcher",
+   "removable" : false
}

删除原有launcher路径:

{
-  "app_dir" : "/system/app/com.ohos.launcher",
-  "removable" : false
}

2:修改 install_list_capability.json

修改设备的特权管控白名单文件 install_list_capability.json(源码路径:/product/preinstall-config/install_list_capability.json, 设备路径:/system/etc/app/install_list_capability.json)
 新增Launcher应用的配置,其中app_signature字段为应用证书指纹,证书存放在HarmonyAppProvision文件的distribution-certificate字段下,Launcher应用证书指纹获取方法详细参考 https://docs.openharmony.cn/pages/v6.0/zh-cn/device-dev/subsystems/subsys-app-privilege-config-guide.md '证书指纹获取'条目

{
  "bundleName": "com.your.launcher",
  "app_signature": ["*****************"],
  "allowAppUsePrivilegeExtension": true
}

附:Launcher应用的一些注意事项


1:EntryView.ets的onPageShows声明周期中需设置bootevent.launcher.ready,否则会出现系统界面卡在开机Logo的问题:

onPageShow(): void {
  Log.showInfo(TAG, 'onPageShow');
  let firstActivate:boolean | undefined = AppStorage.get('firstActivate');
  if (firstActivate) {
    this.voteBootEvent();
  }
}

...

private voteBootEvent(): void {
  Log.showInfo(TAG, 'voteBootEvent for launcher begin');
  try {
    AppStorage.setOrCreate('firstActivate', false);
    AppStorage.setOrCreate('loaded', true);
    systemParameter.setSync('bootevent.launcher.ready', 'true');
  } catch (err) {
    Log.showError(TAG, `set voteBootEvent err, ${JSON.stringify(err)}`);
  }
  Log.showInfo(TAG, 'voteBootEvent for launcher end');
}

2:应用的module.json5 文件需配置 type为service类型的 sextensionAbilities

普通UIAbility加载页面的方式

windowStage.getMainWindow().then((win) => {
  let loadContentUrl = 'pages/Index';
      windowStage.loadContent(loadContentUrl, (err) => {
        if (err.code) {
          return;
        }
      })
})

需修改为自己手动创建窗口后加载页面:

 window.createWindow(cfg)
        .then((win: window.Window) => {
          win.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED);
          win.setUIContent(loadContent)
            .then(() => {
            ...

详细参考 系统Launcher源码:applications/standard/launcher/common/src/main/ets/default/manager/WindowManager.ts createWindow函数

extensionAbilities.skills 配置为:

"skills": [
        {
            "entities": [
                "entity.system.home",
                "flag.home.intent.from.system"
            ],

            "actions": [
                "action.system.home",
                "com.ohos.action.main",
                "action.form.publish"
            ]
        }
    ]

 

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐