Loading cmds/statsd/src/atoms.proto +12 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import "frameworks/base/core/proto/android/server/connectivity/data_stall_event. import "frameworks/base/core/proto/android/server/enums.proto"; import "frameworks/base/core/proto/android/server/location/enums.proto"; import "frameworks/base/core/proto/android/service/procstats_enum.proto"; import "frameworks/base/core/proto/android/service/usb.proto"; import "frameworks/base/core/proto/android/stats/enums.proto"; import "frameworks/base/core/proto/android/stats/docsui/docsui_enums.proto"; import "frameworks/base/core/proto/android/stats/launcher/launcher.proto"; Loading Loading @@ -207,6 +208,7 @@ message Atom { AttentionManagerServiceResultReported attention_manager_service_result_reported = 143; AdbConnectionChanged adb_connection_changed = 144; SpeechDspStatReported speech_dsp_stat_reported = 145; UsbContaminantReported usb_contaminant_reported = 146; } // Pulled events will start at field 10000. Loading Loading @@ -4537,3 +4539,13 @@ message SpeechDspStatReported { optional int32 total_crash_count = 3; optional int32 total_recover_count = 4; } /** * Logs USB connector contaminant status. * * Logged from: USB Service. */ message UsbContaminantReported { optional string id = 1; optional android.service.usb.ContaminantPresenceStatus status = 2; } core/proto/android/service/usb.proto +9 −8 Original line number Diff line number Diff line Loading @@ -228,6 +228,15 @@ message UsbPortProto { repeated Mode supported_modes = 2; } /* Same as android.hardware.usb.V1_2.Constants.ContaminantPresenceStatus */ enum ContaminantPresenceStatus { CONTAMINANT_STATUS_UNKNOWN = 0; CONTAMINANT_STATUS_NOT_SUPPORTED = 1; CONTAMINANT_STATUS_DISABLED = 2; CONTAMINANT_STATUS_NOT_DETECTED = 3; CONTAMINANT_STATUS_DETECTED = 4; } message UsbPortStatusProto { option (android.msg_privacy).dest = DEST_AUTOMATIC; Loading @@ -245,14 +254,6 @@ message UsbPortStatusProto { DATA_ROLE_DEVICE = 2; } /* Same as android.hardware.usb.V1_2.Constants.ContaminantPresenceStatus */ enum ContaminantPresenceStatus { CONTAMINANT_STATUS_NOT_SUPPORTED = 0; CONTAMINANT_STATUS_DISABLED = 1; CONTAMINANT_STATUS_NOT_DETECTED = 2; CONTAMINANT_STATUS_DETECTED = 3; } optional bool connected = 1; optional UsbPortProto.Mode current_mode = 2; optional PowerRole power_role = 3; Loading services/usb/java/com/android/server/usb/UsbPortManager.java +62 −2 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ import android.os.SystemClock; import android.os.UserHandle; import android.service.usb.UsbPortInfoProto; import android.service.usb.UsbPortManagerProto; import android.service.usb.UsbServiceProto; import android.util.ArrayMap; import android.util.Log; import android.util.Slog; Loading @@ -74,7 +75,6 @@ import com.android.internal.util.dump.DualDumpOutputStream; import com.android.server.FgThread; import java.util.ArrayList; import java.util.HashMap; import java.util.NoSuchElementException; /** Loading Loading @@ -141,7 +141,11 @@ public class UsbPortManager { // Maintains the current connected status of the port. // Uploads logs only when the connection status is changes. private final HashMap<String, Boolean> mConnected = new HashMap<>(); private final ArrayMap<String, Boolean> mConnected = new ArrayMap<>(); // Maintains the USB contaminant status that was previously logged. // Logs get uploaded only when contaminant presence status changes. private final ArrayMap<String, Integer> mContaminantStatus = new ArrayMap<>(); private NotificationManager mNotificationManager; Loading Loading @@ -959,6 +963,24 @@ public class UsbPortManager { updateContaminantNotification(); } // Constants have to be converted between USB HAL V1.2 ContaminantDetectionStatus // to usb.proto as proto guidelines recommends 0 to be UNKNOWN/UNSUPPORTTED // whereas HAL policy is against a loosely defined constant. private static int convertContaminantDetectionStatusToProto(int contaminantDetectionStatus) { switch (contaminantDetectionStatus) { case UsbPortStatus.CONTAMINANT_DETECTION_NOT_SUPPORTED: return UsbServiceProto.CONTAMINANT_STATUS_NOT_SUPPORTED; case UsbPortStatus.CONTAMINANT_DETECTION_DISABLED: return UsbServiceProto.CONTAMINANT_STATUS_DISABLED; case UsbPortStatus.CONTAMINANT_DETECTION_NOT_DETECTED: return UsbServiceProto.CONTAMINANT_STATUS_NOT_DETECTED; case UsbPortStatus.CONTAMINANT_DETECTION_DETECTED: return UsbServiceProto.CONTAMINANT_STATUS_DETECTED; default: return UsbServiceProto.CONTAMINANT_STATUS_UNKNOWN; } } private void sendPortChangedBroadcastLocked(PortInfo portInfo) { final Intent intent = new Intent(UsbManager.ACTION_USB_PORT_CHANGED); intent.addFlags( Loading @@ -973,6 +995,33 @@ public class UsbPortManager { Manifest.permission.MANAGE_USB)); // Log to statsd // Port is removed if (portInfo.mUsbPortStatus == null) { if (mConnected.containsKey(portInfo.mUsbPort.getId())) { //Previous logged a connected. Set it to disconnected. if (mConnected.get(portInfo.mUsbPort.getId())) { StatsLog.write(StatsLog.USB_CONNECTOR_STATE_CHANGED, StatsLog.USB_CONNECTOR_STATE_CHANGED__STATE__STATE_DISCONNECTED, portInfo.mUsbPort.getId(), portInfo.mLastConnectDurationMillis); } mConnected.remove(portInfo.mUsbPort.getId()); } if (mContaminantStatus.containsKey(portInfo.mUsbPort.getId())) { //Previous logged a contaminant detected. Set it to not detected. if ((mContaminantStatus.get(portInfo.mUsbPort.getId()) == UsbPortStatus.CONTAMINANT_DETECTION_DETECTED)) { StatsLog.write(StatsLog.USB_CONTAMINANT_REPORTED, portInfo.mUsbPort.getId(), convertContaminantDetectionStatusToProto( UsbPortStatus.CONTAMINANT_DETECTION_NOT_DETECTED)); } mContaminantStatus.remove(portInfo.mUsbPort.getId()); } return; } if (!mConnected.containsKey(portInfo.mUsbPort.getId()) || (mConnected.get(portInfo.mUsbPort.getId()) != portInfo.mUsbPortStatus.isConnected())) { Loading @@ -983,6 +1032,17 @@ public class UsbPortManager { StatsLog.USB_CONNECTOR_STATE_CHANGED__STATE__STATE_DISCONNECTED, portInfo.mUsbPort.getId(), portInfo.mLastConnectDurationMillis); } if (!mContaminantStatus.containsKey(portInfo.mUsbPort.getId()) || (mContaminantStatus.get(portInfo.mUsbPort.getId()) != portInfo.mUsbPortStatus.getContaminantDetectionStatus())) { mContaminantStatus.put(portInfo.mUsbPort.getId(), portInfo.mUsbPortStatus.getContaminantDetectionStatus()); StatsLog.write(StatsLog.USB_CONTAMINANT_REPORTED, portInfo.mUsbPort.getId(), convertContaminantDetectionStatusToProto( portInfo.mUsbPortStatus.getContaminantDetectionStatus())); } } private static void logAndPrint(int priority, IndentingPrintWriter pw, String msg) { Loading Loading
cmds/statsd/src/atoms.proto +12 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import "frameworks/base/core/proto/android/server/connectivity/data_stall_event. import "frameworks/base/core/proto/android/server/enums.proto"; import "frameworks/base/core/proto/android/server/location/enums.proto"; import "frameworks/base/core/proto/android/service/procstats_enum.proto"; import "frameworks/base/core/proto/android/service/usb.proto"; import "frameworks/base/core/proto/android/stats/enums.proto"; import "frameworks/base/core/proto/android/stats/docsui/docsui_enums.proto"; import "frameworks/base/core/proto/android/stats/launcher/launcher.proto"; Loading Loading @@ -207,6 +208,7 @@ message Atom { AttentionManagerServiceResultReported attention_manager_service_result_reported = 143; AdbConnectionChanged adb_connection_changed = 144; SpeechDspStatReported speech_dsp_stat_reported = 145; UsbContaminantReported usb_contaminant_reported = 146; } // Pulled events will start at field 10000. Loading Loading @@ -4537,3 +4539,13 @@ message SpeechDspStatReported { optional int32 total_crash_count = 3; optional int32 total_recover_count = 4; } /** * Logs USB connector contaminant status. * * Logged from: USB Service. */ message UsbContaminantReported { optional string id = 1; optional android.service.usb.ContaminantPresenceStatus status = 2; }
core/proto/android/service/usb.proto +9 −8 Original line number Diff line number Diff line Loading @@ -228,6 +228,15 @@ message UsbPortProto { repeated Mode supported_modes = 2; } /* Same as android.hardware.usb.V1_2.Constants.ContaminantPresenceStatus */ enum ContaminantPresenceStatus { CONTAMINANT_STATUS_UNKNOWN = 0; CONTAMINANT_STATUS_NOT_SUPPORTED = 1; CONTAMINANT_STATUS_DISABLED = 2; CONTAMINANT_STATUS_NOT_DETECTED = 3; CONTAMINANT_STATUS_DETECTED = 4; } message UsbPortStatusProto { option (android.msg_privacy).dest = DEST_AUTOMATIC; Loading @@ -245,14 +254,6 @@ message UsbPortStatusProto { DATA_ROLE_DEVICE = 2; } /* Same as android.hardware.usb.V1_2.Constants.ContaminantPresenceStatus */ enum ContaminantPresenceStatus { CONTAMINANT_STATUS_NOT_SUPPORTED = 0; CONTAMINANT_STATUS_DISABLED = 1; CONTAMINANT_STATUS_NOT_DETECTED = 2; CONTAMINANT_STATUS_DETECTED = 3; } optional bool connected = 1; optional UsbPortProto.Mode current_mode = 2; optional PowerRole power_role = 3; Loading
services/usb/java/com/android/server/usb/UsbPortManager.java +62 −2 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ import android.os.SystemClock; import android.os.UserHandle; import android.service.usb.UsbPortInfoProto; import android.service.usb.UsbPortManagerProto; import android.service.usb.UsbServiceProto; import android.util.ArrayMap; import android.util.Log; import android.util.Slog; Loading @@ -74,7 +75,6 @@ import com.android.internal.util.dump.DualDumpOutputStream; import com.android.server.FgThread; import java.util.ArrayList; import java.util.HashMap; import java.util.NoSuchElementException; /** Loading Loading @@ -141,7 +141,11 @@ public class UsbPortManager { // Maintains the current connected status of the port. // Uploads logs only when the connection status is changes. private final HashMap<String, Boolean> mConnected = new HashMap<>(); private final ArrayMap<String, Boolean> mConnected = new ArrayMap<>(); // Maintains the USB contaminant status that was previously logged. // Logs get uploaded only when contaminant presence status changes. private final ArrayMap<String, Integer> mContaminantStatus = new ArrayMap<>(); private NotificationManager mNotificationManager; Loading Loading @@ -959,6 +963,24 @@ public class UsbPortManager { updateContaminantNotification(); } // Constants have to be converted between USB HAL V1.2 ContaminantDetectionStatus // to usb.proto as proto guidelines recommends 0 to be UNKNOWN/UNSUPPORTTED // whereas HAL policy is against a loosely defined constant. private static int convertContaminantDetectionStatusToProto(int contaminantDetectionStatus) { switch (contaminantDetectionStatus) { case UsbPortStatus.CONTAMINANT_DETECTION_NOT_SUPPORTED: return UsbServiceProto.CONTAMINANT_STATUS_NOT_SUPPORTED; case UsbPortStatus.CONTAMINANT_DETECTION_DISABLED: return UsbServiceProto.CONTAMINANT_STATUS_DISABLED; case UsbPortStatus.CONTAMINANT_DETECTION_NOT_DETECTED: return UsbServiceProto.CONTAMINANT_STATUS_NOT_DETECTED; case UsbPortStatus.CONTAMINANT_DETECTION_DETECTED: return UsbServiceProto.CONTAMINANT_STATUS_DETECTED; default: return UsbServiceProto.CONTAMINANT_STATUS_UNKNOWN; } } private void sendPortChangedBroadcastLocked(PortInfo portInfo) { final Intent intent = new Intent(UsbManager.ACTION_USB_PORT_CHANGED); intent.addFlags( Loading @@ -973,6 +995,33 @@ public class UsbPortManager { Manifest.permission.MANAGE_USB)); // Log to statsd // Port is removed if (portInfo.mUsbPortStatus == null) { if (mConnected.containsKey(portInfo.mUsbPort.getId())) { //Previous logged a connected. Set it to disconnected. if (mConnected.get(portInfo.mUsbPort.getId())) { StatsLog.write(StatsLog.USB_CONNECTOR_STATE_CHANGED, StatsLog.USB_CONNECTOR_STATE_CHANGED__STATE__STATE_DISCONNECTED, portInfo.mUsbPort.getId(), portInfo.mLastConnectDurationMillis); } mConnected.remove(portInfo.mUsbPort.getId()); } if (mContaminantStatus.containsKey(portInfo.mUsbPort.getId())) { //Previous logged a contaminant detected. Set it to not detected. if ((mContaminantStatus.get(portInfo.mUsbPort.getId()) == UsbPortStatus.CONTAMINANT_DETECTION_DETECTED)) { StatsLog.write(StatsLog.USB_CONTAMINANT_REPORTED, portInfo.mUsbPort.getId(), convertContaminantDetectionStatusToProto( UsbPortStatus.CONTAMINANT_DETECTION_NOT_DETECTED)); } mContaminantStatus.remove(portInfo.mUsbPort.getId()); } return; } if (!mConnected.containsKey(portInfo.mUsbPort.getId()) || (mConnected.get(portInfo.mUsbPort.getId()) != portInfo.mUsbPortStatus.isConnected())) { Loading @@ -983,6 +1032,17 @@ public class UsbPortManager { StatsLog.USB_CONNECTOR_STATE_CHANGED__STATE__STATE_DISCONNECTED, portInfo.mUsbPort.getId(), portInfo.mLastConnectDurationMillis); } if (!mContaminantStatus.containsKey(portInfo.mUsbPort.getId()) || (mContaminantStatus.get(portInfo.mUsbPort.getId()) != portInfo.mUsbPortStatus.getContaminantDetectionStatus())) { mContaminantStatus.put(portInfo.mUsbPort.getId(), portInfo.mUsbPortStatus.getContaminantDetectionStatus()); StatsLog.write(StatsLog.USB_CONTAMINANT_REPORTED, portInfo.mUsbPort.getId(), convertContaminantDetectionStatusToProto( portInfo.mUsbPortStatus.getContaminantDetectionStatus())); } } private static void logAndPrint(int priority, IndentingPrintWriter pw, String msg) { Loading