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 com { 26 namespace android { 27 namespace server { 28 namespace wifi { 29 namespace wificond { 30 31 const uint32_t PnoSettings::kFastScanIterations = 3; 32 const uint32_t PnoSettings::kSlowScanIntervalMultiplier = 3; 33 writeToParcel(::android::Parcel * parcel) const34status_t PnoSettings::writeToParcel(::android::Parcel* parcel) const { 35 RETURN_IF_FAILED(parcel->writeInt32(interval_ms_)); 36 RETURN_IF_FAILED(parcel->writeInt32(min_2g_rssi_)); 37 RETURN_IF_FAILED(parcel->writeInt32(min_5g_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->readInt32(&interval_ms_)); 50 RETURN_IF_FAILED(parcel->readInt32(&min_2g_rssi_)); 51 RETURN_IF_FAILED(parcel->readInt32(&min_5g_rssi_)); 52 int32_t num_pno_networks = 0; 53 RETURN_IF_FAILED(parcel->readInt32(&num_pno_networks)); 54 for (int i = 0; i < num_pno_networks; i++) { 55 PnoNetwork network; 56 // From Java writeTypedList(): 57 // A leading number 1 means this object is not null. 58 // We never expect a 0 or other values here. 59 int32_t leading_number = 0; 60 RETURN_IF_FAILED(parcel->readInt32(&leading_number)); 61 if (leading_number != 1) { 62 LOG(ERROR) << "Unexpected leading number before an object: " 63 << leading_number; 64 return ::android::BAD_VALUE; 65 } 66 RETURN_IF_FAILED(network.readFromParcel(parcel)); 67 pno_networks_.push_back(network); 68 } 69 return ::android::OK; 70 } 71 72 } // namespace wificond 73 } // namespace wifi 74 } // namespace server 75 } // namespace android 76 } // namespace com 77