blob: 6108702c05061c1cace92d11e0224a83f1fa9a5f [file] [log] [blame]
<html devsite><head>
<title>动态可用的 HAL</title>
<meta name="project_path" value="/_project.yaml"/>
<meta name="book_path" value="/_book.yaml"/>
</head>
<body>
<!--
Copyright 2018 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.
-->
Android 9 支持动态关停未使用或不需要的 Android 硬件子系统。例如,如果用户未使用 WLAN,则 WLAN 子系统不应占用内存、耗损电量或使用其他系统资源。早期版本的 Android 中,在 Android 手机启动的整个持续时间内,Android 设备上的 HAL/驱动程序都会保持开启状态。
<p>实现动态关停涉及连接数据流以及执行动态进程,下文对此进行了详细介绍。</p>
<h2 id="changes-HAL-definitions">对 HAL 定义所做的更改</h2>
<p>要实现动态关停,需要有关于哪些进程为哪些 HAL 接口提供服务的信息(此类信息之后在其他上下文中也可能很有用),还需要确保在设备启动时不启动进程,而且在进程退出后,直到系统再次请求启动它们之前,都不重新启动它们。</p>
<pre class="prettyprint"># some init.rc script associated with the HAL
service vendor.some-service-name /vendor/bin/hw/some-binary-service
# init language extension, provides information of what service is served
# if multiple interfaces are served, they can be specified one on each line
interface android.hardware.light@2.0::ILight default
# restarted if hwservicemanager dies
# would also cause the hal to start early during boot if oneshot wasn't set
class hal
# will not be restarted if it exits until it is requested to be restarted
oneshot
# will only be started when requested
disabled
# ... other properties</pre>
<h2 id="changes-init-and-hwservicemanager">对 init 和 hwservicemanager 所做的更改</h2>
<p>要实现动态关停,还需要让 <code>hwservicemanager</code> 告知 <code>init</code> 启动所请求的服务。在 Android 9 中,<code>init</code> 包含三个额外的控制消息(例如,<code>ctl.start</code>):<code>ctl.interface_start</code><code>ctl.interface_stop</code><code>ctl.interface_restart</code>。这些消息可用于指示 <code>init</code> 打开或关闭特定硬件接口。如果系统请求使用某个服务但该服务未注册,则 <code>hwservicemanager</code> 将请求启动该服务。</p>
<h2 id="determining-HAL-exit">确定 HAL 退出</h2>
<p>要实现动态关停,需要多个政策来决定何时启动和关停 HAL。如果 HAL 出于任何原因而决定退出,则当系统再次需要用到它时,它将使用以下信息和基础架构自动重新启动:HAL 定义中提供的信息,以及通过更改 <code>init</code><code>hwservicemanager</code> 提供的基础架构。这可能会涉及多个不同的政策,包括:</p>
<ul>
<li>如果有人对 HAL 调用关闭命令或类似的 API,则 HAL 可能会选择自行调用退出命令。此行为必须在相应的 HAL 接口中指定。</li>
<li>HAL 可在任务完成后关停(记录在 HAL 文件中)。</li>
</ul>
</body></html>