From ab6424701b66301165d1d602890deaa03352afc7 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 14 Oct 2019 14:40:33 +0200 Subject: [PATCH 1/6] codacy: Avoid unused method parameters such as 'appVersion'. Signed-off-by: Andy Scherzinger --- .../com/owncloud/android/ui/activity/SettingsActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index aa9e0b3851..3dcae8f757 100644 --- a/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/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)); From 638a5b9fc09c406de70cad6650cd228137703975 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 14 Oct 2019 14:43:48 +0200 Subject: [PATCH 2/6] codacy: Avoid unused imports such as 'androidx.fragment.app.Fragment' Signed-off-by: Andy Scherzinger --- .../com/owncloud/android/ui/preview/PreviewMediaFragment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java index b485b4f908..ca91c8869e 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/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). From e0802a0da483c0f1992fd1ebfae91ef9e742e56d Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 14 Oct 2019 14:45:50 +0200 Subject: [PATCH 3/6] codacy: Avoid using Literals in Conditional Statements Signed-off-by: Andy Scherzinger --- .../com/owncloud/android/providers/FileContentProvider.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/owncloud/android/providers/FileContentProvider.java b/src/main/java/com/owncloud/android/providers/FileContentProvider.java index 421073dd95..bcfe381e53 100644 --- a/src/main/java/com/owncloud/android/providers/FileContentProvider.java +++ b/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); From 2dabd04aa962d8b21897ec9a7f573a38c63de82f Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 14 Oct 2019 14:48:01 +0200 Subject: [PATCH 4/6] codacy: These nested if statements could be combined Signed-off-by: Andy Scherzinger --- .../com/owncloud/android/ui/asynctasks/PrintAsyncTask.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java b/src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java index 5b8ebbad1a..6fe587f1aa 100644 --- a/src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java +++ b/src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java @@ -81,10 +81,8 @@ public class PrintAsyncTask extends AsyncTask { 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(); From 2ab45a72ac234ce5c38a4f38952e3fa24590636f Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 14 Oct 2019 14:57:31 +0200 Subject: [PATCH 5/6] codacy: Deeply nested if..then statements are hard to read Signed-off-by: Andy Scherzinger --- .../owncloud/android/datamodel/MediaProvider.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/owncloud/android/datamodel/MediaProvider.java b/src/main/java/com/owncloud/android/datamodel/MediaProvider.java index 48da22cc3c..24eba0dd3e 100644 --- a/src/main/java/com/owncloud/android/datamodel/MediaProvider.java +++ b/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( From 31b62a86345eb67e369beeffe773f929ea2d5ca5 Mon Sep 17 00:00:00 2001 From: nextcloud-android-bot Date: Mon, 14 Oct 2019 13:08:30 +0000 Subject: [PATCH 6/6] Drone: update FindBugs results to reflect reduced error/warning count [skip ci] Signed-off-by: nextcloud-android-bot --- scripts/analysis/findbugs-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index b872400059..82a1667ba9 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -427 \ No newline at end of file +426 \ No newline at end of file