diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index c97fea13d8..3c2af958d8 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -533 \ No newline at end of file +526 \ No newline at end of file diff --git a/src/main/java/com/owncloud/android/authentication/PassCodeManager.java b/src/main/java/com/owncloud/android/authentication/PassCodeManager.java index 559308028a..940edfbc8e 100644 --- a/src/main/java/com/owncloud/android/authentication/PassCodeManager.java +++ b/src/main/java/com/owncloud/android/authentication/PassCodeManager.java @@ -110,8 +110,7 @@ public final class PassCodeManager { } private void setUnlockTimestamp(Activity activity) { - Long timestamp = System.currentTimeMillis(); - PreferenceManager.setLockTimestamp(activity, timestamp); + PreferenceManager.setLockTimestamp(activity, System.currentTimeMillis()); } private boolean passCodeShouldBeRequested(Long timestamp) { @@ -120,7 +119,7 @@ public final class PassCodeManager { } private boolean passCodeIsEnabled() { - return PreferenceManager.getLockPreference(MainApp.getAppContext()).equals(Preferences.LOCK_PASSCODE); + return Preferences.LOCK_PASSCODE.equals(PreferenceManager.getLockPreference(MainApp.getAppContext())); } private boolean deviceCredentialsShouldBeRequested(Long timestamp, Activity activity) { @@ -129,7 +128,7 @@ public final class PassCodeManager { } private boolean deviceCredentialsAreEnabled(Activity activity) { - return PreferenceManager.getLockPreference(MainApp.getAppContext()).equals(Preferences.LOCK_DEVICE_CREDENTIALS) + return Preferences.LOCK_DEVICE_CREDENTIALS.equals(PreferenceManager.getLockPreference(MainApp.getAppContext())) || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && (PreferenceManager.isUseFingerprint(MainApp.getAppContext()) && DeviceCredentialUtils.areCredentialsAvailable(activity)); diff --git a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index 1c708c2c73..5d1fc28046 100644 --- a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -259,7 +259,7 @@ public class FileDataStorageManager { * @return the parent file */ public OCFile saveFileWithParent(OCFile file, Context context) { - if (file.getParentId() == 0 && !file.getRemotePath().equals("/")) { + if (file.getParentId() == 0 && !"/".equals(file.getRemotePath())) { String remotePath = file.getRemotePath(); String parentPath = remotePath.substring(0, remotePath.lastIndexOf(file.getFileName())); diff --git a/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 9f299d8230..f76b6208ed 100644 --- a/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -115,19 +115,29 @@ public final class ThumbnailsCacheManager { if (mThumbnailCache == null) { try { - // Check if media is mounted or storage is built-in, if so, - // try and use external cache dir; otherwise use internal cache dir - File cacheDir = MainApp.getAppContext().getExternalCacheDir(); + File cacheDir = MainApp.getAppContext().getCacheDir(); - if (cacheDir != null) { - String cachePath = cacheDir.getPath() + File.separator + CACHE_FOLDER; - Log_OC.d(TAG, "create dir: " + cachePath); - File diskCacheDir = new File(cachePath); - mThumbnailCache = new DiskLruImageCache(diskCacheDir, DISK_CACHE_SIZE, mCompressFormat, - mCompressQuality); - } else { + if (cacheDir == null) { throw new FileNotFoundException("Thumbnail cache could not be opened"); } + + String cachePath = cacheDir.getPath() + File.separator + CACHE_FOLDER; + Log_OC.d(TAG, "thumbnail cache dir: " + cachePath); + File diskCacheDir = new File(cachePath); + + // migrate from external cache to internal cache + File oldCacheDir = MainApp.getAppContext().getExternalCacheDir(); + + if (oldCacheDir != null && oldCacheDir.exists()) { + String cacheOldPath = oldCacheDir.getPath() + File.separator + CACHE_FOLDER; + File diskOldCacheDir = new File(cacheOldPath); + + FileStorageUtils.copyDirs(diskOldCacheDir, diskCacheDir); + FileStorageUtils.deleteRecursive(diskOldCacheDir); + } + + mThumbnailCache = new DiskLruImageCache(diskCacheDir, DISK_CACHE_SIZE, mCompressFormat, + mCompressQuality); } catch (Exception e) { Log_OC.d(TAG, e.getMessage()); mThumbnailCache = null; @@ -279,7 +289,7 @@ public final class ThumbnailsCacheManager { if (bitmap != null) { // Handle PNG - if (file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) { + if (PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) { bitmap = handlePNG(bitmap, pxW, pxH); } @@ -308,7 +318,7 @@ public final class ThumbnailsCacheManager { } // Handle PNG - if (thumbnail != null && file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) { + if (thumbnail != null && PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) { thumbnail = handlePNG(thumbnail, thumbnail.getWidth(), thumbnail.getHeight()); } @@ -526,7 +536,7 @@ public final class ThumbnailsCacheManager { if (bitmap != null) { // Handle PNG - if (ocFile.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) { + if (PNG_MIMETYPE.equalsIgnoreCase(ocFile.getMimeType())) { bitmap = handlePNG(bitmap, pxW, pxH); } @@ -578,7 +588,7 @@ public final class ThumbnailsCacheManager { } // Handle PNG - if (file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) { + if (PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) { thumbnail = handlePNG(thumbnail, pxW, pxH); } } catch (Exception e) { @@ -1163,7 +1173,7 @@ public final class ThumbnailsCacheManager { if (bitmap != null) { // Handle PNG - if (file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) { + if (PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) { bitmap = handlePNG(bitmap, pxW, pxH); } @@ -1204,7 +1214,7 @@ public final class ThumbnailsCacheManager { // Add thumbnail to cache if (thumbnail != null) { // Handle PNG - if (file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) { + if (PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) { thumbnail = handlePNG(thumbnail, pxW, pxH); } diff --git a/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java b/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java index c6204b2e88..baf6e6592f 100644 --- a/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java @@ -197,7 +197,7 @@ public class PassCodeActivity extends AppCompatActivity { private void onPassCodeEditTextFocusChange(final int passCodeIndex) { for (int i = 0; i < passCodeIndex; i++) { - if (mPassCodeEditTexts[i].getText().toString().equals("")) { + if ("".equals(mPassCodeEditTexts[i].getText().toString())) { mPassCodeEditTexts[i].requestFocus(); break; } diff --git a/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 78eab7df40..cccbbf3dcc 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -1,4 +1,4 @@ -/* + /* * Nextcloud Android client application * * @author Tobias Kaminsky diff --git a/src/main/java/com/owncloud/android/utils/FileStorageUtils.java b/src/main/java/com/owncloud/android/utils/FileStorageUtils.java index 9f39f9304e..7172f49078 100644 --- a/src/main/java/com/owncloud/android/utils/FileStorageUtils.java +++ b/src/main/java/com/owncloud/android/utils/FileStorageUtils.java @@ -345,6 +345,24 @@ public final class FileStorageUtils { } } + public static boolean copyDirs(File sourceFolder, File targetFolder) { + if (!targetFolder.mkdirs()) { + return false; + } + + for (File f : sourceFolder.listFiles()) { + if (f.isDirectory()) { + if (!copyDirs(f, new File(targetFolder, f.getName()))) { + return false; + } + } else if (!FileStorageUtils.copyFile(f, new File(targetFolder, f.getName()))) { + return false; + } + } + + return true; + } + public static void deleteRecursively(File file, FileDataStorageManager storageManager) { if (file.isDirectory()) { for (File child : file.listFiles()) { @@ -356,6 +374,16 @@ public final class FileStorageUtils { file.delete(); } + public static boolean deleteRecursive(File file) { + boolean res = true; + if (file.isDirectory()) { + for (File c : file.listFiles()) { + res = deleteRecursive(c) && res; + } + } + return file.delete() && res; + } + public static void checkIfFileFinishedSaving(OCFile file) { long lastModified = 0; long lastSize = 0;