1 /* 2 * Copyright (C) 2020 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 #pragma once 18 19 #include <vhal_v2_0/VehicleObjectPool.h> 20 #include <vhal_v2_0/VehicleServer.h> 21 22 #include "GeneratorHub.h" 23 24 namespace android::hardware::automotive::vehicle::V2_0::impl { 25 26 // This contains the common server operations that will be used by 27 // both native and virtualized VHAL server. Notice that in the virtualized 28 // scenario, the server may be run on a different OS than Android. 29 class VehicleHalServer : public IVehicleServer { 30 public: 31 // Methods from IVehicleServer 32 33 std::vector<VehiclePropConfig> onGetAllPropertyConfig() const override; 34 35 StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) override; 36 37 // Set the Property Value Pool used in this server 38 void setValuePool(VehiclePropValuePool* valuePool); 39 40 private: 41 using VehiclePropValuePtr = recyclable_ptr<VehiclePropValue>; 42 43 GeneratorHub* getGenerator(); 44 45 VehiclePropValuePool* getValuePool() const; 46 47 void onFakeValueGenerated(const VehiclePropValue& value); 48 49 StatusCode handleGenerateFakeDataRequest(const VehiclePropValue& request); 50 51 VehiclePropValuePtr createApPowerStateReq(VehicleApPowerStateReq req, int32_t param); 52 53 VehiclePropValuePtr createHwInputKeyProp(VehicleHwKeyInputAction action, int32_t keyCode, 54 int32_t targetDisplay); 55 56 private: 57 GeneratorHub mGeneratorHub{ 58 std::bind(&VehicleHalServer::onFakeValueGenerated, this, std::placeholders::_1)}; 59 60 VehiclePropValuePool* mValuePool{nullptr}; 61 }; 62 63 } // namespace android::hardware::automotive::vehicle::V2_0::impl 64