• 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/single_scan_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 SingleScanSettings::writeToParcel(::android::Parcel* parcel) const {
32   RETURN_IF_FAILED(parcel->writeInt32(channel_settings_.size()));
33   for (const auto& channel : channel_settings_) {
34     // For Java readTypedList():
35     // A leading number 1 means this object is not null.
36     RETURN_IF_FAILED(parcel->writeInt32(1));
37     RETURN_IF_FAILED(channel.writeToParcel(parcel));
38   }
39   RETURN_IF_FAILED(parcel->writeInt32(hidden_networks_.size()));
40   for (const auto& network : hidden_networks_) {
41     // For Java readTypedList():
42     // A leading number 1 means this object is not null.
43     RETURN_IF_FAILED(parcel->writeInt32(1));
44     RETURN_IF_FAILED(network.writeToParcel(parcel));
45   }
46   return ::android::OK;
47 }
48 
readFromParcel(const::android::Parcel * parcel)49 status_t SingleScanSettings::readFromParcel(const ::android::Parcel* parcel) {
50   int32_t num_channels = 0;
51   RETURN_IF_FAILED(parcel->readInt32(&num_channels));
52   // Convention used by Java side writeTypedList():
53   // -1 means a null list.
54   // 0 means an empty list.
55   // Both are mapped to an empty vector in C++ code.
56   for (int i = 0; i < num_channels; i++) {
57     ChannelSettings channel;
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(channel.readFromParcel(parcel));
69     channel_settings_.push_back(channel);
70   }
71   int32_t num_hidden_networks = 0;
72   RETURN_IF_FAILED(parcel->readInt32(&num_hidden_networks));
73   // Convention used by Java side writeTypedList():
74   // -1 means a null list.
75   // 0 means an empty list.
76   // Both are mapped to an empty vector in C++ code.
77   for (int i = 0; i < num_hidden_networks; i++) {
78     HiddenNetwork network;
79     // From Java writeTypedList():
80     // A leading number 1 means this object is not null.
81     // We never expect a 0 or other values here.
82     int32_t leading_number = 0;
83     RETURN_IF_FAILED(parcel->readInt32(&leading_number));
84     if (leading_number != 1) {
85       LOG(ERROR) << "Unexpected leading number before an object: "
86                  << leading_number;
87       return ::android::BAD_VALUE;
88     }
89     RETURN_IF_FAILED(network.readFromParcel(parcel));
90     hidden_networks_.push_back(network);
91   }
92   return ::android::OK;
93 }
94 
95 }  // namespace wificond
96 }  // namespace wifi
97 }  // namespace server
98 }  // namespace android
99 }  // namespace com
100