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

圖 1. AAOS 電源狀態圖表。
以下說明各個電源狀態:
| 值 | 說明 | 
|---|---|
| 關閉 | 
 | 
| 等待 VHAL | 
 
 | 
| 開啟 | 
 
 | 
| 關機準備 | 
 | 
| 等待 VHAL 完成 | 
 
 | 
| 暫停至 RAM (STR) | 
 | 
| 暫停至磁碟 (STD) | 
 | 
如何定義電源政策?
  實作者會在 /vendor/etc/automotive/power_policy.xml 中定義電源政策,其功能如下:
- 定義電源政策。
- 定義電源政策群組,其中包含預設電源政策,並在電源狀態轉換時自動套用。
- 覆寫系統電源政策。
電源政策
電源政策包含一組硬體和軟體元件的預期電源狀態。AAOS 在電源政策中支援下列元件:
| 音訊 媒體 螢幕 藍牙 | WIFI 行動網路 乙太網路 投影 | NFC INPUT VOICE_INTERACTION VISUAL_INTERACTION | TRUSTED_DEVICE_DETECTION 位置資訊 麥克風 中央處理器 | 
供應商也可以定義自訂電源元件,搭配電源政策使用。在與電源政策相同的 XML 檔案中定義自訂電源元件,如以下範例所示:
<customComponents>CUSTOM_COMPONENT_1000 CUSTOM_COMPONENT_SPECIAL_SENSOR CUSTOM_COMPONENT_AUX_INPUT </customComponents>
電源政策群組
系統會在電源政策群組中指定的電源狀態轉換時,自動套用預設電源政策。供應商可以為「等待 VHAL」、「開機」和「等待 VHAL 完成」(深度休眠進入或關機開始) 定義預設電源政策。
系統電源政策
AAOS 支援兩種系統電源政策,分別是「無使用者互動」和「暫停準備」。裝置進入靜音模式、車庫模式、暫停至 RAM 或暫停至磁碟時,系統會套用電源政策。
  下表列出系統電源政策中各個元件的行為。實作者可以在無使用者互動的系統電源政策中,覆寫藍牙、NFC 和信任裝置偵測功能。覆寫值會套用至 /vendor/etc/power_policy.xml。
沒有使用者互動
系統電源政策的「無使用者互動」行為已在下表中定義:
| 元件 | 電源狀態 | 可設定 | 
|---|---|---|
| 音訊 | 關閉 | 否 | 
| 媒體 | 關閉 | 否 | 
| 螢幕 | 關閉 | 否 | 
| 藍牙 | 關閉 | 是 | 
| Wi-Fi | 開啟 | 否 | 
| 行動網路 | 開啟 | 否 | 
| 乙太網路 | 開啟 | 否 | 
| 預測值 | 關閉 | 否 | 
| NFC | 關閉 | 是 | 
| 輸入 | 關閉 | 否 | 
| Google 助理 | 關閉 | 否 | 
| 使用者互動 | 關閉 | 否 | 
| 使用者登入時偵測可信任的裝置 | 開啟 | 是 | 
| 位置 | 關閉 | 否 | 
| 麥克風 | 關閉 | 否 | 
| CPU | 開啟 | 否 | 
暫停準備
下表定義了「暫停準備」系統電源政策的行為:
| 元件 | 電源狀態 | 原始設備製造商 (OEM) 可設定 | 
|---|---|---|
| 音訊 | 關閉 | 否 | 
| 媒體 | 無 | 否 | 
| 螢幕 | 無 | 否 | 
| 藍牙 | 關閉 | 否 | 
| Wi-Fi | 關閉 | 否 | 
| 行動網路 | 無 | 否 | 
| 乙太網路 | 無 | 否 | 
| 預測值 | 無 | 否 | 
| NFC | 無 | 否 | 
| 輸入 | 無 | 否 | 
| Google 助理 | 無 | 否 | 
| 使用者互動 | 無 | 否 | 
| 使用者登入時偵測可信任的裝置 | 無 | 否 | 
| 位置 | 關閉 | 否 | 
| 麥克風 | 關閉 | 否 | 
| CPU | 關閉 | 否 | 
與 VHAL 互動
在系統層中執行的車輛電源政策守護程序會訂閱兩個屬性,以便監聽 VHAL 的要求:
- POWER_POLICY_REQVHAL 會將電源政策 ID 寫入此屬性。
- POWER_POLICY_GROUP_REQVHAL 會將電源政策群組 ID 寫入此屬性。
  除了 VHAL 之外,系統中的電源政策也可以由其他模組變更。在這種情況下,車輛電源政策守護程式會更新 CURRENT_POWER_POLICY 屬性,通知 VHAL 變更。
與原生程序互動
如上所述,車輛電源政策守護程式會在系統層執行,在電源政策管理方面,提供的功能幾乎與在架構層執行的 CPMS 相同。此外,假設車輛電源政策守護程序和 CPMS 已完全同步。
汽車電源政策 Daemon 會匯出 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
