blob: 6bd66008dff34997fcf5c84123ef7f09da7a19ee [file] [log] [blame]
<html devsite><head>
<meta name="book_path" value="/_book.yaml"/>
<meta name="project_path" value="/_project.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.
-->
<h1 id="health" class="page-title">运行状况</h1>
<p>Android 9 引入了从 health@1.0 HAL 升级的主要版本 <code>android.hardware.health</code> HAL 2.0。新版 HAL 具有以下优势:</p>
<ul>
<li>框架代码和供应商代码之间的区别更清楚。</li>
<li>弃用了不必要的 <code>healthd</code> 守护进程。</li>
<li>供应商对运行状况信息报告进行自定义的自由度更高。</li>
<li>更多设备运行状况信息(不仅包括电池信息)。</li>
</ul>
<h2 id="requirements">要求</h2>
<p>搭载 Android 9 的设备必须提供 2.0 HAL(而不得提供 1.0 HAL)。未搭载 Android 9 但计划将供应商映像更新为 Target Framework Compatibility Matrix 版本 3(Android 9 中发布的版本)的设备必须移除现有的 1.0 HAL 实现,并提供 2.0 HAL。</p>
<p>AOSP 包含多个帮助程序库,旨在帮助您实现 2.0 HAL 以及完成从旧版 1.0 HAL 的过渡。</p>
<h2 id="terminology">术语</h2>
<ul>
<li><strong>health@1.0</strong><code>android.hardware.health@1.0</code> 的缩写,指的是 Android 8.0 中发布的运行状况 HIDL 的 1.0 版 HAL。</li>
<li><strong>health@2.0</strong><code>android.hardware.health@2.0</code> 的缩写,指的是 Android 9 中发布的运行状况 HIDL 的 2.0 版 HAL。</li>
<li><strong>charger</strong>:在关机模式充电过程中运行的可执行文件,用于显示手机充电动画。</li>
<li><strong>recovery</strong>:在恢复模式下运行的可执行文件,必须检索电池信息。</li>
<li><strong>healthd</strong>:在 Android 中运行的旧版守护进程,用于检索与运行状况相关的信息并将其提供给框架。</li>
<li><strong>storaged</strong>:在 Android 中运行的守护进程,用于检索存储信息并将其提供给框架。</li>
</ul>
<h2 id="health_in_android_8x">Android 8.x 中的运行状况</h2>
<p>在 Android 8.x 中,运行状况组件的工作原理详情如下图所示:</p>
<p><img src="images/health-component-1.png" width="512" alt="Android 8.x 中的运行状况"/></p>
<p><strong>图 1</strong>. Android 8.x 中的运行状况</p>
<p>在此图中:</p>
<ul>
<li>框架通过一 (1) 次 Binder 调用和一 (1) 次 hwbinder 调用与硬件进行通信。</li>
<li><code>healthd</code> 静态链接到 <code>libhealthd_android</code><code>libbatterymonitor</code><code>libbatteryservice</code></li>
<li>health@1.0-impl 静态链接到 <code>libhealthd.<var>BOARD</var></code></li>
</ul>
<p>每个开发板都可以自定义不同的 <code>libhealthd.<var>BOARD</var></code>;charger、health@1.0-impl 和 recovery 链接到哪个开发板是在编译时确定的。</p>
<p>对于其他模式:</p>
<p><img src="images/health-1-charging-recovery.png" width alt="Android 8.x 中的关机模式充电和恢复模式"/></p>
<p><strong>图 2.</strong> Android 8.x 中的运行状况、关机模式充电和恢复模式</p>
<ul>
<li>charger 静态链接到 <code>libhealthd.<var>BOARD</var></code><code>libhealthd_charger</code><code>libbatterymonitor</code></li>
<li>recovery 静态链接到 <code>libhealthd.<var>BOARD</var></code><code>libbatterymonitor</code></li>
</ul>
<h2 id="health_in_android">Android 9 中的运行状况</h2>
<p>在 Android 9 中,运行状况组件的工作原理详情如下图所示:
<img src="images/health-component-2.png" width="553" alt="Android 9 中的运行状况"/></p>
<p><strong>图 3</strong>. Android 9 中的运行状况</p>
<p>该框架尝试从 <code>hwservicemanager</code> 中检索 health@2.0 服务。如果检索失败,它将调用 health@1.0(在 Android 8.x 中提供)。同时,它还会保留原有代码路径,以便 Android 9 系统映像与 Android 8.x 供应商映像兼容。该框架不会同时从两个 HAL 中检索信息,因为设备上只能存在一个服务版本(1.0 或 2.0)。</p>
<aside class="note"><strong>注意</strong><span>对于原有代码路径,流程/库将一直保留到 health@1.0 <a href="/devices/architecture/vintf/fcm#hal-version-deprecation">被弃用</a></span></aside>
<p>对于其他模式:</p>
<p><img src="images/health-2-charging-recovery.png" width="397" alt="Android 9 中的关机模式充电和恢复模式"/></p>
<p><strong>图 4.</strong> Android 9 中的运行状况、关机模式充电和恢复模式</p>
<h2 id="hal_interface">HAL 接口</h2>
<p>health@2.0 HAL 为框架提供了与旧版 healthd 守护进程相同的功能。此外,它还提供了与 healthd 以前作为 Binder 服务提供的 API 类似的 API(即 <a href="https://android.googlesource.com/platform/frameworks/base/+/2392cbd888212f61a242058f749bcc39d495bf4b/core/java/android/os/IBatteryPropertiesRegistrar.aidl" class="external">IBatteryPropertiesRegistrar</a>)。</p>
<p>主界面 <a href="https://android.googlesource.com/platform/hardware/interfaces/+/de542acbbf46812cfb53d231ecb50048baf8780e/health/2.0/IHealth.hal" class="external">IHealth</a> 提供以下函数:</p>
<ul>
<li><code>registerCallback</code>,用于替换 <code>IBatteryPropertiesRegistrar.registerListener</code></li>
<li><code>unregisterCallback</code>,用于替换 <code>IBatteryPropertiesRegistrar.unregisterListener</code></li>
<li><code>update</code>,用于替换 <code>IBatteryPropertiesRegistrar.scheduleUpdate</code></li>
<li><code>IBatteryPropertiesRegistrar.getProperties</code> 将由以下内容替换:
<ul>
<li><code>getChargeCounter</code></li>
<li><code>getCurrentNow</code></li>
<li><code>getCurrentAverage</code></li>
<li><code>getCapacity</code></li>
<li><code>getEnergyCounter</code></li>
<li><code>getChargeStatus</code></li>
<li><code>getHealthInfo</code></li>
</ul></li>
</ul>
<p>此外,<code>IHealth</code> 还为 <code>storaged</code> 提供了以下新 API,以检索特定于供应商的存储相关信息:</p>
<ul>
<li><code>getStorageInfo</code></li>
<li><code>getDiskStats</code></li>
</ul>
<p>通过回调和 <code>getHealthInfo</code> 返回一个新结构 <code>@2.0::HealthInfo</code>,此结构包含可通过 health@2.0 HAL 访问的所有设备运行状况信息,包括:</p>
<ul>
<li>充电信息(交流电/USB/无线、电流、电压等)</li>
<li>电池信息(状态、电池电量、电流、电压、充电、技术等)</li>
<li>存储信息(存储设备信息、磁盘统计信息)</li>
</ul>
<p>要详细了解如何实现运行状况服务,请参阅<a href="/devices/tech/health/implementation">实现运行状况</a></p>
</body></html>