Support Link/Unlink Cicam to Frontend in Tuner HAL 1.1

The previous linkCicam API does not support local transport stream id
return. Added the support in this CL.

Also added an unlink API to unlink the cicam when needed.

INVALID_LTS_ID will be used on failed operation of linkCicam
and in Tuner java framework as the default value

Test: make android.hardware.tv.tuner@1.1-service
Bug: 158818696
Change-Id: Ief9c5097c667ce41a534b0d1d759869acd79ca7f
diff --git a/tv/tuner/1.1/IFrontend.hal b/tv/tuner/1.1/IFrontend.hal
index e9c5e19..63f0655 100644
--- a/tv/tuner/1.1/IFrontend.hal
+++ b/tv/tuner/1.1/IFrontend.hal
@@ -77,11 +77,22 @@
      * directly from the frontend.
      *
      * @param ciCamId specify CI-CAM Id to link.
+     * @return ltsId Local Transport Stream Id.
      * @return result Result status of the operation.
      *         SUCCESS if successful,
      *         UNKNOWN_ERROR if failed for other reasons.
      */
-    linkCiCam(uint32_t ciCamId) generates (Result result);
+    linkCiCam(uint32_t ciCamId) generates (Result result, uint32_t ltsId);
+
+    /**
+     * Unlink Conditional Access Modules (CAM) to Frontend.
+     *
+     * @param ciCamId specify CI-CAM Id to unlink.
+     * @return result Result status of the operation.
+     *         SUCCESS if successful,
+     *         UNKNOWN_ERROR if failed for other reasons.
+     */
+    unlinkCiCam(uint32_t ciCamId) generates (Result result);
 
     /**
      * Get the v1_1 extended statuses of the frontend.
diff --git a/tv/tuner/1.1/default/Frontend.cpp b/tv/tuner/1.1/default/Frontend.cpp
index 971e335..86be9ad 100644
--- a/tv/tuner/1.1/default/Frontend.cpp
+++ b/tv/tuner/1.1/default/Frontend.cpp
@@ -361,10 +361,19 @@
     return Result::SUCCESS;
 }
 
-Return<Result> Frontend::linkCiCam(uint32_t ciCamId) {
+Return<void> Frontend::linkCiCam(uint32_t ciCamId, linkCiCam_cb _hidl_cb) {
     ALOGV("%s", __FUNCTION__);
 
     mCiCamId = ciCamId;
+    _hidl_cb(Result::SUCCESS, 0 /*ltsId*/);
+
+    return Void();
+}
+
+Return<Result> Frontend::unlinkCiCam(uint32_t /*ciCamId*/) {
+    ALOGV("%s", __FUNCTION__);
+
+    mCiCamId = -1;
 
     return Result::SUCCESS;
 }
diff --git a/tv/tuner/1.1/default/Frontend.h b/tv/tuner/1.1/default/Frontend.h
index 4c35718..a28fb64 100644
--- a/tv/tuner/1.1/default/Frontend.h
+++ b/tv/tuner/1.1/default/Frontend.h
@@ -66,7 +66,9 @@
 
     virtual Return<Result> setLnb(uint32_t lnb) override;
 
-    virtual Return<Result> linkCiCam(uint32_t ciCamId) override;
+    virtual Return<void> linkCiCam(uint32_t ciCamId, linkCiCam_cb _hidl_cb) override;
+
+    virtual Return<Result> unlinkCiCam(uint32_t ciCamId) override;
 
     FrontendType getFrontendType();
 
diff --git a/tv/tuner/1.1/types.hal b/tv/tuner/1.1/types.hal
index b20e625..057351f 100644
--- a/tv/tuner/1.1/types.hal
+++ b/tv/tuner/1.1/types.hal
@@ -58,6 +58,11 @@
      * be used to reset the configured ip context id.
      */
     INVALID_IP_FILTER_CONTEXT_ID = 0xFFFFFFFF,
+    /**
+     * An invalid local transport stream id used as the return value on a failed operation of
+     * IFrontend.linkCiCam.
+     */
+    INVALID_LTS_ID = 0xFFFFFFFF,
 };
 
 @export