AOSP/system/vold/model/Dish.h
这里定义用于区分设备类型的值:
enum Flags {
/* Flag that disk is adoptable */
kAdoptable = 1 << 0,
/* Flag that disk is considered primary when the user hasn't
* explicitly picked a primary storage location */
kDefaultPrimary = 1 << 1,
/* Flag that disk is SD card */
kSd = 1 << 2,
/* Flag that disk is USB disk */
kUsb = 1 << 3,
/* Flag that disk is EMMC internal */
kEmmc = 1 << 4,
};
这个值会在挂载的时候用到:
void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
std::lock_guard<std::mutex> lock(mLock);
if (mDebug) {
LOG(VERBOSE) << "----------------";
LOG(VERBOSE) << "handleBlockEvent with action " << (int) evt->getAction();
evt->dump();
}
std::string eventPath(evt->findParam("DEVPATH")?evt->findParam("DEVPATH"):"");
std::string devType(evt->findParam("DEVTYPE")?evt->findParam("DEVTYPE"):"");
if (devType != "disk") return;
int major = std::stoi(evt->findParam("MAJOR"));
int minor = std::stoi(evt->findParam("MINOR"));
dev_t device = makedev(major, minor);
switch (evt->getAction()) {
case NetlinkEvent::Action::kAdd: {
for (const auto& source : mDiskSources) {
if (source->matches(eventPath)) {
// For now, assume that MMC and virtio-blk (the latter is
// emulator-specific; see Disk.cpp for details) devices are SD,
// and that everything else is USB
int flags = source->getFlags();
if (major == kMajorBlockMmc
|| (android::vold::IsRunningInEmulator()
&& major >= (int) kMajorBlockExperimentalMin
&& major <= (int) kMajorBlockExperimentalMax)) {
flags |= android::vold::Disk::Flags::kSd;
} else {
flags |= android::vold::Disk::Flags::kUsb;
}
最终,挂载的设备被封装成VolumeInfo,传到StorageManagerService:
private void onVolumeCreatedLocked(VolumeInfo vol) {
...
if (vol.disk.isAdoptable()) {
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
}
我们可以通过vol.disk.isUsb()等方法来判断设备类型。
让sd卡被识别为usb
修改Dish.h即可:
/* Flag that disk is SD card */
// 让sd卡当成usb
kSd = 1 << 3,
/* Flag that disk is USB disk */
kUsb = 1 << 3,
网友评论