hwc: Processing of HDMI connection request when WFD is active

  when HDMI is connected during active WFD session, teardown
  WFD and process HDMI connection request.

CRs-Fixed: 442226
Change-Id: I4b22ff9f1ab3175bab47babdaf040cb2289ebe4d
diff --git a/libexternal/external.cpp b/libexternal/external.cpp
index 3f13906..b336b84 100644
--- a/libexternal/external.cpp
+++ b/libexternal/external.cpp
@@ -99,6 +99,8 @@
     setResolution(mode);
     setDpyHdmiAttr();
     setExternalDisplay(true, mHdmiFbNum);
+    // set system property
+    property_set("hw.hdmiON", "1");
     return 0;
 }
 
@@ -128,6 +130,8 @@
         closeFrameBuffer();
         resetInfo();
         setExternalDisplay(false);
+        // unset system property
+        property_set("hw.hdmiON", "0");
     }
     return 0;
 }
@@ -142,29 +146,17 @@
     return 0;
 }
 
-void ExternalDisplay::processUEventOnline(const char *str) {
+int ExternalDisplay::ignoreRequest(const char *str) {
     const char *s1 = str + strlen("change@/devices/virtual/switch/");
-    if(!strncmp(s1,"hdmi",strlen(s1))) {
-        // hdmi online event..!
-        configureHDMIDisplay();
-        // set system property
-        property_set("hw.hdmiON", "1");
-    }else if(!strncmp(s1,"wfd",strlen(s1))) {
-        // wfd online event..!
-        configureWFDDisplay();
+    if(!strncmp(s1,"wfd",strlen(s1))) {
+        if(mConnectedFbNum == mHdmiFbNum) {
+            ALOGE("Ignore wfd event when HDMI is active");
+            return true;
+        }
     }
+    return false;
 }
 
-void ExternalDisplay::processUEventOffline(const char *str) {
-    const char *s1 = str + strlen("change@/devices/virtual/switch/");
-    if(!strncmp(s1,"hdmi",strlen(s1))) {
-        teardownHDMIDisplay();
-        // unset system property
-        property_set("hw.hdmiON", "0");
-    }else if(!strncmp(s1,"wfd",strlen(s1))) {
-        teardownWFDDisplay();
-    }
-}
 
 ExternalDisplay::ExternalDisplay(hwc_context_t* ctx):mFd(-1),
     mCurrentMode(-1), mConnected(0), mConnectedFbNum(0), mModeCount(0),
diff --git a/libexternal/external.h b/libexternal/external.h
index d46eec1..847b25c 100644
--- a/libexternal/external.h
+++ b/libexternal/external.h
@@ -47,11 +47,16 @@
     void setExternalDisplay(bool connected, int extFbNum = 0);
     bool isExternalConnected() { return mConnected;};
     void  setExtDpyNum(int extDpyNum) { mExtDpyNum = extDpyNum;};
+    int  getExternalType() {return mConnectedFbNum;};
+    bool isWFDActive() {return (mConnectedFbNum == mWfdFbNum);};
     void setHPD(uint32_t startEnd);
     void setEDIDMode(int resMode);
     void setActionSafeDimension(int w, int h);
-    void processUEventOnline(const char *str);
-    void processUEventOffline(const char *str);
+    int ignoreRequest(const char *str);
+    int  configureHDMIDisplay();
+    int  configureWFDDisplay();
+    int  teardownHDMIDisplay();
+    int  teardownWFDDisplay();
 
 private:
     void readCEUnderscanInfo();
@@ -72,10 +77,6 @@
     void setDpyWfdAttr();
     void getAttrForMode(int& width, int& height, int& fps);
     void updateExtDispDevFbIndex();
-    int  configureHDMIDisplay();
-    int  configureWFDDisplay();
-    int  teardownHDMIDisplay();
-    int  teardownWFDDisplay();
     int  getExtFbNum(int &fbNum);
 
     mutable android::Mutex mExtDispLock;