Android下开机启动后U盘经常不能自动挂载

原因大致为状态机混乱:

Initializing  No-Media  Idle-Unmounted  Pending  Mounted  Unmounting  Checking  Formatting  Shared-Unmounted  Shared-Mounted  Unknown-Error

一、问题描述

挂U盘开机正常;开机后挂U盘不正常。经常出现状态混乱。

二、正确流程

1.挂载

  1. D/Vold    ( 1148): Volume 1214-9D53 state changing -1 (Initializing) -> 0 (No-Media)  
  2. D/Vold    ( 1148): Volume 1214-9D53 state changing 0 (No-Media) -> 1 (Idle-Unmounted)  
  3. D/Vold    ( 1148): Volume 1214-9D53 state changing 1 (Idle-Unmounted) -> 3 (Checking)  
  4. D/Vold    ( 1148): Volume 1214-9D53 state changing 3 (Checking) -> 4 (Mounted)  
D/Vold    ( 1148): Volume 1214-9D53 state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 1148): Volume 1214-9D53 state changing 0 (No-Media) -> 1 (Idle-Unmounted)
D/Vold    ( 1148): Volume 1214-9D53 state changing 1 (Idle-Unmounted) -> 3 (Checking)
D/Vold    ( 1148): Volume 1214-9D53 state changing 3 (Checking) -> 4 (Mounted)
2.卸载
  1. D/Vold    ( 1148): Volume 1214-9D53 state changing 4 (Mounted) -> 5 (Unmounting)  
  2. D/Vold    ( 1148): Volume 1214-9D53 state changing 5 (Unmounting) -> 1 (Idle-Unmounted)  
  3. D/Vold    ( 1148): Volume 1214-9D53 state changing 1 (Idle-Unmounted) -> 0 (No-Media)  
D/Vold    ( 1148): Volume 1214-9D53 state changing 4 (Mounted) -> 5 (Unmounting)
D/Vold    ( 1148): Volume 1214-9D53 state changing 5 (Unmounting) -> 1 (Idle-Unmounted)
D/Vold    ( 1148): Volume 1214-9D53 state changing 1 (Idle-Unmounted) -> 0 (No-Media)

MountService启动:

private void readStorageListLocked();

3.MountService启动时U盘已经挂上

  1. D/MountService( 2044): got storage path: null description: SD卡 primary: false removable: false emulated: true mtpReserve: 0 allowMassStorage: false maxFileSize: 0  
  2. D/MountService( 2044): addVolumeLocked() StorageVolume:  
  3. D/MountService( 2044):     mStorageId=65537 mPath=/storage/emulated/0 mDescriptionId=17040783   
  4. D/MountService( 2044):     mPrimary=true mRemovable=false mEmulated=true mMtpReserveSpace=0   
  5. D/MountService( 2044):     mAllowMassStorage=false mMaxFileSize=0 mOwner=UserHandle{0} mUuid=null   
  6. D/MountService( 2044):     mUserLabel=null mState=null   
  7. D/MountService( 2044): got storage path: /mnt/sdcard description: SD卡 primary: true removable: false emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0  
  8. D/MountService( 2044): addVolumeLocked() StorageVolume:  
  9. D/MountService( 2044):     mStorageId=0 mPath=/mnt/sdcard mDescriptionId=17040783 mPrimary=true   
  10. D/MountService( 2044):     mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=false   
  11. D/MountService( 2044):     mMaxFileSize=0 mOwner=null mUuid=null mUserLabel=null mState=null   
  12. D/MountService( 2044): got storage path: null description: USB存储器 primary: false removable: false emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0  
  13. I/MountService( 2044): Updating valid state unmounted  
  14. D/MountService( 2044): addVolumeLocked() StorageVolume:  
  15. D/MountService( 2044):     mStorageId=0 mPath=/mnt/usb/1214-9D53 mDescriptionId=17040784   
  16. D/MountService( 2044):     mPrimary=false mRemovable=true mEmulated=false mMtpReserveSpace=0   
  17. D/MountService( 2044):     mAllowMassStorage=false mMaxFileSize=0 mOwner=null mUuid=null   
  18. D/MountService( 2044):     mUserLabel=null mState=null   
  19. D/MountService( 2044): volume state changed for /mnt/usb/1214-9D53 (removed -> unmounted)  
  20. W/MountService( 2044): getSecureContainerList() called when storage not mounted  
  21. W/MountService( 2044): getSecureContainerList() called when storage not mounted  
  22. I/MountService( 2044): doMountVolume: Mouting /mnt/sdcard  
  23. E/MountService( 2044): Boot-time mount failed (-1)  
  24. I/MountService( 2044): doMountVolume: Mouting /mnt/usb/1214-9D53  
D/MountService( 2044): got storage path: null description: SD卡 primary: false removable: false emulated: true mtpReserve: 0 allowMassStorage: false maxFileSize: 0
D/MountService( 2044): addVolumeLocked() StorageVolume:
D/MountService( 2044):     mStorageId=65537 mPath=/storage/emulated/0 mDescriptionId=17040783 
D/MountService( 2044):     mPrimary=true mRemovable=false mEmulated=true mMtpReserveSpace=0 
D/MountService( 2044):     mAllowMassStorage=false mMaxFileSize=0 mOwner=UserHandle{0} mUuid=null 
D/MountService( 2044):     mUserLabel=null mState=null 
D/MountService( 2044): got storage path: /mnt/sdcard description: SD卡 primary: true removable: false emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0
D/MountService( 2044): addVolumeLocked() StorageVolume:
D/MountService( 2044):     mStorageId=0 mPath=/mnt/sdcard mDescriptionId=17040783 mPrimary=true 
D/MountService( 2044):     mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=false 
D/MountService( 2044):     mMaxFileSize=0 mOwner=null mUuid=null mUserLabel=null mState=null 
D/MountService( 2044): got storage path: null description: USB存储器 primary: false removable: false emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0
I/MountService( 2044): Updating valid state unmounted
D/MountService( 2044): addVolumeLocked() StorageVolume:
D/MountService( 2044):     mStorageId=0 mPath=/mnt/usb/1214-9D53 mDescriptionId=17040784 
D/MountService( 2044):     mPrimary=false mRemovable=true mEmulated=false mMtpReserveSpace=0 
D/MountService( 2044):     mAllowMassStorage=false mMaxFileSize=0 mOwner=null mUuid=null 
D/MountService( 2044):     mUserLabel=null mState=null 
D/MountService( 2044): volume state changed for /mnt/usb/1214-9D53 (removed -> unmounted)
W/MountService( 2044): getSecureContainerList() called when storage not mounted
W/MountService( 2044): getSecureContainerList() called when storage not mounted
I/MountService( 2044): doMountVolume: Mouting /mnt/sdcard
E/MountService( 2044): Boot-time mount failed (-1)
I/MountService( 2044): doMountVolume: Mouting /mnt/usb/1214-9D53
4.MountService启动时U盘没有挂上
  1. D/MountService( 2015): got storage path: null description: SD卡 primary: false removable: false emulated: true mtpReserve: 0 allowMassStorage: false maxFileSize: 0  
  2. D/MountService( 2015): addVolumeLocked() StorageVolume:  
  3. D/MountService( 2015):     mStorageId=65537 mPath=/storage/emulated/0 mDescriptionId=17040783   
  4. D/MountService( 2015):     mPrimary=true mRemovable=false mEmulated=true mMtpReserveSpace=0   
  5. D/MountService( 2015):     mAllowMassStorage=false mMaxFileSize=0 mOwner=UserHandle{0} mUuid=null   
  6. D/MountService( 2015):     mUserLabel=null mState=null   
  7. D/MountService( 2015): got storage path: /mnt/sdcard description: SD卡 primary: true removable: false emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0  
  8. D/MountService( 2015): addVolumeLocked() StorageVolume:  
  9. D/MountService( 2015):     mStorageId=0 mPath=/mnt/sdcard mDescriptionId=17040783 mPrimary=true   
  10. D/MountService( 2015):     mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=false   
  11. D/MountService( 2015):     mMaxFileSize=0 mOwner=null mUuid=null mUserLabel=null mState=null   
  12. D/MountService( 2015): got storage path: null description: USB存储器 primary: false removable: false emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0  
  13. W/MountService( 2015): getSecureContainerList() called when storage not mounted  
  14. W/MountService( 2015): getSecureContainerList() called when storage not mounted  
  15. I/MountService( 2015): doMountVolume: Mouting /mnt/sdcard  
  16. E/MountService( 2015): Boot-time mount failed (-1)  
  17. W/MountService( 2015): Duplicate state transition (mounted -> mounted) for /storage/emulated/0  
D/MountService( 2015): got storage path: null description: SD卡 primary: false removable: false emulated: true mtpReserve: 0 allowMassStorage: false maxFileSize: 0
D/MountService( 2015): addVolumeLocked() StorageVolume:
D/MountService( 2015):     mStorageId=65537 mPath=/storage/emulated/0 mDescriptionId=17040783 
D/MountService( 2015):     mPrimary=true mRemovable=false mEmulated=true mMtpReserveSpace=0 
D/MountService( 2015):     mAllowMassStorage=false mMaxFileSize=0 mOwner=UserHandle{0} mUuid=null 
D/MountService( 2015):     mUserLabel=null mState=null 
D/MountService( 2015): got storage path: /mnt/sdcard description: SD卡 primary: true removable: false emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0
D/MountService( 2015): addVolumeLocked() StorageVolume:
D/MountService( 2015):     mStorageId=0 mPath=/mnt/sdcard mDescriptionId=17040783 mPrimary=true 
D/MountService( 2015):     mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=false 
D/MountService( 2015):     mMaxFileSize=0 mOwner=null mUuid=null mUserLabel=null mState=null 
D/MountService( 2015): got storage path: null description: USB存储器 primary: false removable: false emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0
W/MountService( 2015): getSecureContainerList() called when storage not mounted
W/MountService( 2015): getSecureContainerList() called when storage not mounted
I/MountService( 2015): doMountVolume: Mouting /mnt/sdcard
E/MountService( 2015): Boot-time mount failed (-1)
W/MountService( 2015): Duplicate state transition (mounted -> mounted) for /storage/emulated/0

三、问题解决

该问题不是逻辑问题;而是creash问题。

后来发现公司添加一个新增接口,对指针没有做判断;存在野指针问题,同时没有在析构函数中做指针为null的free判断,导致vold进程不定时creash、导致mount状态混乱。

通过在free后至null、解决野指针问题;在析构函数中做null判断,显示调用free后;问题解决。





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值