EnvironmentStoragePointProvider.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Nextcloud Android client application
  3. *
  4. * @author Bartosz Przybylski
  5. * Copyright (C) 2016 Nextcloud
  6. * Copyright (C) 2016 Bartosz Przybylski
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.datastorage.providers;
  22. import android.text.TextUtils;
  23. import com.owncloud.android.datastorage.StoragePoint;
  24. import java.util.Vector;
  25. /**
  26. * @author Bartosz Przybylski
  27. */
  28. public class EnvironmentStoragePointProvider extends AbstractStoragePointProvider {
  29. private static final String sSecondaryStorageEnvName = "SECONDARY_STORAGE";
  30. @Override
  31. public boolean canProvideStoragePoints() {
  32. return !TextUtils.isEmpty(System.getenv(sSecondaryStorageEnvName));
  33. }
  34. @Override
  35. public Vector<StoragePoint> getAvailableStoragePoint() {
  36. Vector<StoragePoint> result = new Vector<>();
  37. addEntriesFromEnv(result, sSecondaryStorageEnvName);
  38. return result;
  39. }
  40. private void addEntriesFromEnv(Vector<StoragePoint> result, String envName) {
  41. String env = System.getenv(envName);
  42. if (env != null)
  43. for (String p : env.split(":"))
  44. if (canBeAddedToAvailableList(result, p))
  45. result.add(new StoragePoint(p, p));
  46. }
  47. }