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

Commit 53b986e7 authored by Badhri Jagan Sridharan's avatar Badhri Jagan Sridharan Committed by Android (Google) Code Review
Browse files

Merge "Usb non-compliant port partner frameworks suez stats"

parents 63cc827b 57228952
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -1082,6 +1082,7 @@ public class UsbPortManager {

    private void handlePortComplianceWarningLocked(PortInfo portInfo, IndentingPrintWriter pw) {
        logAndPrint(Log.INFO, pw, "USB port compliance warning changed: " + portInfo);
        logToStatsdComplianceWarnings(portInfo);
        sendComplianceWarningBroadcastLocked(portInfo);
    }

@@ -1108,6 +1109,33 @@ public class UsbPortManager {
        }
    }

    // Constants have to be converted to stats-log constants
    private static int[] toStatsLogConstant(@NonNull int[] complianceWarnings) {
        IntArray complianceWarningsProto = new IntArray();
        for (int warning : complianceWarnings) {
            switch (warning) {
                case UsbPortStatus.COMPLIANCE_WARNING_OTHER:
                    complianceWarningsProto.add(FrameworkStatsLog
                        .USB_COMPLIANCE_WARNINGS_REPORTED__COMPLIANCE_WARNINGS__COMPLIANCE_WARNING_OTHER);
                    continue;
                case UsbPortStatus.COMPLIANCE_WARNING_DEBUG_ACCESSORY:
                    complianceWarningsProto.add(FrameworkStatsLog
                        .USB_COMPLIANCE_WARNINGS_REPORTED__COMPLIANCE_WARNINGS__COMPLIANCE_WARNING_DEBUG_ACCESSORY);
                    continue;
                case UsbPortStatus.COMPLIANCE_WARNING_BC_1_2:
                    complianceWarningsProto.add(FrameworkStatsLog
                        .USB_COMPLIANCE_WARNINGS_REPORTED__COMPLIANCE_WARNINGS__COMPLIANCE_WARNING_BC_1_2);
                    continue;
                case UsbPortStatus.COMPLIANCE_WARNING_MISSING_RP:
                    complianceWarningsProto.add(FrameworkStatsLog
                        .USB_COMPLIANCE_WARNINGS_REPORTED__COMPLIANCE_WARNINGS__COMPLIANCE_WARNING_MISSING_RP);
                    continue;
            }
        }
        return complianceWarningsProto.toArray();
    }


    private void sendPortChangedBroadcastLocked(PortInfo portInfo) {
        final Intent intent = new Intent(UsbManager.ACTION_USB_PORT_CHANGED);
        intent.addFlags(
@@ -1219,6 +1247,20 @@ public class UsbPortManager {
        }
    }

    // Need to create new version to prevent double counting existing stats due
    // to new broadcast
    private void logToStatsdComplianceWarnings(PortInfo portInfo) {
        if (portInfo.mUsbPortStatus == null) {
            FrameworkStatsLog.write(FrameworkStatsLog.USB_COMPLIANCE_WARNINGS_REPORTED,
                portInfo.mUsbPort.getId(), new int[0]);
            return;
        }

        FrameworkStatsLog.write(FrameworkStatsLog.USB_COMPLIANCE_WARNINGS_REPORTED,
                portInfo.mUsbPort.getId(),
                toStatsLogConstant(portInfo.mUsbPortStatus.getComplianceWarnings()));
    }

    public static void logAndPrint(int priority, IndentingPrintWriter pw, String msg) {
        Slog.println(priority, TAG, msg);
        if (pw != null) {