OSDN Git Service

Wificond: Expose IChip and IClientInterface object
authorNingyuan Wang <nywang@google.com>
Tue, 14 Jun 2016 18:35:58 +0000 (11:35 -0700)
committerNingyuan Wang <nywang@google.com>
Wed, 15 Jun 2016 23:50:00 +0000 (16:50 -0700)
This CL enabls wificond to expose chips and client
interfaces through binder.

This also adds an intergration test to verify we can
access these objects through binder.

BUG=29222398
TEST=compile
TEST=unit tests passed
TEST=new intergration tests passed

Change-Id: I352928de382aa22e9bdb27e9dfb49fdc8ce36994

Android.mk
chip.cpp [new file with mode: 0644]
chip.h [new file with mode: 0644]
client_interface.cpp [new file with mode: 0644]
client_interface.h [new file with mode: 0644]
server.cpp
server.h
tests/integration/life_cycle_test.cpp

index ba47dde..f8815f2 100644 (file)
@@ -40,6 +40,8 @@ include $(CLEAR_VARS)
 LOCAL_MODULE := libwificond
 LOCAL_CPPFLAGS := $(wificond_cpp_flags)
 LOCAL_SRC_FILES := \
+    chip.cpp \
+    client_interface.cpp \
     looper_backed_event_loop.cpp \
     server.cpp
 LOCAL_SHARED_LIBRARIES := \
diff --git a/chip.cpp b/chip.cpp
new file mode 100644 (file)
index 0000000..a135c67
--- /dev/null
+++ b/chip.cpp
@@ -0,0 +1,66 @@
+/*
+ * 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 "chip.h"
+
+using std::vector;
+using android::sp;
+
+namespace android {
+namespace wificond {
+
+Chip::Chip()
+    : ichip_callback_(nullptr),
+      client_interface_id_(0) {
+}
+
+android::binder::Status Chip::RegisterCallback(const sp<android::net::wifi::IChipCallback>& callback) {
+  ichip_callback_ = callback;
+  return binder::Status::ok();
+}
+
+android::binder::Status Chip::UnregisterCallback(const sp<android::net::wifi::IChipCallback>& callback) {
+  ichip_callback_ = nullptr;
+  return binder::Status::ok();
+}
+
+android::binder::Status Chip::ConfigureClientInterface(int32_t* _aidl_return) {
+  // TODO: Configure client interface using HAL.
+  android::wificond::ClientInterface* interface =
+      new android::wificond::ClientInterface();
+  client_interfaces_.push_back(interface);
+  *_aidl_return = client_interface_id_++;
+
+  return binder::Status::ok();
+}
+
+android::binder::Status Chip::ConfigureApInterface(int32_t* _aidl_return) {
+  // TODO: Implement this function
+  return binder::Status::ok();
+}
+
+android::binder::Status Chip::GetClientInterfaces(vector<sp<android::IBinder>>* _aidl_return) {
+  *_aidl_return = client_interfaces_;
+  return binder::Status::ok();
+}
+
+android::binder::Status Chip::GetApInterfaces(vector<sp<android::IBinder>>* _aidl_return) {
+  // TODO: Implement this function
+  return binder::Status::ok();
+}
+
+}  // namespace wificond
+}  // namespace android
diff --git a/chip.h b/chip.h
new file mode 100644 (file)
index 0000000..7f9ef93
--- /dev/null
+++ b/chip.h
@@ -0,0 +1,57 @@
+/*
+ * 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_CHIP_H_
+#define WIFICOND_CHIP_H_
+
+#include <vector>
+
+#include <android-base/macros.h>
+
+#include "android/net/wifi/BnChip.h"
+#include "client_interface.h"
+
+namespace android {
+namespace wificond {
+
+class Chip : public android::net::wifi::BnChip {
+ public:
+  explicit Chip();
+  ~Chip() override = default;
+  android::binder::Status RegisterCallback(
+      const android::sp<android::net::wifi::IChipCallback>& callback) override;
+  android::binder::Status UnregisterCallback(
+      const android::sp<android::net::wifi::IChipCallback>& callback) override;
+  android::binder::Status ConfigureClientInterface(
+      int32_t* _aidl_return) override;
+  android::binder::Status ConfigureApInterface(int32_t* _aidl_return) override;
+  android::binder::Status GetClientInterfaces(
+      std::vector<android::sp<android::IBinder>>* _aidl_return) override;
+  android::binder::Status GetApInterfaces(
+      std::vector<android::sp<android::IBinder>>* _aidl_return) override;
+
+ private:
+  android::sp<android::net::wifi::IChipCallback> ichip_callback_;
+  std::vector<android::sp<android::IBinder>> client_interfaces_;
+  int32_t client_interface_id_;
+
+  DISALLOW_COPY_AND_ASSIGN(Chip);
+};
+
+}  // namespace wificond
+}  // namespace android
+
+#endif  // WIFICOND_CHIP_H_
diff --git a/client_interface.cpp b/client_interface.cpp
new file mode 100644 (file)
index 0000000..1159097
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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 "client_interface.h"
+
+namespace android {
+namespace wificond {
+
+}  // namespace wificond
+}  // namespace android
diff --git a/client_interface.h b/client_interface.h
new file mode 100644 (file)
index 0000000..704b612
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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_CLIENT_INTERFACE_H_
+#define WIFICOND_CLIENT_INTERFACE_H_
+
+#include <android-base/macros.h>
+
+#include "android/net/wifi/BnClientInterface.h"
+
+namespace android {
+namespace wificond {
+
+class ClientInterface : public android::net::wifi::BnClientInterface {
+ public:
+  ClientInterface() = default;
+  ~ClientInterface() override = default;
+  // TODO: Add functions configuring an interface.
+
+ private:
+  // TODO: Add fields decribing an interface.
+
+  DISALLOW_COPY_AND_ASSIGN(ClientInterface);
+};
+
+}  // namespace wificond
+}  // namespace android
+
+#endif  // WIFICOND_CLIENT_INTERFACE_H_
index 4be217e..1111002 100644 (file)
 namespace android {
 namespace wificond {
 
+Server::Server() {
+  // TODO: Get chip information from HAL.
+  android::wificond::Chip* chip = new android::wificond::Chip();
+  chips_.push_back(chip);
+}
+
 android::binder::Status Server::GetChips(std::vector<sp<IBinder>>* chips) {
-  // TODO: Enumerate chips and return the ones we know about.
-  chips->clear();
+  *chips = chips_;
   return binder::Status::ok();
 }
 
index 2f9b1f7..d7ca4fa 100644 (file)
--- a/server.h
+++ b/server.h
 #include <android-base/macros.h>
 
 #include "android/net/wifi/BnWificond.h"
+#include "chip.h"
 
 namespace android {
 namespace wificond {
 
 class Server : public android::net::wifi::BnWificond {
  public:
-  Server() = default;
+  Server();
   ~Server() override = default;
 
-  android::binder::Status GetChips(std::vector<sp<IBinder>>* chips);
+  android::binder::Status GetChips(std::vector<sp<IBinder>>* chips) override;
 
  private:
+  std::vector<sp<IBinder>> chips_;
+
   DISALLOW_COPY_AND_ASSIGN(Server);
 };
 
index b087f37..c836f24 100644 (file)
 #include <utils/StrongPointer.h>
 
 #include "android/net/wifi/IWificond.h"
+#include "android/net/wifi/IChip.h"
 #include "tests/shell_utils.h"
 
 using android::String16;
 using android::base::Trim;
+using android::net::wifi::IChip;
 using android::net::wifi::IWificond;
 using android::wificond::tests::integration::RunShellCommand;
 
@@ -88,5 +90,23 @@ TEST(LifeCycleTest, ProcessStartsUp) {
   EXPECT_TRUE(WaitForTrue(IsRegistered, kWificondStartTimeoutSeconds));
 }
 
+TEST(LifeCycleTest, ExposeChipAndInterfaceTest) {
+  sp<IWificond> service;
+  EXPECT_EQ(getService(String16(kWificondServiceName), &service), NO_ERROR);
+  std::vector<sp<IBinder>> chips;
+  service->GetChips(&chips);
+  EXPECT_TRUE(chips.size() == 1);
+
+  sp<IChip> chip = IChip::asInterface(chips[0]);
+  int32_t request_id;
+  chip->ConfigureClientInterface(&request_id);
+  EXPECT_EQ(request_id, 0);
+
+  std::vector<sp<IBinder>> interfaces;
+  chip->GetClientInterfaces(&interfaces);
+  EXPECT_TRUE(interfaces.size() == 1);
+}
+
+
 }  // namespace wificond
 }  // namespace android