只要應用程式與車輛螢幕相容,就能在車輛裝置上順暢運作。
各項功能包括:
- DPI 縮放:根據螢幕 DPI 縮放應用程式 UI 元素。
- 應用程式算繪安全區:將應用程式內容放在安全區內,避免系統 UI 元素遮蔽內容。
- 應用程式分類邏輯:找出需要車用螢幕相容性的應用程式。
相容性功能
這個平台提供多種機制,可最佳化車用螢幕上的應用程式算繪和縮放作業。
DPI 縮放
裝置製造商可透過 DPI 縮放功能,縮放個別應用程式或所有需要車輛螢幕相容性的應用程式的密度 DPI。
如要設定應用程式的密度縮放比例,請按照下列步驟操作:
新增設定檔
/product/etc/display_compat_config.xml:<?xml version="1.0" encoding="utf-8"?> <!-- Each scale factor can have the following attributes display (required) Specifies the displayId to which this scale factor will be applied. packageName (optional) Specifies the packageName to which the scale factor will be applied. If omitted, the scaling will apply to all packages. For example: <scale display="0" packageName="com.android.car.media.localmediaplayer">0.5</scale> This means that only package `com.android.car.media.localmediaplayer` on display `0` will be scaled. --> <config> <scale display="0">1.0</scale> </config>如要為所有需要 Car Display Compat 的應用程式設定預設縮放值,請將螢幕 0 的預設縮放值變更為
<scale display="0">1.0</scale>。這個值是反向比例值。舉例來說,如要將需要車輛螢幕相容性的應用程式縮放為 1.5 倍,請將縮放值設為(1 / 1.5) = 0.67:<config> <scale display="0">0.67</scale> </config>如要為特定應用程式設定比例值,請在 config 中新增
scale元素。在本例中,YouTube Automotive 的縮放比例為 1.43 倍 (例如(1 / 1.43) = 0.7)。<config> <scale display="0">0.67</scale> <scale display="0" packageName="com.google.android.apps.automotive.youtube">0.7</scale> </config>
如果您在系統執行時變更 /product/etc/display_compat_config.xml,必須清除快取,新設定才會生效。使用這個巨集清除快取:
SECURE_SETTING_KEY="android.software.car.display_compatibility:settings:secure"
USER_ID_LIST=$(adb shell cmd user list -v | grep 'id=' | cut -d'=' -f2 | cut -d',' -f1)
for USER_ID in $USER_ID_LIST; do
echo "Deleting Display Compat config for user: $USER_ID"
adb shell settings delete secure --user $USER_ID $SECURE_SETTING_KEY
sleep 1
echo
done
將設定檔和功能宣告新增至 AAOS 建構版本,例如
vendor/OEM_NAME/products/displaycompat:# File: vendor/OEM_NAME/products/displaycompat/Android.bp prebuilt_etc { name: "display_compat_config", filename: "display_compat_config.xml", src: "display_compat_config.xml", product_specific: true, }
應用程式安全區域
手機和平板電腦應用程式通常並非專為 Automotive 的大型系統資訊列設計。這類應用程式不得在系統資訊列或系統疊加層下方繪製內容。否則,系統可能會在使用者看不到的區域中,算繪互動式元素。
安全應用程式區域是使用 Scalable UI SafeBounds 實作。
應用程式分類邏輯
您可以使用 CarPackageManager.requiresDisplayCompat(..) 建構其他功能,提升應用程式相容性。舉例來說,您可以使用這項功能新增返回按鈕或其他 UI。
應用程式開發人員可以在應用程式資訊清單中加入中繼資料,選擇支援車輛螢幕:
<meta-data
android:name="android.software.car.display_compatibility"
android:value="true" />
系統會使用下列邏輯 (依序評估),判斷應用程式是否需要車輛螢幕相容性功能:
- 資訊清單中繼資料
android.software.car.display_compatibility:- 如果
android:value="true"→ 應用程式需要相容性 - 如果
android:value="false"→ 應用程式不需要相容性 - 如果缺少中繼資料,請繼續下一個檢查步驟。
- 如果
- 使用功能
android.hardware.type.automotive:- 如果已聲明功能 (不論是
android:required、true或false) → 應用程式不需要相容性 - 如果沒有這項功能,請繼續下一個檢查步驟。
- 如果已聲明功能 (不論是
- 應用程式活動:
- 如果應用程式沒有活動 (例如 RRO、無頭應用程式或服務) → 應用程式不需要相容性
- 如果應用程式有活動,請繼續進行下一個檢查。
- 申請資訊:
- 如果應用程式具有特殊權限 → 應用程式不需要相容性
- 如果應用程式是系統應用程式 (
FLAG_SYSTEM) → 應用程式不需要相容性 - 否則,請繼續進行下一項檢查。
- 簽名資訊:
- 如果應用程式是平台簽署 (與 Android 架構使用相同的簽名簽署) → 應用程式不需要相容性
- 否則,請繼續進行下一項檢查。
- Fallback 決策:
- 如果所有檢查都通過,且您未選擇停用 → 應用程式需要相容性
請參閱「CarDisplayCompatScaleProviderUpdatableImpl.requiresDisplayCompatNotCachedLocked」。
確認裝置支援情形
支援車輛螢幕相容性的裝置必須使用功能宣告聲明支援:
<feature name="android.software.car.display_compatibility" />