為確保硬體和軟體元件 (例如螢幕、音訊和語音互動) 可視需要開啟和關閉,AAOS 提供電源政策,其中包含一組硬體和軟體元件的預期開啟和關閉狀態。當 Android 電源狀態轉換或滿足等待條件時,VHAL 或系統權限供應商服務可以套用新的電源政策。
在「等待 VHAL」和「開啟」狀態 (有時會有一些限制) 下,可以套用電源政策。在關機準備期間,車庫模式會持續運作,不應受到電源狀態變更影響。雖然無法套用一般電源政策,但系統會在「關機準備」階段套用特殊電源政策,也就是名為「沒有使用者互動」的系統電源政策。
AAOS 電源狀態
AAOS 裝置的電源狀態圖如下:

圖 1. AAOS 電源狀態圖。
各個電源狀態說明如下:
| 值 | 說明 |
|---|---|
| 關閉 |
|
| 等待 VHAL |
|
| 開啟 |
|
| 準備關機 |
|
| 等待 VHAL 完成 |
|
| 暫停至 RAM (STR) |
|
| 暫停到磁碟 (STD) |
|
電源原則的定義方式
實作者會在 /vendor/etc/automotive/power_policy.xml 中定義電源原則,這些原則:
- 定義電源政策。
- 定義電源政策群組,包括預設電源政策,並在電源狀態轉換時自動套用。
- 覆寫系統電源政策。
電源政策
電源原則包含一組硬體和軟體元件的預期電源狀態。 AAOS 在電源政策中支援下列元件:
|
音訊 媒體 螢幕 藍牙 |
Wi-Fi 行動網路 乙太網路 投影 |
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 或暫停至磁碟時,系統會套用系統電源政策。
下表列出系統電源原則中每個元件的行為。
實作者可以在「no user interaction」(無使用者互動) 系統電源政策中,覆寫藍牙、NFC 和信任的裝置偵測功能。系統會在 /vendor/etc/power_policy.xml 中套用覆寫。
沒有使用者互動
下表定義了「沒有使用者互動」系統電源政策的行為:
| 元件 | 電源狀態 | 可自行設定 |
|---|---|---|
| 音訊 | 關閉 | 否 |
| 媒體 | 關閉 | 否 |
| 螢幕 | 關閉 | 否 |
| 藍牙 | 關閉 | 是 |
| Wifi | 開啟 | 否 |
| 行動網路 | 開啟 | 否 |
| 乙太網路 | 開啟 | 否 |
| 投影 | 關閉 | 否 |
| NFC | 關閉 | 是 |
| 輸入 | 關閉 | 否 |
| 助理 | 關閉 | 否 |
| 使用者互動 | 關閉 | 否 |
| 偵測使用者登入時是否使用信任的裝置 | 開啟 | 是 |
| 位置 | 關閉 | 否 |
| 麥克風 | 關閉 | 否 |
| CPU | 開啟 | 否 |
暫停前置作業
下表定義了 suspend prep 系統電源政策的行為:
| 元件 | 電源狀態 | 可由原始設備製造商設定 |
|---|---|---|
| 音訊 | 關閉 | 否 |
| 媒體 | 不適用 | 否 |
| 螢幕 | 不適用 | 否 |
| 藍牙 | 關閉 | 否 |
| Wifi | 關閉 | 否 |
| 行動網路 | 不適用 | 否 |
| 乙太網路 | 不適用 | 否 |
| 投影 | 不適用 | 否 |
| NFC | 不適用 | 否 |
| 輸入 | 不適用 | 否 |
| 助理 | 不適用 | 否 |
| 使用者互動 | 不適用 | 否 |
| 偵測使用者登入時是否使用信任的裝置 | 不適用 | 否 |
| 位置 | 關閉 | 否 |
| 麥克風 | 關閉 | 否 |
| CPU | 關閉 | 否 |
與 VHAL 互動
在系統層執行的車輛電源政策 Daemon 會訂閱兩項屬性,以監聽 VHAL 的要求:
POWER_POLICY_REQVHAL 會將電源政策 ID 寫入這個屬性。POWER_POLICY_GROUP_REQVHAL 會將電源政策群組 ID 寫入這個屬性。
系統中目前的電源政策可由 VHAL 以外的模組變更。在這種情況下,車輛電源政策精靈會更新 CURRENT_POWER_POLICY 屬性,向 VHAL 通知這項變更。
與原生程序互動
CarPowerManagementService (CPMS) 會將電源政策管理作業委派給車輛電源政策精靈。這個精靈是系統中電源原則的單一可靠資料來源。車輛電源政策精靈會管理電源政策狀態,並將變更通知 CPMS、VHAL 和其他原生用戶端。
車輛電源政策守護程序會匯出 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