Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Working with Custom Android Devices and AOSP bu...

Erik Hellman
November 15, 2023

Working with Custom Android Devices and AOSP build system

An overview of how to use the AOSP build system for working with custom Android devices, and how to add apps and SDK add-ons.

Erik Hellman

November 15, 2023
Tweet

More Decks by Erik Hellman

Other Decks in Programming

Transcript

  1. Agenda • Working with repo • Lunch targets and variants

    • Adding a new device • System properties • Resource overlays • Adding new modules • Soong build system • Apps • Library
  2. Repo init - with mirror $ cd <path to mirror>

    $ repo init -u <url> -b <branch> -m <manifest> --mirror $ repo sync -c -j <jobs> $ cd <path to new workspace> $ repo init -u <url> -b <branch> -m <manifest> \ --reference=<path to mirror> $ repo sync -c -j <jobs>
  3. Lunch targets $ lunch You're building on Linux Lunch menu...

    pick a combo: ... 28. aosp_flame-userdebug 29. aosp_flame_car-userdebug 30. aosp_redfin-userdebug 31. aosp_redfin_car-userdebug ... Which would you like? [aosp_arm-eng]
  4. Adding a new device to AOSP $ mkdir device/<vendor>/<product> $

    vim device/<vendor>/<product>/AndroidProducts.mk
  5. aosp_my_device.mk # Inherit from the common Open Source product configuration

    $(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk) $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk) PRODUCT_NAME := aosp_my_device PRODUCT_DEVICE := my_device PRODUCT_BRAND := Android PRODUCT_MODEL := Eriks AOSP on Pixel5 PRODUCT_MANUFACTURER := Hellsoft PRODUCT_RESTRICT_VENDOR_FILES := true $(call inherit-product, device/google/redfin/device-redfin.mk) $(call inherit-product-if-exists, vendor/google_devices/redfid/device-vendor-redfin.mk)
  6. Resource overlays $ pwd /mnt/aosp/device/google/redfin/redfin/overlay $ ls frameworks packages vendor

    $ tree -C -d frameworks frameworks └── base ├── core │ └── res │ └── res │ ├── values │ └── xml └── packages └── SystemUI └── res ├── drawable ├── values └── values-land
  7. Add a new app Android.bp android_app { name: "my_system_app", resource_dirs:

    ["res"], sdk_version: "current", srcs: [ "src/**/*.kt", "gen/**/*.java", ], product_specific: true, static_libs: [ "androidx.annotation_annotation", "androidx.collection_collection", "androidx.arch.core_core-common", "androidx.lifecycle_lifecycle-common", "com.google.android.material_material", "androidx.lifecycle_lifecycle-runtime", "androidx.core_core", "androidx.recyclerview_recyclerview", ], }
  8. Import an APK android_app_import { name: "my_imported_app", apk: "remote_display_manager.apk", certificate:

    "platform", privileged: true, required: ["privapp_whitelist_se.hellsoft.myapp"] }
  9. Grant permissions to preinstalled apps <?xml version="1.0" encoding="utf-8"?> <permissions> <privapp-permissions

    package="se.hellsoft.myapp"> <permission name="android.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND" /> <permission name="android.permission.FOREGROUND_SERVICE" /> <permission name="android.permission.INTERNET" /> <permission name="android.permission.INJECT_EVENTS" /> <permission name="android.permission.CAPTURE_VIDEO_OUTPUT" /> <permission name="android.permission.MANAGE_APP_TOKENS" /> <permission name="android.permission.REMOTE_DISPLAY_PROVIDER" /> <permission name="android.permission.RECEIVE_BOOT_COMPLETED" /> <permission name="android.permission.SYSTEM_ALERT_WINDOW" /> <permission name="android.permission.QUERY_ALL_PACKAGES" /> <permission name="android.permission.INTERNAL_SYSTEM_WINDOW" /> <permission name="android.permission.USE_DATA_IN_BACKGROUND" /> </privapp-permissions> </permissions>
  10. Including permissions file in AOSP build prebuilt_etc { name: "privapp_whitelist_se.hellsoft.myapp",

    system_ext_specific: true, sub_dir: "permissions", src: "se.hellsoft.myapp.xml", filename_from_src: true, }
  11. Java SDK library java_sdk_library { name: "my_java_sdk_library", public: { enabled:

    true, }, system: { enabled: true, }, srcs: [ "src/**/*.java", ], api_packages: [ "se.hellsoft.mylib", ], }