Home | History | Annotate | Download | only in bluetooth
      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/scan_result.h"
     18 
     19 #include <base/logging.h>
     20 #include <binder/Parcel.h>
     21 #include <utils/String16.h>
     22 #include <utils/String8.h>
     23 
     24 using android::Parcelable;
     25 using android::Parcel;
     26 using android::String8;
     27 using android::String16;
     28 using android::status_t;
     29 using android::OK;
     30 
     31 namespace android {
     32 namespace bluetooth {
     33 
     34 status_t ScanResult::writeToParcel(Parcel* parcel) const {
     35   status_t status =
     36       parcel->writeString16(String16(String8(device_address_.c_str())));
     37   if (status != OK) return status;
     38 
     39   status = parcel->writeByteVector(scan_record_);
     40   if (status != OK) return status;
     41 
     42   status = parcel->writeInt32(rssi_);
     43   return status;
     44 }
     45 
     46 status_t ScanResult::readFromParcel(const Parcel* parcel) {
     47   String16 addr;
     48   status_t status = parcel->readString16(&addr);
     49   if (status != OK) return status;
     50   device_address_ = std::string(String8(addr).string());
     51 
     52   status = parcel->readByteVector(&scan_record_);
     53   if (status != OK) return status;
     54 
     55   status = parcel->readInt32(&rssi_);
     56   return status;
     57 }
     58 
     59 }  // namespace bluetooth
     60 }  // namespace android
     61