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 30 const uint32_t PnoSettings::kFastScanIterations = 3; 31 const uint32_t PnoSettings::kSlowScanIntervalMultiplier = 3; 32 writeToParcel(::android::Parcel * parcel) const33status_t PnoSettings::writeToParcel(::android::Parcel* parcel) const { 34 RETURN_IF_FAILED(parcel->writeInt64(interval_ms_)); 35 RETURN_IF_FAILED(parcel->writeInt32(min_2g_rssi_)); 36 RETURN_IF_FAILED(parcel->writeInt32(min_5g_rssi_)); 37 RETURN_IF_FAILED(parcel->writeInt32(min_6g_rssi_)); 38 RETURN_IF_FAILED(parcel->writeInt32(pno_networks_.size())); 39 for (const auto& network : pno_networks_) { 40 // For Java readTypedList(): 41 // A leading number 1 means this object is not null. 42 RETURN_IF_FAILED(parcel->writeInt32(1)); 43 RETURN_IF_FAILED(network.writeToParcel(parcel)); 44 } 45 return ::android::OK; 46 } 47 readFromParcel(const::android::Parcel * parcel)48status_t PnoSettings::readFromParcel(const ::android::Parcel* parcel) { 49 RETURN_IF_FAILED(parcel->readInt64(&interval_ms_)); 50 RETURN_IF_FAILED(parcel->readInt32(&min_2g_rssi_)); 51 RETURN_IF_FAILED(parcel->readInt32(&min_5g_rssi_)); 52 RETURN_IF_FAILED(parcel->readInt32(&min_6g_rssi_)); 53 int32_t num_pno_networks = 0; 54 RETURN_IF_FAILED(parcel->readInt32(&num_pno_networks)); 55 for (int i = 0; i < num_pno_networks; i++) { 56 PnoNetwork network; 57 // From Java writeTypedList(): 58 // A leading number 1 means this object is not null. 59 // We never expect a 0 or other values here. 60 int32_t leading_number = 0; 61 RETURN_IF_FAILED(parcel->readInt32(&leading_number)); 62 if (leading_number != 1) { 63 LOG(ERROR) << "Unexpected leading number before an object: " 64 << leading_number; 65 return ::android::BAD_VALUE; 66 } 67 RETURN_IF_FAILED(network.readFromParcel(parcel)); 68 pno_networks_.push_back(network); 69 } 70 return ::android::OK; 71 } 72 73 } // namespace nl80211 74 } // namespace wifi 75 } // namespace net 76 } // namespace android 77