浏览代码

further findbugs/pmd fixes for new feature (sd card)

AndyScherzinger 8 年之前
父节点
当前提交
54f4dc7032

+ 1 - 1
src/com/owncloud/android/MainApp.java

@@ -70,7 +70,7 @@ public class MainApp extends Application {
 
 
         SharedPreferences appPrefs =
         SharedPreferences appPrefs =
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
-        MainApp.storagePath = appPrefs.getString(Preferences.Keys.STORAGE_PATH, Environment.
+        MainApp.storagePath = appPrefs.getString(Preferences.PreferenceKeys.STORAGE_PATH, Environment.
                               getExternalStorageDirectory().getAbsolutePath());
                               getExternalStorageDirectory().getAbsolutePath());
 
 
         boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
         boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));

+ 10 - 28
src/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -729,9 +729,9 @@ public class FileDataStorageManager {
     }
     }
 
 
     public void migrateStoredFiles(String srcPath, String dstPath) throws Exception {
     public void migrateStoredFiles(String srcPath, String dstPath) throws Exception {
-        Cursor c = null;
+        Cursor cursor = null;
         if (getContentResolver() != null) {
         if (getContentResolver() != null) {
-            c = getContentResolver().query(ProviderTableMeta.CONTENT_URI_FILE,
+            cursor = getContentResolver().query(ProviderTableMeta.CONTENT_URI_FILE,
                     null,
                     null,
                     ProviderTableMeta.FILE_STORAGE_PATH  + " IS NOT NULL",
                     ProviderTableMeta.FILE_STORAGE_PATH  + " IS NOT NULL",
                     null,
                     null,
@@ -739,41 +739,23 @@ public class FileDataStorageManager {
 
 
         } else {
         } else {
             try {
             try {
-                c = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI_FILE,
+                cursor = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI_FILE,
                         new String[]{ProviderTableMeta._ID, ProviderTableMeta.FILE_STORAGE_PATH},
                         new String[]{ProviderTableMeta._ID, ProviderTableMeta.FILE_STORAGE_PATH},
                         ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL",
                         ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL",
                         null,
                         null,
                         null);
                         null);
             } catch (RemoteException e) {
             } catch (RemoteException e) {
-                Log_OC.e(TAG, e.getMessage());
+                Log_OC.e(TAG, e.getMessage(), e);
                 throw e;
                 throw e;
             }
             }
-        } catch (IOException ex) {
-            ret = false;
-        } finally {
-            if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException e) {
-                    Log_OC.d(TAG, e.getMessage(), e);
-                }
-            }
-            if (out != null) {
-                try {
-                    out.close();
-                } catch (IOException e) {
-                    Log_OC.d(TAG, e.getMessage(), e);
-                }
-            }
         }
         }
 
 
-        ArrayList<ContentProviderOperation> operations =
-                new ArrayList<ContentProviderOperation>(c.getCount());
-        if (c.moveToFirst()) {
+        ArrayList<ContentProviderOperation> operations = new ArrayList<>(cursor.getCount());
+        if (cursor.moveToFirst()) {
             do {
             do {
                 ContentValues cv = new ContentValues();
                 ContentValues cv = new ContentValues();
-                long fileId = c.getLong(c.getColumnIndex(ProviderTableMeta._ID));
-                String oldFileStoragePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
+                long fileId = cursor.getLong(cursor.getColumnIndex(ProviderTableMeta._ID));
+                String oldFileStoragePath = cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
 
 
                 if (oldFileStoragePath.startsWith(srcPath)) {
                 if (oldFileStoragePath.startsWith(srcPath)) {
 
 
@@ -791,9 +773,9 @@ public class FileDataStorageManager {
                                     .build());
                                     .build());
                 }
                 }
 
 
-            } while (c.moveToNext());
+            } while (cursor.moveToNext());
         }
         }
-        c.close();
+        cursor.close();
 
 
         /// 3. apply updates in batch
         /// 3. apply updates in batch
         if (getContentResolver() != null) {
         if (getContentResolver() != null) {

+ 8 - 4
src/com/owncloud/android/datastorage/DataStorageProvider.java

@@ -60,8 +60,9 @@ public class DataStorageProvider {
     private DataStorageProvider() {}
     private DataStorageProvider() {}
 
 
     public StoragePoint[] getAvailableStoragePoints() {
     public StoragePoint[] getAvailableStoragePoints() {
-        if (mCachedStoragePoints.size() != 0)
+        if (mCachedStoragePoints.size() != 0) {
             return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
             return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
+        }
 
 
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
             for (File f : MainApp.getAppContext().getExternalFilesDirs(null)) {
             for (File f : MainApp.getAppContext().getExternalFilesDirs(null)) {
@@ -70,19 +71,22 @@ public class DataStorageProvider {
                 }
                 }
             }
             }
         } else {
         } else {
-            for (IStoragePointProvider p : mStorageProviders)
+            for (IStoragePointProvider p : mStorageProviders) {
                 if (p.canProvideStoragePoints()) {
                 if (p.canProvideStoragePoints()) {
                     mCachedStoragePoints.addAll(p.getAvailableStoragePoint());
                     mCachedStoragePoints.addAll(p.getAvailableStoragePoint());
                 }
                 }
+            }
         }
         }
 
 
         return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
         return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
     }
     }
 
 
     public String getStorageDescriptionByPath(String path) {
     public String getStorageDescriptionByPath(String path) {
-        for (StoragePoint s : getAvailableStoragePoints())
-            if (s.getPath().equals(path))
+        for (StoragePoint s : getAvailableStoragePoints()) {
+            if (s.getPath().equals(path)) {
                 return s.getDescription();
                 return s.getDescription();
+            }
+        }
         return MainApp.getAppContext().getString(R.string.storage_description_unknown);
         return MainApp.getAppContext().getString(R.string.storage_description_unknown);
     }
     }
 
 

+ 4 - 2
src/com/owncloud/android/datastorage/UniqueStorageList.java

@@ -36,8 +36,9 @@ public class UniqueStorageList extends Vector<StoragePoint> {
             for (StoragePoint s : this) {
             for (StoragePoint s : this) {
                 String thisCanonPath = new File(s.getPath()).getCanonicalPath();
                 String thisCanonPath = new File(s.getPath()).getCanonicalPath();
                 String otherCanonPath = new File(sp.getPath()).getCanonicalPath();
                 String otherCanonPath = new File(sp.getPath()).getCanonicalPath();
-                if (thisCanonPath.equals(otherCanonPath))
+                if (thisCanonPath.equals(otherCanonPath)) {
                     return true;
                     return true;
+                }
             }
             }
         } catch (IOException e) {
         } catch (IOException e) {
             return false;
             return false;
@@ -47,8 +48,9 @@ public class UniqueStorageList extends Vector<StoragePoint> {
 
 
     @Override
     @Override
     public synchronized boolean addAll(Collection<? extends StoragePoint> collection) {
     public synchronized boolean addAll(Collection<? extends StoragePoint> collection) {
-        for (StoragePoint sp : collection)
+        for (StoragePoint sp : collection) {
             add(sp);
             add(sp);
+        }
         return true;
         return true;
     }
     }
 }
 }

+ 16 - 12
src/com/owncloud/android/datastorage/providers/AbstractCommandLineStoragePoint.java

@@ -21,15 +21,18 @@
 
 
 package com.owncloud.android.datastorage.providers;
 package com.owncloud.android.datastorage.providers;
 
 
+import com.owncloud.android.lib.common.utils.Log_OC;
+
 import java.io.InputStream;
 import java.io.InputStream;
 import java.util.Arrays;
 import java.util.Arrays;
 
 
 /**
 /**
  * @author Bartosz Przybylski
  * @author Bartosz Przybylski
  */
  */
-abstract public class AbstractCommandLineStoragePoint extends AbstractStoragePointProvider {
+abstract class AbstractCommandLineStoragePoint extends AbstractStoragePointProvider {
+    private static final String TAG = AbstractCommandLineStoragePoint.class.getSimpleName();
 
 
-    static protected final int sCommandLineOKReturnValue = 0;
+    private static final int COMMAND_LINE_OK_RETURN_VALUE = 0;
 
 
     protected abstract String[] getCommand();
     protected abstract String[] getCommand();
 
 
@@ -42,23 +45,24 @@ abstract public class AbstractCommandLineStoragePoint extends AbstractStoragePoi
         } catch (Exception e) {
         } catch (Exception e) {
             return false;
             return false;
         }
         }
-        return process != null && process.exitValue() == sCommandLineOKReturnValue;
+        return process != null && process.exitValue() == COMMAND_LINE_OK_RETURN_VALUE;
     }
     }
 
 
-    protected String getCommandLineResult() {
-        String s = "";
+    String getCommandLineResult() {
+        StringBuilder s = new StringBuilder();
         try {
         try {
-            final Process process = new ProcessBuilder().command(getCommand())
-                    .redirectErrorStream(true).start();
+            final Process process = new ProcessBuilder().command(getCommand()).redirectErrorStream(true).start();
 
 
             process.waitFor();
             process.waitFor();
             final InputStream is = process.getInputStream();
             final InputStream is = process.getInputStream();
             final byte buffer[] = new byte[1024];
             final byte buffer[] = new byte[1024];
-            while (is.read(buffer) != -1)
-                s += new String(buffer);
+            while (is.read(buffer) != -1) {
+                s.append(new String(buffer, "UTF8"));
+            }
             is.close();
             is.close();
-        } catch (final Exception e) { }
-        return s;
+        } catch (final Exception e) {
+            Log_OC.e(TAG, "Error retrieving command line results!", e);
+        }
+        return s.toString();
     }
     }
-
 }
 }

+ 11 - 5
src/com/owncloud/android/datastorage/providers/AbstractStoragePointProvider.java

@@ -29,13 +29,19 @@ import java.util.Vector;
 /**
 /**
  * @author Bartosz Przybylski
  * @author Bartosz Przybylski
  */
  */
-abstract public class AbstractStoragePointProvider implements IStoragePointProvider {
+abstract 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))
+    boolean canBeAddedToAvailableList(Vector<StoragePoint> currentList, String path) {
+        if (path == null) {
+            return false;
+        }
+
+        for (StoragePoint storage : currentList) {
+            if (storage.getPath().equals(path)) {
                 return false;
                 return false;
+            }
+        }
+
         File f = new File(path);
         File f = new File(path);
         return f.exists() && f.isDirectory() && f.canRead() && f.canWrite();
         return f.exists() && f.isDirectory() && f.canRead() && f.canWrite();
     }
     }

+ 6 - 3
src/com/owncloud/android/datastorage/providers/EnvironmentStoragePointProvider.java

@@ -50,9 +50,12 @@ public class EnvironmentStoragePointProvider extends AbstractStoragePointProvide
 
 
     private void addEntriesFromEnv(Vector<StoragePoint> result, String envName) {
     private void addEntriesFromEnv(Vector<StoragePoint> result, String envName) {
         String env = System.getenv(envName);
         String env = System.getenv(envName);
-        if (env != null)
-            for (String p : env.split(":"))
-                if (canBeAddedToAvailableList(result, p))
+        if (env != null) {
+            for (String p : env.split(":")) {
+                if (canBeAddedToAvailableList(result, p)) {
                     result.add(new StoragePoint(p, p));
                     result.add(new StoragePoint(p, p));
+                }
+            }
+        }
     }
     }
 }
 }

+ 5 - 3
src/com/owncloud/android/datastorage/providers/HardcodedStoragePointProvider.java

@@ -30,7 +30,7 @@ import java.util.Vector;
  */
  */
 public class HardcodedStoragePointProvider extends AbstractStoragePointProvider {
 public class HardcodedStoragePointProvider extends AbstractStoragePointProvider {
 
 
-    static private final String[] sPaths = {
+    private static final String[] PATHS = {
             "/mnt/external_sd/",
             "/mnt/external_sd/",
             "/mnt/extSdCard/",
             "/mnt/extSdCard/",
             "/storage/extSdCard",
             "/storage/extSdCard",
@@ -47,9 +47,11 @@ public class HardcodedStoragePointProvider extends AbstractStoragePointProvider
     public Vector<StoragePoint> getAvailableStoragePoint() {
     public Vector<StoragePoint> getAvailableStoragePoint() {
         Vector<StoragePoint> result = new Vector<>();
         Vector<StoragePoint> result = new Vector<>();
 
 
-        for (String s : sPaths)
-            if (canBeAddedToAvailableList(result, s))
+        for (String s : PATHS) {
+            if (canBeAddedToAvailableList(result, s)) {
                 result.add(new StoragePoint(s, s));
                 result.add(new StoragePoint(s, s));
+            }
+        }
 
 
         return result;
         return result;
     }
     }

+ 8 - 5
src/com/owncloud/android/datastorage/providers/MountCommandStoragePointProvider.java

@@ -45,9 +45,11 @@ public class MountCommandStoragePointProvider extends AbstractCommandLineStorage
     public Vector<StoragePoint> getAvailableStoragePoint() {
     public Vector<StoragePoint> getAvailableStoragePoint() {
         Vector<StoragePoint> result = new Vector<>();
         Vector<StoragePoint> result = new Vector<>();
 
 
-        for (String p : getPotentialPaths(getCommandLineResult()))
-            if (canBeAddedToAvailableList(result, p))
+        for (String p : getPotentialPaths(getCommandLineResult())) {
+            if (canBeAddedToAvailableList(result, p)) {
                 result.add(new StoragePoint(p, p));
                 result.add(new StoragePoint(p, p));
+            }
+        }
 
 
         return result;
         return result;
     }
     }
@@ -55,15 +57,16 @@ public class MountCommandStoragePointProvider extends AbstractCommandLineStorage
     private Vector<String> getPotentialPaths(String mounted) {
     private Vector<String> getPotentialPaths(String mounted) {
         final Vector<String> result = new Vector<>();
         final Vector<String> result = new Vector<>();
 
 
-        for (String line : mounted.split("\n"))
+        for (String line : mounted.split("\n")) {
             if (!line.toLowerCase(Locale.US).contains("asec") && sPattern.matcher(line).matches()) {
             if (!line.toLowerCase(Locale.US).contains("asec") && sPattern.matcher(line).matches()) {
                 String parts[] = line.split(" ");
                 String parts[] = line.split(" ");
                 for (String path : parts) {
                 for (String path : parts) {
-                    if (path.startsWith("/") &&
-                            !path.toLowerCase(Locale.US).contains("vold"))
+                    if (path.startsWith("/") && !path.toLowerCase(Locale.US).contains("vold")) {
                         result.add(path);
                         result.add(path);
+                    }
                 }
                 }
             }
             }
+        }
         return result;
         return result;
     }
     }
 }
 }

+ 4 - 2
src/com/owncloud/android/datastorage/providers/VDCStoragePointProvider.java

@@ -58,13 +58,15 @@ public class VDCStoragePointProvider extends AbstractCommandLineStoragePoint {
             String vdcLine[] = line.split(" ");
             String vdcLine[] = line.split(" ");
             try {
             try {
                 int status = Integer.parseInt(vdcLine[0]);
                 int status = Integer.parseInt(vdcLine[0]);
-                if (status != sVDCVolumeList)
+                if (status != sVDCVolumeList) {
                     continue;
                     continue;
+                }
                 final String description = vdcLine[1];
                 final String description = vdcLine[1];
                 final String path = vdcLine[2];
                 final String path = vdcLine[2];
 
 
-                if (canBeAddedToAvailableList(result, path))
+                if (canBeAddedToAvailableList(result, path)) {
                     result.add(new StoragePoint(description, path));
                     result.add(new StoragePoint(description, path));
+                }
 
 
             } catch (NumberFormatException e) {
             } catch (NumberFormatException e) {
                 Log_OC.e(TAG, "Incorrect VDC output format " + e);
                 Log_OC.e(TAG, "Incorrect VDC output format " + e);

+ 1 - 1
src/com/owncloud/android/media/MediaService.java

@@ -65,7 +65,7 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
     public static final String ACTION_PLAY_FILE = MY_PACKAGE + ".action.PLAY_FILE";
     public static final String ACTION_PLAY_FILE = MY_PACKAGE + ".action.PLAY_FILE";
     public static final String ACTION_STOP_ALL = MY_PACKAGE + ".action.STOP_ALL";
     public static final String ACTION_STOP_ALL = MY_PACKAGE + ".action.STOP_ALL";
 
 
-    /// Keys to add extras to the action
+    /// PreferenceKeys to add extras to the action
     public static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
     public static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
     public static final String EXTRA_ACCOUNT = MY_PACKAGE + ".extra.ACCOUNT";
     public static final String EXTRA_ACCOUNT = MY_PACKAGE + ".extra.ACCOUNT";
     public static final String EXTRA_START_POSITION = MY_PACKAGE + ".extra.START_POSITION";
     public static final String EXTRA_START_POSITION = MY_PACKAGE + ".extra.START_POSITION";

+ 13 - 11
src/com/owncloud/android/ui/activity/Preferences.java

@@ -112,7 +112,7 @@ public class Preferences extends PreferenceActivity
     private ListPreference mPrefStoragePath;
     private ListPreference mPrefStoragePath;
     private String mStoragePath;
     private String mStoragePath;
 
 
-    public static class Keys {
+    public static class PreferenceKeys {
         public static final String STORAGE_PATH = "storage_path";
         public static final String STORAGE_PATH = "storage_path";
         public static final String INSTANT_UPLOAD_PATH = "instant_upload_path";
         public static final String INSTANT_UPLOAD_PATH = "instant_upload_path";
         public static final String INSTANT_VIDEO_UPLOAD_PATH = "instant_video_upload_path";
         public static final String INSTANT_VIDEO_UPLOAD_PATH = "instant_video_upload_path";
@@ -338,7 +338,7 @@ public class Preferences extends PreferenceActivity
             }
             }
         }
         }
 
 
-        mPrefStoragePath =  (ListPreference) findPreference(Keys.STORAGE_PATH);
+        mPrefStoragePath =  (ListPreference) findPreference(PreferenceKeys.STORAGE_PATH);
         if (mPrefStoragePath != null) {
         if (mPrefStoragePath != null) {
             StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints();
             StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints();
             String[] entries = new String[storageOptions.length];
             String[] entries = new String[storageOptions.length];
@@ -354,8 +354,9 @@ public class Preferences extends PreferenceActivity
                     @Override
                     @Override
                     public boolean onPreferenceChange(Preference preference, Object newValue) {
                     public boolean onPreferenceChange(Preference preference, Object newValue) {
                         String newPath = (String)newValue;
                         String newPath = (String)newValue;
-                        if (mStoragePath.equals(newPath))
+                        if (mStoragePath.equals(newPath)) {
                             return true;
                             return true;
+                        }
 
 
                         StorageMigration storageMigration = new StorageMigration(Preferences.this, mStoragePath, newPath);
                         StorageMigration storageMigration = new StorageMigration(Preferences.this, mStoragePath, newPath);
 
 
@@ -369,7 +370,7 @@ public class Preferences extends PreferenceActivity
 
 
         }
         }
 
 
-        mPrefInstantUploadPath = (PreferenceWithLongSummary)findPreference(Keys.INSTANT_UPLOAD_PATH);
+        mPrefInstantUploadPath = (PreferenceWithLongSummary)findPreference(PreferenceKeys.INSTANT_UPLOAD_PATH);
         if (mPrefInstantUploadPath != null){
         if (mPrefInstantUploadPath != null){
 
 
             mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
             mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -408,7 +409,7 @@ public class Preferences extends PreferenceActivity
             }
             }
         });
         });
 
 
-        mPrefInstantVideoUploadPath =  findPreference(Keys.INSTANT_VIDEO_UPLOAD_PATH);
+        mPrefInstantVideoUploadPath =  findPreference(PreferenceKeys.INSTANT_VIDEO_UPLOAD_PATH);
         if (mPrefInstantVideoUploadPath != null){
         if (mPrefInstantVideoUploadPath != null){
 
 
             mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
             mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -727,7 +728,7 @@ public class Preferences extends PreferenceActivity
     private void loadInstantUploadPath() {
     private void loadInstantUploadPath() {
         SharedPreferences appPrefs =
         SharedPreferences appPrefs =
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
-        mUploadPath = appPrefs.getString(Keys.INSTANT_UPLOAD_PATH, getString(R.string.instant_upload_path));
+        mUploadPath = appPrefs.getString(PreferenceKeys.INSTANT_UPLOAD_PATH, getString(R.string.instant_upload_path));
         mPrefInstantUploadPath.setSummary(mUploadPath);
         mPrefInstantUploadPath.setSummary(mUploadPath);
     }
     }
 
 
@@ -740,7 +741,7 @@ public class Preferences extends PreferenceActivity
         mStoragePath = newStoragePath;
         mStoragePath = newStoragePath;
         MainApp.setStoragePath(mStoragePath);
         MainApp.setStoragePath(mStoragePath);
         SharedPreferences.Editor editor = appPrefs.edit();
         SharedPreferences.Editor editor = appPrefs.edit();
-        editor.putString(Keys.STORAGE_PATH, mStoragePath);
+        editor.putString(PreferenceKeys.STORAGE_PATH, mStoragePath);
         editor.commit();
         editor.commit();
         String storageDescription = DataStorageProvider.getInstance().getStorageDescriptionByPath(mStoragePath);
         String storageDescription = DataStorageProvider.getInstance().getStorageDescriptionByPath(mStoragePath);
         mPrefStoragePath.setSummary(storageDescription);
         mPrefStoragePath.setSummary(storageDescription);
@@ -753,7 +754,7 @@ public class Preferences extends PreferenceActivity
     private void loadStoragePath() {
     private void loadStoragePath() {
         SharedPreferences appPrefs =
         SharedPreferences appPrefs =
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
-        mStoragePath = appPrefs.getString(Keys.STORAGE_PATH, Environment.getExternalStorageDirectory()
+        mStoragePath = appPrefs.getString(PreferenceKeys.STORAGE_PATH, Environment.getExternalStorageDirectory()
                                                          .getAbsolutePath());
                                                          .getAbsolutePath());
         String storageDescription = DataStorageProvider.getInstance().getStorageDescriptionByPath(mStoragePath);
         String storageDescription = DataStorageProvider.getInstance().getStorageDescriptionByPath(mStoragePath);
         mPrefStoragePath.setSummary(storageDescription);
         mPrefStoragePath.setSummary(storageDescription);
@@ -766,7 +767,7 @@ public class Preferences extends PreferenceActivity
         SharedPreferences appPrefs =
         SharedPreferences appPrefs =
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
         SharedPreferences.Editor editor = appPrefs.edit();
         SharedPreferences.Editor editor = appPrefs.edit();
-        editor.putString(Keys.INSTANT_UPLOAD_PATH, mUploadPath);
+        editor.putString(PreferenceKeys.INSTANT_UPLOAD_PATH, mUploadPath);
         editor.commit();
         editor.commit();
     }
     }
 
 
@@ -787,14 +788,15 @@ public class Preferences extends PreferenceActivity
         SharedPreferences appPrefs =
         SharedPreferences appPrefs =
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
         SharedPreferences.Editor editor = appPrefs.edit();
         SharedPreferences.Editor editor = appPrefs.edit();
-        editor.putString(Keys.INSTANT_VIDEO_UPLOAD_PATH, mUploadVideoPath);
+        editor.putString(PreferenceKeys.INSTANT_VIDEO_UPLOAD_PATH, mUploadVideoPath);
         editor.commit();
         editor.commit();
     }
     }
 
 
     @Override
     @Override
     public void onStorageMigrationFinished(String storagePath, boolean succeed) {
     public void onStorageMigrationFinished(String storagePath, boolean succeed) {
-        if (succeed)
+        if (succeed) {
             saveStoragePath(storagePath);
             saveStoragePath(storagePath);
+        }
     }
     }
 
 
     @Override
     @Override

+ 30 - 19
src/com/owncloud/android/ui/activity/StorageMigration.java

@@ -68,9 +68,9 @@ public class StorageMigration {
     }
     }
 
 
     public void migrate() {
     public void migrate() {
-        if (storageFolderAlreadyExists())
+        if (storageFolderAlreadyExists()) {
             askToOverride();
             askToOverride();
-        else {
+        } else {
             ProgressDialog progressDialog = createMigrationProgressDialog();
             ProgressDialog progressDialog = createMigrationProgressDialog();
             progressDialog.show();
             progressDialog.show();
             new FileMigrationTask(
             new FileMigrationTask(
@@ -80,7 +80,7 @@ public class StorageMigration {
                     progressDialog,
                     progressDialog,
                     mListener).execute();
                     mListener).execute();
 
 
-            progressDialog.getButton(progressDialog.BUTTON_POSITIVE).setVisibility(View.GONE);
+            progressDialog.getButton(ProgressDialog.BUTTON_POSITIVE).setVisibility(View.GONE);
         }
         }
     }
     }
 
 
@@ -97,15 +97,17 @@ public class StorageMigration {
                 .setOnCancelListener(new DialogInterface.OnCancelListener() {
                 .setOnCancelListener(new DialogInterface.OnCancelListener() {
                     @Override
                     @Override
                     public void onCancel(DialogInterface dialogInterface) {
                     public void onCancel(DialogInterface dialogInterface) {
-                        if (mListener != null)
+                        if (mListener != null) {
                             mListener.onCancelMigration();
                             mListener.onCancelMigration();
+                        }
                     }
                     }
                 })
                 })
                 .setNegativeButton(R.string.common_cancel, new OnClickListener() {
                 .setNegativeButton(R.string.common_cancel, new OnClickListener() {
                     @Override
                     @Override
                     public void onClick(DialogInterface dialogInterface, int i) {
                     public void onClick(DialogInterface dialogInterface, int i) {
-                        if (mListener != null)
+                        if (mListener != null) {
                             mListener.onCancelMigration();
                             mListener.onCancelMigration();
+                        }
                     }
                     }
                 })
                 })
                 .setNeutralButton(R.string.file_migration_use_data_folder, new OnClickListener() {
                 .setNeutralButton(R.string.file_migration_use_data_folder, new OnClickListener() {
@@ -160,7 +162,7 @@ public class StorageMigration {
         return progressDialog;
         return progressDialog;
     }
     }
 
 
-    abstract static private class FileMigrationTaskBase extends AsyncTask<Void, Integer, Integer> {
+    private static abstract class FileMigrationTaskBase extends AsyncTask<Void, Integer, Integer> {
         protected String mStorageSource;
         protected String mStorageSource;
         protected String mStorageTarget;
         protected String mStorageTarget;
         protected Context mContext;
         protected Context mContext;
@@ -355,17 +357,21 @@ public class StorageMigration {
             File srcFile = new File(mStorageSource);
             File srcFile = new File(mStorageSource);
             File dstFile = new File(mStorageTarget);
             File dstFile = new File(mStorageTarget);
 
 
-            if (!dstFile.canRead() || !srcFile.canRead())
+            if (!dstFile.canRead() || !srcFile.canRead()) {
                 throw new MigrationException(R.string.file_migration_failed_not_readable);
                 throw new MigrationException(R.string.file_migration_failed_not_readable);
+            }
 
 
-            if (!dstFile.canWrite() || !srcFile.canWrite())
+            if (!dstFile.canWrite() || !srcFile.canWrite()) {
                 throw new MigrationException(R.string.file_migration_failed_not_writable);
                 throw new MigrationException(R.string.file_migration_failed_not_writable);
+            }
 
 
-            if (new File(dstFile, MainApp.getDataFolder()).exists())
+            if (new File(dstFile, MainApp.getDataFolder()).exists()) {
                 throw new MigrationException(R.string.file_migration_failed_dir_already_exists);
                 throw new MigrationException(R.string.file_migration_failed_dir_already_exists);
+            }
 
 
-            if (dstFile.getFreeSpace() < FileStorageUtils.getFolderSize(new File(srcFile, MainApp.getDataFolder())))
+            if (dstFile.getFreeSpace() < FileStorageUtils.getFolderSize(new File(srcFile, MainApp.getDataFolder()))) {
                 throw new MigrationException(R.string.file_migration_failed_not_enough_space);
                 throw new MigrationException(R.string.file_migration_failed_not_enough_space);
+            }
         }
         }
 
 
         void copyFiles() throws MigrationException {
         void copyFiles() throws MigrationException {
@@ -376,14 +382,16 @@ public class StorageMigration {
         }
         }
 
 
         void copyDirs(File src, File dst) throws MigrationException {
         void copyDirs(File src, File dst) throws MigrationException {
-            if (!dst.mkdirs())
+            if (!dst.mkdirs()) {
                 throw new MigrationException(R.string.file_migration_failed_while_coping);
                 throw new MigrationException(R.string.file_migration_failed_while_coping);
+            }
 
 
             for (File f : src.listFiles()) {
             for (File f : src.listFiles()) {
-                if (f.isDirectory())
+                if (f.isDirectory()) {
                     copyDirs(f, new File(dst, f.getName()));
                     copyDirs(f, new File(dst, f.getName()));
-                else if (!FileStorageUtils.copyFile(f, new File(dst, f.getName())))
+                } else if (!FileStorageUtils.copyFile(f, new File(dst, f.getName()))) {
                     throw new MigrationException(R.string.file_migration_failed_while_coping);
                     throw new MigrationException(R.string.file_migration_failed_while_coping);
+                }
             }
             }
 
 
         }
         }
@@ -401,24 +409,27 @@ public class StorageMigration {
 
 
         void cleanup() {
         void cleanup() {
             File srcFile = new File(mStorageSource + File.separator + MainApp.getDataFolder());
             File srcFile = new File(mStorageSource + File.separator + MainApp.getDataFolder());
-            if (!deleteRecursive(srcFile))
+            if (!deleteRecursive(srcFile)) {
                 Log_OC.w(TAG, "Migration cleanup step failed");
                 Log_OC.w(TAG, "Migration cleanup step failed");
+            }
             srcFile.delete();
             srcFile.delete();
         }
         }
 
 
         boolean deleteRecursive(File f) {
         boolean deleteRecursive(File f) {
             boolean res = true;
             boolean res = true;
-            if (f.isDirectory())
-                for (File c : f.listFiles())
+            if (f.isDirectory()) {
+                for (File c : f.listFiles()) {
                     res = deleteRecursive(c) && res;
                     res = deleteRecursive(c) && res;
+                }
+            }
             return f.delete() && res;
             return f.delete() && res;
         }
         }
 
 
         void rollback() {
         void rollback() {
             File dstFile = new File(mStorageTarget + File.separator + MainApp.getDataFolder());
             File dstFile = new File(mStorageTarget + File.separator + MainApp.getDataFolder());
-            if (dstFile.exists())
-                if (!dstFile.delete())
-                    Log_OC.w(TAG, "Rollback step failed");
+            if (dstFile.exists() && !dstFile.delete()) {
+                Log_OC.w(TAG, "Rollback step failed");
+            }
         }
         }
     }
     }
 }
 }

+ 22 - 16
src/com/owncloud/android/utils/FileStorageUtils.java

@@ -24,7 +24,6 @@ import android.accounts.Account;
 import android.content.Context;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences;
 import android.net.Uri;
 import android.net.Uri;
-import android.os.Environment;
 import android.preference.PreferenceManager;
 import android.preference.PreferenceManager;
 import android.webkit.MimeTypeMap;
 import android.webkit.MimeTypeMap;
 
 
@@ -430,9 +429,10 @@ public class FileStorageUtils {
 
 
         return files;
         return files;
     }
     }
-    
+
     /**
     /**
-     * Local Folder size
+     * Local Folder size.
+     *
      * @param dir File
      * @param dir File
      * @return Size in bytes
      * @return Size in bytes
      */
      */
@@ -440,10 +440,11 @@ public class FileStorageUtils {
         if (dir.exists()) {
         if (dir.exists()) {
             long result = 0;
             long result = 0;
             for (File f : dir.listFiles()) {
             for (File f : dir.listFiles()) {
-                if (f.isDirectory())
+                if (f.isDirectory()) {
                     result += getFolderSize(f);
                     result += getFolderSize(f);
-                else
+                } else {
                     result += f.length();
                     result += f.length();
+                }
             }
             }
             return result;
             return result;
         }
         }
@@ -451,9 +452,10 @@ public class FileStorageUtils {
     }
     }
 
 
     /**
     /**
-     * Mimetype String of a file
-     * @param path
-     * @return
+     * Mimetype String of a file.
+     *
+     * @param path the file path
+     * @return the mime type based on the file name
      */
      */
     public static String getMimeTypeFromName(String path) {
     public static String getMimeTypeFromName(String path) {
         String extension = "";
         String extension = "";
@@ -510,15 +512,19 @@ public class FileStorageUtils {
         } catch (IOException ex) {
         } catch (IOException ex) {
             ret = false;
             ret = false;
         } finally {
         } finally {
-            if (in != null) try {
-                in.close();
-            } catch (IOException e) {
-                Log_OC.e(TAG, "Error closing input stream during copy", e);
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                    Log_OC.e(TAG, "Error closing input stream during copy", e);
+                }
             }
             }
-            if (out != null) try {
-                out.close();
-            } catch (IOException e) {
-                Log_OC.e(TAG, "Error closing output stream during copy", e);
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException e) {
+                    Log_OC.e(TAG, "Error closing output stream during copy", e);
+                }
             }
             }
         }
         }