Merge "hwc: Add secure display attribute"
diff --git a/libexternal/external.cpp b/libexternal/external.cpp
index 3e93712..d37a915 100644
--- a/libexternal/external.cpp
+++ b/libexternal/external.cpp
@@ -587,6 +587,11 @@
         mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = width;
         mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = height;
         mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].mDownScaleMode = false;
+        //FIXME: for now assume HDMI as secure
+        //Will need to read the HDCP status from the driver
+        //and update this accordingly
+        mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].secure = true;
+
         if(!qdutils::MDPVersion::getInstance().is8x26()
                 && mHwcContext->mMDPDownscaleEnabled) {
             int priW = mHwcContext->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 4238eaf..b085993 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -822,6 +822,7 @@
         HWC_DISPLAY_HEIGHT,
         HWC_DISPLAY_DPI_X,
         HWC_DISPLAY_DPI_Y,
+        HWC_DISPLAY_SECURE,
         HWC_DISPLAY_NO_ATTRIBUTE,
     };
 
@@ -849,6 +850,9 @@
         case HWC_DISPLAY_DPI_Y:
             values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
             break;
+        case HWC_DISPLAY_SECURE:
+            values[i] = (int32_t) (ctx->dpyAttr[disp].secure);
+            break;
         default:
             ALOGE("Unknown display attribute %d",
                     attributes[i]);
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 41358be..d00f820 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -136,6 +136,7 @@
     ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
     ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
     ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / fps;
+    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
 
     //Unblank primary on first boot
     if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index b105e83..12c6d69 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -78,6 +78,7 @@
     uint32_t stride;
     float xdpi;
     float ydpi;
+    bool secure;
     int fd;
     bool connected; //Applies only to pluggable disp.
     //Connected does not mean it ready to use.
diff --git a/libvirtual/virtual.cpp b/libvirtual/virtual.cpp
index bed5e4c..3c8d3c5 100644
--- a/libvirtual/virtual.cpp
+++ b/libvirtual/virtual.cpp
@@ -84,6 +84,7 @@
     // this to distinguish between an ONLINE and RESUME event.
     mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].xres = 0;
     mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].yres = 0;
+    mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].secure = 0;
     return 0;
 }
 
@@ -170,12 +171,45 @@
     }
 }
 
+bool VirtualDisplay::isSinkSecure() {
+    char sysFsPath[MAX_SYSFS_FILE_PATH];
+    bool ret = false;
+    int fbNum = overlay::Overlay::getInstance()->
+        getFbForDpy(HWC_DISPLAY_VIRTUAL);
+    snprintf(sysFsPath, sizeof(sysFsPath),
+             "/sys/devices/virtual/graphics/fb%d/"
+             "secure", fbNum);
+
+    int fileFd = open(sysFsPath, O_RDONLY, 0);
+    if (fileFd < 0) {
+        ALOGE("In %s: file '%s' not found", __FUNCTION__, sysFsPath);
+        ret = false;
+    } else {
+        char buf;
+        ssize_t err = read(fileFd, &buf, 1);
+        if (err <= 0) {
+            ALOGE("%s: empty file '%s'", __FUNCTION__, sysFsPath);
+        } else {
+            if (buf == '1') {
+                // HDCP Supported: secure
+                ret = true;
+            } else {
+                // NonHDCP: non-secure
+                ret = false;
+            }
+        }
+        close(fileFd);
+    }
+    return ret;
+}
+
 void VirtualDisplay::setAttributes() {
     if(mHwcContext) {
         uint32_t &extW = mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].xres;
         uint32_t &extH = mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].yres;
         uint32_t priW = mHwcContext->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
         uint32_t priH = mHwcContext->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
+        bool &secure = mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].secure;
 
         // Dynamic Resolution Change depends on MDP downscaling.
         // MDP downscale property will be ignored to exercise DRC use case.
@@ -197,6 +231,11 @@
         }
         mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].vsync_period =
                 1000000000l /60;
+        if(mHwcContext->mVirtualonExtActive) {
+            //For WFD using V4l2 read the sysfs node to determine
+            //if the sink is secure
+            secure = isSinkSecure();
+        }
         ALOGD_IF(DEBUG,"%s: Setting Virtual Attr: res(%d x %d)",__FUNCTION__,
                  mVInfo.xres, mVInfo.yres);
     }
diff --git a/libvirtual/virtual.h b/libvirtual/virtual.h
index a6aec40..4f9d7ab 100644
--- a/libvirtual/virtual.h
+++ b/libvirtual/virtual.h
@@ -51,6 +51,7 @@
 private:
     bool openFrameBuffer();
     bool closeFrameBuffer();
+    bool isSinkSecure();
     void setAttributes();
     void initResolution(uint32_t &extW, uint32_t &extH);
     void setToPrimary(uint32_t maxArea, uint32_t priW, uint32_t priH,