#
# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

PRODUCT_MANIFEST_FILES += device/google/cuttlefish/shared/config/product_manifest.xml
SYSTEM_EXT_MANIFEST_FILES += device/google/cuttlefish/shared/config/system_ext_manifest.xml

$(call inherit-product, packages/services/Car/car_product/build/car_vendor.mk)

$(call inherit-product, frameworks/native/build/phone-xhdpi-2048-dalvik-heap.mk)
$(call inherit-product, device/google/cuttlefish/shared/biometrics_face/device_vendor.mk)
$(call inherit-product, device/google/cuttlefish/shared/biometrics_fingerprint/device_vendor.mk)
$(call inherit-product, device/google/cuttlefish/shared/bluetooth/device_vendor.mk)
$(call inherit-product, device/google/cuttlefish/shared/gnss/device_vendor.mk)
$(call inherit-product, device/google/cuttlefish/shared/graphics/device_vendor.mk)
$(call inherit-product, device/google/cuttlefish/shared/secure_element/device_vendor.mk)
$(call inherit-product, device/google/cuttlefish/shared/swiftshader/device_vendor.mk)
$(call inherit-product, device/google/cuttlefish/shared/telephony/device_vendor.mk)
$(call inherit-product, device/google/cuttlefish/shared/sensors/device_vendor.mk)
$(call inherit-product, device/google/cuttlefish/shared/device.mk)

# Extend cuttlefish common sepolicy with auto-specific functionality
BOARD_SEPOLICY_DIRS += device/google/cuttlefish/shared/auto/sepolicy \
                       device/google/cuttlefish/shared/auto/sepolicy/vendor \

SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS += device/google/cuttlefish/shared/auto/sepolicy/system_ext/private
SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS += device/google/cuttlefish/shared/auto/sepolicy/system_ext/public

################################################
# Begin general Android Auto Embedded configurations

PRODUCT_COPY_FILES += \
    packages/services/Car/car_product/init/init.bootstat.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.bootstat.rc \
    packages/services/Car/car_product/init/init.car.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.car.rc

# Override default sensor files in device_vendor.mk
LOCAL_SENSOR_FILE_OVERRIDES := true
# Add the sensor files that are supported on Automotive
PRODUCT_COPY_FILES += \
    frameworks/native/data/etc/android.hardware.sensor.accelerometer.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.accelerometer.xml \
    frameworks/native/data/etc/android.hardware.sensor.gyroscope.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.gyroscope.xml

PRODUCT_PRODUCT_PROPERTIES += \
    ro.boot.uwbcountrycode=US

PRODUCT_SYSTEM_PROPERTIES += \
    ro.sys.hibernate_enabled=1 \
    ro.sys.swap_storage_device=/dev/block/vda19

PRODUCT_COPY_FILES += \
    frameworks/native/data/etc/car_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/car_core_hardware.xml \
    frameworks/native/data/etc/android.hardware.broadcastradio.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.broadcastradio.xml \
    frameworks/native/data/etc/android.hardware.touchscreen.multitouch.distinct.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.touchscreen.multitouch.distinct.xml \
    frameworks/native/data/etc/android.hardware.screen.landscape.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.screen.landscape.xml \
    frameworks/native/data/etc/android.software.activities_on_secondary_displays.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.activities_on_secondary_displays.xml \

# Preinstalled packages per user type
PRODUCT_COPY_FILES += \
    device/google/cuttlefish/shared/auto/preinstalled-packages-product-car-cuttlefish.xml:$(TARGET_COPY_OUT_PRODUCT)/etc/sysconfig/preinstalled-packages-product-car-cuttlefish.xml

# Install automotive specific battery health HAL
PRODUCT_PACKAGES += \
    android.hardware.health-service.automotive \
    android.hardware.health-service.automotive_recovery \

# Include display settings for an auto device.
PRODUCT_COPY_FILES += \
    device/google/cuttlefish/shared/auto/display_settings.xml:$(TARGET_COPY_OUT_VENDOR)/etc/display_settings.xml

# Include the fstab needed for suspend to disk
PRODUCT_COPY_FILES += \
    device/google/cuttlefish/shared/auto/hibernation_swap/fstab.hibernationswap:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.hibernationswap

# vehicle HAL
ifeq ($(LOCAL_VHAL_PRODUCT_PACKAGE),)
    LOCAL_VHAL_PRODUCT_PACKAGE := com.android.hardware.automotive.vehicle.cf
    BOARD_SEPOLICY_DIRS += device/google/cuttlefish/shared/auto/sepolicy/vhal
endif
PRODUCT_PACKAGES += $(LOCAL_VHAL_PRODUCT_PACKAGE)

# Set car power policy daemon connect to VHAL timeout to 60s for emulator (default is 5s).
PRODUCT_SYSTEM_PROPERTIES += cppd.connectvhal.Timeoutmillis=60000

# Ethernet setup script for vehicle HAL
ENABLE_AUTO_ETHERNET ?= true
ifeq ($(ENABLE_AUTO_ETHERNET), true)
    PRODUCT_PACKAGES += auto_ethernet_setup_script
    PRODUCT_PACKAGES += auto_ethernet_config_script
endif

# Remote access HAL
PRODUCT_PACKAGES += android.hardware.automotive.remoteaccess@V2-default-service

# Broadcast Radio
PRODUCT_PACKAGES += android.hardware.broadcastradio-service.default

# IVN HAL
PRODUCT_PACKAGES += android.hardware.automotive.ivn@V1-default-service

# AudioControl HAL
# OEM may override the default service of the virtual device.
ifeq ($(LOCAL_AUDIOCONTROL_HAL_PRODUCT_PACKAGE),)
    LOCAL_AUDIOCONTROL_HAL_PRODUCT_PACKAGE := android.hardware.automotive.audiocontrol-service.example
    BOARD_SEPOLICY_DIRS += device/google/cuttlefish/shared/auto/sepolicy/audio
endif
PRODUCT_PACKAGES += $(LOCAL_AUDIOCONTROL_HAL_PRODUCT_PACKAGE)

# CAN bus HAL
PRODUCT_PACKAGES += android.hardware.automotive.can-service

# MACSEC HAL
PRODUCT_PACKAGES += android.hardware.macsec-service
PRODUCT_PACKAGES += wpa_supplicant_macsec
PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/macsec/wpa_supplicant_macsec.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wpa_supplicant_macsec.conf \
    $(LOCAL_PATH)/macsec/init.wpa_supplicant_macsec.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.wpa_supplicant_macsec.rc

# Occupant Awareness HAL
PRODUCT_PACKAGES += android.hardware.automotive.occupant_awareness@1.0-service
include packages/services/Car/car_product/occupant_awareness/OccupantAwareness.mk
BOARD_SEPOLICY_DIRS += packages/services/Car/car_product/occupant_awareness/sepolicy

ENABLE_CARTELEMETRY_SERVICE ?= true
USE_EMULATED_CAMERA2_HAL ?= false

ifeq ($(USE_EMULATED_CAMERA2_HAL), true)
ENABLE_CAMERA_SERVICE := true
PRODUCT_SOONG_NAMESPACES += hardware/google/camera/devices/EmulatedCamera
PRODUCT_PACKAGES += com.google.emulated.camera.provider.hal

PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.camera.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.xml \
frameworks/native/data/etc/android.hardware.camera.concurrent.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.concurrent.xml \
frameworks/native/data/etc/android.hardware.camera.front.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.front.xml

PRODUCT_PACKAGES += \
    emu_camera_back.json \
    emu_camera_front.json \
    emu_camera_depth.json

else
# EVS
# By default, we enable EvsManager, a sample EVS app, and a mock EVS HAL implementation.
# If you want to use your own EVS HAL implementation, please set ENABLE_MOCK_EVSHAL as false
# and add your HAL implementation to the product.  Please also check init.evs.rc and see how
# you can configure EvsManager to use your EVS HAL implementation.  Similarly, please set
# ENABLE_SAMPLE_EVS_APP as false if you want to use your own EVS app configuration or own EVS
# app implementation.
ENABLE_EVS_SERVICE ?= true
ENABLE_MOCK_EVSHAL ?= true
ENABLE_CAREVSSERVICE_SAMPLE ?= true
ENABLE_SAMPLE_EVS_APP ?= true

ifeq ($(ENABLE_MOCK_EVSHAL), true)
CUSTOMIZE_EVS_SERVICE_PARAMETER := true
PRODUCT_PACKAGES += android.hardware.automotive.evs-aidl-default-service
PRODUCT_COPY_FILES += \
    device/google/cuttlefish/shared/auto/evs/init.evs.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.evs.rc
endif
BOARD_SEPOLICY_DIRS += device/google/cuttlefish/shared/auto/sepolicy/evs

ifeq ($(ENABLE_SAMPLE_EVS_APP), true)
PRODUCT_COPY_FILES += \
    device/google/cuttlefish/shared/auto/evs/evs_app_config.json:$(TARGET_COPY_OUT_VENDOR)/etc/automotive/evs/config_override.json
endif
endif

BOARD_IS_AUTOMOTIVE := true

DEVICE_PACKAGE_OVERLAYS += device/google/cuttlefish/shared/auto/overlay

PRODUCT_PACKAGES += CarServiceOverlayCuttleFish
GOOGLE_CAR_SERVICE_OVERLAY += CarServiceOverlayCuttleFishGoogle

PRODUCT_PACKAGES += ConnectivityOverlayCuttleFish
GOOGLE_CAR_SERVICE_OVERLAY += ConnectivityOverlayCuttleFishGoogle

TARGET_BOARD_INFO_FILE ?= device/google/cuttlefish/shared/auto/android-info.txt
BOARD_BOOTCONFIG += androidboot.hibernation_resume_device=259:3

# TODO (b/405655265) Remove once the BT issue is fixed
BOARD_BOOTCONFIG += androidboot.cuttlefish_service_bluetooth_checker=false

# Telephony: Use Minradio RIL instead of Cuttlefish RIL
TARGET_USES_CF_RILD := false
PRODUCT_PACKAGES += com.android.hardware.radio.minradio.virtual
PRODUCT_PACKAGES += ConnectivityOverlayMinradio

# Disable thread network
CF_VENDOR_NO_THREADNETWORK := true

# Disable light HAL
LOCAL_ENABLE_LIGHT := false

# Wifi setup
PRODUCT_PACKAGES += wifi_on

# Auto CF target is configured to use Configurable Audio Policy Engine if vendor audio configuration
# flag is not set. However, to prevent fallback on common cuttlefish audio configuration files, make
# use of the vendor flag even for default cuttlefish auto config.
LOCAL_USE_VENDOR_AUDIO_CONFIGURATION ?= false
ifeq ($(LOCAL_USE_VENDOR_AUDIO_CONFIGURATION),false)
LOCAL_USE_VENDOR_AUDIO_CONFIGURATION := true
$(call inherit-product, device/google/cuttlefish/shared/auto/audio_policy_engine.mk)
endif
