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