Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ android {

android.applicationVariants.all { variant ->
String variantName = variant.name
String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1);
String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
tasks.register("spotbugs${capVariantName}", SpotBugsTask) {
ignoreFailures = false
effort = "max"
Expand Down Expand Up @@ -273,7 +273,6 @@ dependencies {
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
implementation 'com.google.android:flexbox:1.1.0'

implementation 'org.parceler:parceler-api:1.1.12'
annotationProcessor 'org.parceler:parceler:1.1.12'
implementation('com.github.bumptech.glide:glide:3.7.0') {
Expand All @@ -282,6 +281,19 @@ dependencies {
implementation 'com.caverock:androidsvg:1.3'
implementation 'androidx.annotation:annotation:1.0.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.jetbrains:annotations:17.0.0'

spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.9.0'
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.3'

implementation 'com.google.dagger:dagger:2.22.1'
implementation 'com.google.dagger:dagger-android:2.22.1'
implementation 'com.google.dagger:dagger-android-support:2.22.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.22.1'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.22.1'

compileOnly "org.projectlombok:lombok:1.18.6"
annotationProcessor "org.projectlombok:lombok:1.18.6"

// dependencies for local unit tests
testImplementation 'junit:junit:4.12'
Expand All @@ -302,26 +314,13 @@ dependencies {
// Espresso core
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
androidTestImplementation 'org.mockito:mockito-core:2.27.0'
// UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
// fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
//androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
implementation 'org.jetbrains:annotations:17.0.0'

compileOnly "org.projectlombok:lombok:1.18.6"
annotationProcessor "org.projectlombok:lombok:1.18.6"

androidTestImplementation 'tools.fastlane:screengrab:1.2.0'

spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.9.0'
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.3'

implementation 'com.google.dagger:dagger:2.22.1'
implementation 'com.google.dagger:dagger-android:2.22.1'
implementation 'com.google.dagger:dagger-android-support:2.22.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.22.1'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.22.1'

// jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
// jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
// androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* ownCloud Android client application
*
* @author David A. Velasco
* 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.util;

import android.accounts.Account;
import android.content.res.Resources;

import com.owncloud.android.MainApp;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.utils.ErrorMessageAdapter;

import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import static junit.framework.TestCase.assertEquals;

@RunWith(AndroidJUnit4.class)
public class ErrorMessageAdapterIT {
private final static String PATH_TO_DELETE = "/path/to/a.file";
private final static String EXPECTED_ERROR_MESSAGE = "You are not permitted to delete this file";
private final static String ACCOUNT_TYPE = "nextcloud";

@Test
public void getErrorCauseMessageForForbiddenRemoval() {
Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
Account account = new Account("name", ACCOUNT_TYPE);

String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(
new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
new RemoveFileOperation(PATH_TO_DELETE, false, account, false, MainApp.getAppContext()),
resources
);

assertEquals(EXPECTED_ERROR_MESSAGE, errorMessage);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.owncloud.android.utils;
package com.owncloud.android.util;

import com.owncloud.android.datamodel.OCFile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,8 @@ private void hidePassword() {
public void onOkClick() {
// this check should be unnecessary
if (mServerInfo.mVersion == null ||
!mServerInfo.mVersion.isVersionValid() ||
mServerInfo.mBaseUrl == null ||
mServerInfo.mBaseUrl.length() == 0) {
!mServerInfo.mVersion.isVersionValid() ||
TextUtils.isEmpty(mServerInfo.mBaseUrl)) {
mServerStatusIcon = R.drawable.ic_alert;
mServerStatusText = getResources().getString(R.string.auth_wtf_reenter_URL);
showServerStatus();
Expand Down Expand Up @@ -1898,8 +1897,7 @@ private void doOnResumeAndBound() {
mOperationsServiceBinder.dispatchResultIfFinished((int) mWaitingForOpId, this);
}

if (!webViewLoginMethod && mHostUrlInput.getText() != null && mHostUrlInput.getText().length() > 0
&& !mServerIsChecked) {
if (!webViewLoginMethod && !TextUtils.isEmpty(mHostUrlInput.getText()) && !mServerIsChecked) {
checkOcServer();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package com.owncloud.android.authentication;

import android.content.Context;
import android.text.TextUtils;

import com.owncloud.android.lib.resources.status.OwnCloudVersion;

Expand Down Expand Up @@ -64,7 +65,7 @@ public static String normalizeUrlSuffix(String url) {
public static String normalizeUrl(String url, boolean sslWhenUnprefixed) {
String normalizedUrl = url;

if (normalizedUrl != null && normalizedUrl.length() > 0) {
if (!TextUtils.isEmpty(normalizedUrl)) {
normalizedUrl = normalizedUrl.trim();

if (!normalizedUrl.toLowerCase(Locale.ROOT).startsWith(HTTP_PROTOCOL) &&
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.core.content.FileProvider;
import com.owncloud.android.R;
Expand Down Expand Up @@ -115,7 +117,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
public OCFile(String path) {
resetData();
needsUpdatingWhileSaving = false;
if (path == null || path.length() <= 0 || !path.startsWith(PATH_SEPARATOR)) {
if (TextUtils.isEmpty(path) || !path.startsWith(PATH_SEPARATOR)) {
throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path);
}
remotePath = path;
Expand Down Expand Up @@ -262,7 +264,7 @@ public boolean isDown() {
* @return true if it is
*/
public boolean existsOnDevice() {
if (localPath != null && localPath.length() > 0) {
if (!TextUtils.isEmpty(localPath)) {
return new File(localPath).exists();
}
return false;
Expand All @@ -283,7 +285,7 @@ public String getStoragePath() {
* @return A URI to the local copy of the file, or NULL if not stored in the device
*/
public Uri getStorageUri() {
if (localPath == null || localPath.length() == 0) {
if (TextUtils.isEmpty(localPath)) {
return null;
}
if (localUri == null) {
Expand All @@ -297,7 +299,7 @@ public Uri getStorageUri() {


public Uri getLegacyExposedFileUri() {
if (localPath == null || localPath.length() == 0) {
if (TextUtils.isEmpty(localPath)) {
return null;
}

Expand All @@ -312,7 +314,7 @@ public Uri getLegacyExposedFileUri() {
Partly disabled because not all apps understand paths that we get via this method for now
*/
public Uri getExposedFileUri(Context context) {
if (localPath == null || localPath.length() == 0) {
if (TextUtils.isEmpty(localPath)) {
return null;
}
if (exposedFileUri == null) {
Expand Down Expand Up @@ -360,8 +362,7 @@ public String getFileName() {
*/
public void setFileName(String name) {
Log_OC.d(TAG, "OCFile name changing from " + remotePath);
if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) &&
!ROOT_PATH.equals(remotePath)) {
if (!TextUtils.isEmpty(name) && !name.contains(PATH_SEPARATOR) && !ROOT_PATH.equals(remotePath)) {
String parent = new File(this.getRemotePath()).getParent();
parent = parent.endsWith(PATH_SEPARATOR) ? parent : parent + PATH_SEPARATOR;
remotePath = parent + name;
Expand Down Expand Up @@ -468,7 +469,7 @@ public void setEtagOnServer(String etag) {
}

public long getLocalModificationTimestamp() {
if (localPath != null && localPath.length() > 0) {
if (!TextUtils.isEmpty(localPath)) {
File f = new File(localPath);
return f.lastModified();
}
Expand All @@ -479,7 +480,7 @@ public long getLocalModificationTimestamp() {
* @return 'True' if the file is hidden
*/
public boolean isHidden() {
return getFileName().length() > 0 && getFileName().charAt(0) == '.';
return !TextUtils.isEmpty(getFileName()) && getFileName().charAt(0) == '.';
}

/**
Expand All @@ -492,7 +493,7 @@ public String getLocalId() {
}

public boolean isInConflict() {
return etagInConflict != null && !"".equals(etagInConflict);
return !TextUtils.isEmpty(etagInConflict);
}

public boolean isSharedWithMe() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
Expand Down Expand Up @@ -89,8 +90,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
// try to access the root folder, following redirections but not SAML SSO redirections
result = operation.execute(client);
String redirectedLocation = result.getRedirectedLocation();
while (redirectedLocation != null && redirectedLocation.length() > 0 &&
!result.isIdPRedirection()) {
while (!TextUtils.isEmpty(redirectedLocation) && !result.isIdPRedirection()) {
client.setBaseUri(Uri.parse(result.getRedirectedLocation()));
result = operation.execute(client);
redirectedLocation = result.getRedirectedLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import android.accounts.Account;
import android.content.Context;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;

import com.owncloud.android.datamodel.DecryptedFolderMetadata;
Expand Down Expand Up @@ -110,7 +111,7 @@ public String getRemotePath() {

public String getMimeType() {
String mimeType = file.getMimeType();
if (mimeType == null || mimeType.length() <= 0) {
if (TextUtils.isEmpty(mimeType)) {
try {
mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package com.owncloud.android.operations;

import android.text.TextUtils;

import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
Expand Down Expand Up @@ -157,7 +159,7 @@ private void saveLocalFile() {
*/
private boolean isValidNewName() throws IOException {
// check tricky names
if (newName == null || newName.length() <= 0 || newName.contains(File.separator)) {
if (TextUtils.isEmpty(newName) || newName.contains(File.separator)) {
return false;
}
// create a test file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.accounts.Account;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader;
Expand Down Expand Up @@ -204,7 +205,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
if (mServerFile != null) {
/// check changes in server and local file
boolean serverChanged;
if (mLocalFile.getEtag() == null || mLocalFile.getEtag().length() == 0) {
if (TextUtils.isEmpty(mLocalFile.getEtag())) {
// file uploaded (null) or downloaded ("") before upgrade to version 1.8.0; check the old condition
serverChanged = mServerFile.getModificationTimestamp() !=
mLocalFile.getModificationTimestampAtLastSyncForData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.accounts.Account;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.owncloud.android.datamodel.FileDataStorageManager;
Expand Down Expand Up @@ -482,7 +483,7 @@ public void cancel() {

public String getFolderPath() {
String path = mLocalFolder.getStoragePath();
if (path != null && path.length() > 0) {
if (!TextUtils.isEmpty(path)) {
return path;
}
return FileStorageUtils.getDefaultSavePathFor(mAccount.name, mLocalFolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;

import com.evernote.android.job.JobRequest;
Expand Down Expand Up @@ -153,7 +154,7 @@ public class UploadFileOperation extends SyncOperation {
public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType) {

// MIME type
if (mimeType == null || mimeType.length() <= 0) {
if (TextUtils.isEmpty(mimeType)) {
mimeType = MimeTypeUtil.getBestMimeTypeByFilename(localPath);
}

Expand All @@ -163,7 +164,7 @@ public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath
newFile.setLastSyncDateForData(0);

// size
if (localPath != null && localPath.length() > 0) {
if (!TextUtils.isEmpty(localPath)) {
File localFile = new File(localPath);
newFile.setFileLength(localFile.length());
newFile.setLastSyncDateForData(localFile.lastModified());
Expand Down Expand Up @@ -192,7 +193,7 @@ public UploadFileOperation(UploadsStorageManager uploadsStorageManager,
if (upload == null) {
throw new IllegalArgumentException("Illegal NULL file in UploadFileOperation creation");
}
if (upload.getLocalPath() == null || upload.getLocalPath().length() <= 0) {
if (TextUtils.isEmpty(upload.getLocalPath())) {
throw new IllegalArgumentException(
"Illegal file in UploadFileOperation; storage path invalid: "
+ upload.getLocalPath());
Expand Down
Loading