1 // 2 // Copyright 2015 Google, Inc. 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 #include "android/bluetooth/bluetooth_gatt_characteristic.h" 18 #include "android/bluetooth/bluetooth_gatt_descriptor.h" 19 #include "android/bluetooth/uuid.h" 20 21 #include <utils/String16.h> 22 #include <utils/String8.h> 23 24 using android::OK; 25 using android::String8; 26 using android::String16; 27 28 namespace android { 29 namespace bluetooth { 30 writeToParcel(Parcel * parcel) const31status_t BluetoothGattCharacteristic::writeToParcel(Parcel* parcel) const { 32 status_t status = parcel->writeInt32(handle_); 33 if (status != OK) return status; 34 35 status = parcel->writeParcelable((UUID)uuid_); 36 if (status != OK) return status; 37 38 status = parcel->writeInt32(properties_); 39 if (status != OK) return status; 40 41 status = parcel->writeInt32(permissions_); 42 if (status != OK) return status; 43 44 std::vector<BluetoothGattDescriptor> descriptors; 45 for (const auto& desc : descriptors_) { 46 descriptors.push_back(desc); 47 } 48 49 status = parcel->writeParcelableVector(descriptors); 50 return status; 51 } 52 readFromParcel(const Parcel * parcel)53status_t BluetoothGattCharacteristic::readFromParcel(const Parcel* parcel) { 54 int32_t tmp; 55 status_t status = parcel->readInt32(&tmp); 56 if (status != OK) return status; 57 handle_ = tmp; 58 59 UUID uuid; 60 status = parcel->readParcelable(&uuid); 61 if (status != OK) return status; 62 uuid_ = uuid.uuid; 63 64 status = parcel->readInt32(&tmp); 65 if (status != OK) return status; 66 properties_ = tmp; 67 68 status = parcel->readInt32(&tmp); 69 if (status != OK) return status; 70 permissions_ = tmp; 71 72 std::vector<BluetoothGattDescriptor> descriptors; 73 status = parcel->readParcelableVector(&descriptors); 74 if (status != OK) return status; 75 76 for (const auto& desc : descriptors) { 77 descriptors_.push_back(desc); 78 } 79 80 return status; 81 } 82 83 } // namespace bluetooth 84 } // namespace android 85