OSDN Git Service

Add parcelable class PnoNetwork
authorNingyuan Wang <nywang@google.com>
Wed, 7 Dec 2016 21:22:36 +0000 (13:22 -0800)
committerNingyuan Wang <nywang@google.com>
Wed, 7 Dec 2016 21:50:07 +0000 (13:50 -0800)
Bug: 33011588
Change-Id: I528112cf4483313511380fd13daf0e7ac0237d19
Test: compile, unit tests

Android.mk
scanning/pno_network.cpp [new file with mode: 0644]
scanning/pno_network.h [new file with mode: 0644]
tests/scan_settings_unittest.cpp

index df0b923..333527e 100644 (file)
@@ -60,6 +60,7 @@ LOCAL_SRC_FILES := \
     rtt/rtt_controller_impl.cpp \
     scanning/channel_settings.cpp \
     scanning/hidden_network.cpp \
+    scanning/pno_network.cpp \
     scanning/scan_result.cpp \
     scanning/single_scan_settings.cpp \
     scanning/scan_utils.cpp \
diff --git a/scanning/pno_network.cpp b/scanning/pno_network.cpp
new file mode 100644 (file)
index 0000000..48e12ac
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wificond/scanning/pno_network.h"
+
+#include <android-base/logging.h>
+
+#include "wificond/parcelable_utils.h"
+
+using android::status_t;
+
+namespace com {
+namespace android {
+namespace server {
+namespace wifi {
+namespace wificond {
+
+status_t PnoNetwork::writeToParcel(::android::Parcel* parcel) const {
+  // This redundant writing of vector length is needed by Java side parsing.
+  // See writeToPracel() in wificond/scanning/scan_result.cpp for detailed
+  // explanation.
+  RETURN_IF_FAILED(parcel->writeInt32(ssid_.size()));
+  RETURN_IF_FAILED(parcel->writeByteVector(ssid_));
+  return ::android::OK;
+}
+
+status_t PnoNetwork::readFromParcel(const ::android::Parcel* parcel) {
+  int32_t ignored = 0;
+  RETURN_IF_FAILED(parcel->readInt32(&ignored));
+  RETURN_IF_FAILED(parcel->readByteVector(&ssid_));
+  return ::android::OK;
+}
+
+}  // namespace wificond
+}  // namespace wifi
+}  // namespace server
+}  // namespace android
+}  // namespace com
diff --git a/scanning/pno_network.h b/scanning/pno_network.h
new file mode 100644 (file)
index 0000000..6239096
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WIFICOND_SCANNING_PNO_NETWORK_H_
+#define WIFICOND_SCANNING_PNO_NETWORK_H_
+
+#include <vector>
+
+#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
+
+namespace com {
+namespace android {
+namespace server {
+namespace wifi {
+namespace wificond {
+
+class PnoNetwork : public ::android::Parcelable {
+ public:
+  PnoNetwork() = default;
+  bool operator==(const PnoNetwork& rhs) const {
+    return ssid_ == rhs.ssid_;
+  }
+  ::android::status_t writeToParcel(::android::Parcel* parcel) const override;
+  ::android::status_t readFromParcel(const ::android::Parcel* parcel) override;
+
+  std::vector<uint8_t> ssid_;
+};
+
+}  // namespace wificond
+}  // namespace wifi
+}  // namespace server
+}  // namespace android
+}  // namespace com
+
+#endif  // WIFICOND_SCANNING_PNO_NETWORK_H_
index 37f8210..b67ddf7 100644 (file)
 
 #include "wificond/scanning/channel_settings.h"
 #include "wificond/scanning/hidden_network.h"
+#include "wificond/scanning/pno_network.h"
 #include "wificond/scanning/single_scan_settings.h"
 
 using ::com::android::server::wifi::wificond::ChannelSettings;
 using ::com::android::server::wifi::wificond::HiddenNetwork;
+using ::com::android::server::wifi::wificond::PnoNetwork;
 using ::com::android::server::wifi::wificond::SingleScanSettings;
 using std::vector;
 
@@ -100,5 +102,21 @@ TEST_F(ScanSettingsTest, SingleScanSettingsParcelableTest) {
   EXPECT_EQ(scan_settings, scan_settings_copy);
 }
 
+TEST_F(ScanSettingsTest, PnoNetworkParcelableTest) {
+  PnoNetwork pno_network;
+  pno_network.ssid_ =
+      vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
+
+  Parcel parcel;
+  EXPECT_EQ(::android::OK, pno_network.writeToParcel(&parcel));
+
+  PnoNetwork pno_network_copy;
+  parcel.setDataPosition(0);
+  EXPECT_EQ(::android::OK, pno_network_copy.readFromParcel(&parcel));
+
+  EXPECT_EQ(pno_network, pno_network_copy);
+}
+
+
 }  // namespace wificond
 }  // namespace android