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

Commit 1a693941 authored by Gabriel Biren's avatar Gabriel Biren
Browse files

Store the min callback interface version

in the Vendor HAL.

Allows us to check if new callback methods
can be invoked.

Bug: 336376538
Test: m
Change-Id: Iddf334d3631f4b3a1c61808aaf658d3c5d6f4bee
parent 2544c471
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
namespace {
std::unordered_map<void* /* callback */, void* /* handler */> callback_handler_map_;
std::mutex callback_handler_lock_;
int32_t min_callback_version_ = INT_MAX;
}

namespace aidl {
@@ -50,6 +51,13 @@ class AidlCallbackHandler {
            return false;
        }

        // Callback interface version indicates which methods are available
        int callbackVersion = getCallbackInterfaceVersion(cb);
        if (callbackVersion < min_callback_version_) {
            LOG(INFO) << "Setting min callback version to " << callbackVersion;
            min_callback_version_ = callbackVersion;
        }

        std::unique_lock<std::mutex> lk(callback_handler_lock_);
        void* cbPtr = reinterpret_cast<void*>(cb->asBinder().get());
        const auto& cbPosition = findCbInSet(cbPtr);
@@ -111,6 +119,8 @@ class AidlCallbackHandler {
        // unique_lock unlocked here
    }

    int32_t getMinCallbackVersion() { return min_callback_version_; }

  private:
    std::set<std::shared_ptr<CallbackType>> cb_set_;
    AIBinder_DeathRecipient* death_handler_;
@@ -145,6 +155,15 @@ class AidlCallbackHandler {
        }
    }

    static int32_t getCallbackInterfaceVersion(std::shared_ptr<CallbackType> callback) {
        int32_t callbackVersion;
        if (!callback->getInterfaceVersion(&callbackVersion).isOk()) {
            LOG(ERROR) << "Unable to check the callback version";
            return INT_MAX;
        }
        return callbackVersion;
    }

    DISALLOW_COPY_AND_ASSIGN(AidlCallbackHandler);
};

+4 −0
Original line number Diff line number Diff line
@@ -672,6 +672,10 @@ std::string WifiNanIface::getName() {
    return ifname_;
}

int32_t WifiNanIface::getMinCallbackVersion() {
    return event_cb_handler_.getMinCallbackVersion();
}

std::set<std::shared_ptr<IWifiNanIfaceEventCallback>> WifiNanIface::getEventCallbacks() {
    LOG(ERROR) << "Using original getEventCallbacks";
    return event_cb_handler_.getCallbacks();
+2 −0
Original line number Diff line number Diff line
@@ -134,6 +134,8 @@ class WifiNanIface : public BnWifiNanIface {
    ndk::ScopedAStatus suspendRequestInternal(char16_t in_cmdId, int8_t sessionId);
    ndk::ScopedAStatus resumeRequestInternal(char16_t in_cmdId, int8_t sessionId);

    int32_t getMinCallbackVersion();

    // Overridden in the gTest suite.
    virtual std::set<std::shared_ptr<IWifiNanIfaceEventCallback>> getEventCallbacks();