低电时限制USB反向充电

如何识别当前的USB连接是向别的设备充电?

       最好的方式是获取USB的供电电流,如果当前低电量,而且供电电流太大,则对USB总线断电。但是在USB服务上没法似乎无法获得供电电流。按功能是否可行?如果USB没有配置音频、视频、录音、录像、拍照, otg存储等功能,也就是没有常用的defined codes, 则掐断电源。

场景 mode power data class sub-c 组合 备注
pc  充电 ufp sink device / / 2 [source:host, sink:device]
pc  mtp ufp sink device / / 2
pc ptp ufp sink device / / 2
pc cdrom ufp sink device / / 2
pc rndis / / / / / / 不支持rndis
充电头 dfp sink host / / 3 [source:host, sink:host, sink:device]
充电头 ufp sink device / / 2 [source:host, sink:device]
headset dfp source host 6 1 2
otg udisk source host 2
printer source host 2
y31s 充电 dfp source host 8 6 2
790 充电 ufp sink device 4 [source:host, source:device, sink:host, sink:device]
790 mtp ufp sink device 4
790 ptp ufp sink device 4
790cdrom ufp sink device 4
790 充电 sink host 255 255 4 受电方可以弹起连接选择框,虽可以
790 mtp sink host 6 1 4 弹起,但是如果切换连接方式,则虽配置
790 ptp sink host 6 1 4 成功,但连接会失败的,因为一个主设备
790cdrom sink host 8 6 4 企图gadget连接从设备,是不允许的。
790 充电 ufp source device 4 供电方不能弹起连接选择框,但是可以
790 mtp source device 4 通过svc usb setFunctions mtp等命令切换
790 ptp source device 4 连接方式
790cdrom source device 4
790 充电 dfp source host 255 255 4
790 mtp source host 6 1 4
790 ptp source host 6 1 4
790cdrom source host 8 6 4

Defined Class Codes 类型

Base Class

Descriptor Usage

Description

00h

Device

Use class information in the Interface Descriptors

01h

Interface

Audio

02h

Both

Communications and CDC Control

03h

Interface

HID (Human Interface Device)

05h

Interface

Physical

06h

Interface

Image

07h

Interface

Printer

08h

Interface

Mass Storage

09h

Device

Hub

0Ah

Interface

CDC-Data

0Bh

Interface

Smart Card

0Dh

Interface

Content Security

0Eh

Interface

Video

0Fh

Interface

Personal Healthcare

10h

Interface

Audio/Video Devices

11h

Device

Billboard Device Class

12h

Interface

USB Type-C Bridge Class

3Ch Interface I3C Device Class

DCh

Both

Diagnostic Device

E0h

Interface

Wireless Controller

EFh

Both

Miscellaneous

FEh

Interface

Application Specific

FFh

Both

Vendor Specific

USB 耳机

07-14 15:34:06.836  1091  2461 I [email protected]: auto suspend usb interfaces /sys/devices/platform/soc/a600000.ssusb/a600000.dwc3/xhci-hcd.2.auto/usb2/2-1
07-14 15:33:51.712 21715 21715 I [21715:kworker/0:3]input: bestechnic HUAWEI USB-C HEADSET as /devices/platform/soc/a600000.ssusb/a600000.dwc3/xhci-hcd.2.auto/usb2/2-1/2-1:1.3/0003:12D1:3A07.0001/input/input6
07-14 15:33:51.784 21715 21715 I [21715:kworker/0:3]hid-generic 0003: 12D1:3A07.0001: input,hidraw0: USB HID v1.11 Device [bestechnic HUAWEI USB-C HEADSET] on usb-xhci-hcd.2.auto-1/input3
07-14 15:34:06.941 12615 12821 D EventHub: No input device configuration file found for device 'bestechnic HUAWEI USB-C HEADSET'.
07-14 15:34:06.947  1091  2461 I [email protected]: auto suspend usb interfaces /sys/devices/platform/soc/a600000.ssusb/a600000.dwc3/xhci-hcd.2.auto/usb2/2-1
07-14 15:34:06.950 12615 12939 D UsbHostManager: USB device attached: vidpid 12d1:3a07 mfg/product/ver/serial bestechnic/HUAWEI USB-C HEADSET/0.24/0296A100000000000000000000000 hasAudio/HID/Storage: true/true/false
07-14 15:34:06.955 12615 12939 D UsbDeviceDescriptor:   1 configs
07-14 15:34:06.958 12615 12939 D UsbHostManager: Added device UsbDevice[mName=/dev/bus/usb/002/002,mVendorId=4817,mProductId=14855,mClass=0,mSubclass=0,mProtocol=0,mManufacturerName=bestechnic,mProductName=HUAWEI USB-C HEADSET,mVersion=0.24,mSerialNumberReader=com.android.server.usb.UsbSerialReader@fb536d0, mHasAudioPlayback=true, mHasAudioCapture=true, mHasMidi=false, mHasVideoCapture=false, mHasVideoPlayback=false, mConfigurations=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbConfiguration[mId=1,mName=null,mAttributes=160,mMaxPower=50,mInterfaces=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=0,mAlternateSetting=0,mName=null,mClass=1,mSubclass=1,mProtocol=0,mEndpoints=[]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=1,mAlternateSetting=0,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=1,mAlternateSetting=1,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=131,mAttributes=13,mMaxPacketSize=192,mInterval=1]]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=2,mAlternateSetting=0,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=2,mAlternateSetting=1,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=3,mAttributes=13,mMaxPacketSize=384,mInterval=1]]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=2,mAlternateSetting=2,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=3,mAttributes=13,mMaxPacketSize=576,mInterval=1]]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=3,mAlternateSetting=0,mName=null,mClass=3,mSubclass=0,mProtocol=0,mEndpoints=[
07-14 15:34:06.958 12615 12939 D UsbHostManager:

UsbEndpoint[mAddress=132,mAttributes=3,mMaxPacketSize=3,mInterval=1]]]]

对端是 DRP端口的手机,仅充电config

07-14 17:59:40.935 11994 11994 I [11994:kworker/u16:2]hub 3-0: 1.0: 1 port detected
07-14 17:59:41.488  1091  2461 I [email protected]: uevent received change@/devices/platform/soc/soc:qcom,pmic_glink/soc:qcom,pmic_glink:qcom,ucsi/typec/port0
07-14 17:59:41.496  1091  2461 I [email protected]: port0
07-14 17:59:41.499  1091  2461 I [email protected]: connected:1 canChangeMode:1 canChagedata:1 canChangePower:1
07-14 17:59:41.501 12615 12911 I UsbPortManager: ClientCallback V1_2: port0
07-14 17:59:41.502 12615 12648 I UsbPortManager: USB port changed: port=UsbPort{id=port0, supportedModes=dual, audio_accsupportedContaminantProtectionModes=5supportsEnableContaminantPresenceProtection=falsesupportsEnableContaminantPresenceDetection=false, status=UsbPortStatus{connected=true, currentMode=dfp, currentPowerRole=source, currentDataRole=host, supportedRoleCombinations=[source:host, source:device, sink:host, sink:device], contaminantDetectionStatus=2, contaminantProtectionStatus=1}, canChangeMode=true, canChangePowerRole=true, canChangeDataRole=true, connectedAtMillis=14369516, lastConnectDurationMillis=0
07-14 17:59:41.504 12615 12615 I UsbDeviceManager: updateHostState UsbPort{id=port0, supportedModes=dual, audio_accsupportedContaminantProtectionModes=5supportsEnableContaminantPresenceProtection=falsesupportsEnableContaminantPresenceDetection=false status=UsbPortStatus{connected=true, currentMode=dfp, currentPowerRole=source, currentDataRole=host, supportedRoleCombinations=[source:host, source:device, sink:host, sink:device], contaminantDetectionStatus=2, contaminantProtectionStatus=1}
07-14 17:59:41.341 31352 31352 I [31352:kworker/0:2]usb 2-1: new high-speed USB device number 2 using xhci-hcd
07-14 17:59:41.500 31352 31352 I [31352:kworker/0:2]usb 2-1: New USB device found, VID=109b, PID=90be
07-14 17:59:42.011 12615 12939 D UsbHostManager: USB device attached: vidpid 109b:90be mfg/product/ver/serial Android/Android/5.04/ABCDEFGH hasAudio/HID/Storage: false/false/false
07-14 17:59:42.020 12615 12939 D UsbDeviceDescriptor:   1 configs
07-14 17:59:42.038 12615 12939 D UsbHostManager: Added device UsbDevice[mName=/dev/bus/usb/002/002,mVendorId=4251,mProductId=37054,mClass=0,mSubclass=0,mProtocol=0,mManufacturerName=Android,mProductName=Android,mVersion=5.04,mSerialNumberReader=com.android.server.usb.UsbSerialReader@c9820d6, mHasAudioPlayback=false, mHasAudioCapture=false, mHasMidi=false, mHasVideoCapture=false, mHasVideoPlayback=false, mConfigurations=[
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbConfiguration[mId=1,mName=diag_adb,mAttributes=192,mMaxPower=0,mInterfaces=[
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbInterface[mId=0,mAlternateSetting=0,mName=null,mClass=255,mSubclass=255,mProtocol=48,mEndpoints=[
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=1,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=129,mAttributes=2,mMaxPacketSize=512,mInterval=0]]
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbInterface[mId=1,mAlternateSetting=0,mName=ADB Interface,mClass=255,mSubclass=66,mProtocol=1,mEndpoints=[
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=2,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=130,mAttributes=2,mMaxPacketSize=512,mInterval=0]]]]
07-14 17:59:42.047 12615 12615 D AS.AudioService: onReceive()  action= android.hardware.usb.action.USB_DEVICE_ATTACHED

对端是手机且设置为mtp

07-14 18:10:49.967 12615 12939 D UsbHostManager: USB device attached: vidpid 109b:9135 mfg/product/ver/serial Android/Android/5.04/ABCDEFGH hasAudio/HID/Storage: false/false/false
07-14 18:10:49.972 12615 12939 D UsbDeviceDescriptor:   1 configs
07-14 18:10:49.991 12615 12939 D UsbHostManager: Added device UsbDevice[mName=/dev/bus/usb/002/003,mVendorId=4251,mProductId=37173,mClass=0,mSubclass=0,mProtocol=0,mManufacturerName=Android,mProductName=Android,mVersion=5.04,mSerialNumberReader=com.android.server.usb.UsbSerialReader@6872391, mHasAudioPlayback=false, mHasAudioCapture=false, mHasMidi=false, mHasVideoCapture=false, mHasVideoPlayback=false, mConfigurations=[
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbConfiguration[mId=1,mName=mtp_adb,mAttributes=192,mMaxPower=0,mInterfaces=[
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbInterface[mId=0,mAlternateSetting=0,mName=MTP,mClass=6,mSubclass=1,mProtocol=1,mEndpoints=[
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=129,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=1,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=130,mAttributes=3,mMaxPacketSize=28,mInterval=6]]
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbInterface[mId=1,mAlternateSetting=0,mName=ADB Interface,mClass=255,mSubclass=66,mProtocol=1,mEndpoints=[
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=2,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=131,mAttributes=2,mMaxPacketSize=512,mInterval=0]]]]

你可能感兴趣的:(android,物联网)