【 PC端无法通过USB识别测试机】

PC端无法通过USB识别测试机

【问题描述】

设备通过USB线连接PC端,连接成功后,设备端进行usb偏好设置,切换成mtp或ptp模式后,PC端无对应设备相关信息
【问题分析】
1、上层分析

系统同事从main log中看到如下log,怀疑UsbFfs出现错误异常,怀疑底层操作有误:

03-24 10:14:43.421680 2338 2637 D UDevice : ZuiPairV2$Header$Companion::parse[45] height5:0 low3Bit:1 deviceId:1 
03-24 10:14:43.423072 2338 2637 D UDevice : ZuiPairV2$Header$Companion::parse[45] height5:0 low3Bit:1 deviceId:1 
03-24 10:14:43.424720 2338 2637 D UDevice : Scan 70:61:EE:41:D5:00 parse success: Lenovo Tab Pen Plus: -61 
03-24 10:14:43.430434 2338 2338 V UDevice : Dspth Get holder(cached) 
03-24 10:14:43.430781 6646 6754 I adbd : USB event: FUNCTIONFS_SUSPEND 
03-24 10:14:43.431380 2338 2338 V UDevice : Mgr 70:61:EE:41:D5:00 BLE_BROADCAST_NEARBY 
03-24 10:14:43.432798 2338 2338 V UDevice : RuleBook::ruleFor[29] Match failure | BLE_BROADCAST_NEARBY(INIT -> ) 
03-24 10:14:43.433686 2338 2338 V UDevice : RuleBook::ruleFor[29] Match failure | BLE_BROADCAST_NEARBY(INIT -> ) 
03-24 10:14:43.434596 2338 2338 V UDevice : RuleBook::ruleFor[29] Match failure | BLE_BROADCAST_NEARBY(INIT -> ) 
03-24 10:14:43.434638 765 1553 I android.hardware.usb@1.2-service-mediatekv2: uevent_event change@/devices/platform/extcon_usb/extcon/extcon0 03-24 10:14:43.435233 6646 6754 I adbd : USB event: FUNCTIONFS_DISABLE 
03-24 10:14:43.435359 2338 2338 V UDevice : RuleBook::ruleFor[29] Match failure | BLE_BROADCAST_NEARBY(INIT -> ) 
03-24 10:14:43.435452 6646 6791 I adbd : UsbFfs: connection terminated: read 4 failed with error Cannot send after transport endpoint shutdown 
03-24 10:14:43.435667 765 1553 I android.hardware.usb@1.2-service-mediatekv2: uevent_event change@/devices/platform/extcon_usb/extcon/extcon0 
03-24 10:14:43.436034 2338 2338 V UDevice : RuleBook::ruleFor[29] Match failure | BLE_BROADCAST_NEARBY(INIT -> ) 
03-24 10:14:43.436091 6646 6646 I adbd : UsbFfs: offline 
03-24 10:14:43.436215 6646 6646 I adbd : destroying transport UsbFfs 
03-24 10:14:43.436442 6646 6646 I adbd : UsbFfsConnection being destroyed

2、底层分析

从底层log看上层切换模式后底层也相对应进行了usb config的设置,故实际设置应是无问题的

补充了解usb config设置流程:

// 1、点击 setting-》usb 偏好设置中的文件传输选项
// sys log打印
04-16 08:08:12.478888 1274 1379 I UsbDeviceManager: Setting USB config to mtp
04-16 08:08:12.478940 1274 1379 D UsbDeviceManager: setUsbConfig(5) request:9
04-16 08:08:12.483023 1274 1379 D UsbDeviceManager: mRecordUsbModeFunctions: 4
04-16 08:08:12.639684 762 762 I android.hardware.usb@1.2-service-mediatekv2: switchUsbFunctions mtp,adb
//kernel log打印
04-16 12:08:12.935 <6>[ 606.324728] (6)[53:kworker/6:1]android_work: sent uevent USB_STATE=CONNECTED
04-16 12:08:12.962 <6>[ 606.351706] (0)[7959:kworker/0:5]android_work: sent uevent USB_STATE=CONFIGURED

// 08:08:38.868878 点击 setting-》usb 偏好设置中的PTP 选项
04-16 08:08:38.868878 1274 1379 I UsbDeviceManager: Setting USB config to ptp
04-16 08:08:38.869002 1274 1379 D UsbDeviceManager: setUsbConfig(17) request:10
04-16 08:08:38.871205 8789 8797 I adbd : UsbFfs: connection terminated: read 4 failed with error Cannot send after transport endpoint shutdown
04-16 08:08:38.871331 762 1534 I android.hardware.usb@1.2-service-mediatekv2: uevent_event change@/devices/virtual/android_usb/android0
04-16 08:08:38.871480 8789 8789 I adbd : UsbFfs: offline

// kernel log打印
//2、底层收到config切换,重新进行usb握手,更新usb_state,直至配置完成
04-16 12:08:38.871 <6>[ 632.260738] (4)[379:kworker/4:2]android_work: sent uevent USB_STATE=DISCONNECTED

//3、服务层切换switchUsbFunction,下发到底层

04-16 08:08:38.876328 1274 1379 D UsbDeviceManager: mRecordUsbModeFunctions: 16
04-16 08:08:39.037964 762 762 I android.hardware.usb@1.2-service-mediatekv2: switchUsbFunctions ptp,adb
// kernel log打印

04-16 12:08:39.331 <6>[ 632.720188] (3)[8560:kworker/3:0]android_work: sent uevent USB_STATE=CONNECTED
04-16 12:08:39.361 <6>[ 632.750424] (6)[301:kworker/6:2]android_work: sent uevent USB_STATE=CONFIGURED
04-16 08:08:39.342394 1726 1757 I Tethering: USB bcast connected:true configured:false rndis:false ncm:false
04-16 08:08:39.366729 1726 1757 I Tethering: USB bcast connected:true configured:true rndis:false ncm:false

既然底层usb设置无误,而实际表现却有问题,这样是不是有可能是文件系统或者系统对应服务出了问题

同时了解到下述打印,实际正常切换时也是有的,另外还有当对应切换模式服务被kill的时候或PC电脑usb被禁的时都会有对应打印,以示服务受限

03-24 10:14:43.435452 6646 6791 I adbd : UsbFfs: connection terminated: read 4 failed with error Cannot send after transport endpoint shutdown

那么接下来的工作就是排查下切换为mtp时,对应进程是否正常了
3、上层分析

排查服务是否出现问题,从下述角度看:

内存清理是否会kill mtp进程,进程是否被异常stop:
开启相关打印:

   开启lmkd模块的debug日志
   setprop persist.debug.zui.lmkd true
    开启ZuiMemoryCleaner debug日志

   setprop persist.debug.zuimemory  true

注意:以上debug日志需要设备重启后生效

内存清理模块收到了内存压力事件:

03-26 20:05:17.245 463 463 I lowmemorykiller: low pressure event triggered
03-26 20:05:17.245 463 463 D lowmemorykiller: ZuiDebug: memory free: 89MB, cached: 3461MB, available: 0MB, total: 7857MB, swap free: 4291MB, swap total: 4306MB, active_anon: 75MB, inactive_anon: 2498MB, active_file: 1305MB, inactive_file: 2130MB, sreclaimable: 129MB, sunreclaimable: 289MB, kernel_stack: 89MB, page_tables: 202MB, ion_heap: 0MB, ion_heap_pool: 0MB, cma_free: 0MB, Gpu: 0MB, pgscan_kswapd: 1312995, pgscan_direct: 14039, wmark = 3 (0-Min<30MB>, 1-Low<78MB>, 2-High<86MB>, 3-None)

//判断当前kswapd活跃,决定进行清理
03-26 20:05:17.246 1378 1432 D ZuiMemoryCleaner: Begin to handle vmpressure event
03-26 20:05:17.246 1378 1432 D ZuiMemoryCleaner: free 91200Kb (89MB) cache 3544380Kb (3461MB) available 4Kb (0MB) total 8046364Kb (7857MB) swap free 4394328Kb (4291MB) swap total 4409688Kb (4306MB) pgscan_kswapd 1312995 pgscan_direct 14039 wmark 3 (0-Min, 1-Low, 2-High, 3-None) nanoTime 381553025253
03-26 20:05:17.252 1378 1432 D ZuiMemoryCleaner: initWhiteList: took time 6ms
03-26 20:05:17.253 1378 1432 D ZuiMemoryCleaner: getMemFreeLevel mem Free: 89MB, threshold: 158MB, critical threshold: 75MB, cached: 3461MB, cached as free: 0%
03-26 20:05:17.253 1378 1432 D ZuiMemoryCleaner: getMemFreeLevel: Low
03-26 20:05:17.253 1378 1432 D ZuiMemoryCleaner: getKswapdActiveLevel speed: 109057 threshold: 40000 highlyActiveThreshold: 80000
03-26 20:05:17.253 1378 1432 D ZuiMemoryCleaner: getKswapdActiveLevel: HighlyActive
03-26 20:05:17.253 1378 1432 D ZuiMemoryCleaner: shouldHandleActiveLevel, Skip double check memfree, return true
03-26 20:05:17.253 1378 1432 I ZuiMemoryCleaner: updateStrategy use: Aggressive (1-Moderate, 2-Aggressive), minAdj: 700subreason: ZuiMemoryCleaner[Aggressive-KSwapdHighlyActive]

//扫描到进程 'android.process.media', 当前的adj、状态符合清理条件 内存清理模块,对于 adj <700的进程,不会进行清理

03-26 20:05:17.263 1378 1432 D ZuiMemoryCleaner: checking process: android.process.media, adj: 999, state: 19, adjtype: cch-empty, cached: true
03-26 20:05:17.263 1378 1432 D ZuiMemoryCleaner: add to killTargetMap: android.process.media appAdj: 999 packagename: com.android.mtp

//该进程被清理

03-26 20:05:17.526 1378 1432 I ZuiMemoryCleaner: forcestop app: com.android.mtp
03-26 20:05:17.534 1378 1432 I ActivityManager: Force stopping com.android.mtp appid=10061 user=0: ZuiMemoryCleaner[Aggressive-KSwapdHighlyActive]
03-26 20:05:17.560 1378 1432 I ActivityManager: Killing 2814:android.process.media/u0a61 (adj 999): stop com.android.mtp due to ZuiMemoryCleaner[Aggressive-KSwapdHighlyActive]

最终定位问题原因: 在没有开启mtp功能时,应用优先级较低,应用被forcestop方式查杀,导致应用被置为了stop状态,后续开启mtp功能时,需要通过广播启动该应用,但是由于应用处于stop状态,所以广播无法启动该应用。

修改:尝试将对应应用添加进保活白名单,提高进程优先级

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值