blob: fcf4bb6b3f179eb84269a63a0a9040a1ec5c50be [file] [log] [blame]
<html devsite><head>
<title>其他资源</title>
<meta name="project_path" value="/_project.yaml"/>
<meta name="book_path" value="/_book.yaml"/>
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>以下资源详细介绍了代码位置、工具、测试和许可信息。</p>
<h2 id="query-api-code">可查询的代码位置</h2>
<p>可查询的供应商接口对象的代码位于 <code><a href="https://android.googlesource.com/platform/system/libvintf/+/master#" class="external">system/libvintf</a></code>(请参阅<a href="/devices/architecture/vintf/objects.html#queryable-api">可查询的 API</a>)。</p>
<h2 id="related-tools">工具</h2>
<p>手写清单文件和兼容性矩阵可能很难。您可以使用以下工具来生成样板清单/兼容性矩阵,从其入手。</p>
<h3 id="lshal">LSHAL</h3>
<p>LSHAL 是一种设备端工具,可以列出向 <code>hwservicemanager</code> 注册的所有 HAL 以及设备上所有可用的直通实现(例如 <code>android.hardware.foo@1.0-impl.so</code>)。它还可以根据该列表生成<strong>设备清单</strong>文件:</p>
<pre class="devsite-terminal">
adb shell su 0 /system/bin/lshal --init-vintf
</pre>
<p>请注意以下几点:</p>
<ol>
<li>如果发现某个软件包既向 <code>hwservicemanager</code> 进行了注册,又发现其属于直通 HAL,则将 <code>&lt;transport&gt;</code> 设置为 <code>hwbinder</code></li>
<li>没有任何 SELinux 版本写入清单中。建议通过 <code>assemble_vintf</code> 注入该元素(如下所述)。</li>
<li>生成的 HAL 清单文件可能不准确。需要手动对比来更正设备清单与 <code>vendor.img</code> 实际提供的内容之间的不一致。</li>
</ol>
<h3 id="assemble_vintf">ASSEMBLE_VINTF</h3>
<p><code>assemble_vintf</code> 是一种主机端工具,可以执行以下操作:</p>
<ol>
<li>验证兼容性矩阵或清单文件是否有效。</li>
<li>将变量注入到构建时可用的清单/兼容性矩阵,并生成应该安装到设备上的新文件。</li>
<li>检查生成的文件与其双重文件之间的兼容性。</li>
<li>如果给出了清单文件,则可以视需要生成与该清单文件兼容的样板兼容性矩阵。</li>
</ol>
<h4><strong>示例:</strong>从框架清单文件生成<strong>设备兼容性矩阵</strong></h4>
<pre class="devsite-terminal">
assemble_vintf -m --hals-only \
-i system/libhidl/manifest.xml \
-o device/manufacturer/device_name/compatibility_matrix.xml
</pre>
<p>请注意,所有 HAL 都设置为 <code>optional="true"</code></p>
<h4><strong>示例:</strong>从设备清单文件生成骨架框架兼容性矩阵</h4>
<pre class="devsite-terminal">
assemble_vintf -m --hals-only \
-i device/foo/bar/manifest.xml \
-o path/to/place/output/compatibility_matrix.xml
</pre>
<p>请注意,所有 HAL 都设置为 <code>optional="true"</code></p>
<h4><strong>示例:</strong>从变量生成 XML 文件</h4>
<p>编译时,如果在 <code>device/manufacturer/device_name/BoardConfig.mk</code> 中定义了以下变量:</p>
<pre class="prettyprint">
DEVICE_MANIFEST_FILE := \
device/manufacturer/device_name/manifest.xml
DEVICE_MATRIX_FILE := \
device/manufacturer/device_name/compatibility_matrix.xml
</pre>
<p>然后,执行以下命令(已在编译系统中修改为省略实现详细信息),以生成所有 XML 文件:</p>
<pre class="prettyprint">
# device manifest; only when DEVICE_MANIFEST_FILE is set
BOARD_SEPOLICY_VERS=10000.0 assemble_vintf \
$(addprefix,-i ,$(DEVICE_MANIFEST_FILE)) \
-o $(TARGET_OUT_VENDOR)/etc/vintf/manifest.xml
# device compatibility matrix; only when DEVICE_MATRIX_FILE is set
assemble_vintf \
-i $(DEVICE_MATRIX_FILE) \
-o $(TARGET_OUT_VENDOR)/etc/vintf/compatibility_matrix.xml
# framework manifest
assemble_vintf
$(addprefix,-i ,system/libhidl/manifest.xml $(DEVICE_FRAMEWORK_MANIFEST_FILE)) \
-o $(TARGET_OUT)/manifest.xml \
-c $(TARGET_OUT_VENDOR)/etc/vintf/compatibility_matrix.xml
# common framework compatibility matrix for each FCM version
BOARD_SEPOLICY_VERS=$(BOARD_SEPOLICY_VERS) \
POLICYVERS=$(POLICYVERS) \
BOARD_AVB_VBMETA_VERSION=$(BOARD_AVB_VBMETA_VERSION)
assemble_vintf \
$(addprefix,-i ,\
hardware/interfaces/compatibility_matrices/compatibility_matrix.empty.xml \
$(DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE)) \
-o $(TARGET_OUT)/etc/vintf/compatibility_matrix.empty.xml
# framework compatibility matrices at each FCM version
assemble_vintf
-i hardware/interfaces/compatibility_matrices/compatibility_matrix.{level}.xml \
-o $(TARGET_OUT)/etc/vintf/compatibility_matrix.{level}.xml \
--kernel=...
# Final framework compatibility matrix to check with device manifest.
# Each input matrix should have a unique "level" attribute.
PRODUCT_ENFORCE_VINTF_MANIFEST=$(PRODUCT_ENFORCE_VINTF_MANIFEST) \
assemble_vintf
-i $(TARGET_OUT)/etc/vintf/compatibility_matrix.*.xml
-o /tmp/compatibility_matrix.xml
-c $(TARGET_OUT_VENDOR)/manifest.xml
</pre>
<h4 id="manifest-fragments"><strong>示例:</strong>从片段生成设备清单</h4>
<p>多个设备清单片段可以在编译时捆绑。例如:</p>
<pre class="prettyprint">
&lt;!-- device/manufacturer/device_name/manifest_common.xml --&gt;
&lt;manifest version="1.0" type="device"&gt;
&lt;!-- common HALs here --&gt;
&lt;/manifest&gt;
</pre>
<pre class="prettyprint">
&lt;!-- device/manufacturer/device_name/ir.xml --&gt;
&lt;manifest version="1.0" type="device"&gt;
&lt;hal&gt;
&lt;name&gt;android.hardware.ir&lt;/name&gt;
&lt;version&gt;1.0&lt;/version&gt;
&lt;!-- other fields --&gt;
&lt;/hal&gt;
&lt;/manifest&gt;
</pre>
<pre class="prettyprint">
# device/manufacturer/device_name/BoardConfig.mk
DEVICE_MANIFEST_FILE := device/manufacturer/device_name/manifest_common.xml
ifdef BOARD_ENABLE_IR
DEVICE_MANIFEST_FILE += device/manufacturer/device_name/ir.xml
endif
</pre>
<p>然后,如果定义了 <code>BOARD_ENABLE_IR</code>,则 <code>assemble_vintf</code> 将 Ir HAL 添加到设备清单;如果未定义 <code>BOARD_ENABLE_IR</code>,则将其省略。执行以下命令(修改为省略实现详细信息)来生成设备清单:</p>
<pre class="prettyprint">
# if BOARD_ENABLE_IR is defined
BOARD_SEPOLICY_VERS=10000.0 assemble_vintf \
-i device/manufacturer/device_name/manifest_common.xml:device/manufacturer/device_name/ir.xml \
-o $(TARGET_OUT_VENDOR)/manifest.xml
# if BOARD_ENABLE_IR is not defined
BOARD_SEPOLICY_VERS=10000.0 assemble_vintf \
-i device/manufacturer/device_name/manifest_common.xml \
-o $(TARGET_OUT_VENDOR)/manifest.xml
</pre>
<p>有关详细信息,请参见:</p>
<pre class="devsite-terminal">assemble_vintf --help</pre>
<h2 id="testing">测试</h2>
<p><code>platform/system/libvintf</code> 项目使用 <a href="https://github.com/google/googletest" class="external">GTest</a> 进行序列化、反序列化和兼容性检查。</p>
<h2 id="licensing">许可</h2>
<ul>
<li><code>tinyxml2</code> (external/tinyxml2) 用于将对象序列化到 XML 或从 XML 反序列化对象。类似于 BSD 的许可证。</li>
<li><code>libselinux</code> (external/selinux/libselinux) 用于获取 policydb 版本。公共网域许可证。</li>
<li><code>libz</code> (external/zlib) 用于解压缩 <code>/proc/config.gz</code>。类似于 BSD 的许可证。</li>
<li><code>libvintf</code> 项目使用 Apache 2.0 许可证(具有适当的 MODULE_LICENSE_APACHE2 和 NOTICE 文件)。</li>
</ul>
</body></html>