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