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 #define LOG_TAG "automotive.vehicle@2.0-connector"
18
19 #include <fstream>
20
21 #include <android-base/logging.h>
22 #include <utils/SystemClock.h>
23
24 #include "DefaultConfig.h"
25 #include "EmulatedVehicleConnector.h"
26 #include "JsonFakeValueGenerator.h"
27 #include "LinearFakeValueGenerator.h"
28 #include "Obd2SensorStore.h"
29
30 namespace android {
31 namespace hardware {
32 namespace automotive {
33 namespace vehicle {
34 namespace V2_0 {
35
36 namespace impl {
37
getEmulatedUserHal()38 EmulatedUserHal* EmulatedVehicleConnector::getEmulatedUserHal() {
39 return &mEmulatedUserHal;
40 }
41
onSetProperty(const VehiclePropValue & value,bool updateStatus)42 StatusCode EmulatedVehicleConnector::onSetProperty(const VehiclePropValue& value,
43 bool updateStatus) {
44 if (mEmulatedUserHal.isSupported(value.prop)) {
45 LOG(INFO) << "onSetProperty(): property " << value.prop << " will be handled by UserHal";
46
47 const auto& ret = mEmulatedUserHal.onSetProperty(value);
48 if (!ret.ok()) {
49 LOG(ERROR) << "onSetProperty(): HAL returned error: " << ret.error().message();
50 return StatusCode(ret.error().code());
51 }
52 auto updatedValue = ret.value().get();
53 if (updatedValue != nullptr) {
54 LOG(INFO) << "onSetProperty(): updating property returned by HAL: "
55 << toString(*updatedValue);
56 onPropertyValueFromCar(*updatedValue, updateStatus);
57 }
58 return StatusCode::OK;
59 }
60 return this->VehicleHalServer::onSetProperty(value, updateStatus);
61 }
62
onDump(const hidl_handle & handle,const hidl_vec<hidl_string> & options)63 bool EmulatedVehicleConnector::onDump(const hidl_handle& handle,
64 const hidl_vec<hidl_string>& options) {
65 int fd = handle->data[0];
66
67 if (options.size() > 0) {
68 if (options[0] == "--help") {
69 dprintf(fd, "Emulator-specific usage:\n");
70 mEmulatedUserHal.showDumpHelp(fd);
71 dprintf(fd, "\n");
72 // Include caller's help options
73 return true;
74 } else if (options[0] == kUserHalDumpOption) {
75 mEmulatedUserHal.dump(fd, "");
76 return false;
77
78 } else {
79 // Let caller handle the options...
80 return true;
81 }
82 }
83
84 dprintf(fd, "Emulator-specific state:\n");
85 mEmulatedUserHal.dump(fd, " ");
86 dprintf(fd, "\n");
87
88 return true;
89 }
90
91 } // namespace impl
92
93 } // namespace V2_0
94 } // namespace vehicle
95 } // namespace automotive
96 } // namespace hardware
97 } // namespace android
98