blob: 47133fd16267cabfecdbe6cddc345d327b94b5df [file] [log] [blame]
Pavel Maltseva2f426a2016-10-04 10:17:05 -07001/*
2 * Copyright (C) 2016 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
Pavel Maltsev2579fb72017-02-02 12:39:36 -080017#define LOG_TAG "automotive.vehicle@2.0-service"
Yifan Hongf9d30342016-11-30 13:45:34 -080018#include <android/log.h>
Martijn Coenen02822372016-12-29 14:03:41 +010019#include <hidl/HidlTransportSupport.h>
Pavel Maltseva2f426a2016-10-04 10:17:05 -070020
21#include <iostream>
22
Eric Jeong908101a2020-04-23 09:43:55 -070023#include <android/binder_process.h>
24#include <utils/Looper.h>
felipeal5a944182020-05-06 15:35:39 -070025#include <vhal_v2_0/EmulatedUserHal.h>
Hao Chenfba3ac82019-11-07 11:55:25 -080026#include <vhal_v2_0/EmulatedVehicleConnector.h>
Pavel Maltsev33676522017-03-31 13:45:54 -070027#include <vhal_v2_0/EmulatedVehicleHal.h>
Hao Chenfba3ac82019-11-07 11:55:25 -080028#include <vhal_v2_0/VehicleHalManager.h>
Eric Jeong908101a2020-04-23 09:43:55 -070029#include <vhal_v2_0/WatchdogClient.h>
Pavel Maltseva2f426a2016-10-04 10:17:05 -070030
31using namespace android;
32using namespace android::hardware;
Pavel Maltsev2579fb72017-02-02 12:39:36 -080033using namespace android::hardware::automotive::vehicle::V2_0;
Pavel Maltseva2f426a2016-10-04 10:17:05 -070034
35int main(int /* argc */, char* /* argv */ []) {
Pavel Maltsev33676522017-03-31 13:45:54 -070036 auto store = std::make_unique<VehiclePropertyStore>();
Hao Chenfba3ac82019-11-07 11:55:25 -080037 auto connector = impl::makeEmulatedPassthroughConnector();
felipeal5a944182020-05-06 15:35:39 -070038 auto userHal = connector->getEmulatedUserHal();
39 auto hal = std::make_unique<impl::EmulatedVehicleHal>(store.get(), connector.get(), userHal);
Pavel Maltsev33676522017-03-31 13:45:54 -070040 auto emulator = std::make_unique<impl::VehicleEmulator>(hal.get());
Pavel Maltseve2603e32016-10-25 16:03:23 -070041 auto service = std::make_unique<VehicleHalManager>(hal.get());
Hao Chenfba3ac82019-11-07 11:55:25 -080042 connector->setValuePool(hal->getValuePool());
Pavel Maltseva2f426a2016-10-04 10:17:05 -070043
Eric Jeong908101a2020-04-23 09:43:55 -070044 configureRpcThreadpool(4, false /* callerWillJoin */);
Martijn Coenen02822372016-12-29 14:03:41 +010045
Pavel Maltseve2603e32016-10-25 16:03:23 -070046 ALOGI("Registering as service...");
Steven Morelande50f2ef2017-04-26 11:42:24 -070047 status_t status = service->registerAsService();
48
49 if (status != OK) {
50 ALOGE("Unable to register vehicle service (%d)", status);
51 return 1;
52 }
Pavel Maltseva2f426a2016-10-04 10:17:05 -070053
Eric Jeong908101a2020-04-23 09:43:55 -070054 // Setup a binder thread pool to be a car watchdog client.
55 ABinderProcess_setThreadPoolMaxThreadCount(1);
56 ABinderProcess_startThreadPool();
57 sp<Looper> looper(Looper::prepare(0 /* opts */));
58 std::shared_ptr<WatchdogClient> watchdogClient =
59 ndk::SharedRefBase::make<WatchdogClient>(looper, service.get());
60 // The current health check is done in the main thread, so it falls short of capturing the real
61 // situation. Checking through HAL binder thread should be considered.
62 if (!watchdogClient->initialize()) {
63 ALOGE("Failed to initialize car watchdog client");
64 return 1;
65 }
Pavel Maltseva2f426a2016-10-04 10:17:05 -070066 ALOGI("Ready");
Eric Jeong908101a2020-04-23 09:43:55 -070067 while (true) {
68 looper->pollAll(-1 /* timeoutMillis */);
69 }
Steven Morelande50f2ef2017-04-26 11:42:24 -070070
71 return 1;
Pavel Maltseva2f426a2016-10-04 10:17:05 -070072}