Loading radio/aidl/compat/libradiocompat/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,6 @@ cc_library { cflags: [ "-Wall", "-Wextra", //"-Wold-style-cast", // TODO(b/203699028) enable after aosp/1900880 gets merged "-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION", ], shared_libs: [ Loading Loading @@ -56,6 +55,7 @@ cc_library { "libutils", ], srcs: [ "CallbackManager.cpp", "DriverContext.cpp", "RadioCompatBase.cpp", "RadioIndication.cpp", Loading radio/aidl/compat/libradiocompat/CallbackManager.cpp 0 → 100644 +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 radio/aidl/compat/libradiocompat/RadioCompatBase.cpp +2 −8 Original line number Diff line number Diff line Loading @@ -21,16 +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) {} V1_6::IRadioResponse& RadioCompatBase::respond() { CHECK(mRadioResponse) << "This shouldn't happen (response functions are passed in constructor)"; return *mRadioResponse; } mCallbackManager(cbMgr) {} } // namespace android::hardware::radio::compat radio/aidl/compat/libradiocompat/RadioResponse.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -27,12 +27,12 @@ RadioResponse::RadioResponse(std::shared_ptr<DriverContext> context) : mContext( Return<void> RadioResponse::acknowledgeRequest(int32_t serial) { LOG_CALL << serial; // TODO(b/203699028): send to correct requestor or confirm if spam is not a problem if (mDataCb) mDataCb->acknowledgeRequest(serial); if (mMessagingCb) mMessagingCb->acknowledgeRequest(serial); if (mModemCb) mModemCb->acknowledgeRequest(serial); if (mNetworkCb) mNetworkCb->acknowledgeRequest(serial); if (mSimCb) mSimCb->acknowledgeRequest(serial); if (mVoiceCb) mVoiceCb->acknowledgeRequest(serial); if (mDataCb) mDataCb.get()->acknowledgeRequest(serial); if (mMessagingCb) mMessagingCb.get()->acknowledgeRequest(serial); if (mModemCb) mModemCb.get()->acknowledgeRequest(serial); if (mNetworkCb) mNetworkCb.get()->acknowledgeRequest(serial); if (mSimCb) mSimCb.get()->acknowledgeRequest(serial); if (mVoiceCb) mVoiceCb.get()->acknowledgeRequest(serial); return {}; } Loading radio/aidl/compat/libradiocompat/commonStructs.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -20,11 +20,11 @@ namespace android::hardware::radio::compat { namespace aidl = ::aidl::android::hardware::radio; V1_6::RadioResponseInfo notSupported(int32_t serial) { aidl::RadioResponseInfo notSupported(int32_t serial) { return { .type = V1_0::RadioResponseType::SOLICITED, .type = aidl::RadioResponseType::SOLICITED, .serial = serial, .error = V1_6::RadioError::REQUEST_NOT_SUPPORTED, .error = aidl::RadioError::REQUEST_NOT_SUPPORTED, }; } Loading Loading
radio/aidl/compat/libradiocompat/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,6 @@ cc_library { cflags: [ "-Wall", "-Wextra", //"-Wold-style-cast", // TODO(b/203699028) enable after aosp/1900880 gets merged "-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION", ], shared_libs: [ Loading Loading @@ -56,6 +55,7 @@ cc_library { "libutils", ], srcs: [ "CallbackManager.cpp", "DriverContext.cpp", "RadioCompatBase.cpp", "RadioIndication.cpp", Loading
radio/aidl/compat/libradiocompat/CallbackManager.cpp 0 → 100644 +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
radio/aidl/compat/libradiocompat/RadioCompatBase.cpp +2 −8 Original line number Diff line number Diff line Loading @@ -21,16 +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) {} V1_6::IRadioResponse& RadioCompatBase::respond() { CHECK(mRadioResponse) << "This shouldn't happen (response functions are passed in constructor)"; return *mRadioResponse; } mCallbackManager(cbMgr) {} } // namespace android::hardware::radio::compat
radio/aidl/compat/libradiocompat/RadioResponse.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -27,12 +27,12 @@ RadioResponse::RadioResponse(std::shared_ptr<DriverContext> context) : mContext( Return<void> RadioResponse::acknowledgeRequest(int32_t serial) { LOG_CALL << serial; // TODO(b/203699028): send to correct requestor or confirm if spam is not a problem if (mDataCb) mDataCb->acknowledgeRequest(serial); if (mMessagingCb) mMessagingCb->acknowledgeRequest(serial); if (mModemCb) mModemCb->acknowledgeRequest(serial); if (mNetworkCb) mNetworkCb->acknowledgeRequest(serial); if (mSimCb) mSimCb->acknowledgeRequest(serial); if (mVoiceCb) mVoiceCb->acknowledgeRequest(serial); if (mDataCb) mDataCb.get()->acknowledgeRequest(serial); if (mMessagingCb) mMessagingCb.get()->acknowledgeRequest(serial); if (mModemCb) mModemCb.get()->acknowledgeRequest(serial); if (mNetworkCb) mNetworkCb.get()->acknowledgeRequest(serial); if (mSimCb) mSimCb.get()->acknowledgeRequest(serial); if (mVoiceCb) mVoiceCb.get()->acknowledgeRequest(serial); return {}; } Loading
radio/aidl/compat/libradiocompat/commonStructs.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -20,11 +20,11 @@ namespace android::hardware::radio::compat { namespace aidl = ::aidl::android::hardware::radio; V1_6::RadioResponseInfo notSupported(int32_t serial) { aidl::RadioResponseInfo notSupported(int32_t serial) { return { .type = V1_0::RadioResponseType::SOLICITED, .type = aidl::RadioResponseType::SOLICITED, .serial = serial, .error = V1_6::RadioError::REQUEST_NOT_SUPPORTED, .error = aidl::RadioError::REQUEST_NOT_SUPPORTED, }; } Loading