From 5b1d1672eaad9bd2f15be6a6fb7ea6f1494888b5 Mon Sep 17 00:00:00 2001 From: Sohani Rao Date: Mon, 22 May 2017 14:20:31 -0700 Subject: [PATCH 1/2] Offload HAL Service: Implements Offload HAL Define OffloadServer class that implements the Offload HAL service and the callback interface to the CHRE platform. This is where the communication to the CHRE interface will take place and this class is created to be testable for unit testing. Bug: 32842314 Test: VTS Change-Id: I9c259ab2b721d7d1ac8cb16083c464002c237a16 --- wifi_offload/Android.bp | 1 + wifi_offload/offload_server.cpp | 75 +++++++++++++++++++++++++++++++++ wifi_offload/offload_server.h | 57 +++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 wifi_offload/offload_server.cpp create mode 100644 wifi_offload/offload_server.h diff --git a/wifi_offload/Android.bp b/wifi_offload/Android.bp index 646994d4..2536d60d 100644 --- a/wifi_offload/Android.bp +++ b/wifi_offload/Android.bp @@ -21,6 +21,7 @@ cc_binary { "service.cpp", "chre_constants.cpp", "chre_interface.cpp", + "offload_server.cpp", ], cflags: ["-Wall", "-Wextra"], shared_libs: [ diff --git a/wifi_offload/offload_server.cpp b/wifi_offload/offload_server.cpp new file mode 100644 index 00000000..6c2e9250 --- /dev/null +++ b/wifi_offload/offload_server.cpp @@ -0,0 +1,75 @@ +#include "offload_server.h" + +#include + +#include + +namespace android { +namespace hardware { +namespace wifi { +namespace offload { +namespace V1_0 { +namespace implementation { + +class OffloadServer; + +OffloadServer::OffloadServer() : mChreInterfaceCallbacks(new ChreInterfaceCallbacksImpl(this)) { + LOG(VERBOSE) << "Wifi Offload HAL impl"; +} + +bool OffloadServer::configureScans(const ScanParam& param, const ScanFilter& filter) { + LOG(INFO) << "configureScans"; + return true; +} + +std::pair OffloadServer::getScanStats() { + LOG(INFO) << "getScanStats"; + return std::make_pair(mScanStats, true); +} + +bool OffloadServer::subscribeScanResults(uint32_t delayMs) { + LOG(INFO) << "subscribeScanResults with delay:" << delayMs; + return true; +} + +bool OffloadServer::unsubscribeScanResults() { + LOG(INFO) << "unsubscribeScanResults"; + return true; +} + +bool OffloadServer::setEventCallback(const sp& cb) { + LOG(INFO) << "Set Event callback"; + bool result = false; + if (cb != nullptr) { + mEventCallback = cb; + result = true; + } else { + LOG(WARNING) << "Invalid callback object"; + } + return result; +} + +ChreInterfaceCallbacksImpl::ChreInterfaceCallbacksImpl(OffloadServer* server) : mServer(server) { +} + +ChreInterfaceCallbacksImpl::~ChreInterfaceCallbacksImpl() { +} + +void ChreInterfaceCallbacksImpl::handleConnectionEvents( + ChreInterfaceCallbacks::ConnectionEvent event) { + LOG(VERBOSE) << "Connection event received " << (int)event; +} + +void ChreInterfaceCallbacksImpl::handleMessage(uint32_t messageType, + const std::vector& message) { + LOG(VERBOSE) << "Message from Nano app " << messageType; +} + +// Methods from ::android::hidl::base::V1_0::IBase follow. + +} // namespace implementation +} // namespace V1_0 +} // namespace offload +} // namespace wifi +} // namespace hardware +} // namespace android diff --git a/wifi_offload/offload_server.h b/wifi_offload/offload_server.h new file mode 100644 index 00000000..c22c4a1e --- /dev/null +++ b/wifi_offload/offload_server.h @@ -0,0 +1,57 @@ +#ifndef WIFI_OFFLOAD_SERVER_H_ +#define WIFI_OFFLOAD_SERVER_H_ + +#include + +#include "chre_interface_callbacks.h" + +namespace android { +namespace hardware { +namespace wifi { +namespace offload { +namespace V1_0 { +namespace implementation { + +class OffloadServer; + +class ChreInterfaceCallbacksImpl : public ChreInterfaceCallbacks { + public: + ChreInterfaceCallbacksImpl(OffloadServer* server); + ~ChreInterfaceCallbacksImpl() override; + + void handleConnectionEvents(ChreInterfaceCallbacks::ConnectionEvent event); + void handleMessage(uint32_t messageType, const std::vector& message); + + private: + OffloadServer* mServer; +}; + +/** + * Interface object to communicate with Offload HAL + */ +class OffloadServer { + public: + OffloadServer(); + + bool configureScans(const ScanParam& param, const ScanFilter& filter); + std::pair getScanStats(); + bool subscribeScanResults(uint32_t delayMs); + bool unsubscribeScanResults(); + bool setEventCallback(const sp& cb); + + private: + ScanStats mScanStats; + std::unique_ptr mChreInterfaceCallbacks; + sp mEventCallback; + + friend class ChreInterfaceCallbacksImpl; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace offload +} // namespace wifi +} // namespace hardware +} // namespace android + +#endif // WIFI_OFFLOAD_SERVER_H_ From 2649db31832abe4cfc4a803f712eae712d273d58 Mon Sep 17 00:00:00 2001 From: Sohani Rao Date: Mon, 22 May 2017 14:28:56 -0700 Subject: [PATCH 2/2] Offload HAL Service: Chre Interface factory In order to make Offload Server testable, introduce a factory that will create the Chre Interface object. This is a part of the dependency injection framework to make OffloadServer testable. Bug: 32842314 Test: VTS Change-Id: I14794981a7b75b376462cb3fe8c6fb34df66a1ae --- wifi_offload/Android.bp | 1 + wifi_offload/chre_interface_factory.cpp | 36 +++++++++++++++++++++ wifi_offload/chre_interface_factory.h | 43 +++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 wifi_offload/chre_interface_factory.cpp create mode 100644 wifi_offload/chre_interface_factory.h diff --git a/wifi_offload/Android.bp b/wifi_offload/Android.bp index 2536d60d..e0b26ce4 100644 --- a/wifi_offload/Android.bp +++ b/wifi_offload/Android.bp @@ -22,6 +22,7 @@ cc_binary { "chre_constants.cpp", "chre_interface.cpp", "offload_server.cpp", + "chre_interface_factory.cpp", ], cflags: ["-Wall", "-Wextra"], shared_libs: [ diff --git a/wifi_offload/chre_interface_factory.cpp b/wifi_offload/chre_interface_factory.cpp new file mode 100644 index 00000000..40ba47cc --- /dev/null +++ b/wifi_offload/chre_interface_factory.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2017 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 "chre_interface_factory.h" + +#include + +namespace android { +namespace hardware { +namespace wifi { +namespace offload { +namespace V1_0 { +namespace implementation { + +ChreInterface* ChreInterfaceFactory::getChreInterface(ChreInterfaceCallbacks* serverCallbacks) { + return new ChreInterface(serverCallbacks); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace offload +} // namespace wifi +} // namespace hardware +} // namespace android diff --git a/wifi_offload/chre_interface_factory.h b/wifi_offload/chre_interface_factory.h new file mode 100644 index 00000000..119ef850 --- /dev/null +++ b/wifi_offload/chre_interface_factory.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 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 WIFI_OFFLOAD_CHRE_INTERFACE_UTILS_H_ +#define WIFI_OFFLOAD_CHRE_INTERFACE_UTILS_H_ + +#include "chre_interface.h" +#include "chre_interface_callbacks.h" + +namespace android { +namespace hardware { +namespace wifi { +namespace offload { +namespace V1_0 { +namespace implementation { + +class ChreInterfaceFactory { + public: + ChreInterfaceFactory() = default; + virtual ~ChreInterfaceFactory() = default; + virtual ChreInterface* getChreInterface(ChreInterfaceCallbacks* server); +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace offload +} // namespace wifi +} // namespace hardware +} // namespace android + +#endif // WIFI_OFFLOAD_CHRE_INTERFACE_UTILS_H_