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

Commit 397a98c8 authored by Badhri Jagan Sridharan's avatar Badhri Jagan Sridharan
Browse files

Refactor actions that are needed to be taken during port status changes.

For any change in port status, the following needs to be done:
1. Send port changed Broadcast
2. Log to statsd
3. Update contaminant notification.

Bug: 128534822
Test: Tested with the mock circuit.
Change-Id: I2c279a2ea0255a69c0a74a98ebf5bf680cae1fe1
parent c227aec2
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -948,22 +948,25 @@ public class UsbPortManager {
        }
    }

    private void handlePortAddedLocked(PortInfo portInfo, IndentingPrintWriter pw) {
        logAndPrint(Log.INFO, pw, "USB port added: " + portInfo);
    private void handlePortLocked(PortInfo portInfo, IndentingPrintWriter pw) {
        sendPortChangedBroadcastLocked(portInfo);
        logToStatsd(portInfo);
        updateContaminantNotification();
    }

    private void handlePortAddedLocked(PortInfo portInfo, IndentingPrintWriter pw) {
        logAndPrint(Log.INFO, pw, "USB port added: " + portInfo);
        handlePortLocked(portInfo, pw);
    }

    private void handlePortChangedLocked(PortInfo portInfo, IndentingPrintWriter pw) {
        logAndPrint(Log.INFO, pw, "USB port changed: " + portInfo);
        sendPortChangedBroadcastLocked(portInfo);
        updateContaminantNotification();
        handlePortLocked(portInfo, pw);
    }

    private void handlePortRemovedLocked(PortInfo portInfo, IndentingPrintWriter pw) {
        logAndPrint(Log.INFO, pw, "USB port removed: " + portInfo);
        sendPortChangedBroadcastLocked(portInfo);
        updateContaminantNotification();
        handlePortLocked(portInfo, pw);
    }

    // Constants have to be converted between USB HAL V1.2 ContaminantDetectionStatus
@@ -996,9 +999,9 @@ public class UsbPortManager {
        // instead of from within the critical section.
        mHandler.post(() -> mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
                Manifest.permission.MANAGE_USB));
    }

        // Log to statsd

    private void logToStatsd(PortInfo portInfo) {
        // Port is removed
        if (portInfo.mUsbPortStatus == null) {
            if (mConnected.containsKey(portInfo.mUsbPort.getId())) {