mirror of
https://github.com/Evolution-X-Devices/device_google_wahoo
synced 2026-02-01 07:50:47 +00:00
Revert "Offload HAL Service: Handle messages from Nano app"
This reverts commit 6445f68be6.
Change-Id: Ic34b12752bbbb5957d7b929a3b6b7d6552a7d596
This commit is contained in:
@@ -8,11 +8,6 @@
|
||||
#include "offload_utils.h"
|
||||
|
||||
using namespace android::hardware::wifi::offload::V1_0::implementation::chre_constants;
|
||||
using android::hardware::wifi::offload::V1_0::OffloadStatus;
|
||||
|
||||
namespace {
|
||||
constexpr auto kScanStatsTimeout = std::chrono::milliseconds(500);
|
||||
}
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
@@ -32,7 +27,7 @@ OffloadServer::OffloadServer(ChreInterfaceFactory* factory)
|
||||
OffloadStatus OffloadServer::configureScans(const ScanParam& param, const ScanFilter& filter) {
|
||||
LOG(INFO) << "configureScans";
|
||||
if (!mChreInterface->isConnected()) {
|
||||
return createOffloadStatus(OffloadStatusCode::NO_CONNECTION,
|
||||
return createOffloadStatus(OffloadStatusCode::ERROR,
|
||||
"Not connected to hardware implementation");
|
||||
}
|
||||
wifi_offload::ScanConfig scanConfig;
|
||||
@@ -55,33 +50,14 @@ OffloadStatus OffloadServer::configureScans(const ScanParam& param, const ScanFi
|
||||
|
||||
std::pair<OffloadStatus, ScanStats> OffloadServer::getScanStats() {
|
||||
LOG(INFO) << "getScanStats";
|
||||
mScanStatsStatus = createOffloadStatus(OffloadStatusCode::OK);
|
||||
if (!mChreInterface->isConnected()) {
|
||||
return {createOffloadStatus(OffloadStatusCode::NO_CONNECTION, "Unable to send scan stats"),
|
||||
{}};
|
||||
}
|
||||
if (!mChreInterface->sendCommandToApp(wifi_offload::HostMessageType::HOST_CMD_GET_SCAN_STATS,
|
||||
{})) {
|
||||
return {createOffloadStatus(OffloadStatusCode::ERROR, "Unable to send scan stats command"),
|
||||
{}};
|
||||
}
|
||||
LOG(VERBOSE) << "Sent getScanStats command";
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mScanStatsLock);
|
||||
auto timeout_status = mScanStatsCond.wait_for(lock, kScanStatsTimeout);
|
||||
if (timeout_status == std::cv_status::timeout) {
|
||||
std::lock_guard<std::mutex> lock(mOffloadLock);
|
||||
LOG(WARNING) << "Timeout waiting for scan stats";
|
||||
return {createOffloadStatus(OffloadStatusCode::TIMEOUT, "Scan stats not received"), {}};
|
||||
}
|
||||
}
|
||||
return std::make_pair(mScanStatsStatus, mScanStats);
|
||||
OffloadStatus status = createOffloadStatus(OffloadStatusCode::OK);
|
||||
return std::make_pair(status, mScanStats);
|
||||
}
|
||||
|
||||
OffloadStatus OffloadServer::subscribeScanResults(uint32_t delayMs) {
|
||||
LOG(INFO) << "subscribeScanResults with delay:" << delayMs;
|
||||
if (!mChreInterface->isConnected()) {
|
||||
return createOffloadStatus(OffloadStatusCode::NO_CONNECTION, "Not connected to hardware");
|
||||
return createOffloadStatus(OffloadStatusCode::ERROR, "Not connected to hardware");
|
||||
}
|
||||
uint32_t* buffer = &delayMs;
|
||||
std::vector<uint8_t> message(reinterpret_cast<uint8_t*>(buffer),
|
||||
@@ -94,6 +70,7 @@ OffloadStatus OffloadServer::subscribeScanResults(uint32_t delayMs) {
|
||||
}
|
||||
|
||||
bool OffloadServer::unsubscribeScanResults() {
|
||||
bool result = false;
|
||||
LOG(INFO) << "unsubscribeScanResults";
|
||||
if (!mChreInterface->isConnected()) {
|
||||
LOG(WARNING) << "Failed to send unsubscribe scan results message";
|
||||
@@ -109,29 +86,21 @@ bool OffloadServer::unsubscribeScanResults() {
|
||||
|
||||
bool OffloadServer::setEventCallback(const sp<IOffloadCallback>& cb) {
|
||||
LOG(INFO) << "Set Event callback";
|
||||
if (cb == nullptr) {
|
||||
return false;
|
||||
bool result = false;
|
||||
if (cb != nullptr) {
|
||||
mEventCallback = cb;
|
||||
result = true;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mOffloadLock);
|
||||
mEventCallback = cb;
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
void OffloadServer::clearEventCallback() {
|
||||
std::lock_guard<std::mutex> lock(mOffloadLock);
|
||||
if (mEventCallback != nullptr) {
|
||||
mEventCallback.clear();
|
||||
}
|
||||
LOG(INFO) << "Event callback cleared";
|
||||
}
|
||||
|
||||
void OffloadServer::invokeErrorCallback(const OffloadStatus& status) {
|
||||
std::lock_guard<std::mutex> lock(mOffloadLock);
|
||||
if (mEventCallback != nullptr) {
|
||||
mEventCallback->onError(status);
|
||||
}
|
||||
}
|
||||
|
||||
ChreInterfaceCallbacksImpl::ChreInterfaceCallbacksImpl(OffloadServer* server) : mServer(server) {
|
||||
}
|
||||
|
||||
@@ -140,88 +109,12 @@ ChreInterfaceCallbacksImpl::~ChreInterfaceCallbacksImpl() {
|
||||
|
||||
void ChreInterfaceCallbacksImpl::handleConnectionEvents(
|
||||
ChreInterfaceCallbacks::ConnectionEvent event) {
|
||||
switch (event) {
|
||||
case ChreInterfaceCallbacks::ConnectionEvent::DISCONNECTED:
|
||||
case ChreInterfaceCallbacks::ConnectionEvent::CONNECTION_ABORT: {
|
||||
LOG(ERROR) << "Connection to socket lost";
|
||||
mServer->invokeErrorCallback(
|
||||
createOffloadStatus(OffloadStatusCode::NO_CONNECTION, "Connection to socket lost"));
|
||||
} break;
|
||||
case ChreInterfaceCallbacks::ConnectionEvent::CONNECTED: {
|
||||
LOG(INFO) << "Connected to socket";
|
||||
mServer->invokeErrorCallback(createOffloadStatus(OffloadStatusCode::OK));
|
||||
} break;
|
||||
default:
|
||||
LOG(WARNING) << "Invalid connection event received " << (int)event;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OffloadServer::handleScanResult(const std::vector<uint8_t>& message) {
|
||||
std::vector<wifi_offload::ScanResult> scanResults;
|
||||
std::vector<ScanResult> hidlScanResults;
|
||||
std::string errorMessage;
|
||||
if (!wifi_offload::fbs::Deserialize((uint8_t*)message.data(), message.size(), &scanResults)) {
|
||||
invokeErrorCallback(
|
||||
createOffloadStatus(OffloadStatusCode::ERROR, "Cannot deserialize scan results"));
|
||||
return;
|
||||
}
|
||||
if (!offload_utils::ToHidlScanResults(scanResults, &hidlScanResults)) {
|
||||
invokeErrorCallback(createOffloadStatus(OffloadStatusCode::ERROR,
|
||||
"Cannot convert scan results to HIDL format"));
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mOffloadLock);
|
||||
if (mEventCallback != nullptr) {
|
||||
mEventCallback->onScanResult(hidlScanResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OffloadServer::handleScanStats(const std::vector<uint8_t>& message) {
|
||||
std::lock_guard<std::mutex> lock(mScanStatsLock);
|
||||
wifi_offload::ScanStats stats;
|
||||
OffloadStatus status;
|
||||
// Deserialize scan stats
|
||||
status = createOffloadStatus(OffloadStatusCode::OK);
|
||||
LOG(VERBOSE) << "Received scan stats";
|
||||
if (!wifi_offload::fbs::Deserialize((uint8_t*)message.data(), message.size(), &stats)) {
|
||||
status = createOffloadStatus(OffloadStatusCode::ERROR, "Cannot deserailize scan stats");
|
||||
} else if (!offload_utils::ToHidlScanStats(stats, &mScanStats)) {
|
||||
status = createOffloadStatus(OffloadStatusCode::ERROR,
|
||||
"Cannot convert Scan stats to HIDL format");
|
||||
}
|
||||
mScanStatsStatus = status;
|
||||
mScanStatsCond.notify_all();
|
||||
LOG(VERBOSE) << "Connection event received " << (int)event;
|
||||
}
|
||||
|
||||
void ChreInterfaceCallbacksImpl::handleMessage(uint32_t messageType,
|
||||
const std::vector<uint8_t>& message) {
|
||||
LOG(VERBOSE) << "Message from Nano app " << messageType;
|
||||
switch (messageType) {
|
||||
case wifi_offload::HostMessageType::HOST_MSG_SCAN_RESULTS: {
|
||||
LOG(INFO) << "Received scan results";
|
||||
mServer->handleScanResult(message);
|
||||
} break;
|
||||
case wifi_offload::HostMessageType::HOST_MSG_SCAN_STATS:
|
||||
LOG(VERBOSE) << "Received scan stats from Nano app";
|
||||
mServer->handleScanStats(message);
|
||||
break;
|
||||
case wifi_offload::HostMessageType::HOST_MSG_ERROR:
|
||||
LOG(VERBOSE) << "Received error message from Nano app";
|
||||
{
|
||||
std::string errorMessage;
|
||||
if (offload_utils::ToHidlErrorMessage(message[0], &errorMessage)) {
|
||||
mServer->invokeErrorCallback(
|
||||
createOffloadStatus(OffloadStatusCode::ERROR, errorMessage));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG(WARNING) << "Unknown message received" << messageType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
||||
|
||||
Reference in New Issue
Block a user