原因大致为状态机混乱:
Initializing No-Media Idle-Unmounted Pending Mounted Unmounting Checking Formatting Shared-Unmounted Shared-Mounted Unknown-Error
一、问题描述
挂U盘开机正常;开机后挂U盘不正常。经常出现状态混乱。
二、正确流程
1.挂载
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.卸载
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盘已经挂上
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-9D534.MountService启动时U盘没有挂上
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后;问题解决。