AOSP host integration guide

The Android Open Source Project (AOSP) Automotive App Host is a part of the Car App Library used by third-party (3P) developers to enable apps for Android Automotive. The App Host is a system app that allows 3P car apps to render OEM-styled user interface (UI) components on its behalf.

To run 3P apps, both the 3P app and the AOSP Automotive App Host must be installed:

  • Automotive App Host provides 3P apps with a a set of UI templates and components optimized for vehicles, including capabilities like usability and safety.
  • OEMs can style these UI templates and components.
  • The result? 3P apps are visually well-integrated into the infotainment system of the OEM.

This page explains how to generate the AOSP Automotive App Host from the Gradle project in the ub-automotive branch and then how to integrate the AOSP Automotive App Host into car targets.

Check out the code

To check out the unbundled code:

  1. Run the following command:
    repo init -u https://android.googlesource.com/platform/manifest -b ub-automotive-master
    repo sync -j4
    
  2. To learn more about working with AOSP source code, see Initialize a Repo client.

  3. Install Android Studio.

Create the AOSP host APK

  1. Check out ub-automotive and then open the Gradle project under packages/apps/Car/Templates/Host.
  2. To configure the project with the Android SDK, configure your project's local.properties file. You can find the path under Android SDK Settings in Android Studio.
    sdk.dir=${path_to_android_sdk_location}
    
  3. Create the host APK as a typical Gradle project. For example, run the gradle command:
    ./gradlew :app:assembleDebug
    

    The APK file is located in:

    packages/apps/Car/Templates/Host/app/build/outputs/apk/debug/app-debug.apk

Embed the AOSP host

  1. Create a new Android.mk file to include the following content:
    LOCAL_PATH := $(my-dir)
    ################## Start of AOSPHost target ##################
    include $(CLEAR_VARS)
    LOCAL_MODULE := CarAOSPHost
    LOCAL_LICENSE_KINDS := legacy_notice
    LOCAL_LICENSE_CONDITIONS := notice
    LOCAL_MODULE_OWNER := google
    LOCAL_SRC_FILES := AOSPHost.apk
    LOCAL_MODULE_CLASS := APPS
    LOCAL_MODULE_TAGS := optional
    LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
    LOCAL_BUILT_MODULE_STEM := package.apk
    LOCAL_CERTIFICATE := PRESIGNED
    LOCAL_PRIVILEGED_MODULE := true
    LOCAL_PRODUCT_MODULE := true
    LOCAL_DEX_PREOPT := false
    include $(BUILD_PREBUILT)
    
  2. Rename the app-debug.apk to AOSPHost.apk and put the APK in the same folder as Android.mk.
  3. Add the CarAOSPHost module to your targets as PRODUCT_PACKAGES:
    PRODUCT_PACKAGES += \
       CarAOSPHost \
    

Add the permissions config

  1. Create a file called com.android.car.templates.host.xml to contain the following:
    <permissions>
        <!-- Rename the package to com.android.car.templates.host -->
        <privapp-permissions package="com.android.car.templates.host">
            <!-- To be able to display activities in the cluster -->
            <permission name="android.car.permission.CAR_DISPLAY_IN_CLUSTER" />
    
            <!-- To be able to show navigation state (turn by turn directions) in the cluster.-->
            <permission name="android.car.permission.CAR_NAVIGATION_MANAGER" />
    
            <!-- To be considered a system-approved host -->
            <permission name="android.car.permission.TEMPLATE_RENDERER" />
        </privapp-permissions>
    
        <!-- Declare support for templated applications. -->
        <feature name="android.software.car.templates_host" />
    </permissions>
    
  2. In your target, add the config file to your targets:
    PRODUCT_COPY_FILES += \
        <the file root>/com.android.car.templates.host.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/com.android.car.templates.host.xml
    

Build the target

When you build the target, the host is installed and permission is granted:

      …
      android.car.permission.CAR_NAVIGATION_MANAGER: granted=true
      android.car.permission.CAR_DISPLAY_IN_CLUSTER: granted=true
      android.car.permission.TEMPLATE_RENDERER: granted=true
      …

Test the integration

To build and install the samples, see this GitHub project, car-samples/car_app_library.