Fix drm aidl listeners

This is a part of change to fix cts test issue on drm framework by using clearkey aidl as the backend plugin.

Test: atest
CtsMediaDrmTestCases: android.media.drm.cts.NativeMediaDrmClearkeyTest#testClearKeyPlaybackCenc
Bug: 206804036
Change-Id: I2ad8a863dc1804e74d0fc40b933473546ed39b4a
diff --git a/drm/libmediadrm/Android.bp b/drm/libmediadrm/Android.bp
index bf0cdd5..408d216 100644
--- a/drm/libmediadrm/Android.bp
+++ b/drm/libmediadrm/Android.bp
@@ -34,6 +34,7 @@
         "CryptoHalHidl.cpp",
         "CryptoHalAidl.cpp",
         "DrmUtils.cpp",
+        "DrmHalListener.cpp",
     ],
 
     local_include_dirs: [
diff --git a/drm/libmediadrm/DrmHal.cpp b/drm/libmediadrm/DrmHal.cpp
index fe8b9f6..aa40793 100644
--- a/drm/libmediadrm/DrmHal.cpp
+++ b/drm/libmediadrm/DrmHal.cpp
@@ -26,7 +26,7 @@
 
 DrmHal::DrmHal() {
     mDrmHalHidl = sp<DrmHalHidl>::make();
-    mDrmHalAidl = ndk::SharedRefBase::make<DrmHalAidl>();
+    mDrmHalAidl = sp<DrmHalAidl>::make();
 }
 
 DrmHal::~DrmHal() {}
diff --git a/drm/libmediadrm/DrmHalAidl.cpp b/drm/libmediadrm/DrmHalAidl.cpp
index 7df57a3..f785c13 100644
--- a/drm/libmediadrm/DrmHalAidl.cpp
+++ b/drm/libmediadrm/DrmHalAidl.cpp
@@ -59,7 +59,6 @@
 using AttributeHidl = ::android::hardware::drm::V1_1::DrmMetricGroup::Attribute;
 using IDrmPluginAidl = ::aidl::android::hardware::drm::IDrmPlugin;
 using EventTypeAidl = ::aidl::android::hardware::drm::EventType;
-using KeyStatusAidl = ::aidl::android::hardware::drm::KeyStatus;
 using ::android::hardware::hidl_vec;
 
 namespace {
@@ -396,7 +395,8 @@
 
 // DrmHalAidl methods
 DrmHalAidl::DrmHalAidl()
-    : mFactories(makeDrmFactories()),
+    : mListener(::ndk::SharedRefBase::make<DrmHalListener>(&mMetrics)),
+      mFactories(makeDrmFactories()),
       mInitCheck((mFactories.size() == 0) ? ERROR_UNSUPPORTED : NO_INIT) {}
 
 status_t DrmHalAidl::initCheck() const {
@@ -427,8 +427,7 @@
 }
 
 status_t DrmHalAidl::setListener(const sp<IDrmClient>& listener) {
-    Mutex::Autolock lock(mEventLock);
-    mListener = listener;
+    mListener->setListener(listener);
     return NO_ERROR;
 }
 
@@ -437,8 +436,9 @@
     Mutex::Autolock autoLock(mLock);
     *isSupported = false;
     Uuid uuidAidl = toAidlUuid(uuid);
-    SecurityLevel levelAidl = static_cast<SecurityLevel>((int32_t)level);
+    SecurityLevel levelAidl = toAidlSecurityLevel(level);
     std::string mimeTypeStr = mimeType.string();
+
     for (ssize_t i = mFactories.size() - 1; i >= 0; i--) {
         if (mFactories[i]
                     ->isCryptoSchemeSupported(uuidAidl, mimeTypeStr, levelAidl, isSupported)
@@ -477,9 +477,14 @@
         mInitCheck = ERROR_UNSUPPORTED;
     } else {
         mInitCheck = OK;
-
-        if (!mPlugin->setListener(shared_from_this()).isOk()) {
+        // Stored pointer mListener upcast to base BnDrmPluginListener
+        ::ndk::ScopedAStatus status = mPlugin
+            ->setListener(std::static_pointer_cast<BnDrmPluginListener>(mListener));
+        if (!status.isOk()) {
             mInitCheck = DEAD_OBJECT;
+            ALOGE("setListener failed: ex %d svc err %d",
+                status.getExceptionCode(),
+                status.getServiceSpecificError());
         }
 
         if (mInitCheck != OK) {
@@ -1203,124 +1208,22 @@
 ::ndk::ScopedAStatus DrmHalAidl::onEvent(EventTypeAidl eventTypeAidl,
                                          const std::vector<uint8_t>& sessionId,
                                          const std::vector<uint8_t>& data) {
-    ::ndk::ScopedAStatus _aidl_status;
-    mMetrics.mEventCounter.Increment((uint32_t)eventTypeAidl);
-
-    mEventLock.lock();
-    sp<IDrmClient> listener = mListener;
-    mEventLock.unlock();
-
-    if (listener != NULL) {
-        Mutex::Autolock lock(mNotifyLock);
-        DrmPlugin::EventType eventType;
-        switch (eventTypeAidl) {
-            case EventTypeAidl::PROVISION_REQUIRED:
-                eventType = DrmPlugin::kDrmPluginEventProvisionRequired;
-                break;
-            case EventTypeAidl::KEY_NEEDED:
-                eventType = DrmPlugin::kDrmPluginEventKeyNeeded;
-                break;
-            case EventTypeAidl::KEY_EXPIRED:
-                eventType = DrmPlugin::kDrmPluginEventKeyExpired;
-                break;
-            case EventTypeAidl::VENDOR_DEFINED:
-                eventType = DrmPlugin::kDrmPluginEventVendorDefined;
-                break;
-            case EventTypeAidl::SESSION_RECLAIMED:
-                eventType = DrmPlugin::kDrmPluginEventSessionReclaimed;
-                break;
-            default:
-                return _aidl_status;
-        }
-
-        listener->sendEvent(eventType, toHidlVec(toVector(sessionId)), toHidlVec(toVector(data)));
-    }
-
-    return _aidl_status;
+    return mListener->onEvent(eventTypeAidl, sessionId, data);
 }
 
 ::ndk::ScopedAStatus DrmHalAidl::onExpirationUpdate(const std::vector<uint8_t>& sessionId,
                                                     int64_t expiryTimeInMS) {
-    ::ndk::ScopedAStatus _aidl_status;
-    mEventLock.lock();
-    sp<IDrmClient> listener = mListener;
-    mEventLock.unlock();
-
-    if (listener != NULL) {
-        Mutex::Autolock lock(mNotifyLock);
-        listener->sendExpirationUpdate(toHidlVec(toVector(sessionId)), expiryTimeInMS);
-    }
-
-    return _aidl_status;
+    return mListener->onExpirationUpdate(sessionId, expiryTimeInMS);
 }
 
 ::ndk::ScopedAStatus DrmHalAidl::onKeysChange(const std::vector<uint8_t>& sessionId,
                                               const std::vector<KeyStatus>& keyStatusListAidl,
                                               bool hasNewUsableKey) {
-    ::ndk::ScopedAStatus _aidl_status;
-    mEventLock.lock();
-    sp<IDrmClient> listener = mListener;
-    mEventLock.unlock();
-
-    if (listener != NULL) {
-        std::vector<DrmKeyStatus> keyStatusList;
-        size_t nKeys = keyStatusListAidl.size();
-        for (size_t i = 0; i < nKeys; ++i) {
-            const KeyStatus& keyStatus = keyStatusListAidl[i];
-            uint32_t type;
-            switch (keyStatus.type) {
-                case KeyStatusType::USABLE:
-                    type = DrmPlugin::kKeyStatusType_Usable;
-                    break;
-                case KeyStatusType::EXPIRED:
-                    type = DrmPlugin::kKeyStatusType_Expired;
-                    break;
-                case KeyStatusType::OUTPUTNOTALLOWED:
-                    type = DrmPlugin::kKeyStatusType_OutputNotAllowed;
-                    break;
-                case KeyStatusType::STATUSPENDING:
-                    type = DrmPlugin::kKeyStatusType_StatusPending;
-                    break;
-                case KeyStatusType::USABLEINFUTURE:
-                    type = DrmPlugin::kKeyStatusType_UsableInFuture;
-                    break;
-                case KeyStatusType::INTERNALERROR:
-                default:
-                    type = DrmPlugin::kKeyStatusType_InternalError;
-                    break;
-            }
-            keyStatusList.push_back({type, toHidlVec(toVector(keyStatus.keyId))});
-            mMetrics.mKeyStatusChangeCounter.Increment((uint32_t)keyStatus.type);
-        }
-
-        Mutex::Autolock lock(mNotifyLock);
-        listener->sendKeysChange(toHidlVec(toVector(sessionId)), keyStatusList, hasNewUsableKey);
-    }
-    else {
-        // There's no listener. But we still want to count the key change
-        // events.
-        size_t nKeys = keyStatusListAidl.size();
-
-        for (size_t i = 0; i < nKeys; i++) {
-            mMetrics.mKeyStatusChangeCounter.Increment((uint32_t)keyStatusListAidl[i].type);
-        }
-    }
-
-    return _aidl_status;
+    return mListener->onKeysChange(sessionId, keyStatusListAidl, hasNewUsableKey);
 }
 
 ::ndk::ScopedAStatus DrmHalAidl::onSessionLostState(const std::vector<uint8_t>& sessionId) {
-    ::ndk::ScopedAStatus _aidl_status;
-    mEventLock.lock();
-    sp<IDrmClient> listener = mListener;
-    mEventLock.unlock();
-
-    if (listener != NULL) {
-        Mutex::Autolock lock(mNotifyLock);
-        listener->sendSessionLostState(toHidlVec(toVector(sessionId)));
-    }
-
-    return _aidl_status;
+    return mListener->onSessionLostState(sessionId);
 }
 
 }  // namespace android
\ No newline at end of file
diff --git a/drm/libmediadrm/DrmHalListener.cpp b/drm/libmediadrm/DrmHalListener.cpp
new file mode 100644
index 0000000..e39264f
--- /dev/null
+++ b/drm/libmediadrm/DrmHalListener.cpp
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "DrmHalListener"
+
+#include <mediadrm/DrmHalListener.h>
+
+using ::aidl::android::hardware::drm::KeyStatusType;
+using ::android::hardware::hidl_vec;
+
+namespace android {
+
+static const Vector<uint8_t> toVector(const std::vector<uint8_t>& vec) {
+    Vector<uint8_t> vector;
+    vector.appendArray(vec.data(), vec.size());
+    return *const_cast<const Vector<uint8_t>*>(&vector);
+}
+
+template <typename T = uint8_t>
+static hidl_vec<T> toHidlVec(const Vector<T>& vector) {
+    hidl_vec<T> vec;
+    vec.setToExternal(const_cast<T*>(vector.array()), vector.size());
+    return vec;
+}
+
+DrmHalListener::DrmHalListener(MediaDrmMetrics* metrics)
+    : mMetrics(metrics) {}
+
+DrmHalListener::~DrmHalListener() {}
+
+void DrmHalListener::setListener(sp<IDrmClient> listener) {
+    Mutex::Autolock lock(mEventLock);
+    mListener = listener;
+}
+
+::ndk::ScopedAStatus DrmHalListener::onEvent(EventTypeAidl eventTypeAidl,
+                                         const std::vector<uint8_t>& sessionId,
+                                         const std::vector<uint8_t>& data) {
+    mMetrics->mEventCounter.Increment((uint32_t)eventTypeAidl);
+
+    mEventLock.lock();
+    sp<IDrmClient> listener = mListener;
+    mEventLock.unlock();
+
+    if (listener != NULL) {
+        Mutex::Autolock lock(mNotifyLock);
+        DrmPlugin::EventType eventType;
+        switch (eventTypeAidl) {
+            case EventTypeAidl::PROVISION_REQUIRED:
+                eventType = DrmPlugin::kDrmPluginEventProvisionRequired;
+                break;
+            case EventTypeAidl::KEY_NEEDED:
+                eventType = DrmPlugin::kDrmPluginEventKeyNeeded;
+                break;
+            case EventTypeAidl::KEY_EXPIRED:
+                eventType = DrmPlugin::kDrmPluginEventKeyExpired;
+                break;
+            case EventTypeAidl::VENDOR_DEFINED:
+                eventType = DrmPlugin::kDrmPluginEventVendorDefined;
+                break;
+            case EventTypeAidl::SESSION_RECLAIMED:
+                eventType = DrmPlugin::kDrmPluginEventSessionReclaimed;
+                break;
+            default:
+                return ::ndk::ScopedAStatus::ok();
+        }
+
+        listener->sendEvent(eventType, toHidlVec(toVector(sessionId)), toHidlVec(toVector(data)));
+    }
+
+    return ::ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus DrmHalListener::onExpirationUpdate(const std::vector<uint8_t>& sessionId,
+                                                    int64_t expiryTimeInMS) {
+    mEventLock.lock();
+    sp<IDrmClient> listener = mListener;
+    mEventLock.unlock();
+
+    if (listener != NULL) {
+        Mutex::Autolock lock(mNotifyLock);
+        listener->sendExpirationUpdate(toHidlVec(toVector(sessionId)), expiryTimeInMS);
+    }
+
+    return ::ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus DrmHalListener::onKeysChange(const std::vector<uint8_t>& sessionId,
+                                              const std::vector<KeyStatusAidl>& keyStatusListAidl,
+                                              bool hasNewUsableKey) {
+    mEventLock.lock();
+    sp<IDrmClient> listener = mListener;
+    mEventLock.unlock();
+
+    if (listener != NULL) {
+        std::vector<DrmKeyStatus> keyStatusList;
+        size_t nKeys = keyStatusListAidl.size();
+        for (size_t i = 0; i < nKeys; ++i) {
+            const KeyStatusAidl keyStatus = keyStatusListAidl[i];
+            uint32_t type;
+            switch (keyStatus.type) {
+                case KeyStatusType::USABLE:
+                    type = DrmPlugin::kKeyStatusType_Usable;
+                    break;
+                case KeyStatusType::EXPIRED:
+                    type = DrmPlugin::kKeyStatusType_Expired;
+                    break;
+                case KeyStatusType::OUTPUTNOTALLOWED:
+                    type = DrmPlugin::kKeyStatusType_OutputNotAllowed;
+                    break;
+                case KeyStatusType::STATUSPENDING:
+                    type = DrmPlugin::kKeyStatusType_StatusPending;
+                    break;
+                case KeyStatusType::USABLEINFUTURE:
+                    type = DrmPlugin::kKeyStatusType_UsableInFuture;
+                    break;
+                case KeyStatusType::INTERNALERROR:
+                default:
+                    type = DrmPlugin::kKeyStatusType_InternalError;
+                    break;
+            }
+            keyStatusList.push_back({type, toHidlVec(toVector(keyStatus.keyId))});
+            mMetrics->mKeyStatusChangeCounter.Increment((uint32_t)keyStatus.type);
+        }
+
+        Mutex::Autolock lock(mNotifyLock);
+        listener->sendKeysChange(toHidlVec(toVector(sessionId)), keyStatusList, hasNewUsableKey);
+    }
+    else {
+        // There's no listener. But we still want to count the key change
+        // events.
+        size_t nKeys = keyStatusListAidl.size();
+
+        for (size_t i = 0; i < nKeys; i++) {
+            mMetrics->mKeyStatusChangeCounter.Increment((uint32_t)keyStatusListAidl[i].type);
+        }
+    }
+
+    return ::ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus DrmHalListener::onSessionLostState(const std::vector<uint8_t>& sessionId) {
+    ::ndk::ScopedAStatus _aidl_status;
+    mEventLock.lock();
+    sp<IDrmClient> listener = mListener;
+    mEventLock.unlock();
+
+    if (listener != NULL) {
+        Mutex::Autolock lock(mNotifyLock);
+        listener->sendSessionLostState(toHidlVec(toVector(sessionId)));
+    }
+
+    return ::ndk::ScopedAStatus::ok();
+}
+
+}  // namespace android
\ No newline at end of file
diff --git a/drm/libmediadrm/include/mediadrm/CryptoHal.h b/drm/libmediadrm/include/mediadrm/CryptoHal.h
index 5be59f0..32a6741 100644
--- a/drm/libmediadrm/include/mediadrm/CryptoHal.h
+++ b/drm/libmediadrm/include/mediadrm/CryptoHal.h
@@ -54,6 +54,6 @@
     DISALLOW_EVIL_CONSTRUCTORS(CryptoHal);
 };
 
-}
+}  // namespace android
 
-#endif
\ No newline at end of file
+#endif  // CRYPTO_HAL_H_
\ No newline at end of file
diff --git a/drm/libmediadrm/include/mediadrm/CryptoHalAidl.h b/drm/libmediadrm/include/mediadrm/CryptoHalAidl.h
index a25b091..fc7f7fb 100644
--- a/drm/libmediadrm/include/mediadrm/CryptoHalAidl.h
+++ b/drm/libmediadrm/include/mediadrm/CryptoHalAidl.h
@@ -89,4 +89,4 @@
 
 }  // namespace android
 
-#endif  // CRYPTO_HAL_H_
+#endif // CRYPTO_HAL_AIDL_H_
diff --git a/drm/libmediadrm/include/mediadrm/DrmHal.h b/drm/libmediadrm/include/mediadrm/DrmHal.h
index bb58585..f5e75ac 100644
--- a/drm/libmediadrm/include/mediadrm/DrmHal.h
+++ b/drm/libmediadrm/include/mediadrm/DrmHal.h
@@ -120,10 +120,10 @@
 
 private:
     sp<IDrm> mDrmHalHidl;
-    std::shared_ptr<IDrm> mDrmHalAidl;
+    sp<IDrm> mDrmHalAidl;
     DISALLOW_EVIL_CONSTRUCTORS(DrmHal);
 };
 
 } // namespace android
 
-#endif
\ No newline at end of file
+#endif  // DRM_HAL_H_
\ No newline at end of file
diff --git a/drm/libmediadrm/include/mediadrm/DrmHalAidl.h b/drm/libmediadrm/include/mediadrm/DrmHalAidl.h
index 6720734..3feda90 100644
--- a/drm/libmediadrm/include/mediadrm/DrmHalAidl.h
+++ b/drm/libmediadrm/include/mediadrm/DrmHalAidl.h
@@ -17,16 +17,16 @@
 #ifndef DRM_HAL_AIDL_H_
 #define DRM_HAL_AIDL_H_
 
+#include <memory>
 #include <aidl/android/hardware/drm/BnDrmPluginListener.h>
 #include <aidl/android/hardware/drm/IDrmFactory.h>
 #include <aidl/android/hardware/drm/IDrmPlugin.h>
 #include <aidl/android/media/BnResourceManagerClient.h>
 #include <mediadrm/DrmMetrics.h>
 #include <mediadrm/DrmSessionManager.h>
+#include <mediadrm/DrmHalListener.h>
 #include <mediadrm/IDrm.h>
-#include <memory>
 
-using ::aidl::android::hardware::drm::BnDrmPluginListener;
 using IDrmPluginAidl = ::aidl::android::hardware::drm::IDrmPlugin;
 using IDrmFactoryAidl = ::aidl::android::hardware::drm::IDrmFactory;
 using EventTypeAidl = ::aidl::android::hardware::drm::EventType;
@@ -34,9 +34,7 @@
 using ::aidl::android::hardware::drm::Uuid;
 
 namespace android {
-struct DrmHalAidl : public IDrm,
-                    public BnDrmPluginListener,
-                    std::enable_shared_from_this<BnDrmPluginListener> {
+struct DrmHalAidl : public IDrm{
     struct DrmSessionClient;
     DrmHalAidl();
     virtual ~DrmHalAidl();
@@ -107,7 +105,7 @@
                                            bool* required) const;
     virtual status_t setPlaybackId(Vector<uint8_t> const& sessionId, const char* playbackId);
     virtual status_t getLogMessages(Vector<drm::V1_4::LogMessage>& logs) const;
-    // Methods of IDrmPluginListenerAidl
+
     ::ndk::ScopedAStatus onEvent(EventTypeAidl in_eventType,
                                  const std::vector<uint8_t>& in_sessionId,
                                  const std::vector<uint8_t>& in_data);
@@ -117,17 +115,14 @@
                                       const std::vector<KeyStatusAidl>& in_keyStatusList,
                                       bool in_hasNewUsableKey);
     ::ndk::ScopedAStatus onSessionLostState(const std::vector<uint8_t>& in_sessionId);
-
   private:
     static Mutex mLock;
-    sp<IDrmClient> mListener;
-    mutable Mutex mEventLock;
-    mutable Mutex mNotifyLock;
+    mutable MediaDrmMetrics mMetrics;
+    std::shared_ptr<DrmHalListener> mListener;
     const std::vector<std::shared_ptr<IDrmFactoryAidl>> mFactories;
     std::shared_ptr<IDrmPluginAidl> mPlugin;
     std::vector<std::shared_ptr<IDrmFactoryAidl>> makeDrmFactories();
     status_t mInitCheck;
-    mutable MediaDrmMetrics mMetrics;
     std::vector<std::shared_ptr<DrmSessionClient>> mOpenSessions;
     void cleanup();
     void closeOpenSessions();
@@ -140,4 +135,4 @@
 
 }  // namespace android
 
-#endif
\ No newline at end of file
+#endif // DRM_HAL_AIDL_H_
\ No newline at end of file
diff --git a/drm/libmediadrm/include/mediadrm/DrmHalHidl.h b/drm/libmediadrm/include/mediadrm/DrmHalHidl.h
index 91dc700..94ef285 100644
--- a/drm/libmediadrm/include/mediadrm/DrmHalHidl.h
+++ b/drm/libmediadrm/include/mediadrm/DrmHalHidl.h
@@ -17,10 +17,6 @@
 #ifndef DRM_HAL_HIDL_H_
 #define DRM_HAL_HIDL_H_
 
-#include <android/hardware/drm/1.0/IDrmFactory.h>
-#include <android/hardware/drm/1.0/IDrmPlugin.h>
-#include <android/hardware/drm/1.1/IDrmFactory.h>
-#include <android/hardware/drm/1.1/IDrmPlugin.h>
 #include <android/hardware/drm/1.2/IDrmFactory.h>
 #include <android/hardware/drm/1.2/IDrmPlugin.h>
 #include <android/hardware/drm/1.2/IDrmPluginListener.h>
@@ -255,4 +251,4 @@
 
 }  // namespace android
 
-#endif  // DRM_HAL_H_
+#endif // DRM_HAL_HIDL_H_
diff --git a/drm/libmediadrm/include/mediadrm/DrmHalListener.h b/drm/libmediadrm/include/mediadrm/DrmHalListener.h
new file mode 100644
index 0000000..22361ad
--- /dev/null
+++ b/drm/libmediadrm/include/mediadrm/DrmHalListener.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#ifndef DRM_HAL_LISTENER_H_
+#define DRM_HAL_LISTENER_H_
+
+#include <aidl/android/hardware/drm/BnDrmPluginListener.h>
+#include <mediadrm/DrmMetrics.h>
+#include <mediadrm/IDrmClient.h>
+
+using EventTypeAidl = ::aidl::android::hardware::drm::EventType;
+using KeyStatusAidl = ::aidl::android::hardware::drm::KeyStatus;
+using aidl::android::hardware::drm::BnDrmPluginListener;
+
+namespace android {
+struct DrmHalListener : public BnDrmPluginListener {
+    explicit DrmHalListener(MediaDrmMetrics* mMetrics);
+    ~DrmHalListener();
+    ::ndk::ScopedAStatus onEvent(EventTypeAidl in_eventType,
+                                 const std::vector<uint8_t>& in_sessionId,
+                                 const std::vector<uint8_t>& in_data);
+    ::ndk::ScopedAStatus onExpirationUpdate(const std::vector<uint8_t>& in_sessionId,
+                                            int64_t in_expiryTimeInMS);
+    ::ndk::ScopedAStatus onKeysChange(const std::vector<uint8_t>& in_sessionId,
+                                      const std::vector<KeyStatusAidl>& in_keyStatusList,
+                                      bool in_hasNewUsableKey);
+    ::ndk::ScopedAStatus onSessionLostState(const std::vector<uint8_t>& in_sessionId);
+    void setListener(sp<IDrmClient> listener);
+private:
+    mutable MediaDrmMetrics* mMetrics;
+    sp<IDrmClient> mListener;
+    mutable Mutex mEventLock;
+    mutable Mutex mNotifyLock;
+};
+} // namespace android
+
+#endif  // DRM_HAL_LISTENER_H_
\ No newline at end of file