aidl: usb: Fix support for contaminant presence detection

* Samsung does not let userspace disable that, so better always show the
  notification instead of leaving users wondering about why USB does no
  longer work

Change-Id: Iab045c8b15a726644ce51ce2877030d4b71cbcf7
diff --git a/aidl/usb/Usb.cpp b/aidl/usb/Usb.cpp
index d39d7ca..bf3b55d 100644
--- a/aidl/usb/Usb.cpp
+++ b/aidl/usb/Usb.cpp
@@ -137,8 +137,7 @@
     return ScopedAStatus::ok();
 }
 
-Status queryMoistureDetectionStatus(android::hardware::usb::Usb *usb,
-                                    std::vector<PortStatus> *currentPortStatus) {
+Status queryMoistureDetectionStatus(std::vector<PortStatus> *currentPortStatus) {
     string enabled, status, path, DetectedPath;
 
     for (int i = 0; i < currentPortStatus->size(); i++) {
@@ -151,7 +150,7 @@
         (*currentPortStatus)[i].supportsEnableContaminantPresenceDetection = true;
         (*currentPortStatus)[i].supportsEnableContaminantPresenceProtection = false;
 
-        if (usb->mMoistureDetectionEnabled) {
+        if (GetProperty(DISABLE_CONTAMINANT_DETECTION, "") != "true") {
             if (readFile(CONTAMINANT_DETECTION_PATH, &status)) {
                 ALOGE("Failed to open %s", CONTAMINANT_DETECTION_PATH);
                 return Status::ERROR;
@@ -296,8 +295,7 @@
     : mLock(PTHREAD_MUTEX_INITIALIZER),
       mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER),
       mPartnerLock(PTHREAD_MUTEX_INITIALIZER),
-      mPartnerUp(false),
-      mMoistureDetectionEnabled(false)
+      mPartnerUp(false)
 {
     pthread_condattr_t attr;
     if (pthread_condattr_init(&attr)) {
@@ -578,7 +576,7 @@
     Status status;
     pthread_mutex_lock(&usb->mLock);
     status = getPortStatusHelper(currentPortStatus);
-    queryMoistureDetectionStatus(usb, currentPortStatus);
+    queryMoistureDetectionStatus(currentPortStatus);
     if (usb->mCallback != NULL) {
         ScopedAStatus ret = usb->mCallback->notifyPortStatusChange(*currentPortStatus,
             status);
@@ -609,17 +607,14 @@
 }
 
 ScopedAStatus Usb::enableContaminantPresenceDetection(const string& in_portName,
-        bool in_enable, int64_t in_transactionId) {
+        bool /* in_enable */, int64_t in_transactionId) {
     std::vector<PortStatus> currentPortStatus;
     std::string disable = GetProperty(DISABLE_CONTAMINANT_DETECTION, "");
 
-    if (disable != "true")
-        mMoistureDetectionEnabled = in_enable;
-
     pthread_mutex_lock(&mLock);
     if (mCallback != NULL) {
         ScopedAStatus ret = mCallback->notifyContaminantEnabledStatus(
-            in_portName, false, Status::SUCCESS, in_transactionId);
+            in_portName, true, Status::SUCCESS, in_transactionId);
         if (!ret.isOk())
             ALOGE("enableContaminantPresenceDetection  error %s", ret.getDescription().c_str());
     } else {
diff --git a/aidl/usb/Usb.h b/aidl/usb/Usb.h
index a0794f3..9cfb22d 100644
--- a/aidl/usb/Usb.h
+++ b/aidl/usb/Usb.h
@@ -76,7 +76,6 @@
     pthread_mutex_t mPartnerLock;
     // Variable to signal partner coming back online after type switch
     bool mPartnerUp;
-    bool mMoistureDetectionEnabled;
   private:
     pthread_t mPoll;
 };