1 /* 2 * Copyright (C) 2015 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 #ifndef ANDROID_IVEHICLE_NETWORK_H 18 #define ANDROID_IVEHICLE_NETWORK_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 23 #include <hardware/vehicle.h> 24 25 #include <utils/RefBase.h> 26 #include <utils/Errors.h> 27 #include <binder/IInterface.h> 28 #include <binder/IMemory.h> 29 #include <binder/Parcel.h> 30 31 #include <VehicleNetworkDataTypes.h> 32 #include <IVehicleNetworkHalMock.h> 33 #include <IVehicleNetworkListener.h> 34 35 namespace android { 36 37 // ---------------------------------------------------------------------------- 38 39 class IVehicleNetwork : public IInterface { 40 public: 41 static const char SERVICE_NAME[]; 42 DECLARE_META_INTERFACE(VehicleNetwork); 43 44 /** 45 * Return configuration of single property (when argument property is not 0) or all properties 46 * (when property = 0). 47 */ 48 virtual sp<VehiclePropertiesHolder> listProperties(int32_t property = 0) = 0; 49 virtual status_t setProperty(const vehicle_prop_value_t& value)= 0; 50 virtual status_t getProperty(vehicle_prop_value_t* value) = 0; 51 virtual status_t subscribe(const sp<IVehicleNetworkListener> &listener, int32_t property, 52 float sampleRate, int32_t zones) = 0; 53 virtual void unsubscribe(const sp<IVehicleNetworkListener> &listener, int32_t property) = 0; 54 /** 55 * Inject event for given property. This should work regardless of mocking but usually 56 * used in mocking. 57 */ 58 virtual status_t injectEvent(const vehicle_prop_value_t& value) = 0; 59 virtual status_t startMocking(const sp<IVehicleNetworkHalMock>& mock) = 0; 60 virtual void stopMocking(const sp<IVehicleNetworkHalMock>& mock) = 0; 61 virtual status_t injectHalError(int32_t errorCode, int32_t property, int32_t operation) = 0; 62 /** 63 * Register listener and listen for global error from vehicle hal. 64 * Per property error will be delivered when the property is subscribed or global error listener 65 * where there is no subscription. 66 */ 67 virtual status_t startErrorListening(const sp<IVehicleNetworkListener> &listener) = 0; 68 virtual void stopErrorListening(const sp<IVehicleNetworkListener> &listener) = 0; 69 /** 70 * Listen for HAL restart. When HAL restarts, as in case of starting or stopping mocking, 71 * all existing subscription becomes invalid. 72 */ 73 virtual status_t startHalRestartMonitoring(const sp<IVehicleNetworkListener> &listener) = 0; 74 virtual void stopHalRestartMonitoring(const sp<IVehicleNetworkListener> &listener) = 0; 75 }; 76 77 // ---------------------------------------------------------------------------- 78 79 class BnVehicleNetwork : public BnInterface<IVehicleNetwork> { 80 virtual status_t onTransact(uint32_t code, 81 const Parcel& data, 82 Parcel* reply, 83 uint32_t flags = 0); 84 virtual bool isOperationAllowed(int32_t property, bool isWrite) = 0; 85 virtual void releaseMemoryFromGet(vehicle_prop_value_t* value) = 0; 86 }; 87 88 // ---------------------------------------------------------------------------- 89 90 class VehicleNetworkUtil { 91 public: countNumberOfZones(int32_t zones)92 static int countNumberOfZones(int32_t zones) { 93 if (zones == 0) { // no-zone, treat as one zone. 94 return 1; 95 } 96 int count = 0; 97 uint32_t flag = 0x1; 98 for (int i = 0; i < 32; i++) { 99 if ((flag & zones) != 0) { 100 count++; 101 } 102 flag <<= 1; 103 } 104 return count; 105 } 106 }; 107 108 // ---------------------------------------------------------------------------- 109 }; // namespace android 110 111 #endif /* ANDROID_IVEHICLE_NETWORK_H */ 112