浏览代码

Because of multiple underlying implementation of storage mount points introduce a mechanism which is querying multiple solutions and lists them to the user

Bartosz Przybylski 9 年之前
父节点
当前提交
5cf019d9de

+ 85 - 0
src/com/owncloud/android/datastorage/DataStorageProvider.java

@@ -0,0 +1,85 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage;
+
+import com.owncloud.android.MainApp;
+import com.owncloud.android.R;
+import com.owncloud.android.datastorage.providers.EnvironmentStoragePointProvider;
+import com.owncloud.android.datastorage.providers.HardcodedStoragePointProvider;
+import com.owncloud.android.datastorage.providers.IStoragePointProvider;
+import com.owncloud.android.datastorage.providers.MountCommandStoragePointProvider;
+import com.owncloud.android.datastorage.providers.SystemDefaultStoragePointProvider;
+import com.owncloud.android.datastorage.providers.VDCStoragePointProvider;
+
+import java.util.Vector;
+
+/**
+ * @author Bartosz Przybylski
+ */
+public class DataStorageProvider {
+
+    private static Vector<IStoragePointProvider> mStorageProviders = new Vector<>();
+    private static UniqueStorageList mCachedStoragePoints = new UniqueStorageList();
+    private static DataStorageProvider sInstance = new DataStorageProvider() {{
+        // There is no system wide way to get usb storage so we need to provide multiple
+        // handcrafted ways to add those.
+        addStoragePointProvider(new SystemDefaultStoragePointProvider());
+        addStoragePointProvider(new EnvironmentStoragePointProvider());
+        addStoragePointProvider(new VDCStoragePointProvider());
+        addStoragePointProvider(new MountCommandStoragePointProvider());
+        addStoragePointProvider(new HardcodedStoragePointProvider());
+    }};
+
+
+    public static DataStorageProvider getInstance() {
+        return sInstance;
+    }
+
+    private DataStorageProvider() {}
+
+    public StoragePoint[] getAvailableStoragePoints() {
+        if (mCachedStoragePoints.size() != 0)
+            return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
+
+
+        for (IStoragePointProvider p : mStorageProviders)
+            if (p.canProvideStoragePoints())
+                mCachedStoragePoints.addAll(p.getAvailableStoragePoint());
+
+        return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
+    }
+
+    public String getStorageDescriptionByPath(String path) {
+        for (StoragePoint s : getAvailableStoragePoints())
+            if (s.getPath().equals(path))
+                return s.getDescription();
+        return MainApp.getAppContext().getString(R.string.storage_description_unknown);
+    }
+
+    public void addStoragePointProvider(IStoragePointProvider provider) {
+        mStorageProviders.add(provider);
+    }
+
+    public void removeStoragePointProvider(IStoragePointProvider provider) {
+        mStorageProviders.remove(provider);
+    }
+}

+ 43 - 0
src/com/owncloud/android/datastorage/StoragePoint.java

@@ -0,0 +1,43 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartek Przybylski
+ *   Copyright (C) 2016  Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage;
+
+/**
+ * @author Bartosz Przybylski
+ */
+public class StoragePoint implements Comparable<StoragePoint> {
+    private String mDescription;
+    private String mPath;
+
+    public StoragePoint(String description, String path) {
+        mDescription = description;
+        mPath = path;
+    }
+
+    public String getPath() { return mPath; }
+    public String getDescription() { return mDescription; }
+
+    @Override
+    public int compareTo(StoragePoint another) {
+        return mPath.compareTo(another.getPath());
+    }
+}

+ 54 - 0
src/com/owncloud/android/datastorage/UniqueStorageList.java

@@ -0,0 +1,54 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Vector;
+
+/**
+ * @author Bartosz Przybylski
+ */
+public class UniqueStorageList extends Vector<StoragePoint> {
+    @Override
+    public boolean add(StoragePoint sp) {
+        try {
+            for (StoragePoint s : this) {
+                String thisCanonPath = new File(s.getPath()).getCanonicalPath();
+                String otherCanonPath = new File(sp.getPath()).getCanonicalPath();
+                if (thisCanonPath.equals(otherCanonPath))
+                    return true;
+            }
+        } catch (IOException e) {
+            return false;
+        }
+        return super.add(sp);
+    }
+
+    @Override
+    public synchronized boolean addAll(Collection<? extends StoragePoint> collection) {
+        for (StoragePoint sp : collection)
+            add(sp);
+        return true;
+    }
+}

+ 64 - 0
src/com/owncloud/android/datastorage/providers/AbstractCommandLineStoragePoint.java

@@ -0,0 +1,64 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage.providers;
+
+import java.io.InputStream;
+import java.util.Arrays;
+
+/**
+ * @author Bartosz Przybylski
+ */
+abstract public class AbstractCommandLineStoragePoint extends AbstractStoragePointProvider {
+
+    static protected final int sCommandLineOKReturnValue = 0;
+
+    protected abstract String[] getCommand();
+
+    @Override
+    public boolean canProvideStoragePoints() {
+        Process process;
+        try {
+            process = new ProcessBuilder().command(Arrays.asList(getCommand())).start();
+            process.waitFor();
+        } catch (Exception e) {
+            return false;
+        }
+        return process != null && process.exitValue() == sCommandLineOKReturnValue;
+    }
+
+    protected String getCommandLineResult() {
+        String s = "";
+        try {
+            final Process process = new ProcessBuilder().command(getCommand())
+                    .redirectErrorStream(true).start();
+
+            process.waitFor();
+            final InputStream is = process.getInputStream();
+            final byte buffer[] = new byte[1024];
+            while (is.read(buffer) != -1)
+                s += new String(buffer);
+            is.close();
+        } catch (final Exception e) { }
+        return s;
+    }
+
+}

+ 42 - 0
src/com/owncloud/android/datastorage/providers/AbstractStoragePointProvider.java

@@ -0,0 +1,42 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage.providers;
+
+import com.owncloud.android.datastorage.StoragePoint;
+
+import java.io.File;
+import java.util.Vector;
+
+/**
+ * @author Bartosz Przybylski
+ */
+abstract public class AbstractStoragePointProvider implements IStoragePointProvider {
+
+    protected boolean canBeAddedToAvailableList(Vector<StoragePoint> currentList, String path) {
+        if (path == null) return false;
+        for (StoragePoint storage : currentList)
+            if (storage.getPath().equals(path))
+                return false;
+        File f = new File(path);
+        return f.exists() && f.isDirectory() && f.canRead() && f.canWrite();
+    }
+}

+ 58 - 0
src/com/owncloud/android/datastorage/providers/EnvironmentStoragePointProvider.java

@@ -0,0 +1,58 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage.providers;
+
+import android.text.TextUtils;
+
+import com.owncloud.android.datastorage.StoragePoint;
+
+import java.util.Vector;
+
+/**
+ * @author Bartosz Przybylski
+ */
+public class EnvironmentStoragePointProvider extends AbstractStoragePointProvider {
+
+    private static final String sSecondaryStorageEnvName = "SECONDARY_STORAGE";
+
+    @Override
+    public boolean canProvideStoragePoints() {
+        return !TextUtils.isEmpty(System.getenv(sSecondaryStorageEnvName));
+    }
+
+    @Override
+    public Vector<StoragePoint> getAvailableStoragePoint() {
+        Vector<StoragePoint> result = new Vector<>();
+
+        addEntriesFromEnv(result, sSecondaryStorageEnvName);
+
+        return result;
+    }
+
+    private void addEntriesFromEnv(Vector<StoragePoint> result, String envName) {
+        String env = System.getenv(envName);
+        if (env != null)
+            for (String p : env.split(":"))
+                if (canBeAddedToAvailableList(result, p))
+                    result.add(new StoragePoint(p, p));
+    }
+}

+ 56 - 0
src/com/owncloud/android/datastorage/providers/HardcodedStoragePointProvider.java

@@ -0,0 +1,56 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage.providers;
+
+import com.owncloud.android.datastorage.StoragePoint;
+
+import java.util.Vector;
+
+/**
+ * @author Bartosz Przybylski
+ */
+public class HardcodedStoragePointProvider extends AbstractStoragePointProvider {
+
+    static private final String[] sPaths = {
+            "/mnt/external_sd/",
+            "/mnt/extSdCard/",
+            "/storage/extSdCard",
+            "/storage/sdcard1/",
+            "/storage/usbcard1/"
+    };
+
+    @Override
+    public boolean canProvideStoragePoints() {
+        return true;
+    }
+
+    @Override
+    public Vector<StoragePoint> getAvailableStoragePoint() {
+        Vector<StoragePoint> result = new Vector<>();
+
+        for (String s : sPaths)
+            if (canBeAddedToAvailableList(result, s))
+                result.add(new StoragePoint(s, s));
+
+        return result;
+    }
+}

+ 48 - 0
src/com/owncloud/android/datastorage/providers/IStoragePointProvider.java

@@ -0,0 +1,48 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage.providers;
+
+import com.owncloud.android.datastorage.StoragePoint;
+
+import java.util.Vector;
+
+/**
+ * @author Bartosz Przybylski
+ */
+public interface IStoragePointProvider {
+
+    /**
+     *  This method is used for querying storage provider to check if it can provide
+     *  usable and reliable data storage places.
+     *
+     *  @return true if provider can reliably return storage path
+     */
+    boolean canProvideStoragePoints();
+
+
+    /**
+     *
+     * @return available storage points
+     */
+    Vector<StoragePoint> getAvailableStoragePoint();
+
+}

+ 67 - 0
src/com/owncloud/android/datastorage/providers/MountCommandStoragePointProvider.java

@@ -0,0 +1,67 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage.providers;
+
+import com.owncloud.android.datastorage.StoragePoint;
+
+import java.util.Locale;
+import java.util.Vector;
+
+/**
+ * @author Bartosz Przybylski
+ */
+public class MountCommandStoragePointProvider extends AbstractCommandLineStoragePoint {
+
+    static private final String[] sCommand = new String[] { "mount" };
+
+    @Override
+    protected String[] getCommand() {
+        return sCommand;
+    }
+
+    @Override
+    public Vector<StoragePoint> getAvailableStoragePoint() {
+        Vector<StoragePoint> result = new Vector<>();
+
+        for (String p : getPotentialPaths(getCommandLineResult()))
+            if (canBeAddedToAvailableList(result, p))
+                result.add(new StoragePoint(p, p));
+
+        return result;
+    }
+
+    private Vector<String> getPotentialPaths(String mounted) {
+        final Vector<String> result = new Vector<>();
+        final String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
+
+        for (String line : mounted.split("\n"))
+            if (!line.toLowerCase(Locale.US).contains("asec") && line.matches(reg)) {
+                String parts[] = line.split(" ");
+                for (String path : parts) {
+                    if (path.startsWith("/") &&
+                            !path.toLowerCase(Locale.US).contains("vold"))
+                        result.add(path);
+                }
+            }
+        return result;
+    }
+}

+ 52 - 0
src/com/owncloud/android/datastorage/providers/SystemDefaultStoragePointProvider.java

@@ -0,0 +1,52 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage.providers;
+
+import android.os.Environment;
+
+import com.owncloud.android.MainApp;
+import com.owncloud.android.R;
+import com.owncloud.android.datastorage.StoragePoint;
+
+import java.util.Vector;
+
+/**
+ * @author Bartosz Przybylski
+ */
+public class SystemDefaultStoragePointProvider extends AbstractStoragePointProvider {
+    @Override
+    public boolean canProvideStoragePoints() {
+        return true;
+    }
+
+    @Override
+    public Vector<StoragePoint> getAvailableStoragePoint() {
+        Vector<StoragePoint> result = new Vector<>();
+
+        final String defaultStringDesc =
+                MainApp.getAppContext().getString(R.string.storage_description_default);
+        final String path = Environment.getExternalStorageDirectory().getAbsolutePath();
+        result.add(new StoragePoint(defaultStringDesc, path));
+
+        return result;
+    }
+}

+ 79 - 0
src/com/owncloud/android/datastorage/providers/VDCStoragePointProvider.java

@@ -0,0 +1,79 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author Bartosz Przybylski
+ *   Copyright (C) 2016 ownCloud Inc.
+ *   Copyright (C) 2016 Bartosz Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datastorage.providers;
+
+import com.owncloud.android.datastorage.StoragePoint;
+import com.owncloud.android.lib.common.utils.Log_OC;
+
+import java.util.Vector;
+
+/**
+ * @author Bartosz Przybylski
+ */
+public class VDCStoragePointProvider extends AbstractCommandLineStoragePoint {
+
+    static private final String TAG = VDCStoragePointProvider.class.getSimpleName();
+
+    static private final String[] sVDCVolListCommand = new String[]{ "/system/bin/vdc", "volume", "list" };
+    static private final int sVDCVolumeList = 110;
+
+
+    @Override
+    public Vector<StoragePoint> getAvailableStoragePoint() {
+        Vector<StoragePoint> result = new Vector<>();
+
+        result.addAll(getPaths(getCommandLineResult()));
+
+        return result;
+    }
+
+    @Override
+    protected String[] getCommand() {
+        return sVDCVolListCommand;
+    }
+
+    private Vector<StoragePoint> getPaths(String vdcResources) {
+        Vector<StoragePoint> result = new Vector<>();
+
+        for (String line : vdcResources.split("\n")) {
+            String vdcLine[] = line.split(" ");
+            try {
+                int status = Integer.parseInt(vdcLine[0]);
+                if (status != sVDCVolumeList)
+                    continue;
+                final String description = vdcLine[1];
+                final String path = vdcLine[2];
+
+                if (canBeAddedToAvailableList(result, path))
+                    result.add(new StoragePoint(description, path));
+
+            } catch (NumberFormatException e) {
+                Log_OC.e(TAG, "Incorrect VDC output format " + e);
+            } catch (Exception e) {
+                Log_OC.e(TAG, "Unexpected exception on VDC parsing " + e);
+            }
+        }
+
+        return result;
+    }
+
+}

+ 9 - 4
src/com/owncloud/android/ui/activity/Preferences.java

@@ -59,13 +59,18 @@ import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.datastorage.DataStorageProvider;
+import com.owncloud.android.datastorage.StoragePoint;
+import com.owncloud.android.db.DbHandler;
+import com.owncloud.android.files.FileOperationsHelper;
+import com.owncloud.android.files.services.FileDownloader;
+import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.OwnCloudAccount;
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.ui.PreferenceWithLongSummary;
 import com.owncloud.android.ui.RadioButtonPreference;
-import com.owncloud.android.utils.DataStorageUtils;
 import com.owncloud.android.utils.DisplayUtils;
 
 import java.io.IOException;
@@ -347,7 +352,7 @@ public class Preferences extends PreferenceActivity
 
         mPrefStoragePath =  (ListPreference) findPreference(Keys.STORAGE_PATH);
         if (mPrefStoragePath != null) {
-            DataStorageUtils.Storage[] storageOptions = DataStorageUtils.getAvailableStoragePoints(getApplicationContext());
+            StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints();
             String[] entries = new String[storageOptions.length];
             String[] values = new String[storageOptions.length];
             for (int i = 0; i < storageOptions.length; ++i) {
@@ -764,7 +769,7 @@ public class Preferences extends PreferenceActivity
         SharedPreferences.Editor editor = appPrefs.edit();
         editor.putString(Keys.STORAGE_PATH, mStoragePath);
         editor.commit();
-        String storageDescription = DataStorageUtils.getStorageDescriptionByPath(mStoragePath, this);
+        String storageDescription = DataStorageProvider.getInstance().getStorageDescriptionByPath(mStoragePath);
         mPrefStoragePath.setSummary(storageDescription);
         mPrefStoragePath.setValue(newStoragePath);
     }
@@ -777,7 +782,7 @@ public class Preferences extends PreferenceActivity
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
         mStoragePath = appPrefs.getString(Keys.STORAGE_PATH, Environment.getExternalStorageDirectory()
                                                          .getAbsolutePath());
-        String storageDescription = DataStorageUtils.getStorageDescriptionByPath(mStoragePath, getApplicationContext());
+        String storageDescription = DataStorageProvider.getInstance().getStorageDescriptionByPath(mStoragePath);
         mPrefStoragePath.setSummary(storageDescription);
     }
 

+ 0 - 124
src/com/owncloud/android/utils/DataStorageUtils.java

@@ -1,124 +0,0 @@
-/**
- *   ownCloud Android client application
- *
- *   @author Bartek Przybylski
- *   Copyright (C) 2015  Bartosz Przybylski
- *   Copyright (C) 2015 ownCloud Inc.
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.utils;
-
-import android.content.Context;
-import android.os.Build;
-import android.os.Environment;
-
-import com.owncloud.android.R;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * @author Bartosz Przybylski
- */
-public class DataStorageUtils {
-	static public final class Storage {
-		private String mDescription;
-		private String mPath;
-
-		Storage(String description, String path) {
-			mDescription = description;
-			mPath = path;
-		}
-
-		public String getPath() { return mPath; }
-		public String getDescription() { return mDescription; }
-	}
-
-	static public Storage[] getAvailableStoragePoints(Context context) {
-        List<Storage> result = new ArrayList<>();
-
-        String storagePath = Environment.getExternalStorageDirectory().getPath();
-        if (canBeAddedToAvailableList(result, storagePath))
-            result.add(new Storage(context.getString(R.string.storage_description_default),
-                    storagePath));
-
-
-        int cardNo = 1;
-
-        for (String potentialPath : getPotentialPaths(getMountedResources()))
-            if (canBeAddedToAvailableList(result, potentialPath))
-                result.add(new Storage(constructSDCardName(context, cardNo++), potentialPath));
-
-        return result.toArray(new Storage[result.size()]);
-	}
-
-	public static String getStorageDescriptionByPath(String path, Context context) {
-		Storage[] storages = getAvailableStoragePoints(context);
-		for (Storage s : storages) {
-			if (s.getPath().equals(path))
-				return s.getDescription();
-		}
-		return context.getString(R.string.storage_description_unknown);
-	}
-
-    private static String constructSDCardName(Context context, int no) {
-        return context.getString(R.string.storage_description_sd_no, no);
-    }
-
-    private static String getMountedResources() {
-        String s = "";
-        try {
-            final Process process = new ProcessBuilder().command("mount")
-                    .redirectErrorStream(true).start();
-
-            process.waitFor();
-            final InputStream is = process.getInputStream();
-            final byte buffer[] = new byte[1024];
-            while (is.read(buffer) != -1)
-                s += new String(buffer);
-            is.close();
-        } catch (final Exception e) { }
-        return s;
-    }
-
-    private static String[] getPotentialPaths(String mounted) {
-        final List<String> result = new ArrayList<String>();
-        final String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
-
-        for (String line : mounted.split("\n"))
-            if (!line.toLowerCase(Locale.US).contains("asec") && line.matches(reg)) {
-                    String parts[] = line.split(" ");
-                    for (String path : parts) {
-                        if (path.startsWith("/") &&
-                                !path.toLowerCase(Locale.US).contains("vold"))
-                            result.add(path);
-                    }
-            }
-        return result.toArray(new String[result.size()]);
-    }
-
-	private static boolean canBeAddedToAvailableList(List<Storage> currentList, String path) {
-		if (path == null) return false;
-        for (Storage storage : currentList)
-            if (storage.getPath().equals(path))
-                return false;
-		File f = new File(path);
-		return f.exists() && f.isDirectory();
-	}
-}