1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <aidl/android/hardware/automotive/ivn/BnIvnAndroidDevice.h> 20 #include <aidl/android/hardware/automotive/ivn/EndpointInfo.h> 21 #include <aidl/android/hardware/automotive/ivn/OccupantZoneInfo.h> 22 #include <android/binder_auto_utils.h> 23 #include <json/json.h> 24 #include <vector> 25 26 #include <unordered_map> 27 28 namespace android { 29 namespace hardware { 30 namespace automotive { 31 namespace ivn { 32 33 struct DeviceInfo { 34 std::vector<aidl::android::hardware::automotive::ivn::OccupantZoneInfo> occupantZones; 35 aidl::android::hardware::automotive::ivn::EndpointInfo endpointInfo; 36 }; 37 38 class IvnAndroidDeviceService 39 : public aidl::android::hardware::automotive::ivn::BnIvnAndroidDevice { 40 public: 41 explicit IvnAndroidDeviceService(std::string_view configPath); 42 43 // Initialize the service, returns true on success. 44 bool init(); 45 46 ndk::ScopedAStatus getMyDeviceId(int* deviceId) override; 47 48 ndk::ScopedAStatus getOtherDeviceIds(std::vector<int>* deviceIds) override; 49 50 ndk::ScopedAStatus getDeviceIdForOccupantZone(int zoneId, int* deviceId) override; 51 52 ndk::ScopedAStatus getOccupantZonesForDevice( 53 int androidDeviceId, 54 std::vector<aidl::android::hardware::automotive::ivn::OccupantZoneInfo>* occupantZones) 55 override; 56 57 ndk::ScopedAStatus getMyEndpointInfo( 58 aidl::android::hardware::automotive::ivn::EndpointInfo* endpointInfo) override; 59 60 ndk::ScopedAStatus getEndpointInfoForDevice( 61 int androidDeviceId, 62 aidl::android::hardware::automotive::ivn::EndpointInfo* endpointInfo) override; 63 64 binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; 65 66 private: 67 Json::Value mConfigRootNode; 68 int mMyDeviceId; 69 std::unordered_map<int, DeviceInfo> mDeviceInfoById; 70 std::string_view mConfigPath; 71 }; 72 73 } // namespace ivn 74 } // namespace automotive 75 } // namespace hardware 76 } // namespace android 77