服务软件包元数据

本页面介绍了如何使用强制性和可选的服务包元数据字段。

在 Android 17 QPR2 及更高版本中,您可以在 VSIDL 系统图中使用 apex 和 service_bundle_manifest 块在 .vsidl 文件中声明服务软件包元数据,以自动生成 sdv_service_bundles_manifest.textproto 和 Soong 构建目标。

强制性元数据

服务包执行模型要求每个服务包定义以下元数据:

VSIDL

在 VSIDL 系统图中定义 APEX 时,请在 apex 块内的 service_bundle_manifest 块中声明服务包元数据。vsidlc 使用此块自动生成 sdv_service_bundles_manifest.textproto:

apex {
  service_bundle_manifest {
    # Required reference to a service_bundle defined in the VSIDL catalog.
    service_bundle: "TheNameOfTheServiceBundle"

    # Optional name of the service bundle in the manifest.
    # Defaults to the unqualified name of service_bundle if omitted.
    name: "TheNameOfTheServiceBundle"

    # Optional Service Bundle Version Number (defaults to 0).
    # Must be non-negative number.
    version_number: 1

    # Optional Service Bundle Version Name (defaults to "0.1 Alpha").
    # Must be non-empty string.
    version_name: "1.0 alpha"

    # Optional path to the native library to be loaded as service bundle
    # (mutually exclusive with native_library; defaults to
    # "lib64/libsdv_lm_<snake_case_service_bundle_fqn>.so").
    # Must be the relative path from the APEX root directory.
    native_library_path: "lib64/libservice_bundle.so"
  }
}
apex {
  # Service bundle one.
  service_bundle_manifest {
    service_bundle: "ServiceBundleOne"
    ...
  }
  # Service bundle two.
  service_bundle_manifest {
    service_bundle: "ServiceBundleTwo"
    ...
  }
}

Textproto

sdv_service_bundle_metadata {
  # Name of the service bundle.
  #
  # Must follow SDV service naming convention rules.
  # Ref: https:/automotive/sdv/core-areas/naming-conventions
  #
  # When using VSIDL catalog and middleware generation, this name must be
  # equal to the service bundle name defined in the catalog.
  name: "TheNameOfTheServiceBundle"

  # Service Bundle Version Number.
  # Must be non-negative number.
  version_number: 1

  # Service Bundle Version Name.
  # Must be non-empty string.
  version_name: "1.0 alpha"

  # Path to the native library to be loaded as service bundle.
  # Must be the relative path from the APEX root directory
  native_library_path: "lib64/libservice_bundle.so"
}
# Service bundle one.
sdv_service_bundle_metadata {
  name: "ServiceBundleOne"
  ...
}
# Service bundle two.
sdv_service_bundle_metadata {
  name: "ServiceBundleTwo"
  ...
}

可选元数据

可选元数据支持特定的 SDV 功能。

编排元数据

SDV 编排配置提供了一种机制,用于控制服务包的启动和关停行为。SDV 编排配置定义了一组规则,用于确定何时以及如何对服务包实例执行操作。这些规则基于车辆、电源和自定义模式。

VSIDL

在 VSIDL 中定义 apex 块时,vsidlc 会根据系统图自动生成服务包的编排配置,并将 orchestration_config_path 设置为 etc/<ServiceBundleName>/orchestrator.textproto。如需使用自定义 textproto 替换生成的文件,或在 APEX 中自定义其目标路径,请向 service_bundle_manifest 添加 orchestration 资源块:

apex {
  service_bundle_manifest {
    service_bundle: "TheNameOfTheServiceBundle"
    ...
    # Optional override for the orchestration config file.
    # src is relative to the catalog directory.
    # dst must be a relative path from the APEX root directory starting with "etc/".
    orchestration {
      src: "configuration.textproto"
      dst: "etc/configuration/orchestration/configuration.textproto"
    }
  }
}

Textproto

如需将编排配置与服务包相关联,请在可选的 orchestration_config_path 字段中提供 prebuilt_etc 模块的路径:

sdv_service_bundle_metadata {
  ...
  # Path to the orchestration config file.
  # Warning: Shall be relative path to the APEX root directory.
  orchestration_config_path: "etc/configuration/orchestration/configuration.textproto"
}

授权政策路径

SDV 授权政策提供了一种机制,用于声明服务包的权限。授权政策定义了服务包可以执行的操作(例如发布、订阅、提供服务或调用)。

VSIDL

在 VSIDL 中定义 apex 块时,vsidlc 会根据服务包的通信单元自动生成授权政策,并将 authorization_policy_path 设置为 etc/<ServiceBundleName>/permissions.textproto。如需使用自定义文件替换生成的政策,或在 APEX 中自定义其目标路径,请向 service_bundle_manifest 添加 authz 资源块:

apex {
  service_bundle_manifest {
    service_bundle: "TheNameOfTheServiceBundle"
    ...
    # Optional override for the authorization policy file.
    # src is relative to the catalog directory.
    # dst must be a relative path from the APEX root directory starting with "etc/".
    authz {
      src: "permissions.textproto"
      dst: "etc/authz/permissions.textproto"
    }
  }
}

Textproto

如需将授权政策与服务包相关联,请在可选的 authorization_policy_path 字段中提供 prebuilt_etc 模块的路径:

sdv_service_bundle_metadata {
  ...
  # Path to the authorization policy file.
  # Warning: Shall be relative path to the APEX root directory.
  authorization_policy_path: "etc/authz/permissions.textproto"
}

VSIDL 提供商元数据

VSIDL 提供程序元数据是用于将服务包与诊断和 SOME/IP 平台代理集成的机制的一部分。

VSIDL

当您在 VSIDL 中定义 apex 块时,vsidlc 会自动生成并注册 VSIDL 架构 (etc/<ServiceBundleName>/vsidl-config.binpb)、诊断配置(etc/<ServiceBundleName>/diagnostics-config.binpb,当 diagnostics_declaration 存在时)和 SOME/IP 配置(etc/<ServiceBundleName>/someip-config.binpb,当 SOME/IP 映射存在时)。如需替换这些文件或在 APEX 中自定义其目标路径,请将 vsidl_schema、diagnostics 或 someip 资源块添加到 service_bundle_manifest:

apex {
  service_bundle_manifest {
    service_bundle: "TheNameOfTheServiceBundle"
    ...
    # Path to the file with protobuf schemas extracted from bundle's VSIDL definition.
    # Warning: Must be relative path to the APEX root directory starting with "etc/".
    vsidl_schema {
      dst: "etc/vsidl_provider/TheNameOfTheServiceBundle-vsidl-config.binpb"
    }

    # Path to the diagnostics config file.
    # Warning: Shall be relative path to the APEX root directory starting with "etc/".
    diagnostics {
      dst: "etc/vsidl_provider/TheNameOfTheServiceBundle-diag-config.binpb"
    }

    # Path to the SOME/IP config file. To be used in SOME/IP configuration apex only.
    # Warning: Must be relative path to the APEX root directory starting with "etc/".
    someip {
      dst: "etc/vsidl_provider/someip-config.binpb"
    }
  }
}

Textproto

如需将 VSIDL 提供程序元数据与服务软件包相关联,请在可选的 vsidl_schemas_path、diagnostics_config_path 或(仅限 SOME/IP 配置 APEX)external_protocol_mapping_path 字段中提供包含生成的元数据文件的 prebuilt_etc 文件的路径:

sdv_service_bundle_metadata {
  ...
  # Path to the file with protobuf schemas extracted from bundle's VSIDL definition.
  # Warning: Must be relative path to the APEX root directory.
  vsidl_schemas_path: "etc/vsidl_provider/TheNameOfTheServiceBundle-vsidl-config.binpb"

  # Path to the diagnostics config file.
  # Warning: Shall be relative path to the APEX root directory.
  diagnostics_config_path: "etc/vsidl_provider/TheNameOfTheServiceBundle-diag-config.binpb"

  # Path to the SOME/IP config file. To be used in SOME/IP configuration apex only.
  # Warning: Must be relative path to the APEX root directory.
  external_protocol_mapping_path: "etc/vsidl_provider/someip-config.binpb"
}

如需了解详情,请参阅 VSIDL 提供程序和中间件概览。

记录标记元数据

日志标记属性用于指定服务包生成的日志的唯一标识符。如果未定义此属性,系统会使用软件包名称、服务软件包名称和实例名称自动生成默认标记。为确保清晰明了,请定义一个简洁且唯一的日志标记。

自定义元数据

借助自定义元数据,OEM 和供应商可以定义特定的服务包元数据。

VSIDL

apex {
  service_bundle_manifest {
    service_bundle: "TheNameOfTheServiceBundle"
    ...
    # Custom service bundle metadata map.
    # Key is a string, value is a string.
    #
    # 1st custom metadata value.
    metadata {
      key: "question"
      value: "Answer to the Ultimate Question of Life, the Universe, and Everything"
    }
    # 2nd custom metadata value.
    metadata {
      key: "answer"
      value: "42"
    }
  }
}

Textproto

sdv_service_bundle_metadata {
  ...
  # Custom service bundle metadata map.
  # Key is a string, value is a string.
  #
  # 1st custom metadata value.
  custom_metadata {
    key: "question"
    value: "Answer to the Ultimate Question of Life, the Universe, and Everything"
  }
  # 2nd custom metadata value.
  custom_metadata {
    key: "answer" value: "42"
  }
}

VSIDL

apex {
  prebuilt_etc: "custom_metadata_file"

  service_bundle_manifest {
    service_bundle: "TheNameOfTheServiceBundle"
    ...
    # Custom metadata values are stored in etc/.
    metadata {
      key: "path_to_custom_metadata"
      value: "etc/configuration/file"
    }
  }
}

Textproto

sdv_service_bundle_metadata {
  ...
  # Custom metadata values are stored in etc/.
  custom_metadata {
    key: "path_to_custom_metadata"
    value: "etc/configuration/file"
  }
}

完整示例

VSIDL

# proto-file: //system/software_defined_vehicle/vsidl/language/src/protos/sdv/vsidl/v1/syntax.proto
# proto-message: VsidlEntry

package: "com.sdv.oem.example"

apex {
  prebuilt_etc: "custom_metadata_file"

  # SDV service bundle manifest.
  service_bundle_manifest {
    # Reference to the service bundle in the catalog.
    service_bundle: "TheNameOfTheServiceBundle"

    # Name of the service bundle.
    # Must follow SDV service naming convention rules.
    name: "TheNameOfTheServiceBundle"

    # Service Bundle Version Number.
    # Must be non-negative number.
    version_number: 42

    # Service Bundle Version Name.
    # Must be non-empty string.
    version_name: "42.0.beta"

    # Path to the native library to be loaded as service bundle.
    # Must be the relative path from the APEX root directory.
    native_library_path: "lib64/libservice_bundle.so"

    # The log tag used for Android logging for the service bundle.
    # If not specified, a tag derived from service bundle FQIN will be used.
    log_tag: "current_service_bundle"

    # Path to the orchestration config file.
    # Warning: Shall be relative path to the APEX root directory.
    orchestration {
      dst: "etc/configuration/orchestration/configuration.textproto"
    }

    # Path to the file with protobuf schemas extracted from bundle's VSIDL definition.
    # Warning: Must be relative path to the APEX root directory.
    vsidl_schema {
      dst: "etc/vsidl_provider/TheNameOfTheServiceBundle-vsidl-config.binpb"
    }

    # Path to the diagnostics config file.
    # Warning: Must be relative path to the APEX root directory.
    diagnostics {
      dst: "etc/vsidl_provider/TheNameOfTheServiceBundle-diag-config.binpb"
    }

    # Path to the SOME/IP config file. To be used in SOME/IP configuration apex only.
    # Warning: Must be relative path to the APEX root directory.
    someip {
      dst: "etc/vsidl_provider/someip-config.binpb"
    }

    # Custom service bundle metadata string.
    # Key is a string, value is a string.
    metadata {
      key: "key"
      value: "value"
    }

    # Custom metadata values are stored in etc/.
    metadata {
      key: "path_to_custom_metadata"
      value: "etc/configuration/file"
    }
  }
}

Textproto

# proto-file: //system/software_defined_vehicle/service_bundles_registry/proto/sdv_service_bundles_manifest.proto
# proto-message: SdvServiceBundleManifest

# SDV service bundle.
sdv_service_bundle_metadata {
  # Name of the service bundle.
  # Must follow SDV service naming convention rules.
  name: "TheNameOfTheServiceBundle"

  # Service Bundle Version Number.
  # Must be non-negative number.
  version_number: 42

  # Service Bundle Version Name.
  # Must be non-empty string.
  version_name: "42.0.beta"

  # Path to the native library to be loaded as service bundle.
  # Must be the relative path from the APEX root directory.
  native_library_path: "lib64/libservice_bundle.so"

  # The log tag used for Android logging for the service bundle.
  # If not specified, a tag derived from service bundle FQIN will be used.
  log_tag: "current_service_bundle"

  # Path to the orchestration config file.
  # Warning: Shall be relative path to the APEX root directory.
  orchestration_config_path: "etc/configuration/orchestration/configuration.textproto"

  # Path to the file with protobuf schemas extracted from bundle's VSIDL definition.
  # Warning: Must be relative path to the APEX root directory.
  vsidl_schemas_path: "etc/vsidl_provider/TheNameOfTheServiceBundle-vsidl-config.binpb"

  # Path to the diagnostics config file.
  # Warning: Must be relative path to the APEX root directory.
  diagnostics_config_path: "etc/vsidl_provider/TheNameOfTheServiceBundle-diag-config.binpb"

  # Path to the SOME/IP config file. To be used in SOME/IP configuration apex only.
  # Warning: Must be relative path to the APEX root directory.
  external_protocol_mapping_path: "etc/vsidl_provider/someip-config.binpb"

  # Custom service bundle metadata string.
  # Key is a string, value is a string.
  custom_metadata {
    key: "key" value: "value"
  }

  # Custom metadata values are stored in etc/.
  custom_metadata {
    key: "path_to_custom_metadata"
    value: "etc/configuration/file"
  }
}

参考