1 /* 2 * Copyright (C) 2016 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 #include "wificond/scanning/pno_settings.h" 18 19 #include <android-base/logging.h> 20 21 #include "wificond/parcelable_utils.h" 22 23 using android::status_t; 24 25 namespace android { 26 namespace net { 27 namespace wifi { 28 namespace nl80211 { 29 writeToParcel(::android::Parcel * parcel) const30status_t PnoSettings::writeToParcel(::android::Parcel* parcel) const { 31 RETURN_IF_FAILED(parcel->writeInt64(interval_ms_)); 32 RETURN_IF_FAILED(parcel->writeInt32(min_2g_rssi_)); 33 RETURN_IF_FAILED(parcel->writeInt32(min_5g_rssi_)); 34 RETURN_IF_FAILED(parcel->writeInt32(min_6g_rssi_)); 35 RETURN_IF_FAILED(parcel->writeUint32(scan_iterations_)); 36 RETURN_IF_FAILED(parcel->writeUint32(scan_interval_multiplier_)); 37 RETURN_IF_FAILED(parcel->writeInt32(pno_networks_.size())); 38 for (const auto& network : pno_networks_) { 39 // For Java readTypedList(): 40 // A leading number 1 means this object is not null. 41 RETURN_IF_FAILED(parcel->writeInt32(1)); 42 RETURN_IF_FAILED(network.writeToParcel(parcel)); 43 } 44 return ::android::OK; 45 } 46 readFromParcel(const::android::Parcel * parcel)47status_t PnoSettings::readFromParcel(const ::android::Parcel* parcel) { 48 RETURN_IF_FAILED(parcel->readInt64(&interval_ms_)); 49 RETURN_IF_FAILED(parcel->readInt32(&min_2g_rssi_)); 50 RETURN_IF_FAILED(parcel->readInt32(&min_5g_rssi_)); 51 RETURN_IF_FAILED(parcel->readInt32(&min_6g_rssi_)); 52 RETURN_IF_FAILED(parcel->readUint32(&scan_iterations_)); 53 RETURN_IF_FAILED(parcel->readUint32(&scan_interval_multiplier_)); 54 int32_t num_pno_networks = 0; 55 RETURN_IF_FAILED(parcel->readInt32(&num_pno_networks)); 56 for (int i = 0; i < num_pno_networks; i++) { 57 PnoNetwork network; 58 // From Java writeTypedList(): 59 // A leading number 1 means this object is not null. 60 // We never expect a 0 or other values here. 61 int32_t leading_number = 0; 62 RETURN_IF_FAILED(parcel->readInt32(&leading_number)); 63 if (leading_number != 1) { 64 LOG(ERROR) << "Unexpected leading number before an object: " 65 << leading_number; 66 return ::android::BAD_VALUE; 67 } 68 RETURN_IF_FAILED(network.readFromParcel(parcel)); 69 pno_networks_.push_back(network); 70 } 71 return ::android::OK; 72 } 73 74 } // namespace nl80211 75 } // namespace wifi 76 } // namespace net 77 } // namespace android 78