Added programInfoChanged callback.

Also, updated tuneComplete_1_1 and afSwitch_1_1 to match the new behavior
(not passing the whole ProgramInfo struct).

Bug: b/32621193
Test: VTS (none added)
Change-Id: Ic8aee15b05cb982d97e550fc0806f34fbe112e22
diff --git a/broadcastradio/1.1/ITunerCallback.hal b/broadcastradio/1.1/ITunerCallback.hal
index 158e217..b1c5b01 100644
--- a/broadcastradio/1.1/ITunerCallback.hal
+++ b/broadcastradio/1.1/ITunerCallback.hal
@@ -28,16 +28,26 @@
     /**
      * Method called by the HAL when a tuning operation completes
      * following a step(), scan() or tune() command.
+     *
+     * This callback supersedes V1_0::tuneComplete. For performance reasons,
+     * the 1.0 callback may not be called when HAL implementation detects 1.1
+     * client (by casting V1_0::ITunerCallback to V1_1::ITunerCallback).
+     *
      * @param result OK if tune succeeded or TIMEOUT in case of time out.
-     * @param info A ProgramInfo structure describing the tuned station.
+     * @param selector A ProgramSelector structure describing the tuned station.
      */
-    oneway tuneComplete_1_1(Result result, ProgramInfo info);
+    oneway tuneComplete_1_1(Result result, ProgramSelector selector);
 
     /**
      * Method called by the HAL when a frequency switch occurs.
-     * @param info A ProgramInfo structure describing the new tuned station.
+     *
+     * This callback supersedes V1_0::afSwitch. For performance reasons,
+     * the 1.0 callback may not be called when HAL implementation detects 1.1
+     * client (by casting V1_0::ITunerCallback to V1_1::ITunerCallback).
+     *
+     * @param selector A ProgramSelector structure describing the tuned station.
      */
-    oneway afSwitch_1_1(ProgramInfo info);
+    oneway afSwitch_1_1(ProgramSelector selector);
 
     /**
      * Called by the HAL when background scan feature becomes available or not.
@@ -69,4 +79,20 @@
      * Client may retrieve the actual list with ITuner::getProgramList.
      */
     oneway programListChanged();
+
+    /**
+     * Method called by the HAL when current program information (including
+     * metadata) is updated.
+     *
+     * Client may retrieve the actual program info with
+     * ITuner::getProgramInformation_1_1.
+     *
+     * This may be called together with tuneComplete_1_1 or afSwitch_1_1.
+     *
+     * This callback supersedes V1_0::tuneComplete, V1_0::afSwitch and
+     * newMetadata. For performance reasons, these callbacks may not be called
+     * when HAL implementation detects 1.1 client (by casting
+     * V1_0::ITunerCallback to V1_1::ITunerCallback).
+     */
+    oneway programInfoChanged();
 };
diff --git a/broadcastradio/1.1/default/Tuner.cpp b/broadcastradio/1.1/default/Tuner.cpp
index 3c43c2e..0238f14 100644
--- a/broadcastradio/1.1/default/Tuner.cpp
+++ b/broadcastradio/1.1/default/Tuner.cpp
@@ -126,9 +126,10 @@
     }
     mIsTuneCompleted = true;
 
-    mCallback->tuneComplete(Result::OK, mCurrentProgramInfo.base);
-    if (mCallback1_1 != nullptr) {
-        mCallback1_1->tuneComplete_1_1(Result::OK, mCurrentProgramInfo);
+    if (mCallback1_1 == nullptr) {
+        mCallback->tuneComplete(Result::OK, mCurrentProgramInfo.base);
+    } else {
+        mCallback1_1->tuneComplete_1_1(Result::OK, mCurrentProgramInfo.selector);
     }
 }
 
@@ -146,8 +147,9 @@
         auto task = [this, direction]() {
             ALOGI("Performing failed scan %s", toString(direction).c_str());
 
-            mCallback->tuneComplete(Result::TIMEOUT, {});
-            if (mCallback1_1 != nullptr) {
+            if (mCallback1_1 == nullptr) {
+                mCallback->tuneComplete(Result::TIMEOUT, {});
+            } else {
                 mCallback1_1->tuneComplete_1_1(Result::TIMEOUT, {});
             }
         };
diff --git a/broadcastradio/1.1/vts/functional/VtsHalBroadcastradioV1_1TargetTest.cpp b/broadcastradio/1.1/vts/functional/VtsHalBroadcastradioV1_1TargetTest.cpp
index 6e6ab44..3b29c75 100644
--- a/broadcastradio/1.1/vts/functional/VtsHalBroadcastradioV1_1TargetTest.cpp
+++ b/broadcastradio/1.1/vts/functional/VtsHalBroadcastradioV1_1TargetTest.cpp
@@ -68,9 +68,9 @@
     MOCK_METHOD0(hardwareFailure, Return<void>());
     MOCK_TIMEOUT_METHOD2(configChange, Return<void>(Result, const BandConfig&));
     MOCK_METHOD2(tuneComplete, Return<void>(Result, const V1_0::ProgramInfo&));
-    MOCK_TIMEOUT_METHOD2(tuneComplete_1_1, Return<void>(Result, const ProgramInfo&));
+    MOCK_TIMEOUT_METHOD2(tuneComplete_1_1, Return<void>(Result, const ProgramSelector&));
     MOCK_METHOD1(afSwitch, Return<void>(const V1_0::ProgramInfo&));
-    MOCK_METHOD1(afSwitch_1_1, Return<void>(const ProgramInfo&));
+    MOCK_METHOD1(afSwitch_1_1, Return<void>(const ProgramSelector&));
     MOCK_METHOD1(antennaStateChange, Return<void>(bool connected));
     MOCK_METHOD1(trafficAnnouncement, Return<void>(bool active));
     MOCK_METHOD1(emergencyAnnouncement, Return<void>(bool active));
@@ -78,6 +78,7 @@
     MOCK_METHOD1(backgroundScanAvailable, Return<void>(bool));
     MOCK_TIMEOUT_METHOD1(backgroundScanComplete, Return<void>(ProgramListResult));
     MOCK_METHOD0(programListChanged, Return<void>());
+    MOCK_METHOD0(programInfoChanged, Return<void>());
 };
 
 class BroadcastRadioHalTest : public ::testing::VtsHalHidlTargetTestBase,
@@ -276,14 +277,14 @@
         return;
     }
 
-    ProgramInfo infoCb;
+    ProgramSelector selCb;
     EXPECT_CALL(*mCallback, tuneComplete(_, _));
     EXPECT_TIMEOUT_CALL(*mCallback, tuneComplete_1_1, Result::OK, _)
-        .WillOnce(DoAll(SaveArg<1>(&infoCb), testing::Return(ByMove(Void()))));
+        .WillOnce(DoAll(SaveArg<1>(&selCb), testing::Return(ByMove(Void()))));
     auto tuneResult = mTuner->tune_1_1(firstProgram.selector);
     ASSERT_EQ(Result::OK, tuneResult);
     EXPECT_TIMEOUT_CALL_WAIT(*mCallback, tuneComplete_1_1, kTuneTimeout);
-    EXPECT_EQ(firstProgram.selector.primaryId, infoCb.selector.primaryId);
+    EXPECT_EQ(firstProgram.selector.primaryId, selCb.primaryId);
 }
 
 INSTANTIATE_TEST_CASE_P(BroadcastRadioHalTestCases, BroadcastRadioHalTest,