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

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

Merge "Log UsbDeviceAttached events for Audio devices"

parents 5b0bc1f7 5ec629f0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1217,6 +1217,12 @@ message UsbDeviceAttached {
    optional bool has_audio = 3;
    optional bool has_hid = 4;
    optional bool has_storage = 5;
    enum State {
        STATE_DISCONNECTED = 0;
        STATE_CONNECTED = 1;
    }
    optional State state = 6;
    optional int64 last_connect_duration_ms = 7;
}


+30 −1
Original line number Diff line number Diff line
@@ -32,7 +32,9 @@ import android.service.usb.UsbConnectionRecordProto;
import android.service.usb.UsbHostManagerProto;
import android.service.usb.UsbIsHeadsetProto;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Slog;
import android.util.StatsLog;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.IndentingPrintWriter;
@@ -86,6 +88,7 @@ public class UsbHostManager {
    private int mNumConnects;    // TOTAL # of connect/disconnect
    private final LinkedList<ConnectionRecord> mConnections = new LinkedList<ConnectionRecord>();
    private ConnectionRecord mLastConnect;
    private final ArrayMap<String, ConnectionRecord> mConnected = new ArrayMap<>();

    /*
     * ConnectionRecord
@@ -300,6 +303,11 @@ public class UsbHostManager {
        if (mode != ConnectionRecord.DISCONNECT) {
            mLastConnect = rec;
        }
        if (mode == ConnectionRecord.CONNECT) {
            mConnected.put(deviceAddress, rec);
        } else if (mode == ConnectionRecord.DISCONNECT) {
            mConnected.remove(deviceAddress);
        }
    }

    private void logUsbDevice(UsbDescriptorParser descriptorParser) {
@@ -408,6 +416,14 @@ public class UsbHostManager {
                // Tracking
                addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT,
                        parser.getRawDescriptors());

                // Stats collection
                if (parser.hasAudioInterface()) {
                    StatsLog.write(StatsLog.USB_DEVICE_ATTACHED, newDevice.getVendorId(),
                            newDevice.getProductId(), parser.hasAudioInterface(),
                            parser.hasHIDInterface(), parser.hasStorageInterface(),
                            StatsLog.USB_DEVICE_ATTACHED__STATE__STATE_CONNECTED, 0);
                }
            }
        }

@@ -432,9 +448,22 @@ public class UsbHostManager {
                mUsbAlsaManager.usbDeviceRemoved(deviceAddress);
                mSettingsManager.usbDeviceRemoved(device);
                getCurrentUserSettings().usbDeviceRemoved(device);

                ConnectionRecord current = mConnected.get(deviceAddress);
                // Tracking
                addConnectionRecord(deviceAddress, ConnectionRecord.DISCONNECT, null);

                if (current != null) {
                    UsbDescriptorParser parser = new UsbDescriptorParser(deviceAddress,
                            current.mDescriptors);
                    if (parser.hasAudioInterface()) {
                        // Stats collection
                        StatsLog.write(StatsLog.USB_DEVICE_ATTACHED, device.getVendorId(),
                                device.getProductId(), parser.hasAudioInterface(),
                                parser.hasHIDInterface(),  parser.hasStorageInterface(),
                                StatsLog.USB_DEVICE_ATTACHED__STATE__STATE_DISCONNECTED,
                                System.currentTimeMillis() - current.mTimestamp);
                    }
                }
            } else {
                Slog.d(TAG, "Removed device at " + deviceAddress + " was already gone");
            }