mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
code cleanup
This commit is contained in:
parent
e2f1637c80
commit
fdde542f15
@ -107,13 +107,11 @@ public class OwnCloudAccount {
|
||||
* 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");
|
||||
|
@ -43,12 +43,10 @@ import java.io.IOException;
|
||||
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;
|
||||
}
|
@ -82,18 +82,13 @@ public class OwnCloudClientManagerFactory {
|
||||
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
|
||||
|
@ -34,6 +34,7 @@ import android.util.Log;
|
||||
|
||||
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;
|
||||
@ -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,
|
||||
@ -76,9 +75,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
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);
|
||||
@ -113,7 +110,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
context.getApplicationContext(),
|
||||
true); // TODO remove dependency on OwnCloudClientFactory
|
||||
client.setAccount(account);
|
||||
client.setContext(context);
|
||||
HttpClient.setContext(context);
|
||||
client.setOwnCloudClientManager(this);
|
||||
|
||||
account.loadCredentials(context);
|
||||
@ -198,10 +195,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
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)) {
|
||||
@ -218,7 +212,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,6 @@ import java.security.KeyStore;
|
||||
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;
|
||||
@ -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);
|
||||
|
||||
@ -71,13 +67,12 @@ public class AdvancedX509TrustManager implements X509TrustManager {
|
||||
*
|
||||
* @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;
|
||||
@ -116,7 +111,7 @@ public class AdvancedX509TrustManager implements X509TrustManager {
|
||||
previousCause = cause;
|
||||
cause = cause.getCause();
|
||||
}
|
||||
if (cause != null && cause instanceof CertPathValidatorException) {
|
||||
if (cause instanceof CertPathValidatorException) {
|
||||
result.setCertPathValidatorException((CertPathValidatorException) cause);
|
||||
} else {
|
||||
result.setOtherCertificateException(c);
|
||||
|
@ -28,10 +28,10 @@ import java.util.Collection;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -58,15 +58,8 @@ 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;
|
||||
|
||||
public GetRemoteUserAvatarOperation(int dimension, String currentEtag) {
|
||||
public GetRemoteUserAvatarOperation(int dimension) {
|
||||
mDimension = dimension;
|
||||
mCurrentEtag = currentEtag;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,9 +71,7 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation<GetRemoteUserA
|
||||
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));
|
||||
@ -101,9 +92,7 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation<GetRemoteUserA
|
||||
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;
|
||||
}
|
||||
@ -115,12 +104,10 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation<GetRemoteUserA
|
||||
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?
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user