電源政策

為確保硬體和軟體元件 (例如螢幕、音訊和語音互動) 可視需要開啟及關閉,AAOS 提供電源政策,其中包含一組硬體和軟體元件的預期開啟和關閉狀態。當 Android 電源狀態轉換或滿足等待條件時,VHAL 或系統專屬供應商服務可以套用新的電源政策。

在「等待 VHAL」、「開啟」和「關機前準備」狀態下,可以套用電源政策 (有時會受到部分限制)。與「Wait for VHAL」和「On」不同,預設電源政策無法在電源政策群組中為「Pre Shutdown Prepare」設定。在核心關機準備階段,車庫模式正在執行,不應受到電源狀態變更干擾。雖然無法套用一般電源政策,但在核心的「關機準備」階段,系統會套用名為「no user interaction」的特殊電源政策。

AAOS 電源狀態

AAOS 裝置的電源狀態圖如下:

AAOS 電源狀態圖

圖 1. AAOS 電源狀態圖。

以下說明各個電源狀態:

值 說明
關閉
  • 應用程式處理器 (AP)、記憶體和周邊裝置不會實際供電。
等待 VHAL
  • 駕駛人與車輛互動時 (例如開啟車門),VMCU 會為 AP、記憶體和周邊裝置供電。
  • AAOS 會從三種狀態 (關閉、暫停至 RAM (STR,等待 VHAL 完成)) 之一轉換,然後進入「等待 VHAL」狀態,等待與 VHAL 協調。
開啟
  • VHAL 會指示 AAOS 進入「開啟」狀態。在這個狀態下,AAOS 會完整運作,並與駕駛人互動。
  • 螢幕是由電源政策控制,而非其他板型規格的 Android 螢幕開啟/關閉呼叫。
準備關機
  • 駕駛人停止駕駛後,VHAL 會指示 AAOS 進入「關機準備」狀態,首先是「關機前準備」階段,接著是「核心關機準備」階段。在核心階段,螢幕和音訊會關閉,且 AAOS 不會與駕駛人互動。Android 系統仍可運作,且可更新應用程式和 Android 系統。更新完成後,Android 系統會進入「等待 VHAL 完成」狀態。
等待 VHAL 完成
  • AAOS 會通知 VHAL 可以關機。車輛微控制器單元 (VMCU) 應將系統單晶片 (SoC) 設為深層睡眠模式,並移除 AP 的電源。此時 AAOS 會處於 STR 狀態,但不會執行任何程式碼。
  • 如果 VHAL 未完成,且駕駛人返回車輛,車用運算主機 (HU) 應直接轉換至「等待 VHAL」狀態。
暫停至 RAM (STR)
  • 車輛和 AP 均處於關閉狀態,沒有執行任何程式碼,且 AP RAM 維持供電。
暫停到磁碟 (STD)
  • 車輛和 AP 均已關閉,沒有執行任何程式碼,且處理單元和 AP RAM 未維持供電。

電源原則的定義為何?

實作者會在 /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」和「開啟」的預設電源政策。

系統電源政策

AAOS 支援兩項系統電源政策,分別是「無使用者互動」和「暫停準備」。裝置進入靜音模式、車庫模式、暫停至 RAM 或暫停至磁碟時,系統會套用系統電源政策。

下表列出系統電源原則中每個元件的行為。 實作者可以在「no user interaction」(無使用者互動) 系統電源政策中,覆寫藍牙、NFC 和信任的裝置偵測功能。系統會在 /vendor/etc/automotive/power_policy.xml 中套用覆寫設定。

沒有使用者互動

下表定義了「沒有使用者互動」系統電源政策的行為:

元件 電源狀態 可自行設定
音訊 關閉 否
媒體 關閉 否
螢幕 關閉 否
藍牙 關閉 是
Wifi 開啟 否
行動網路 開啟 否
乙太網路 開啟 否
投影 關閉 否
NFC 關閉 是
輸入 關閉 否
助理 關閉 否
使用者互動 關閉 否
偵測使用者登入時是否使用信任的裝置 開啟 是
位置 關閉 否
麥克風 關閉 否
CPU 開啟 否

暫停準備

下表定義了 suspend prep 系統電源政策的行為:

元件 電源狀態 可由原始設備製造商設定
音訊 關閉 否
媒體 不適用 否
螢幕 不適用 否
藍牙 關閉 否
Wifi 關閉 否
行動網路 不適用 否
乙太網路 不適用 否
投影 不適用 否
NFC 不適用 否
輸入 不適用 否
助理 不適用 否
使用者互動 不適用 否
偵測使用者登入時是否使用信任的裝置 不適用 否
位置 關閉 否
麥克風 關閉 否
CPU 關閉 否

與 VHAL 互動

在系統層執行的車輛電源政策精靈會訂閱兩項屬性,以監聽 VHAL 的要求:

  • POWER_POLICY_REQ VHAL 會將電源政策 ID 寫入這個屬性。
  • POWER_POLICY_GROUP_REQ VHAL 會將電源政策群組 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