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
urubino
Tim Zimmermann 2 years ago committed by Bruno Martins
parent 04dfa0c9e5
commit 58bcd82cd8
  1. 17
      aidl/usb/Usb.cpp
  2. 1
      aidl/usb/Usb.h

@ -137,8 +137,7 @@ ScopedAStatus Usb::resetUsbPort(const string& in_portName, int64_t in_transactio
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 @@ Status queryMoistureDetectionStatus(android::hardware::usb::Usb *usb,
(*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 @@ Usb::Usb()
: 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 @@ void queryVersionHelper(android::hardware::usb::Usb *usb,
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::queryPortStatus(int64_t in_transactionId) {
}
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 {

@ -76,7 +76,6 @@ struct Usb : public BnUsb {
pthread_mutex_t mPartnerLock;
// Variable to signal partner coming back online after type switch
bool mPartnerUp;
bool mMoistureDetectionEnabled;
private:
pthread_t mPoll;
};

Loading…
Cancel
Save