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

Commit be14c9fb authored by Yu Shan's avatar Yu Shan
Browse files

Add binder lifecycle monitor.

Add binder lifecycle monitor for registerSupportedValueChange. If
the client binder dies, we need to call unregister for the client
and clear stored information.

Flag: EXEMPT hal
Test: atest DefaultVehicleHalTest
Bug: 377348572
Change-Id: I7271a609c7eb4cae98eb5fc684d1212ffc921db9
parent ae629f86
Loading
Loading
Loading
Loading
+21 −9
Original line number Diff line number Diff line
@@ -953,7 +953,9 @@ ScopedAStatus DefaultVehicleHal::subscribe(const CallbackType& callback,
    }

    {
        // Lock to make sure onBinderDied would not be called concurrently.
        // Lock to make sure onBinderDied would not be called concurrently
        // (before subscribe). Without this, we may create a new subscription for an already dead
        // client which will never be unsubscribed.
        std::scoped_lock lockGuard(mLock);
        if (!monitorBinderLifeCycleLocked(callback->asBinder().get())) {
            return ScopedAStatus::fromExceptionCodeWithMessage(EX_TRANSACTION_FAILED,
@@ -1178,8 +1180,17 @@ ScopedAStatus DefaultVehicleHal::registerSupportedValueChangeCallback(
    if (propIdAreaIdsToSubscribe.empty()) {
        return ScopedAStatus::ok();
    }
    auto result =
            mSubscriptionManager->subscribeSupportedValueChange(callback, propIdAreaIdsToSubscribe);
    {
        // Lock to make sure onBinderDied would not be called concurrently
        // (before subscribeSupportedValueChange). Without this, we may create a new subscription
        // for an already dead client which will never be unsubscribed.
        std::scoped_lock lockGuard(mLock);
        if (!monitorBinderLifeCycleLocked(callback->asBinder().get())) {
            return ScopedAStatus::fromExceptionCodeWithMessage(EX_TRANSACTION_FAILED,
                                                               "client died");
        }
        auto result = mSubscriptionManager->subscribeSupportedValueChange(callback,
                                                                          propIdAreaIdsToSubscribe);
        if (!result.ok()) {
            ALOGW("registerSupportedValueChangeCallback: failed to subscribe supported value change"
                  " for %s, error: %s",
@@ -1187,6 +1198,7 @@ ScopedAStatus DefaultVehicleHal::registerSupportedValueChangeCallback(
                  result.error().message().c_str());
            return toScopedAStatus(result);
        }
    }
    return ScopedAStatus::ok();
}

+116 −89

File changed.

Preview size limit exceeded, changes collapsed.