Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3df51131 authored by Badhri Jagan Sridharan's avatar Badhri Jagan Sridharan
Browse files

UsbPortManager: Re-enable contaminant detection when port is unplugged

SystemUI disables contaminant detection when user wants to continue
using the port. Re-enable contaminant detection when the accessory
is unplugged.

Bug: 128534822
Test: Tested with the mock circuit.
Change-Id: I22a3c839264876409c68c6a3145c9fcc6278f381
parent 26c490c5
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -965,6 +965,7 @@ public class UsbPortManager {

    private void handlePortLocked(PortInfo portInfo, IndentingPrintWriter pw) {
        sendPortChangedBroadcastLocked(portInfo);
        enableContaminantDetectionIfNeeded(portInfo, pw);
        logToStatsd(portInfo, pw);
        updateContaminantNotification();
    }
@@ -1016,6 +1017,22 @@ public class UsbPortManager {
                Manifest.permission.MANAGE_USB));
    }

    private void enableContaminantDetectionIfNeeded(PortInfo portInfo, IndentingPrintWriter pw) {
        if (!mConnected.containsKey(portInfo.mUsbPort.getId())) {
            return;
        }

        if (mConnected.get(portInfo.mUsbPort.getId())
                && !portInfo.mUsbPortStatus.isConnected()
                && portInfo.mUsbPortStatus.getContaminantDetectionStatus()
                == UsbPortStatus.CONTAMINANT_DETECTION_DISABLED) {
            // Contaminant detection might have been temporarily disabled by the user
            // through SystemUI.
            // Re-enable contaminant detection when the accessory is unplugged.
            enableContaminantDetection(portInfo.mUsbPort.getId(), true, pw);
        }
    }

    private void logToStatsd(PortInfo portInfo, IndentingPrintWriter pw) {
        // Port is removed
        if (portInfo.mUsbPortStatus == null) {
@@ -1052,12 +1069,6 @@ public class UsbPortManager {
                    ? StatsLog.USB_CONNECTOR_STATE_CHANGED__STATE__STATE_CONNECTED :
                    StatsLog.USB_CONNECTOR_STATE_CHANGED__STATE__STATE_DISCONNECTED,
                    portInfo.mUsbPort.getId(), portInfo.mLastConnectDurationMillis);
            // Contaminant detection might have been temporarily disabled by the user
            // through SystemUI.
            // Re-enable contaminant detection when the accessory is unplugged.
            if (!portInfo.mUsbPortStatus.isConnected()) {
                enableContaminantDetection(portInfo.mUsbPort.getId(), true, pw);
            }
        }

        if (!mContaminantStatus.containsKey(portInfo.mUsbPort.getId())