• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <utils/Errors.h>
22 #include <utils/Looper.h>
23 #include <utils/StrongPointer.h>
24 
25 #include <vhal_v2_0/EmulatedVehicleConnector.h>
26 #include <vhal_v2_0/EmulatedVehicleHal.h>
27 #include <vhal_v2_0/VehicleHalManager.h>
28 
29 #include "GrpcVehicleClient.h"
30 #include "Utils.h"
31 #include "WatchdogClient.h"
32 
33 using android::Looper;
34 using android::OK;
35 using android::status_t;
36 using android::hardware::configureRpcThreadpool;
37 using android::hardware::joinRpcThreadpool;
38 using android::hardware::automotive::vehicle::V2_0::VehicleHalManager;
39 using android::hardware::automotive::vehicle::V2_0::VehiclePropertyStore;
40 
main(int argc,char * argv[])41 int main(int argc, char* argv[]) {
42     namespace vhal_impl = android::hardware::automotive::vehicle::V2_0::impl;
43 
44     auto serverInfo = vhal_impl::VirtualizedVhalServerInfo::fromRoPropertyStore();
45     CHECK(serverInfo.has_value()) << "Invalid server CID/port combination";
46     LOG(INFO) << "Connecting to vsock server at " << serverInfo->vsock.str();
47 
48     auto store = std::make_unique<VehiclePropertyStore>();
49     auto connector = vhal_impl::makeGrpcVehicleClient(serverInfo->getServerUri());
50     auto hal = std::make_unique<vhal_impl::EmulatedVehicleHal>(store.get(), connector.get());
51     auto emulator = std::make_unique<vhal_impl::VehicleEmulator>(hal.get());
52     auto service = std::make_unique<VehicleHalManager>(hal.get());
53 
54     configureRpcThreadpool(4, true /* callerWillJoin */);
55 
56     LOG(INFO) << "Registering as service...";
57     status_t status = service->registerAsService();
58 
59     if (status != OK) {
60         LOG(ERROR) << "Unable to register vehicle service (" << status << ")";
61         return 1;
62     }
63 
64     LOG(INFO) << "Ready";
65 
66     // Setup a binder thread pool to be a car watchdog client.
67     ABinderProcess_setThreadPoolMaxThreadCount(1);
68     ABinderProcess_startThreadPool();
69     android::sp<Looper> looper(Looper::prepare(0 /* opts */));
70     auto watchdogClient =
71             ndk::SharedRefBase::make<vhal_impl::WatchdogClient>(looper, service.get());
72     if (!watchdogClient->initialize()) {
73         ALOGE("Failed to initialize car watchdog client");
74         return 1;
75     }
76 
77     while (true) {
78         looper->pollAll(-1 /* timeoutMillis */);
79     }
80 
81     // We don't ever actually expect to return, so return an error if we do get here
82     return 1;
83 }
84