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

Commit 738e59bd authored by Orlando Arbildo's avatar Orlando Arbildo
Browse files

hwcryptohal: Adding maps cleanup

Adding cleanup functionality to remove binder objects
from maps once the objects are destroyed.

Bug: 393162614
Test: cf build/ manual test
Change-Id: Iee20a2b1922bcc2a8dd3fd252f76bedbe17657b9
parent 36fe049d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -115,11 +115,14 @@ static std::optional<cpp_hwcrypto::types::ExplicitKeyMaterial> convertExplicitKe
class HwCryptoOperationContextNdk : public ndk_hwcrypto::BnCryptoOperationContext {
  private:
    sp<cpp_hwcrypto::ICryptoOperationContext> mContext;
    std::weak_ptr<ndk_hwcrypto::ICryptoOperationContext> self;

  public:
    HwCryptoOperationContextNdk(sp<cpp_hwcrypto::ICryptoOperationContext> operations)
        : mContext(std::move(operations)) {}

    ~HwCryptoOperationContextNdk() { contextMapping.erase(self); }

    static std::shared_ptr<HwCryptoOperationContextNdk> Create(
            sp<cpp_hwcrypto::ICryptoOperationContext> operations) {
        if (operations == nullptr) {
@@ -132,6 +135,7 @@ class HwCryptoOperationContextNdk : public ndk_hwcrypto::BnCryptoOperationContex
            LOG(ERROR) << "failed to allocate HwCryptoOperationContext";
            return nullptr;
        }
        contextNdk->self = contextNdk;
        return contextNdk;
    }
};
@@ -592,10 +596,13 @@ class HwCryptoOperationsNdk : public ndk_hwcrypto::BnHwCryptoOperations {
class OpaqueKeyNdk : public ndk_hwcrypto::BnOpaqueKey {
  private:
    sp<cpp_hwcrypto::IOpaqueKey> mOpaqueKey;
    std::weak_ptr<ndk_hwcrypto::IOpaqueKey> self;

  public:
    OpaqueKeyNdk(sp<cpp_hwcrypto::IOpaqueKey> opaqueKey) : mOpaqueKey(std::move(opaqueKey)) {}

    ~OpaqueKeyNdk() { keyMapping.erase(self); }

    static std::shared_ptr<OpaqueKeyNdk> Create(sp<cpp_hwcrypto::IOpaqueKey> opaqueKey) {
        if (opaqueKey == nullptr) {
            return nullptr;
@@ -607,6 +614,7 @@ class OpaqueKeyNdk : public ndk_hwcrypto::BnOpaqueKey {
            LOG(ERROR) << "failed to allocate HwCryptoKey";
            return nullptr;
        }
        opaqueKeyNdk->self = opaqueKeyNdk;
        return opaqueKeyNdk;
    }