MediaEvent should be sent when shared memory info is passed.

Bug: 191825295
Test: atest android.media.tv.tuner.cts on both AIDL and HIDL HAL.
Test: sampletunertvinput
Change-Id: I4a6bcfd95bff7ecd0a12210f102d92a9b981eae2
diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp
index 5cbdc13..f1c72f8 100644
--- a/media/jni/android_media_tv_Tuner.cpp
+++ b/media/jni/android_media_tv_Tuner.cpp
@@ -633,7 +633,9 @@
                                  offset, nullptr, isSecureMemory, avDataId, mpuSequenceNumber,
                                  isPesPrivateData, audioDescriptor);
 
-    if (mediaEvent.avMemory.fds.size() > 0 || mediaEvent.avDataId != 0) {
+    uint64_t avSharedMemSize = mFilterClient->getAvSharedHandleInfo().size;
+    if (mediaEvent.avMemory.fds.size() > 0 || mediaEvent.avDataId != 0 ||
+        (dataLength > 0 && (dataLength + offset) < avSharedMemSize)) {
         sp<MediaEvent> mediaEventSp =
                 new MediaEvent(mFilterClient, dupFromAidl(mediaEvent.avMemory),
                                mediaEvent.avDataId, dataLength + offset, obj);
@@ -1756,15 +1758,16 @@
 }
 
 jobject JTuner::openDvr(DvrType type, jlong bufferSize) {
-    ALOGD("JTuner::openDvr");
+    ALOGV("JTuner::openDvr");
     if (mDemuxClient == nullptr) {
         return nullptr;
     }
+
     sp<DvrClient> dvrClient;
     sp<DvrClientCallbackImpl> callback = new DvrClientCallbackImpl();
     dvrClient = mDemuxClient->openDvr(type, (int) bufferSize, callback);
-
     if (dvrClient == nullptr) {
+        ALOGD("Failed to open Dvr");
         return nullptr;
     }
 
@@ -4060,7 +4063,7 @@
         ALOGD("Failed to set FD for dvr: dvr client not found");
         return;
     }
-    dvrClient->setFd((int)fd);
+    dvrClient->setFd(fd);
     ALOGV("set fd = %d", fd);
 }