android文件管理器不显示u盘内容

From source codes,
Vold sets the device as adoptable or not based on the flag(encryptable/forceencrypt) as shown
below.
231 if (fs_mgr_is_encryptable(&fstab->recs[i])) {
    
    
232 flags |= android::vold::Disk::Flags::kAdoptable;
233 has_adoptable = true;
234 }
Which is further passed to Mountservice, which marks only the adoptable volumes as Visible
devices.
1285 } else if (vol.type == VolumeInfo.TYPE_PUBLIC) {
    
    
1286 // TODO: only look at first public partition
1287 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, mPrimaryStorageUuid)
1288 && vol.disk.isDefaultPrimary()) {
    
    
1289 Slog.v(TAG, "Found primary storage at " + vol);
1290 vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
1291 vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
1292 }
1293
1294 // Adoptable public disks are visible to apps, since they meet
1295 // public API requirement of being in a stable location.
1296 if (vol.disk.isAdoptable()) {
    
    
1297 vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
1298 }
Non adoptable volumes are NOT exposed to apps.
And hence, in vold, while Mounting(), the app-exposed-mountpoint -> /storage/<ID> is not mounted
for invisible devices.
120 if (getMountFlags() & MountFlags::kVisible) {
    
    
121 setPath(StringPrintf("/storage/%s", stableName.c_str()));
122 } else {
    
    
Settings is a privileged Platform app, shared system uid, so it can call frameworks APIs directly,
which can't be done by CMFilemanager(which is just system app)


[解决方案]
If we want to see the the non-adoptable volumes (like UDisk and Pen-driver via OTG) in
FileManager app, we can modify MountService.java as below , then have a try.
1294 // Adoptable public disks are visible to apps, since they meet
1295 // public API requirement of being in a stable location
- if (vol.disk.isAdoptable()) {
    
    
+ if (vol.disk.isAdoptable() || vol.disk.isUsb()) {
    
    
1297 vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
1298 }

猜你喜欢

转载自blog.csdn.net/sdrgtywretyeruet/article/details/115438372
今日推荐