keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 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 | #define LOG_TAG "VehicleNetwork" |
| 18 | |
| 19 | #include <memory> |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 20 | #include <string.h> |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 21 | |
| 22 | #include <binder/IPCThreadState.h> |
Keun-young Park | ba48548 | 2016-03-24 13:24:31 -0700 | [diff] [blame] | 23 | #include <binder/Status.h> |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 24 | |
| 25 | #include <utils/Log.h> |
| 26 | |
| 27 | #include <IVehicleNetwork.h> |
| 28 | #include <VehicleNetworkProto.pb.h> |
| 29 | |
keunyoung | 15882e5 | 2015-09-16 16:57:58 -0700 | [diff] [blame] | 30 | #include "BinderUtil.h" |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 31 | #include "VehicleNetworkProtoUtil.h" |
| 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | enum { |
| 36 | LIST_PROPERTIES = IBinder::FIRST_CALL_TRANSACTION, |
| 37 | SET_PROPERTY, |
| 38 | GET_PROPERTY, |
| 39 | SUBSCRIBE, |
| 40 | UNSUBSCRIBE, |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 41 | INJECT_EVENT, |
| 42 | START_MOCKING, |
| 43 | STOP_MOCKING, |
Keun-young Park | 28dd470 | 2015-11-19 18:06:04 -0800 | [diff] [blame] | 44 | INJECT_HAL_ERROR, |
| 45 | START_ERROR_LISTENING, |
| 46 | STOP_ERROR_LISTENING, |
| 47 | START_HAL_RESTART_MONITORING, |
| 48 | STOP_HAL_RESTART_MONITORING |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | // ---------------------------------------------------------------------------- |
| 52 | |
keunyoung | 15882e5 | 2015-09-16 16:57:58 -0700 | [diff] [blame] | 53 | const char IVehicleNetwork::SERVICE_NAME[] = "com.android.car.vehiclenetwork.IVehicleNetwork"; |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 54 | |
| 55 | // ---------------------------------------------------------------------------- |
| 56 | |
| 57 | class BpVehicleNetwork : public BpInterface<IVehicleNetwork> { |
| 58 | public: |
Chih-Hung Hsieh | 239e640 | 2016-05-02 11:53:32 -0700 | [diff] [blame] | 59 | explicit BpVehicleNetwork(const sp<IBinder> & impl) |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 60 | : BpInterface<IVehicleNetwork>(impl) { |
| 61 | } |
| 62 | |
| 63 | virtual sp<VehiclePropertiesHolder> listProperties(int32_t property) { |
| 64 | sp<VehiclePropertiesHolder> holder; |
| 65 | Parcel data, reply; |
| 66 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 67 | data.writeInt32(property); |
| 68 | status_t status = remote()->transact(LIST_PROPERTIES, data, &reply); |
| 69 | if (status == NO_ERROR) { |
keunyoung | 15882e5 | 2015-09-16 16:57:58 -0700 | [diff] [blame] | 70 | reply.readExceptionCode(); // for compatibility with java |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 71 | if (reply.readInt32() == 0) { // no result |
| 72 | return holder; |
| 73 | } |
| 74 | ReadableBlobHolder blob(new Parcel::ReadableBlob()); |
| 75 | if (blob.blob == NULL) { |
| 76 | ALOGE("listProperties, no memory"); |
| 77 | return holder; |
| 78 | } |
| 79 | int32_t size = reply.readInt32(); |
Keun-young Park | 20539ba | 2016-10-10 17:57:34 -0700 | [diff] [blame] | 80 | if (size < 0) { |
| 81 | ALOGE("listProperties, bad blob size %d", size); |
| 82 | return holder; |
| 83 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 84 | status = reply.readBlob(size, blob.blob); |
| 85 | if (status != NO_ERROR) { |
| 86 | ALOGE("listProperties, cannot read blob %d", status); |
| 87 | return holder; |
| 88 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 89 | std::unique_ptr<VehiclePropConfigs> configs(new VehiclePropConfigs()); |
| 90 | if (configs.get() == NULL) { |
| 91 | return holder; |
| 92 | } |
| 93 | if(!configs->ParseFromArray(blob.blob->data(), size)) { |
| 94 | ALOGE("listProperties, cannot parse reply"); |
| 95 | return holder; |
| 96 | } |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 97 | holder = new VehiclePropertiesHolder(); |
| 98 | ASSERT_OR_HANDLE_NO_MEMORY(holder.get(), return); |
| 99 | status = VehicleNetworkProtoUtil::fromVehiclePropConfigs(*configs.get(), |
| 100 | holder->getList()); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 101 | if (status != NO_ERROR) { |
| 102 | ALOGE("listProperties, cannot convert VehiclePropConfigs %d", status); |
| 103 | return holder; |
| 104 | } |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 105 | |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 106 | } |
| 107 | return holder; |
| 108 | } |
| 109 | |
| 110 | virtual status_t setProperty(const vehicle_prop_value_t& value) { |
| 111 | Parcel data, reply; |
| 112 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
keunyoung | 7d74e6d | 2015-10-14 15:43:10 -0700 | [diff] [blame] | 113 | status_t status = VehiclePropValueBinderUtil::writeToParcel(data, value); |
| 114 | if (status != NO_ERROR) { |
| 115 | return status; |
| 116 | } |
| 117 | status = remote()->transact(SET_PROPERTY, data, &reply); |
Keun-young Park | 883a241 | 2016-04-25 18:59:22 -0700 | [diff] [blame] | 118 | if (status == NO_ERROR) { |
| 119 | int32_t exceptionCode = reply.readExceptionCode(); |
| 120 | if (exceptionCode != NO_ERROR) { |
| 121 | if (exceptionCode == binder::Status::EX_SERVICE_SPECIFIC) { |
| 122 | return -EAGAIN; |
| 123 | } else if (exceptionCode == binder::Status::EX_ILLEGAL_STATE) { |
| 124 | return -ESHUTDOWN; |
| 125 | } |
| 126 | return exceptionCode; |
| 127 | } |
| 128 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 129 | return status; |
| 130 | } |
| 131 | |
| 132 | virtual status_t getProperty(vehicle_prop_value_t* value) { |
| 133 | Parcel data, reply; |
keunyoung | 7d74e6d | 2015-10-14 15:43:10 -0700 | [diff] [blame] | 134 | if (value == NULL) { |
| 135 | return BAD_VALUE; |
| 136 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 137 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
keunyoung | 7d74e6d | 2015-10-14 15:43:10 -0700 | [diff] [blame] | 138 | status_t status = VehiclePropValueBinderUtil::writeToParcel(data, *value); |
| 139 | if (status != NO_ERROR) { |
| 140 | ALOGE("getProperty, cannot write"); |
| 141 | return status; |
| 142 | } |
| 143 | status = remote()->transact(GET_PROPERTY, data, &reply); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 144 | if (status == NO_ERROR) { |
Keun-young Park | ba48548 | 2016-03-24 13:24:31 -0700 | [diff] [blame] | 145 | int32_t exceptionCode = reply.readExceptionCode(); |
| 146 | if (exceptionCode != NO_ERROR) { |
| 147 | if (exceptionCode == binder::Status::EX_SERVICE_SPECIFIC) { |
| 148 | return -EAGAIN; |
Steve Paik | b224b85 | 2016-07-08 16:11:43 -0700 | [diff] [blame] | 149 | } else if (exceptionCode == binder::Status::EX_ILLEGAL_STATE) { |
| 150 | return -ESHUTDOWN; |
Keun-young Park | ba48548 | 2016-03-24 13:24:31 -0700 | [diff] [blame] | 151 | } |
| 152 | return exceptionCode; |
| 153 | } |
keunyoung | 7d74e6d | 2015-10-14 15:43:10 -0700 | [diff] [blame] | 154 | status = VehiclePropValueBinderUtil::readFromParcel(reply, value); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 155 | } |
| 156 | return status; |
| 157 | } |
| 158 | |
| 159 | virtual status_t subscribe(const sp<IVehicleNetworkListener> &listener, int32_t property, |
Pavel Maltsev | b0324b4 | 2016-09-27 21:00:41 -0700 | [diff] [blame] | 160 | float sampleRate, int32_t zones, int32_t flags) { |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 161 | Parcel data, reply; |
| 162 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 163 | data.writeStrongBinder(IInterface::asBinder(listener)); |
| 164 | data.writeInt32(property); |
| 165 | data.writeFloat(sampleRate); |
Keun-young Park | 0727f95 | 2015-12-21 14:30:07 -0800 | [diff] [blame] | 166 | data.writeInt32(zones); |
Pavel Maltsev | b0324b4 | 2016-09-27 21:00:41 -0700 | [diff] [blame] | 167 | data.writeInt32(flags); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 168 | status_t status = remote()->transact(SUBSCRIBE, data, &reply); |
| 169 | return status; |
| 170 | } |
| 171 | |
| 172 | virtual void unsubscribe(const sp<IVehicleNetworkListener> &listener, int32_t property) { |
| 173 | Parcel data, reply; |
| 174 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 175 | data.writeStrongBinder(IInterface::asBinder(listener)); |
| 176 | data.writeInt32(property); |
| 177 | status_t status = remote()->transact(UNSUBSCRIBE, data, &reply); |
| 178 | if (status != NO_ERROR) { |
| 179 | ALOGI("unsubscribing property %d failed %d", property, status); |
| 180 | } |
| 181 | } |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 182 | |
| 183 | virtual status_t injectEvent(const vehicle_prop_value_t& value) { |
| 184 | Parcel data, reply; |
| 185 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 186 | data.writeInt32(1); // 0 means no value. For compatibility with aidl based code. |
| 187 | std::unique_ptr<VehiclePropValue> v(new VehiclePropValue()); |
| 188 | ASSERT_OR_HANDLE_NO_MEMORY(v.get(), return NO_MEMORY); |
| 189 | VehicleNetworkProtoUtil::toVehiclePropValue(value, *v.get()); |
| 190 | int size = v->ByteSize(); |
| 191 | WritableBlobHolder blob(new Parcel::WritableBlob()); |
| 192 | ASSERT_OR_HANDLE_NO_MEMORY(blob.blob, return NO_MEMORY); |
| 193 | data.writeInt32(size); |
| 194 | data.writeBlob(size, false, blob.blob); |
| 195 | v->SerializeToArray(blob.blob->data(), size); |
| 196 | status_t status = remote()->transact(INJECT_EVENT, data, &reply); |
| 197 | return status; |
| 198 | } |
| 199 | |
| 200 | virtual status_t startMocking(const sp<IVehicleNetworkHalMock>& mock) { |
| 201 | Parcel data, reply; |
| 202 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 203 | data.writeStrongBinder(IInterface::asBinder(mock)); |
| 204 | status_t status = remote()->transact(START_MOCKING, data, &reply); |
| 205 | return status; |
| 206 | } |
| 207 | |
| 208 | virtual void stopMocking(const sp<IVehicleNetworkHalMock>& mock) { |
| 209 | Parcel data, reply; |
| 210 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 211 | data.writeStrongBinder(IInterface::asBinder(mock)); |
| 212 | status_t status = remote()->transact(STOP_MOCKING, data, &reply); |
| 213 | if (status != NO_ERROR) { |
| 214 | ALOGI("stop mocking failed %d", status); |
| 215 | } |
| 216 | } |
Keun-young Park | 28dd470 | 2015-11-19 18:06:04 -0800 | [diff] [blame] | 217 | |
| 218 | status_t injectHalError(int32_t errorCode, int32_t property, int32_t operation) { |
| 219 | Parcel data, reply; |
| 220 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 221 | data.writeInt32(errorCode); |
| 222 | data.writeInt32(property); |
| 223 | data.writeInt32(operation); |
| 224 | status_t status = remote()->transact(INJECT_HAL_ERROR, data, &reply); |
| 225 | return status; |
| 226 | } |
| 227 | |
| 228 | virtual status_t startErrorListening(const sp<IVehicleNetworkListener> &listener) { |
| 229 | Parcel data, reply; |
| 230 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 231 | data.writeStrongBinder(IInterface::asBinder(listener)); |
| 232 | status_t status = remote()->transact(START_ERROR_LISTENING, data, &reply); |
| 233 | return status; |
| 234 | } |
| 235 | |
| 236 | virtual void stopErrorListening(const sp<IVehicleNetworkListener> &listener) { |
| 237 | Parcel data, reply; |
| 238 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 239 | data.writeStrongBinder(IInterface::asBinder(listener)); |
| 240 | status_t status = remote()->transact(STOP_ERROR_LISTENING, data, &reply); |
| 241 | if (status != NO_ERROR) { |
| 242 | ALOGI("stopErrorListening %d", status); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | virtual status_t startHalRestartMonitoring(const sp<IVehicleNetworkListener> &listener) { |
| 247 | Parcel data, reply; |
| 248 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 249 | data.writeStrongBinder(IInterface::asBinder(listener)); |
| 250 | status_t status = remote()->transact(START_HAL_RESTART_MONITORING, data, &reply); |
| 251 | return status; |
| 252 | } |
| 253 | |
| 254 | virtual void stopHalRestartMonitoring(const sp<IVehicleNetworkListener> &listener) { |
| 255 | Parcel data, reply; |
| 256 | data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor()); |
| 257 | data.writeStrongBinder(IInterface::asBinder(listener)); |
| 258 | status_t status = remote()->transact(STOP_HAL_RESTART_MONITORING, data, &reply); |
| 259 | if (status != NO_ERROR) { |
| 260 | ALOGI("stopHalRestartMonitoring %d", status); |
| 261 | } |
| 262 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | IMPLEMENT_META_INTERFACE(VehicleNetwork, IVehicleNetwork::SERVICE_NAME); |
| 266 | |
| 267 | // ---------------------------------------------------------------------- |
| 268 | |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 269 | status_t BnVehicleNetwork::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 270 | uint32_t flags) { |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 271 | status_t r; |
| 272 | switch (code) { |
| 273 | case LIST_PROPERTIES: { |
| 274 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 275 | if (!isOperationAllowed(0, false)) { |
| 276 | return PERMISSION_DENIED; |
| 277 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 278 | int32_t property = data.readInt32(); |
| 279 | sp<VehiclePropertiesHolder> holder = listProperties(property); |
| 280 | if (holder.get() == NULL) { // given property not found |
keunyoung | 15882e5 | 2015-09-16 16:57:58 -0700 | [diff] [blame] | 281 | BinderUtil::fillObjectResultReply(reply, false /* isValid */); |
| 282 | return NO_ERROR; |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 283 | } |
| 284 | std::unique_ptr<VehiclePropConfigs> configs(new VehiclePropConfigs()); |
| 285 | ASSERT_OR_HANDLE_NO_MEMORY(configs.get(), return NO_MEMORY); |
keunyoung | d32f4e6 | 2015-09-21 11:33:06 -0700 | [diff] [blame] | 286 | VehicleNetworkProtoUtil::toVehiclePropConfigs(holder->getList(), *configs.get()); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 287 | int size = configs->ByteSize(); |
| 288 | WritableBlobHolder blob(new Parcel::WritableBlob()); |
| 289 | ASSERT_OR_HANDLE_NO_MEMORY(blob.blob, return NO_MEMORY); |
keunyoung | 15882e5 | 2015-09-16 16:57:58 -0700 | [diff] [blame] | 290 | BinderUtil::fillObjectResultReply(reply, true); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 291 | reply->writeInt32(size); |
| 292 | reply->writeBlob(size, false, blob.blob); |
| 293 | configs->SerializeToArray(blob.blob->data(), size); |
| 294 | return NO_ERROR; |
| 295 | } break; |
| 296 | case SET_PROPERTY: { |
| 297 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 298 | ScopedVehiclePropValue value; |
keunyoung | 7d74e6d | 2015-10-14 15:43:10 -0700 | [diff] [blame] | 299 | r = VehiclePropValueBinderUtil::readFromParcel(data, &value.value, |
| 300 | false /* deleteMembers */); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 301 | if (r != NO_ERROR) { |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 302 | return r; |
| 303 | } |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 304 | if (!isOperationAllowed(value.value.prop, true)) { |
| 305 | return PERMISSION_DENIED; |
| 306 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 307 | r = setProperty(value.value); |
Keun-young Park | 883a241 | 2016-04-25 18:59:22 -0700 | [diff] [blame] | 308 | if (r == NO_ERROR) { |
| 309 | reply->writeNoException(); |
| 310 | } else if (r == -EAGAIN) { |
| 311 | // this should be handled specially to throw ServiceSpecificException in java. |
| 312 | reply->writeInt32(binder::Status::EX_SERVICE_SPECIFIC); |
| 313 | return NO_ERROR; |
| 314 | } else if (r == -ESHUTDOWN) { |
| 315 | // this should be handled specially to throw IllegalStateException in java. |
| 316 | reply->writeInt32(binder::Status::EX_ILLEGAL_STATE); |
| 317 | return NO_ERROR; |
| 318 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 319 | return r; |
| 320 | } break; |
| 321 | case GET_PROPERTY: { |
| 322 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 323 | vehicle_prop_value_t value; |
| 324 | memset(&value, 0, sizeof(value)); |
| 325 | r = VehiclePropValueBinderUtil::readFromParcel(data, &value, |
keunyoung | 7d74e6d | 2015-10-14 15:43:10 -0700 | [diff] [blame] | 326 | false /* deleteMembers */, true /*canIgnoreNoData*/); |
| 327 | if (r != NO_ERROR) { |
| 328 | ALOGE("getProperty cannot read %d", r); |
| 329 | return r; |
| 330 | } |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 331 | if (!isOperationAllowed(value.prop, false)) { |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 332 | return PERMISSION_DENIED; |
| 333 | } |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 334 | r = getProperty(&value); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 335 | if (r == NO_ERROR) { |
Steve Paik | b224b85 | 2016-07-08 16:11:43 -0700 | [diff] [blame] | 336 | // If int32 or float value is out of range, throw an exception: |
| 337 | switch (value.value_type) { |
| 338 | case VEHICLE_VALUE_TYPE_INT32: |
| 339 | case VEHICLE_VALUE_TYPE_ZONED_INT32: |
Steve Paik | b224b85 | 2016-07-08 16:11:43 -0700 | [diff] [blame] | 340 | if (value.value.int32_value == VEHICLE_INT_OUT_OF_RANGE_OFF) { |
| 341 | // this should be handled specially to throw IllegalStateException in java. |
| 342 | reply->writeInt32(binder::Status::EX_ILLEGAL_STATE); |
| 343 | return NO_ERROR; |
| 344 | } |
| 345 | break; |
| 346 | case VEHICLE_VALUE_TYPE_FLOAT: |
| 347 | case VEHICLE_VALUE_TYPE_ZONED_FLOAT: |
Steve Paik | b224b85 | 2016-07-08 16:11:43 -0700 | [diff] [blame] | 348 | if (value.value.float_value == VEHICLE_FLOAT_OUT_OF_RANGE_OFF) { |
| 349 | // this should be handled specially to throw IllegalStateException in java. |
| 350 | reply->writeInt32(binder::Status::EX_ILLEGAL_STATE); |
| 351 | return NO_ERROR; |
| 352 | } |
| 353 | break; |
| 354 | } |
keunyoung | 7d74e6d | 2015-10-14 15:43:10 -0700 | [diff] [blame] | 355 | reply->writeNoException(); |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 356 | r = VehiclePropValueBinderUtil::writeToParcel(*reply, value); |
| 357 | releaseMemoryFromGet(&value); |
Keun-young Park | ba48548 | 2016-03-24 13:24:31 -0700 | [diff] [blame] | 358 | } else if (r == -EAGAIN) { |
| 359 | // this should be handled specially to throw ServiceSpecificException in java. |
| 360 | reply->writeInt32(binder::Status::EX_SERVICE_SPECIFIC); |
| 361 | return NO_ERROR; |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 362 | } |
| 363 | return r; |
| 364 | } break; |
| 365 | case SUBSCRIBE: { |
| 366 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 367 | sp<IVehicleNetworkListener> listener = |
| 368 | interface_cast<IVehicleNetworkListener>(data.readStrongBinder()); |
| 369 | int32_t property = data.readInt32(); |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 370 | if (!isOperationAllowed(property, false)) { |
| 371 | return PERMISSION_DENIED; |
| 372 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 373 | float sampleRate = data.readFloat(); |
Keun-young Park | 0727f95 | 2015-12-21 14:30:07 -0800 | [diff] [blame] | 374 | int32_t zones = data.readInt32(); |
Pavel Maltsev | b0324b4 | 2016-09-27 21:00:41 -0700 | [diff] [blame] | 375 | int32_t flags = data.readInt32(); |
| 376 | r = subscribe(listener, property, sampleRate, zones, flags); |
keunyoung | 15882e5 | 2015-09-16 16:57:58 -0700 | [diff] [blame] | 377 | BinderUtil::fillNoResultReply(reply); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 378 | return r; |
| 379 | } break; |
| 380 | case UNSUBSCRIBE: { |
| 381 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 382 | sp<IVehicleNetworkListener> listener = |
| 383 | interface_cast<IVehicleNetworkListener>(data.readStrongBinder()); |
| 384 | int32_t property = data.readInt32(); |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 385 | if (!isOperationAllowed(property, false)) { |
| 386 | return PERMISSION_DENIED; |
| 387 | } |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 388 | unsubscribe(listener, property); |
keunyoung | 15882e5 | 2015-09-16 16:57:58 -0700 | [diff] [blame] | 389 | BinderUtil::fillNoResultReply(reply); |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 390 | return NO_ERROR; |
| 391 | } break; |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 392 | case INJECT_EVENT: { |
| 393 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 394 | if (data.readInt32() == 0) { // java side allows passing null with this. |
| 395 | return BAD_VALUE; |
| 396 | } |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 397 | if (!isOperationAllowed(0, true)) { |
| 398 | return PERMISSION_DENIED; |
| 399 | } |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 400 | ScopedVehiclePropValue value; |
| 401 | ReadableBlobHolder blob(new Parcel::ReadableBlob()); |
| 402 | ASSERT_OR_HANDLE_NO_MEMORY(blob.blob, return NO_MEMORY); |
| 403 | int32_t size = data.readInt32(); |
Keun-young Park | 20539ba | 2016-10-10 17:57:34 -0700 | [diff] [blame] | 404 | if (size < 0) { |
| 405 | ALOGE("injectEvent:service, bad blob size %d", size); |
| 406 | return BAD_VALUE; |
| 407 | } |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 408 | r = data.readBlob(size, blob.blob); |
| 409 | if (r != NO_ERROR) { |
| 410 | ALOGE("injectEvent:service, cannot read blob"); |
| 411 | return r; |
| 412 | } |
| 413 | std::unique_ptr<VehiclePropValue> v(new VehiclePropValue()); |
| 414 | ASSERT_OR_HANDLE_NO_MEMORY(v.get(), return NO_MEMORY); |
| 415 | if (!v->ParseFromArray(blob.blob->data(), size)) { |
| 416 | ALOGE("injectEvent:service, cannot parse data"); |
| 417 | return BAD_VALUE; |
| 418 | } |
| 419 | r = VehicleNetworkProtoUtil::fromVehiclePropValue(*v.get(), value.value); |
| 420 | if (r != NO_ERROR) { |
| 421 | ALOGE("injectEvent:service, cannot convert data"); |
| 422 | return BAD_VALUE; |
| 423 | } |
| 424 | r = injectEvent(value.value); |
| 425 | BinderUtil::fillNoResultReply(reply); |
| 426 | return r; |
| 427 | } break; |
| 428 | case START_MOCKING: { |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 429 | if (!isOperationAllowed(0, true)) { |
| 430 | return PERMISSION_DENIED; |
| 431 | } |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 432 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 433 | sp<IVehicleNetworkHalMock> mock = |
| 434 | interface_cast<IVehicleNetworkHalMock>(data.readStrongBinder()); |
| 435 | r = startMocking(mock); |
| 436 | BinderUtil::fillNoResultReply(reply); |
| 437 | return r; |
| 438 | } break; |
| 439 | case STOP_MOCKING: { |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 440 | if (!isOperationAllowed(0, true)) { |
| 441 | return PERMISSION_DENIED; |
| 442 | } |
keunyoung | 1ab8e18 | 2015-09-24 09:25:22 -0700 | [diff] [blame] | 443 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 444 | sp<IVehicleNetworkHalMock> mock = |
| 445 | interface_cast<IVehicleNetworkHalMock>(data.readStrongBinder()); |
| 446 | stopMocking(mock); |
| 447 | BinderUtil::fillNoResultReply(reply); |
| 448 | return NO_ERROR; |
| 449 | } break; |
Keun-young Park | 28dd470 | 2015-11-19 18:06:04 -0800 | [diff] [blame] | 450 | case INJECT_HAL_ERROR: { |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 451 | if (!isOperationAllowed(0, true)) { |
| 452 | return PERMISSION_DENIED; |
| 453 | } |
Keun-young Park | 28dd470 | 2015-11-19 18:06:04 -0800 | [diff] [blame] | 454 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 455 | int32_t errorCode = data.readInt32(); |
| 456 | int32_t property = data.readInt32(); |
| 457 | int32_t operation = data.readInt32(); |
| 458 | r = injectHalError(errorCode, property, operation); |
| 459 | BinderUtil::fillNoResultReply(reply); |
| 460 | return r; |
| 461 | } break; |
| 462 | case START_ERROR_LISTENING: { |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 463 | if (!isOperationAllowed(0, false)) { |
| 464 | return PERMISSION_DENIED; |
| 465 | } |
Keun-young Park | 28dd470 | 2015-11-19 18:06:04 -0800 | [diff] [blame] | 466 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 467 | sp<IVehicleNetworkListener> listener = |
| 468 | interface_cast<IVehicleNetworkListener>(data.readStrongBinder()); |
| 469 | r = startErrorListening(listener); |
| 470 | BinderUtil::fillNoResultReply(reply); |
| 471 | return r; |
| 472 | } break; |
| 473 | case STOP_ERROR_LISTENING: { |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 474 | if (!isOperationAllowed(0, false)) { |
| 475 | return PERMISSION_DENIED; |
| 476 | } |
Keun-young Park | 28dd470 | 2015-11-19 18:06:04 -0800 | [diff] [blame] | 477 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 478 | sp<IVehicleNetworkListener> listener = |
| 479 | interface_cast<IVehicleNetworkListener>(data.readStrongBinder()); |
| 480 | stopErrorListening(listener); |
| 481 | BinderUtil::fillNoResultReply(reply); |
| 482 | return NO_ERROR; |
| 483 | } break; |
| 484 | case START_HAL_RESTART_MONITORING: { |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 485 | if (!isOperationAllowed(0, false)) { |
| 486 | return PERMISSION_DENIED; |
| 487 | } |
Keun-young Park | 28dd470 | 2015-11-19 18:06:04 -0800 | [diff] [blame] | 488 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 489 | sp<IVehicleNetworkListener> listener = |
| 490 | interface_cast<IVehicleNetworkListener>(data.readStrongBinder()); |
| 491 | r = startHalRestartMonitoring(listener); |
| 492 | BinderUtil::fillNoResultReply(reply); |
| 493 | return r; |
| 494 | } break; |
| 495 | case STOP_HAL_RESTART_MONITORING: { |
Keun-young Park | 737cdfb | 2016-02-12 15:11:39 -0800 | [diff] [blame] | 496 | if (!isOperationAllowed(0, false)) { |
| 497 | return PERMISSION_DENIED; |
| 498 | } |
Keun-young Park | 28dd470 | 2015-11-19 18:06:04 -0800 | [diff] [blame] | 499 | CHECK_INTERFACE(IVehicleNetwork, data, reply); |
| 500 | sp<IVehicleNetworkListener> listener = |
| 501 | interface_cast<IVehicleNetworkListener>(data.readStrongBinder()); |
| 502 | stopHalRestartMonitoring(listener); |
| 503 | BinderUtil::fillNoResultReply(reply); |
| 504 | return NO_ERROR; |
| 505 | } break; |
keunyoung | e18e25d | 2015-08-28 15:57:19 -0700 | [diff] [blame] | 506 | default: |
| 507 | return BBinder::onTransact(code, data, reply, flags); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | }; // namespace android |