• 【IVI】VehicleService启动


    【IVI】VehicleService启动

    android12-release
    Android Automotive OS知识体系

    1、rc文件android.hardware.automotive.vehicle@2.0-service.rc

    VehicleService进程名:vendor.vehicle-hal-2.0
    bin文件:/vendor/bin/hw/android.hardware.automotive.vehicle@2.0-service
    对应启动入口:hardware/interfaces/automotive/vehicle/2.0/default/VehicleService.cpp
    在这里插入图片描述

    hardware/interfaces/automotive/vehicle/2.0/default/android.hardware.automotive.vehicle@2.0-service.rc

    service vendor.vehicle-hal-2.0 /vendor/bin/hw/android.hardware.automotive.vehicle@2.0-service
        class hal
        user vehicle_network
        group system inet
    

    hardware/interfaces/automotive/vehicle/2.0/default/android.hardware.automotive.vehicle@2.0-service.xml

    <manifest version="1.0" type="device">
        <hal format="hidl">
            <name>android.hardware.automotive.vehiclename>
            <transport>hwbindertransport>
            <version>2.0version>
            <interface>
                <name>IVehiclename>
                <instance>defaultinstance>
            interface>
        hal>
    manifest>
    

    2、VehicleService.cpp#main()启动

    • EmulatedVehicleConnector继承VehicleHalClient、VehicleHalServer(即是IVehicleServer、IVehicleClient
    • hal = std::make_unique(store.get(), connector.get(), userHal)与VehicleHal通行,EmulatedVehicleHal最终继承VehicleHal
    • configureRpcThreadpool、joinRpcThreadpool 组队出现的东西,libhidl 库,用于自动生成HIDL语言,并辅助服务添加到 hwbinder域
    • VehicleHalManager 继承IVehicle ,再查看service->registerAsService()注册到 /dev/hwbinder 并添加到 defaultServiceManager()
    int main(int /* argc */, char* /* argv */ []) {
        auto store = std::make_unique<VehiclePropertyStore>();
        auto connector = std::make_unique<impl::EmulatedVehicleConnector>();
        auto userHal = connector->getEmulatedUserHal();
        auto hal = std::make_unique<impl::EmulatedVehicleHal>(store.get(), connector.get(), userHal);
        auto emulator = std::make_unique<impl::VehicleEmulator>(hal.get());
        auto service = std::make_unique<VehicleHalManager>(hal.get());
        connector->setValuePool(hal->getValuePool());
    
        configureRpcThreadpool(4, true /* callerWillJoin */);
    
        ALOGI("Registering as service...");
        status_t status = service->registerAsService();
    
        if (status != OK) {
            ALOGE("Unable to register vehicle service (%d)", status);
            return 1;
        }
    
        ALOGI("Ready");
        joinRpcThreadpool();
    
        return 1;
    }
    

    2.1 libhidl、libhwbinder路径

    Binder 域
    system/libhidl/transport/HidlTransportSupport.cpp
    system/libhidl/transport/include/hidl/HidlTransportSupport.h
    system/libhidl/transport/ServiceManagement.cpp
    system/libhidl/transport/include/hidl/ServiceManagement.h

    system/libhwbinder/ProcessState.cpp
    system/libhwbinder/IPCThreadState.cpp

    2.2 hidl-gen自动生成代码文件Bp、Bn端:types.hal、IVehicle.hal、IVehicleCallback.hal

    在这里插入图片描述
    参考:
    在这里插入图片描述

    // This file is autogenerated by hidl-gen -Landroidbp.
    
    package {
        // See: http://go/android-license-faq
        // A large-scale-change added 'default_applicable_licenses' to import
        // all of the 'license_kinds' from "hardware_interfaces_license"
        // to get the below license kinds:
        //   SPDX-license-identifier-Apache-2.0
        default_applicable_licenses: ["hardware_interfaces_license"],
    }
    
    hidl_interface {
        name: "android.hardware.automotive.vehicle@2.0",
        root: "android.hardware",
        srcs: [
            "types.hal",
            "IVehicle.hal",
            "IVehicleCallback.hal",
        ],
        interfaces: [
            "android.hidl.base@1.0",
        ],
        gen_java: true,
    }
    

    3、时序图

    在这里插入图片描述

    4. 上层调用

    packages/services/Car/service/src/com/android/car/CarService.java

    private static IVehicle getVehicle() {
        final String instanceName = SystemProperties.get("ro.vehicle.hal", "default");
    
        try {
            return android.hardware.automotive.vehicle.V2_0.IVehicle.getService(instanceName);
        } catch (RemoteException e) {
            Slog.e(CarLog.TAG_SERVICE, "Failed to get IVehicle/" + instanceName + " service", e);
        } catch (NoSuchElementException e) {
            Slog.e(CarLog.TAG_SERVICE, "IVehicle/" + instanceName + " service not registered yet");
        }
        return null;
    }
    
  • 相关阅读:
    Mybatis按年月日时分秒查询,MySQL年月日时分秒查询
    vsto 任务面板 添加自定义控件
    保护 Java 字节码不被反编译
    配置git在Linux服务器上
    std::unique_ptr(基础和仿写)
    01-mysql5.7安装部署-yum安装
    Bug:Mac版Goland无法进行debug
    28岁转行软件测试真的很难吗?按照我整理出的这份3000字学习指南就没问题...
    深度学习笔记-------KNN算法
    【项目源码】反编译Java字节码生成源码
  • 原文地址:https://blog.csdn.net/qq_23452385/article/details/127036668