電源政策

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

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

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 系統會進入「Wait for VHAL Finish」狀態。
等待 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」和「開啟」的預設電源政策。

每次轉換至「等待 VHAL」或「開啟」狀態時,系統都會套用預設電源政策,包括取消關機且 Android 返回「等待 VHAL」狀態時。如果目前電源政策群組中的特定狀態未定義預設電源政策,車輛電源政策 Daemon 會套用內建電源政策。例外情況是系統處於靜音模式:汽車電源政策 Daemon 會將目前或要求的常規電源政策儲存為待處理,鎖定常規電源政策變更,並套用無使用者互動系統電源政策。套用電源政策時,只會變更政策涵蓋的元件,未涵蓋的元件則會維持現狀。

系統電源政策

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

下表列出系統電源政策中各個元件的行為。實作者可以在無使用者互動系統電源政策中,覆寫藍牙、NFC 和信任的裝置偵測。覆寫設定會套用至 /vendor/etc/automotive/power_policy.xml。

無使用者互動

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

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

暫停準備

下表定義了暫停準備系統電源政策的行為:

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

與 VHAL 互動

在系統層中執行的車輛電源政策 Daemon 會訂閱兩個屬性,藉此監聽來自 VHAL 的要求:

  • POWER_POLICY_REQ VHAL 會將電源政策 ID 寫入這個屬性。
  • POWER_POLICY_GROUP_REQ:VHAL 會將電源政策群組 ID 寫入這個屬性。

系統目前的電源政策可由 VHAL 以外的模組變更。在這種情況下,車輛電源政策 Daemon 會更新 CURRENT_POWER_POLICY 屬性,將變更通知 VHAL。

與原生程序互動

CarPowerManagementService (CPMS) 會將電源政策管理作業委派給車輛電源政策 Daemon。Daemon 是系統中電源政策的單一事實來源。車輛電源政策 Daemon 會管理電源政策狀態,並將變更通知 CPMS、VHAL 和其他原生用戶端。

車輛電源政策 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 註冊電源政策變更事件監聽器。