为了确保根据需要选择性地开启和关闭硬件和软件组件(例如屏幕、音频和语音互动),AAOS 提供了电源政策,其中包含针对硬件和软件组件的一组预期电源开启和关闭状态。VHAL(即系统特权供应商服务)可以在 Android 电源状态转换时或其正在等待的条件达到时应用新的电源政策。
在“等待 VHAL”和“开启”状态下,可以应用电源政策(有时会受到一些限制)。在“关闭准备”状态下,车库模式运行,不应受电源状态更改的干扰。虽然在“关闭准备”状态下无法应用常规电源政策,但此时会应用一项特殊的电源政策,即名为“没有用户互动”的系统电源政策。
AAOS 电源状态
AAOS 设备遵循以下电源状态图:

图 1. AAOS 电源状态图
下面介绍了每种电源状态:
| 值 | 说明 |
|---|---|
| 关闭 |
|
| 等待 VHAL |
|
| 开启 |
|
| 关闭准备 |
|
| 等待 VHAL 完成 |
|
| 挂起到 RAM (STR) |
|
| 挂起到磁盘 (STD) |
|
电源政策是如何定义的?
实现人员在 /vendor/etc/automotive/power_policy.xml 中定义电源政策,该文件用于如下用途:
- 定义电源政策。
- 定义电源政策组,其中包括默认电源政策,并在电源状态转换时自动应用。
- 替换系统电源政策。
电源政策
电源政策包含一组预期的硬件和软件组件电源状态。 在电源政策中,AAOS 支持以下组件:
|
AUDIO MEDIA DISPLAY BLUETOOTH |
WIFI CELLULAR ETHERNET PROJECTION |
NFC INPUT VOICE_INTERACTION VISUAL_INTERACTION |
TRUSTED_DEVICE_DETECTION LOCATION MICROPHONE CPU |
供应商还可以定义自己的自定义电源组件,以便与电源政策搭配使用。在与电源政策相同的 XML 文件中定义自定义电源组件,如以下示例所示:
<customComponents>CUSTOM_COMPONENT_1000 CUSTOM_COMPONENT_SPECIAL_SENSOR CUSTOM_COMPONENT_AUX_INPUT </customComponents>
电源政策组
电源状态转换时自动应用的默认电源政策在电源政策组中指定。供应商可以定义以下状态的默认电源政策:“等待 VHAL”“开启”和“等待 VHAL 完成”(进入深度休眠或开始关闭)。
系统电源政策
AAOS 支持两项系统电源政策,即没有用户互动和挂起准备。系统电源政策在设备进入静音模式、车库模式、挂起到 RAM 或挂起到磁盘时应用。
下表列出了系统电源政策中每种组件的行为。实现人员可以在无用户互动系统电源政策中替换蓝牙、NFC 和可信设备检测。替换在 /vendor/etc/power_policy.xml 中应用。
无用户互动
无用户互动系统电源政策的行为在下表中定义:
| 组件 | 电源状态 | 可配置 |
|---|---|---|
| 音频 | 关闭 | 否 |
| 媒体 | 关闭 | 否 |
| 显示屏 | 关闭 | 否 |
| 蓝牙 | 关闭 | 是 |
| Wifi | 开启 | 否 |
| 移动网络 | 开启 | 否 |
| 以太网 | 开启 | 否 |
| 投影 | 关闭 | 否 |
| NFC | 关闭 | 是 |
| 输入 | 关闭 | 否 |
| Google 助理 | 关闭 | 否 |
| 用户互动 | 关闭 | 否 |
| 针对用户登录的可信设备检测 | 开启 | 是 |
| 位置信息 | 关闭 | 否 |
| 麦克风 | 关闭 | 否 |
| CPU | 开启 | 否 |
挂起准备
挂起准备系统电源政策的行为在下表中定义:
| 组件 | 电源状态 | 是否可由 OEM 配置 |
|---|---|---|
| 音频 | 关闭 | 否 |
| 媒体 | 不适用 | 否 |
| 显示屏 | 不适用 | 否 |
| 蓝牙 | 关闭 | 否 |
| Wifi | 关闭 | 否 |
| 移动网络 | 不适用 | 否 |
| 以太网 | 不适用 | 否 |
| 投影 | 不适用 | 否 |
| NFC | 不适用 | 否 |
| 输入 | 不适用 | 否 |
| Google 助理 | 不适用 | 否 |
| 用户互动 | 不适用 | 否 |
| 针对用户登录的可信设备检测 | 不适用 | 否 |
| 位置信息 | 关闭 | 否 |
| 麦克风 | 关闭 | 否 |
| CPU | 关闭 | 否 |
与 VHAL 交互
在系统层中运行的汽车电源政策守护程序通过订阅两个属性来监听 VHAL 发出的请求:
POWER_POLICY_REQ,VHAL 将电源政策 ID 写入此属性。POWER_POLICY_GROUP_REQ,VHAL 将电源政策组 ID 写入此属性。
除 VHAL 外的其他模块可以更改系统中的当前电源政策。在这种情况下,汽车电源政策守护程序会更新 CURRENT_POWER_POLICY 属性,以向 VHAL 通知此更改。
与原生进程交互
如上所述,汽车电源政策守护程序在系统层运行,就电源政策管理而言,其提供的功能与框架层中运行的 CPMS 几乎相同。此外,假设汽车电源政策守护程序与 CPMS 完全同步。
汽车电源政策守护程序会导出 AIDL 接口供 HAL 和其他原生进程使用。 当新的电源政策更改时,这些进程会收到通知。换言之,届时每个进程都必须更改其电源状态。
ICarPowerPolicyServer.aidl
package android.frameworks.automotive.powerpolicy;
import android.frameworks.automotive.powerpolicy.CarPowerPolicy;
import android.frameworks.automotive.powerpolicy.CarPowerPolicyFilter;
import android.frameworks.automotive.powerpolicy.ICarPowerPolicyChangeCallback;
import android.frameworks.automotive.powerpolicy.PowerComponent;
/**
* ICarPowerPolicyServer is an interface implemented by the power policy daemon.
* VHAL changes the power policy and the power policy daemon notifies the change to
* registered subscribers. When subscribing to policy changes, a filter can be specified so
* that the registered callbacks can listen only to a specific power component's change.
*/
@VintfStability
interface ICarPowerPolicyServer {
/**
* Gets the current power policy.
* @throws IllegalStateException if the current policy is not set.
*/
CarPowerPolicy getCurrentPowerPolicy();
/**
* Gets whether the power component is turned on or off.
*
* @param componentId Power component ID defined in PowerComponent.aidl to check power
* state.
* @return True if the component's power state is on.
* @throws IllegalArgumentException if the componentId is invalid.
*/
boolean getPowerComponentState(in PowerComponent componentId);
/**
* Subscribes to power policy change.
* Notification is sent to the registered callback when the power policy changes and the
* power state of the components which the callback is interested in changes.
*
* @param callback Callback that is invoked when the power policy changes.
* @param filter The list of components which the callback is interested in.
* @throws IllegalArgumentException if the callback is already registered.
* @throws IllegalStateException if the callback is dead.
*/
void registerPowerPolicyChangeCallback(in ICarPowerPolicyChangeCallback callback,
in CarPowerPolicyFilter filter);
/**
* Unsubscribes from power policy change.
*
* @param callback Callback that doesn't want to receive power policy change.
* @throws IllegalArgumentException if the callback is not registered.
*/
void unregisterPowerPolicyChangeCallback(in ICarPowerPolicyChangeCallback callback);
/**
* Applies the power policy.
*
* {@code policyId} should be one of power policy IDs defined in
* {@code /vendor/etc/automotive/power_policy.xml} or predefined system power policies.
*
* @param policyId ID of power policy.
* @throws IllegalArgumentException if {@code policyId} is invalid.
*/
void applyPowerPolicy(in @utf8InCpp String policyId);
/**
* Sets the current power policy group.
*
*
{@code policyGroupId} should be one of power policy group IDs defined in
* {@code /vendor/etc/automotive/power_policy.xml}.
*
* @param policyGroupId ID of power policy group.
* @throws IllegalArgumentException if {@code policyGroupId} is invalid.
*/
void setPowerPolicyGroup(in @utf8InCpp String policyGroupId);
}
ICarPowerPolicyChangeCallback.aidl
package android.frameworks.automotive.powerpolicy;
import android.frameworks.automotive.powerpolicy.CarPowerPolicy;
/**
* ICarPowerPolicyChangeCallback is notified when a power policy changes.
*/
@VintfStability
oneway interface ICarPowerPolicyChangeCallback {
/**
* Called when a power policy is fully changed.
*
* @param policy The current policy.
*/
void onPolicyChanged(in CarPowerPolicy policy);
}
与 Java 模块交互
CarPowerManager 提供了用于进行电源政策管理的方法:
- 获取当前电源政策
- 应用新的电源政策
- 设置新的电源政策组
只有系统特权模块才能使用这些方法。希望在应用电源政策时收到通知的模块可向 CarPowerManager 注册一个电源政策更改监听器。