1 // 2 // Copyright 2017 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_remote_device_props.h" 18 19 #include <utils/String16.h> 20 #include <utils/String8.h> 21 22 #include "android/bluetooth/uuid.h" 23 24 using android::OK; 25 using android::String16; 26 using android::String8; 27 28 namespace android { 29 namespace bluetooth { 30 writeToParcel(Parcel * parcel) const31status_t BluetoothRemoteDeviceProps::writeToParcel(Parcel* parcel) const { 32 status_t status = 33 parcel->writeString16(String16(name_.c_str(), name_.size())); 34 if (status != OK) return status; 35 36 status = parcel->writeString16(String16(address_.c_str(), address_.size())); 37 if (status != OK) return status; 38 39 std::vector<UUID> uuids; 40 for (const auto& uuid : service_uuids_) { 41 uuids.push_back(uuid); 42 } 43 44 status = parcel->writeParcelableVector(uuids); 45 if (status != OK) return status; 46 47 status = parcel->writeInt32(device_class_); 48 if (status != OK) return status; 49 50 status = parcel->writeInt32(device_type_); 51 if (status != OK) return status; 52 53 status = parcel->writeInt32(rssi_); 54 if (status != OK) return status; 55 56 return status; 57 } 58 readFromParcel(const Parcel * parcel)59status_t BluetoothRemoteDeviceProps::readFromParcel(const Parcel* parcel) { 60 String16 name; 61 status_t status = parcel->readString16(&name); 62 if (status != OK) return status; 63 name_ = String8(name).string(); 64 65 String16 address; 66 status = parcel->readString16(&address); 67 if (status != OK) return status; 68 address_ = String8(address).string(); 69 70 std::vector<UUID> uuids; 71 status = parcel->readParcelableVector(&uuids); 72 if (status != OK) return status; 73 74 for (const auto& uuid : uuids) { 75 service_uuids_.push_back(uuid.uuid); 76 } 77 78 status = parcel->readInt32(&device_class_); 79 if (status != OK) return status; 80 81 status = parcel->readInt32(&device_type_); 82 if (status != OK) return status; 83 84 status = parcel->readInt32(&rssi_); 85 if (status != OK) return status; 86 87 return status; 88 } 89 90 } // namespace bluetooth 91 } // namespace android 92