Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

code cleanup #235

Merged
merged 2 commits into from
Nov 12, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,11 @@ public OwnCloudAccount(Uri baseUri, OwnCloudCredentials credentials) {
* Method for deferred load of account attributes from AccountManager
*
* @param context
* @throws AccountNotFoundException
* @throws AuthenticatorException
* @throws IOException
* @throws OperationCanceledException
*/
public void loadCredentials(Context context) throws AuthenticatorException,
IOException, OperationCanceledException {
public void loadCredentials(Context context) throws AuthenticatorException, IOException, OperationCanceledException {

if (context == null) {
throw new IllegalArgumentException("Parameter 'context' cannot be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@
public interface OwnCloudClientManager {

OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws AccountNotFoundException,
OperationCanceledException, AuthenticatorException,
IOException;
OperationCanceledException, AuthenticatorException, IOException;

OwnCloudClient removeClientFor(OwnCloudAccount account);

void saveAllClients(Context context, String accountType)
throws AccountNotFoundException, AuthenticatorException,
IOException, OperationCanceledException;
void saveAllClients(Context context, String accountType) throws AccountNotFoundException, AuthenticatorException, IOException,
OperationCanceledException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,13 @@ private static boolean defaultSingletonMustBeUpdated(Policy policy) {
if (sDefaultSingleton == null) {
return false;
}
if (policy == Policy.ALWAYS_NEW_CLIENT &&
!(sDefaultSingleton instanceof SimpleFactoryManager)) {
if (policy == Policy.ALWAYS_NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager)) {
return true;
}
if (policy == Policy.SINGLE_SESSION_PER_ACCOUNT &&
!(sDefaultSingleton instanceof SingleSessionManager)) {
return true;
}
return false;
return policy == Policy.SINGLE_SESSION_PER_ACCOUNT && !(sDefaultSingleton instanceof SingleSessionManager);
}

public static enum Policy {
public enum Policy {
ALWAYS_NEW_CLIENT,
SINGLE_SESSION_PER_ACCOUNT,
SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.authentication.OwnCloudSamlSsoCredentials;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.utils.Log_OC;

import java.io.IOException;
Expand All @@ -56,11 +57,9 @@ public class SingleSessionManager implements OwnCloudClientManager {

private static final String TAG = SingleSessionManager.class.getSimpleName();

private ConcurrentMap<String, OwnCloudClient> mClientsWithKnownUsername =
new ConcurrentHashMap<>();
private ConcurrentMap<String, OwnCloudClient> mClientsWithKnownUsername = new ConcurrentHashMap<>();

private ConcurrentMap<String, OwnCloudClient> mClientsWithUnknownUsername =
new ConcurrentHashMap<>();
private ConcurrentMap<String, OwnCloudClient> mClientsWithUnknownUsername = new ConcurrentHashMap<>();

@Override
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws OperationCanceledException,
Expand All @@ -76,9 +75,7 @@ public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) thr
OwnCloudClient client = null;
String accountName = account.getName();
String sessionName = account.getCredentials() == null ? "" :
AccountUtils.buildAccountName(
account.getBaseUri(),
account.getCredentials().getAuthToken());
AccountUtils.buildAccountName(account.getBaseUri(), account.getCredentials().getAuthToken());

if (accountName != null) {
client = mClientsWithKnownUsername.get(accountName);
Expand Down Expand Up @@ -113,7 +110,7 @@ public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) thr
context.getApplicationContext(),
true); // TODO remove dependency on OwnCloudClientFactory
client.setAccount(account);
client.setContext(context);
HttpClient.setContext(context);
client.setOwnCloudClientManager(this);

account.loadCredentials(context);
Expand Down Expand Up @@ -198,10 +195,7 @@ public void saveAllClients(Context context, String accountType) {
while (accountNames.hasNext()) {
accountName = accountNames.next();
account = new Account(accountName, accountType);
AccountUtils.saveClient(
mClientsWithKnownUsername.get(accountName),
account,
context);
AccountUtils.saveClient(mClientsWithKnownUsername.get(accountName), account, context);
}

if (Log.isLoggable(TAG, Log.DEBUG)) {
Expand All @@ -218,7 +212,7 @@ private void keepCookiesUpdated(Context context, OwnCloudAccount account, OwnClo
if (am != null && account.getSavedAccount() != null) {
String recentCookies = am.getUserData(account.getSavedAccount(), AccountUtils.Constants.KEY_COOKIES);
String previousCookies = reusedClient.getCookiesString();
if (recentCookies != null && previousCookies != "" && !recentCookies.equals(previousCookies)) {
if (recentCookies != null && !previousCookies.equals("") && !recentCookies.equals(previousCookies)) {
AccountUtils.restoreCookies(account.getSavedAccount(), reusedClient, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public class BearerCredentials {
* @param token The bearer token
*/
public BearerCredentials(String token) {
/*if (token == null) {
throw new IllegalArgumentException("Bearer token may not be null");
}*/
mAccessToken = (token == null) ? "" : token;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertPathValidatorException;
import java.security.cert.CertStoreException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
Expand All @@ -46,20 +45,17 @@ public class AdvancedX509TrustManager implements X509TrustManager {

private static final String TAG = AdvancedX509TrustManager.class.getSimpleName();

private X509TrustManager mStandardTrustManager = null;
private X509TrustManager mStandardTrustManager;
private KeyStore mKnownServersKeyStore;

/**
* Constructor for AdvancedX509TrustManager
*
* @param knownServersKeyStore Local certificates store with server certificates explicitly trusted by the user.
* @throws CertStoreException When no default X509TrustManager instance was found in the system.
*/
public AdvancedX509TrustManager(KeyStore knownServersKeyStore)
throws NoSuchAlgorithmException, KeyStoreException, CertStoreException {
public AdvancedX509TrustManager(KeyStore knownServersKeyStore) throws NoSuchAlgorithmException, KeyStoreException {
super();
TrustManagerFactory factory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
factory.init((KeyStore) null);
mStandardTrustManager = findX509TrustManager(factory);

Expand All @@ -71,13 +67,12 @@ public AdvancedX509TrustManager(KeyStore knownServersKeyStore)
*
* @param factory TrustManagerFactory to inspect in the search for a X509TrustManager
* @return The first X509TrustManager found in factory.
* @throws CertStoreException When no X509TrustManager instance was found in factory
*/
private X509TrustManager findX509TrustManager(TrustManagerFactory factory) throws CertStoreException {
private X509TrustManager findX509TrustManager(TrustManagerFactory factory) {
TrustManager tms[] = factory.getTrustManagers();
for (int i = 0; i < tms.length; i++) {
if (tms[i] instanceof X509TrustManager) {
return (X509TrustManager) tms[i];
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return (X509TrustManager) tm;
}
}
return null;
Expand Down Expand Up @@ -116,7 +111,7 @@ public void checkServerTrusted(X509Certificate[] certificates, String authType)
previousCause = cause;
cause = cause.getCause();
}
if (cause != null && cause instanceof CertPathValidatorException) {
if (cause instanceof CertPathValidatorException) {
result.setCertPathValidatorException((CertPathValidatorException) cause);
} else {
result.setOtherCertificateException(c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

public interface ProgressiveDataTransferer {

public void addDatatransferProgressListener(OnDatatransferProgressListener listener);
void addDatatransferProgressListener(OnDatatransferProgressListener listener);

public void addDatatransferProgressListeners(Collection<OnDatatransferProgressListener> listeners);
void addDatatransferProgressListeners(Collection<OnDatatransferProgressListener> listeners);

public void removeDatatransferProgressListener(OnDatatransferProgressListener listener);
void removeDatatransferProgressListener(OnDatatransferProgressListener listener);

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation<GetRemoteUserA
*/
private int mDimension;

/**
* Etag of current local copy of the avatar; if not null, remote avatar will be downloaded only
* if its Etag changed.
*/
private String mCurrentEtag;

@Deprecated
public GetRemoteUserAvatarOperation(int dimension, String currentEtag) {
this(dimension);
}

public GetRemoteUserAvatarOperation(int dimension) {
abelgardep marked this conversation as resolved.
Show resolved Hide resolved
mDimension = dimension;
mCurrentEtag = currentEtag;
}

@Override
Expand All @@ -78,9 +76,7 @@ protected RemoteOperationResult<ResultData> run(OwnCloudClient client) {
ByteArrayOutputStream bos = null;

try {
final String url =
client.getBaseUri() + NON_OFFICIAL_AVATAR_PATH +
client.getCredentials().getUsername() + "/" + mDimension;
final String url = client.getBaseUri() + NON_OFFICIAL_AVATAR_PATH + client.getCredentials().getUsername() + "/" + mDimension;
Log_OC.d(TAG, "avatar URI: " + url);

getMethod = new GetMethod(new URL(url));
Expand All @@ -101,9 +97,7 @@ protected RemoteOperationResult<ResultData> run(OwnCloudClient client) {
String contentType = getMethod.getResponseHeader(HttpConstants.CONTENT_TYPE_HEADER);

if (contentType == null || !contentType.startsWith("image")) {
Log_OC.e(
TAG, "Not an image, failing with no avatar"
);
Log_OC.e(TAG, "Not an image, failing with no avatar");
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.FILE_NOT_FOUND);
return result;
}
Expand All @@ -115,12 +109,10 @@ protected RemoteOperationResult<ResultData> run(OwnCloudClient client) {
bis = new BufferedInputStream(inputStream);
bos = new ByteArrayOutputStream(totalToTransfer);

long transferred = 0;
byte[] bytes = new byte[4096];
int readResult = 0;
int readResult;
while ((readResult = bis.read(bytes)) != -1) {
bos.write(bytes, 0, readResult);
transferred += readResult;
}
// TODO check total bytes transferred?

Expand Down