1 /* 2 * Copyright (C) 2019 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 #include <android-base/logging.h> 18 #include <android/binder_process.h> 19 #include <hidl/HidlTransportSupport.h> 20 21 #include <vhal_v2_0/DefaultVehicleHal.h> 22 #include <vhal_v2_0/VehicleHalManager.h> 23 24 #include "GrpcVehicleClient.h" 25 #include "Utils.h" 26 27 using android::OK; 28 using android::status_t; 29 using android::hardware::configureRpcThreadpool; 30 using android::hardware::joinRpcThreadpool; 31 using android::hardware::automotive::vehicle::V2_0::VehicleHalManager; 32 using android::hardware::automotive::vehicle::V2_0::VehiclePropertyStore; 33 main(int argc,char * argv[])34int main(int argc, char* argv[]) { 35 namespace vhal_impl = android::hardware::automotive::vehicle::V2_0::impl; 36 37 auto serverInfo = vhal_impl::VirtualizedVhalServerInfo::fromRoPropertyStore(); 38 CHECK(serverInfo.has_value()) << "Invalid server CID/port combination"; 39 LOG(INFO) << "Connecting to vsock server at " << serverInfo->vsock.str(); 40 41 auto store = std::make_unique<VehiclePropertyStore>(); 42 auto connector = vhal_impl::makeGrpcVehicleClient(serverInfo->getServerUri()); 43 auto hal = std::make_unique<vhal_impl::DefaultVehicleHal>(store.get(), connector.get()); 44 auto service = std::make_unique<VehicleHalManager>(hal.get()); 45 46 configureRpcThreadpool(4, true /* callerWillJoin */); 47 48 LOG(INFO) << "Registering as service..."; 49 status_t status = service->registerAsService(); 50 51 if (status != OK) { 52 LOG(ERROR) << "Unable to register vehicle service (" << status << ")"; 53 return 1; 54 } 55 56 LOG(INFO) << "Ready"; 57 joinRpcThreadpool(); 58 59 // We don't ever actually expect to return, so return an error if we do get here 60 return 1; 61 } 62