前言

众所周知,现在市面上主流的两家移动操作系统Android和iOS,其搭载设备出厂时,都会附带有已经安装好的默认应用。对比闭源的iOS自带的都是Apple公司自身开发的系统应用,基于开源Android定制的各个厂商os除开官方系统应用外,还会预置一些与三方应用厂商合作的外部应用。因此,本文将着重介绍,如何在OpenHarmony里预置默认应用,并赋予其默认动态权限。

 

示例环境

系统版本:3.2release(3.2.11.9及以后)

芯片型号:rk3568

设备型号:DAYU200

示例应用:Camera(系统相机)

 

开发流程

步骤一 新增hap

将编译好的Camera.hap放到applications/standard/hap下。

 

步骤二 新增build配置

applications/standard/hap/BUILD.gn

下新增

ohos_prebuilt_etc("camera_hap") {
  source = "Camera.hap"
  module_install_dir = "app/com.ohos.camera"
  part_name = "prebuilt_hap"
  subsystem_name = "applications"
}
group("hap") {
  deps = [
    ···
    "//applications/standard/hap:camera_hap",
    ···
  ]
  if (defined(product_name) && product_name == "watchos") {
    deps -= [
      ···
      "//applications/standard/hap:camera_hap",
      ···
    ]
  }
  ···
}

 

步骤三 新增预安装配置

vendor/hihope/rk3568/preinstall-config/install_list.json

下新增

"install_list" : [
    ···
    {
        "app_dir" : "/system/app/com.ohos.camera",
        "removable" : false
    },
    ···
]

 

步骤四 新增默认动态权限

vendor/hihope/rk3568/preinstall-config/install_list_permissions.json

下新增

[
    ···
    {
        "bundleName": "com.ohos.camera",
        "app_signature" : ["62C298EE70BEEB3D58082FFEFFEAD4F26BE83350B46B75C393281BA6AAED2A91"],
        "permissions" : [
            {
                "name" : "ohos.permission.READ_IMAGEVIDEO",
                "userCancellable" : false
            },
            {
                "name" : "ohos.permission.WRITE_IMAGEVIDEO",
                "userCancellable" : false
            },
            {
                "name" : "ohos.permission.MEDIA_LOCATION",
                "userCancellable" : false
            },
            {
                "name" : "ohos.permission.DISTRIBUTED_DATASYNC",
                "userCancellable" : false
            },
            {
                "name" : "ohos.permission.CAMERA",
                "userCancellable" : false
            },
            {
                "name" : "ohos.permission.MICROPHONE",
                "userCancellable" : false
            },
            {
                "name" : "ohos.permission.LOCATION",
                "userCancellable" : false
            },
            {
                "name" : "ohos.permission.LOCATION_IN_BACKGROUND",
                "userCancellable" : false
            },
            {
                "name" : "ohos.permission.APPROXIMATELY_LOCATION",
                "userCancellable" : false
            }
        ]
    },
    ···
]

 

至此,重新编译镜像烧录后,Camera应用会默认随着系统的启动安装,应用启动时也无需在进行手动动态授权。

 

相关仓

applications_camera

applications_hap

vendor_hihope

Logo

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

更多推荐