MountCommandStoragePointProvider.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author Bartosz Przybylski
  5. * Copyright (C) 2016 ownCloud Inc.
  6. * Copyright (C) 2016 Bartosz Przybylski
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. package com.owncloud.android.datastorage.providers;
  22. import com.owncloud.android.datastorage.StoragePoint;
  23. import java.util.Locale;
  24. import java.util.Vector;
  25. /**
  26. * @author Bartosz Przybylski
  27. */
  28. public class MountCommandStoragePointProvider extends AbstractCommandLineStoragePoint {
  29. static private final String[] sCommand = new String[] { "mount" };
  30. @Override
  31. protected String[] getCommand() {
  32. return sCommand;
  33. }
  34. @Override
  35. public Vector<StoragePoint> getAvailableStoragePoint() {
  36. Vector<StoragePoint> result = new Vector<>();
  37. for (String p : getPotentialPaths(getCommandLineResult()))
  38. if (canBeAddedToAvailableList(result, p))
  39. result.add(new StoragePoint(p, p));
  40. return result;
  41. }
  42. private Vector<String> getPotentialPaths(String mounted) {
  43. final Vector<String> result = new Vector<>();
  44. final String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
  45. for (String line : mounted.split("\n"))
  46. if (!line.toLowerCase(Locale.US).contains("asec") && line.matches(reg)) {
  47. String parts[] = line.split(" ");
  48. for (String path : parts) {
  49. if (path.startsWith("/") &&
  50. !path.toLowerCase(Locale.US).contains("vold"))
  51. result.add(path);
  52. }
  53. }
  54. return result;
  55. }
  56. }