Extend Scan Message and Message Type in Tuner HAL 1.1

A new API would be added in IFrontendCallback 1.1:
onScanMessageExt to receive the extended scan message

Test: atest VtsHalTvTunerV1_1TargetTest
Bug: 158818695
Change-Id: If12535dada78ee2d2c7282ff17f9ab5f4983c750
diff --git a/tv/tuner/1.1/Android.bp b/tv/tuner/1.1/Android.bp
index 6cf47f5..daa3683 100644
--- a/tv/tuner/1.1/Android.bp
+++ b/tv/tuner/1.1/Android.bp
@@ -7,6 +7,7 @@
         "IFilter.hal",
         "IFrontend.hal",
         "IFilterCallback.hal",
+        "IFrontendCallback.hal",
         "ITuner.hal",
         "types.hal",
     ],
diff --git a/tv/tuner/1.1/IFrontendCallback.hal b/tv/tuner/1.1/IFrontendCallback.hal
new file mode 100644
index 0000000..e148b1e
--- /dev/null
+++ b/tv/tuner/1.1/IFrontendCallback.hal
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2020 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.
+ */
+
+package android.hardware.tv.tuner@1.1;
+
+import @1.0::IFrontendCallback;
+import FrontendScanMessageExt1_1;
+import FrontendScanMessageTypeExt1_1;
+
+interface IFrontendCallback extends @1.0::IFrontendCallback {
+    /**
+     * The callback function that must be called by HAL implementation to notify
+     * the client of the v1_1 extended scan messages.
+     *
+     * @param type the type of v1_1 extended scan message.
+     * @param message the v1_1 extended scan message sent by HAL to the client.
+     */
+    onScanMessageExt1_1(FrontendScanMessageTypeExt1_1 type, FrontendScanMessageExt1_1 messageExt);
+};
diff --git a/tv/tuner/1.1/default/Frontend.cpp b/tv/tuner/1.1/default/Frontend.cpp
index c5aeace..971e335 100644
--- a/tv/tuner/1.1/default/Frontend.cpp
+++ b/tv/tuner/1.1/default/Frontend.cpp
@@ -17,7 +17,7 @@
 #define LOG_TAG "android.hardware.tv.tuner@1.1-Frontend"
 
 #include "Frontend.h"
-#include <android/hardware/tv/tuner/1.0/IFrontendCallback.h>
+#include <android/hardware/tv/tuner/1.1/IFrontendCallback.h>
 #include <utils/Log.h>
 
 namespace android {
@@ -118,6 +118,17 @@
     mCallback->onScanMessage(FrontendScanMessageType::LOCKED, msg);
     mIsLocked = true;
 
+    sp<V1_1::IFrontendCallback> frontendCallback_v1_1 =
+            V1_1::IFrontendCallback::castFrom(mCallback);
+    if (frontendCallback_v1_1 != NULL) {
+        V1_1::FrontendScanMessageExt1_1 msg;
+        msg.dvbc(FrontendDvbcModulation::MOD_16QAM);
+        frontendCallback_v1_1->onScanMessageExt1_1(V1_1::FrontendScanMessageTypeExt1_1::MODULATION,
+                                                   msg);
+    } else {
+        ALOGD("[Filter] Couldn't cast to V1_1 IFrontendCallback");
+    }
+
     return Result::SUCCESS;
 }
 
diff --git a/tv/tuner/1.1/types.hal b/tv/tuner/1.1/types.hal
index 9387513..29b999f 100644
--- a/tv/tuner/1.1/types.hal
+++ b/tv/tuner/1.1/types.hal
@@ -37,6 +37,7 @@
 import @1.0::FrontendIsdbtGuardInterval;
 import @1.0::FrontendIsdbtMode;
 import @1.0::FrontendIsdbtModulation;
+import @1.0::FrontendScanMessageType;
 import @1.0::FrontendStatusType;
 import @1.0::FrontendType;
 import android.hidl.safe_union@1.0;
@@ -522,3 +523,9 @@
      */
     vec<uint32_t> tsDataRate;
 };
+
+enum FrontendScanMessageTypeExt1_1 : uint32_t {
+    MODULATION = @1.0::FrontendScanMessageType:ATSC3_PLP_INFO + 1,
+};
+
+typedef FrontendModulation FrontendScanMessageExt1_1;
diff --git a/tv/tuner/1.1/vts/functional/FrontendTests.cpp b/tv/tuner/1.1/vts/functional/FrontendTests.cpp
index 1700e43..3bc7114 100644
--- a/tv/tuner/1.1/vts/functional/FrontendTests.cpp
+++ b/tv/tuner/1.1/vts/functional/FrontendTests.cpp
@@ -47,6 +47,51 @@
     return Void();
 }
 
+Return<void> FrontendCallback::onScanMessageExt1_1(FrontendScanMessageTypeExt1_1 type,
+                                                   const FrontendScanMessageExt1_1& message) {
+    android::Mutex::Autolock autoLock(mMsgLock);
+    ALOGD("[vts] frontend ext1_1 scan message. Type: %d", type);
+    switch (type) {
+        case FrontendScanMessageTypeExt1_1::MODULATION:
+            readFrontendScanMessageExt1_1Modulation(message);
+            break;
+        default:
+            break;
+    }
+    return Void();
+}
+
+void FrontendCallback::readFrontendScanMessageExt1_1Modulation(FrontendModulation modulation) {
+    switch (modulation.getDiscriminator()) {
+        case FrontendModulation::hidl_discriminator::dvbc:
+            ALOGD("[vts] frontend ext1_1 scan message modulation dvbc: %d", modulation.dvbc());
+            break;
+        case FrontendModulation::hidl_discriminator::dvbs:
+            ALOGD("[vts] frontend ext1_1 scan message modulation dvbs: %d", modulation.dvbs());
+            break;
+        case FrontendModulation::hidl_discriminator::isdbs:
+            ALOGD("[vts] frontend ext1_1 scan message modulation isdbs: %d", modulation.isdbs());
+            break;
+        case FrontendModulation::hidl_discriminator::isdbs3:
+            ALOGD("[vts] frontend ext1_1 scan message modulation isdbs3: %d", modulation.isdbs3());
+            break;
+        case FrontendModulation::hidl_discriminator::isdbt:
+            ALOGD("[vts] frontend ext1_1 scan message modulation isdbt: %d", modulation.isdbt());
+            break;
+        case FrontendModulation::hidl_discriminator::atsc:
+            ALOGD("[vts] frontend ext1_1 scan message modulation atsc: %d", modulation.atsc());
+            break;
+        case FrontendModulation::hidl_discriminator::atsc3:
+            ALOGD("[vts] frontend ext1_1 scan message modulation atsc3: %d", modulation.atsc3());
+            break;
+        case FrontendModulation::hidl_discriminator::dvbt:
+            ALOGD("[vts] frontend ext1_1 scan message modulation dvbt: %d", modulation.dvbt());
+            break;
+        default:
+            break;
+    }
+}
+
 void FrontendCallback::tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings,
                                       FrontendSettingsExt1_1 settingsExt1_1) {
     sp<android::hardware::tv::tuner::V1_1::IFrontend> frontend_1_1;
diff --git a/tv/tuner/1.1/vts/functional/FrontendTests.h b/tv/tuner/1.1/vts/functional/FrontendTests.h
index 106f653..243d9de 100644
--- a/tv/tuner/1.1/vts/functional/FrontendTests.h
+++ b/tv/tuner/1.1/vts/functional/FrontendTests.h
@@ -15,9 +15,9 @@
  */
 
 #include <android-base/logging.h>
-#include <android/hardware/tv/tuner/1.0/IFrontendCallback.h>
 #include <android/hardware/tv/tuner/1.0/types.h>
 #include <android/hardware/tv/tuner/1.1/IFrontend.h>
+#include <android/hardware/tv/tuner/1.1/IFrontendCallback.h>
 #include <android/hardware/tv/tuner/1.1/ITuner.h>
 #include <binder/MemoryDealer.h>
 #include <gtest/gtest.h>
@@ -54,9 +54,12 @@
 using android::hardware::tv::tuner::V1_0::FrontendScanMessageType;
 using android::hardware::tv::tuner::V1_0::FrontendScanType;
 using android::hardware::tv::tuner::V1_0::IFrontend;
-using android::hardware::tv::tuner::V1_0::IFrontendCallback;
 using android::hardware::tv::tuner::V1_0::Result;
 using android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities;
+using android::hardware::tv::tuner::V1_1::FrontendModulation;
+using android::hardware::tv::tuner::V1_1::FrontendScanMessageExt1_1;
+using android::hardware::tv::tuner::V1_1::FrontendScanMessageTypeExt1_1;
+using android::hardware::tv::tuner::V1_1::IFrontendCallback;
 using android::hardware::tv::tuner::V1_1::ITuner;
 
 using ::testing::AssertionResult;
@@ -71,6 +74,8 @@
     virtual Return<void> onEvent(FrontendEventType frontendEventType) override;
     virtual Return<void> onScanMessage(FrontendScanMessageType type,
                                        const FrontendScanMessage& message) override;
+    virtual Return<void> onScanMessageExt1_1(FrontendScanMessageTypeExt1_1 type,
+                                             const FrontendScanMessageExt1_1& message) override;
 
     void tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings,
                         FrontendSettingsExt1_1 settingsExt1_1);
@@ -81,6 +86,8 @@
     void resetBlindScanStartingFrequency(FrontendConfig& config, uint32_t resetingFreq);
 
   private:
+    void readFrontendScanMessageExt1_1Modulation(FrontendModulation modulation);
+
     bool mEventReceived = false;
     bool mScanMessageReceived = false;
     bool mLockMsgReceived = false;