瀏覽代碼

Merge pull request #4681 from nextcloud/codacy

Codacy
Tobias Kaminsky 5 年之前
父節點
當前提交
2286981dbe

+ 1 - 1
scripts/analysis/findbugs-results.txt

@@ -1 +1 @@
-427
+426

+ 11 - 3
src/main/java/com/owncloud/android/datamodel/MediaProvider.java

@@ -119,7 +119,7 @@ public final class MediaProvider {
                                 MediaStore.MediaColumns.DATA));
 
                         // check if valid path and file exists
-                        if (filePath != null && filePath.lastIndexOf('/') > 0 && new File(filePath).exists()) {
+                        if (isValidAndExistingFilePath(filePath)) {
                             mediaFolder.filePaths.add(filePath);
                             mediaFolder.absolutePath = filePath.substring(0, filePath.lastIndexOf('/'));
                         }
@@ -127,7 +127,7 @@ public final class MediaProvider {
                     cursorImages.close();
 
                     // only do further work if folder is not within the Nextcloud app itself
-                    if (mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath)) {
+                    if (isFolderOutsideOfAppPath(dataPath, mediaFolder)) {
 
                         // count images
                         Cursor count = contentResolver.query(
@@ -152,6 +152,14 @@ public final class MediaProvider {
         return mediaFolders;
     }
 
+    private static boolean isFolderOutsideOfAppPath(String dataPath, MediaFolder mediaFolder) {
+        return mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath);
+    }
+
+    private static boolean isValidAndExistingFilePath(String filePath) {
+        return filePath != null && filePath.lastIndexOf('/') > 0 && new File(filePath).exists();
+    }
+
     private static void checkPermissions(@Nullable Activity activity) {
         if (activity != null &&
                 !PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
@@ -229,7 +237,7 @@ public final class MediaProvider {
                     cursorVideos.close();
 
                     // only do further work if folder is not within the Nextcloud app itself
-                    if (mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath)) {
+                    if (isFolderOutsideOfAppPath(dataPath, mediaFolder)) {
 
                         // count images
                         Cursor count = contentResolver.query(

+ 2 - 1
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -89,6 +89,7 @@ public class FileContentProvider extends ContentProvider {
     private static final String UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";
     private static final int SINGLE_PATH_SEGMENT = 1;
     public static final int ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION = 20;
+    public static final int MINIMUM_PATH_SEGMENTS_SIZE = 1;
 
     private DataBaseHelper mDbHelper;
     private Context mContext;
@@ -186,7 +187,7 @@ public class FileContentProvider extends ContentProvider {
             children.close();
         }
 
-        if (uri.getPathSegments().size() > 1) {
+        if (uri.getPathSegments().size() > MINIMUM_PATH_SEGMENTS_SIZE) {
             count += db.delete(ProviderTableMeta.FILE_TABLE_NAME,
                                ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1)
                                    + (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""), whereArgs);

+ 2 - 2
src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java

@@ -170,7 +170,7 @@ public class SettingsActivity extends PreferenceActivity
         setupDetailsCategory(accentColor, preferenceScreen);
 
         // More
-        setupMoreCategory(accentColor, appVersion);
+        setupMoreCategory(accentColor);
 
         // About
         setupAboutCategory(accentColor, appVersion);
@@ -308,7 +308,7 @@ public class SettingsActivity extends PreferenceActivity
         }
     }
 
-    private void setupMoreCategory(int accentColor, String appVersion) {
+    private void setupMoreCategory(int accentColor) {
         PreferenceCategory preferenceCategoryMore = (PreferenceCategory) findPreference("more");
         preferenceCategoryMore.setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_more),
                 accentColor));

+ 2 - 4
src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java

@@ -81,10 +81,8 @@ public class PrintAsyncTask extends AsyncTask<Void, Void, Boolean> {
         try {
             int status = client.executeMethod(getMethod);
             if (status == HttpStatus.SC_OK) {
-                if (file.exists()) {
-                    if (!file.delete()) {
-                        return false;
-                    }
+                if (file.exists() && !file.delete()) {
+                    return false;
                 }
 
                 file.getParentFile().mkdirs();

+ 0 - 1
src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -79,7 +79,6 @@ import javax.inject.Inject;
 import androidx.annotation.DrawableRes;
 import androidx.annotation.NonNull;
 import androidx.annotation.StringRes;
-import androidx.fragment.app.Fragment;
 
 /**
  * This fragment shows a preview of a downloaded media file (audio or video).