電源政策

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

在「等待 VHAL」和「開啟」狀態 (有時會有一些限制) 下,可以套用電源政策。在關機準備期間,車庫模式會持續運作,不應受到電源狀態變更影響。雖然無法套用一般電源政策,但系統會在「關機準備」階段套用特殊電源政策,也就是名為「沒有使用者互動」的系統電源政策。

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」、「開啟」和「等待 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_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