Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64854866 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk Committed by Automerger Merge Worker
Browse files

Set HAL response functions after framework sets all of theirs. am: 963a56f7

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1936782

Change-Id: I0445bfb4e0733d35fe5690bee0ea64c9b04dee0c
parents fc09a73a 963a56f7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ cc_library {
        "libutils",
    ],
    srcs: [
        "CallbackManager.cpp",
        "DriverContext.cpp",
        "RadioCompatBase.cpp",
        "RadioIndication.cpp",
+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 <libradiocompat/CallbackManager.h>

#include <android-base/logging.h>

using namespace std::literals::chrono_literals;

namespace android::hardware::radio::compat {

/**
 * How much setter thread will wait with setting response functions after the last
 * setResponseFunctions call from the framework. Subsequent calls from the framework reset the
 * clock, so this number should be larger than the longest time between setResponseFunctions calls
 * from the framework.
 *
 * Real world measurements with Cuttlefish give <10ms delay between Modem and Data and <2ms delays
 * between all others.
 */
static constexpr auto kDelayedSetterDelay = 100ms;

CallbackManager::CallbackManager(std::shared_ptr<DriverContext> context, sp<V1_5::IRadio> hidlHal)
    : mHidlHal(hidlHal),
      mRadioResponse(sp<compat::RadioResponse>::make(context)),
      mRadioIndication(sp<compat::RadioIndication>::make(context)),
      mDelayedSetterThread(&CallbackManager::delayedSetterThread, this) {}

CallbackManager::~CallbackManager() {
    {
        std::unique_lock<std::mutex> lock(mDelayedSetterGuard);
        mDelayedSetterDeadline = std::nullopt;
        mDestroy = true;
        mDelayedSetterCv.notify_all();
    }
    mDelayedSetterThread.join();
}

RadioResponse& CallbackManager::response() const {
    return *mRadioResponse;
}

void CallbackManager::setResponseFunctionsDelayed() {
    std::unique_lock<std::mutex> lock(mDelayedSetterGuard);
    mDelayedSetterDeadline = std::chrono::steady_clock::now() + kDelayedSetterDelay;
    mDelayedSetterCv.notify_all();
}

void CallbackManager::delayedSetterThread() {
    while (!mDestroy) {
        std::unique_lock<std::mutex> lock(mDelayedSetterGuard);
        auto deadline = mDelayedSetterDeadline;

        // not waiting to set response functions
        if (!deadline) {
            mDelayedSetterCv.wait(lock);
            continue;
        }

        // waiting to set response functions, but not yet
        if (*deadline > std::chrono::steady_clock::now()) {
            mDelayedSetterCv.wait_until(lock, *deadline);
            continue;
        }

        mHidlHal->setResponseFunctions(mRadioResponse, mRadioIndication).assertOk();
        mDelayedSetterDeadline = std::nullopt;
    }
}

}  // namespace android::hardware::radio::compat
+2 −3
Original line number Diff line number Diff line
@@ -21,11 +21,10 @@
namespace android::hardware::radio::compat {

RadioCompatBase::RadioCompatBase(std::shared_ptr<DriverContext> context, sp<V1_5::IRadio> hidlHal,
                                 sp<RadioResponse> radioResponse, sp<RadioIndication> radioInd)
                                 std::shared_ptr<CallbackManager> cbMgr)
    : mContext(context),
      mHal1_5(hidlHal),
      mHal1_6(V1_6::IRadio::castFrom(hidlHal)),
      mRadioResponse(radioResponse),
      mRadioIndication(radioInd) {}
      mCallbackManager(cbMgr) {}

}  // namespace android::hardware::radio::compat
+1 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ ScopedAStatus RadioConfig::setResponseFunctions(

    mRadioConfigResponse->setResponseFunction(radioConfigResponse);
    mRadioConfigIndication->setResponseFunction(radioConfigIndication);
    mHal1_1->setResponseFunctions(mRadioConfigResponse, mRadioConfigIndication);
    mHal1_1->setResponseFunctions(mRadioConfigResponse, mRadioConfigIndication).assertOk();

    return ok();
}
+5 −11
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ namespace aidlCommon = ::aidl::android::hardware::radio;
constexpr auto ok = &ScopedAStatus::ok;

std::shared_ptr<aidl::IRadioDataResponse> RadioData::respond() {
    return mRadioResponse->dataCb();
    return mCallbackManager->response().dataCb();
}

ScopedAStatus RadioData::allocatePduSessionId(int32_t serial) {
@@ -129,16 +129,10 @@ ScopedAStatus RadioData::setInitialAttachApn(int32_t serial, const aidl::DataPro
}

ScopedAStatus RadioData::setResponseFunctions(
        const std::shared_ptr<aidl::IRadioDataResponse>& dataResponse,
        const std::shared_ptr<aidl::IRadioDataIndication>& dataIndication) {
    LOG_CALL << dataResponse << ' ' << dataIndication;

    CHECK(dataResponse);
    CHECK(dataIndication);

    mRadioResponse->setResponseFunction(dataResponse);
    mRadioIndication->setResponseFunction(dataIndication);

        const std::shared_ptr<aidl::IRadioDataResponse>& response,
        const std::shared_ptr<aidl::IRadioDataIndication>& indication) {
    LOG_CALL << response << ' ' << indication;
    mCallbackManager->setResponseFunctions(response, indication);
    return ok();
}

Loading