/** * 读取配置文件/system/etc/vold.fstab获取设备 如 [/mnt/sdcard, /mnt/extsdcard, /mnt/fat] */ private static void readVold(List<String> mVold) { mVold.add("/mnt/sdcard"); try { File voldFile = new File("/system/etc/vold.fstab"); if (voldFile.exists()) { Scanner scanner = new Scanner(voldFile); while (scanner.hasNext()) { String line = scanner.nextLine(); if (line.startsWith("dev_mount")) { String[] lineElements = line.split(" "); String element = lineElements[2]; if (element.contains(":")) { element = element.substring(0, element.indexOf(":")); } if (!element.equals("/mnt/sdcard")) { mVold.add(element); } } } } } catch (IOException e) { mVold.clear(); XLog.e(CLASS_NAME, e.getMessage()); } }
/** 读取配置文件/proc/mounts 获取文件系统挂载信息 如 [/mnt/sdcard, /mnt/extsdcard] */ private static void readMounts(List<String> mMounts) { mMounts.add("/mnt/sdcard"); try { File mountFile = new File("/proc/mounts"); if (mountFile.exists()) { Scanner scanner = new Scanner(mountFile); while (scanner.hasNext()) { String line = scanner.nextLine(); if (line.startsWith("/dev/block/vold/")) { String[] lineElements = line.split(" "); String element = lineElements[1]; if (!element.equals("/mnt/sdcard")) { mMounts.add(element); } } } } } catch (IOException e) { mMounts.clear(); XLog.e(CLASS_NAME, e.getMessage()); } }