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

图 1. AAOS 电源状态图。
下面介绍了每种电源状态
| 值 | 说明 |
|---|---|
| 关闭 |
|
| 等待 VHAL |
|
| 开启 |
|
| 准备关机 |
|
| 等待 VHAL 完成 |
|
| 挂起到内存 (STR) |
|
| 挂起到磁盘 (STD) |
|
如何定义电源策略?
实施者在 /vendor/etc/automotive/power_policy.xml 中定义电源策略,该文件
- 定义电源策略。
- 定义电源策略组,其中包括默认电源策略,并在电源状态转换发生时自动应用。
- 替换系统电源策略。
电源策略
电源策略包含一组硬件和软件组件的预期电源状态。AAOS 在电源策略中支持以下组件
| 音频 媒体 显示屏 蓝牙 |
无线网络 移动网络 以太网 投射 |
NFC 输入 语音互动 视觉互动 |
可信设备检测 位置信息 麦克风 CPU |
供应商还可以定义自己的自定义电源组件,以便与电源策略结合使用。在与电源策略相同的 XML 文件中定义自定义电源组件,如以下示例所示
<customComponents>CUSTOM_COMPONENT_1000 CUSTOM_COMPONENT_SPECIAL_SENSOR CUSTOM_COMPONENT_AUX_INPUT </customComponents>
电源策略组
默认电源策略在电源状态转换时自动应用,并在电源策略组中指定。供应商可以为“等待 VHAL”、“开启”和“等待 VHAL 完成”(深度睡眠进入或关机开始)定义默认电源策略。
系统电源策略
AAOS 支持两种系统电源策略,即无用户互动和准备挂起。当设备进入静音模式、车库模式、挂起到内存或挂起到磁盘时,会应用系统电源策略。
下表列出了系统电源策略中每个组件的行为。实施者可以在无用户互动系统电源策略中替换蓝牙、NFC 和可信设备检测。替换在 /vendor/etc/power_policy.xml 中应用。
无用户互动
下表定义了无用户互动系统电源策略的行为
| 组件 | 电源状态 | 可配置 |
|---|---|---|
| 音频 | 关闭 | 否 |
| 媒体 | 关闭 | 否 |
| 显示 | 关闭 | 否 |
| 蓝牙 | 关闭 | 是 |
| 无线网络 | 开启 | 否 |
| 移动网络 | 开启 | 否 |
| 以太网 | 开启 | 否 |
| 投射 | 关闭 | 否 |
| NFC | 关闭 | 是 |
| 输入 | 关闭 | 否 |
| 助理 | 关闭 | 否 |
| 用户互动 | 关闭 | 否 |
| 用于用户登录的可信设备检测 | 开启 | 是 |
| 位置信息 | 关闭 | 否 |
| 麦克风 | 关闭 | 否 |
| CPU | 开启 | 否 |
准备挂起
下表定义了准备挂起系统电源策略的行为
| 组件 | 电源状态 | OEM 可配置 |
|---|---|---|
| 音频 | 关闭 | 否 |
| 媒体 | 不适用 | 否 |
| 显示 | 不适用 | 否 |
| 蓝牙 | 关闭 | 否 |
| 无线网络 | 关闭 | 否 |
| 移动网络 | 不适用 | 否 |
| 以太网 | 不适用 | 否 |
| 投射 | 不适用 | 否 |
| NFC | 不适用 | 否 |
| 输入 | 不适用 | 否 |
| 助理 | 不适用 | 否 |
| 用户互动 | 不适用 | 否 |
| 用于用户登录的可信设备检测 | 不适用 | 否 |
| 位置信息 | 关闭 | 否 |
| 麦克风 | 关闭 | 否 |
| CPU | 关闭 | 否 |
与 VHAL 互动
在系统层中运行的汽车电源策略守护程序订阅两个属性以监听来自 VHAL 的请求
POWER_POLICY_REQVHAL 将电源策略 ID 写入此属性。POWER_POLICY_GROUP_REQVHAL 将电源策略组 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 注册电源策略更改监听器