现象:插入OTG U盘 之后,文件管理器没自动刷新出来,需要退出进入才刷新。
分析:发现是下面的两个广播没有
Action: "android.intent.action.MEDIA_MOUNTED"
Action: "android.intent.action.MEDIA_UNMOUNTED"
分析这2个广播发送的地方
frameworks\base\services\core\java\com\android\server\StorageManagerService.java
case H_VOLUME_BROADCAST: {
final StorageVolume userVol = (StorageVolume) msg.obj;
final String envState = userVol.getState();
final String action = VolumeInfo.getBroadcastForEnvironment(envState);
Slog.d(TAG, "Volume " + userVol.getId() + " broadcasting " + envState + " to "
+ userVol.getOwner() + "action ="+action);
if (action != null) {
final Intent intent = new Intent(action,
Uri.fromFile(userVol.getPathFile()));
intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, userVol);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
| Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
mContext.sendBroadcastAsUser(intent, userVol.getOwner());
}
break;
}
解决方法:盘符没有显示给app ,放开判断就可以。
@@ -1180,9 +1181,9 @@ class StorageManagerService extends IStorageManager.Stub
// Adoptable public disks are visible to apps, since they meet
// public API requirement of being in a stable location.
- if (vol.disk.isAdoptable()) {
- vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
- }
+ //if (vol.disk.isAdoptable()) {
+ vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
+ //}