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

Commit 57228952 authored by RD Babiera's avatar RD Babiera Committed by Badhri Jagan Sridharan
Browse files

Usb non-compliant port partner frameworks suez stats

On compliance warning change, reports to FrameworkStatsLog.

Eldar: https://eldar.corp.google.com/assessments/990567567/revisions/1?jsmode=o#sections/999001

Test: manually ran adb shell cmd stats print-logs,
adb logcat | grep statsd | grep \(582\)
Bug: 236322506
Change-Id: If96e8037cd0dabf4dde12b4aa2d30c817d2cb63c
parent 4c6d93bc
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) {