1 // 2 // Copyright (C) 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 "service/common/android/bluetooth/bluetooth_gatt_service.h" 18 #include "service/common/android/bluetooth/bluetooth_gatt_characteristic.h" 19 #include "service/common/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 BluetoothGattService::writeToParcel(Parcel* parcel) const { 32 status_t status = parcel->writeInt32(handle_); 33 if (status != OK) return status; 34 35 status = parcel->writeBool(primary_); 36 if (status != OK) return status; 37 38 status = parcel->writeParcelable((UUID)uuid_); 39 if (status != OK) return status; 40 41 std::vector<BluetoothGattCharacteristic> characteristics; 42 for (const auto& chrc : characteristics_) characteristics.push_back(chrc); 43 44 status = parcel->writeParcelableVector(characteristics); 45 46 std::vector<BluetoothGattIncludedService> includedServices; 47 for (const auto& service : included_services_) 48 includedServices.push_back(service); 49 50 status = parcel->writeParcelableVector(includedServices); 51 52 return status; 53 } 54 readFromParcel(const Parcel * parcel)55status_t BluetoothGattService::readFromParcel(const Parcel* parcel) { 56 int32_t tmp; 57 status_t status = parcel->readInt32(&tmp); 58 if (status != OK) return status; 59 handle_ = tmp; 60 61 status = parcel->readBool(&primary_); 62 if (status != OK) return status; 63 64 UUID uuid; 65 status = parcel->readParcelable(&uuid); 66 if (status != OK) return status; 67 uuid_ = uuid; 68 69 std::vector<BluetoothGattCharacteristic> characteristics; 70 status = parcel->readParcelableVector(&characteristics); 71 if (status != OK) return status; 72 73 for (const auto& chrc : characteristics) characteristics_.push_back(chrc); 74 75 std::vector<BluetoothGattIncludedService> includedServices; 76 status = parcel->readParcelableVector(&includedServices); 77 if (status != OK) return status; 78 79 for (const auto& srvc : includedServices) 80 included_services_.push_back(BluetoothGattService(srvc)); 81 82 return status; 83 } 84 85 } // namespace bluetooth 86 } // namespace android 87