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
|
* Method for deferred load of account attributes from AccountManager
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @throws AccountNotFoundException
|
|
||||||
* @throws AuthenticatorException
|
* @throws AuthenticatorException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws OperationCanceledException
|
* @throws OperationCanceledException
|
||||||
*/
|
*/
|
||||||
public void loadCredentials(Context context) throws AuthenticatorException,
|
public void loadCredentials(Context context) throws AuthenticatorException, IOException, OperationCanceledException {
|
||||||
IOException, OperationCanceledException {
|
|
||||||
|
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'context' cannot be null");
|
throw new IllegalArgumentException("Parameter 'context' cannot be null");
|
||||||
|
@ -43,12 +43,10 @@ import java.io.IOException;
|
|||||||
public interface OwnCloudClientManager {
|
public interface OwnCloudClientManager {
|
||||||
|
|
||||||
OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws AccountNotFoundException,
|
OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws AccountNotFoundException,
|
||||||
OperationCanceledException, AuthenticatorException,
|
OperationCanceledException, AuthenticatorException, IOException;
|
||||||
IOException;
|
|
||||||
|
|
||||||
OwnCloudClient removeClientFor(OwnCloudAccount account);
|
OwnCloudClient removeClientFor(OwnCloudAccount account);
|
||||||
|
|
||||||
void saveAllClients(Context context, String accountType)
|
void saveAllClients(Context context, String accountType) throws AccountNotFoundException, AuthenticatorException, IOException,
|
||||||
throws AccountNotFoundException, AuthenticatorException,
|
OperationCanceledException;
|
||||||
IOException, OperationCanceledException;
|
|
||||||
}
|
}
|
@ -82,18 +82,13 @@ public class OwnCloudClientManagerFactory {
|
|||||||
if (sDefaultSingleton == null) {
|
if (sDefaultSingleton == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (policy == Policy.ALWAYS_NEW_CLIENT &&
|
if (policy == Policy.ALWAYS_NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager)) {
|
||||||
!(sDefaultSingleton instanceof SimpleFactoryManager)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (policy == Policy.SINGLE_SESSION_PER_ACCOUNT &&
|
return policy == Policy.SINGLE_SESSION_PER_ACCOUNT && !(sDefaultSingleton instanceof SingleSessionManager);
|
||||||
!(sDefaultSingleton instanceof SingleSessionManager)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum Policy {
|
public enum Policy {
|
||||||
ALWAYS_NEW_CLIENT,
|
ALWAYS_NEW_CLIENT,
|
||||||
SINGLE_SESSION_PER_ACCOUNT,
|
SINGLE_SESSION_PER_ACCOUNT,
|
||||||
SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING
|
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.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.authentication.OwnCloudSamlSsoCredentials;
|
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 com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -56,11 +57,9 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
|
|
||||||
private static final String TAG = SingleSessionManager.class.getSimpleName();
|
private static final String TAG = SingleSessionManager.class.getSimpleName();
|
||||||
|
|
||||||
private ConcurrentMap<String, OwnCloudClient> mClientsWithKnownUsername =
|
private ConcurrentMap<String, OwnCloudClient> mClientsWithKnownUsername = new ConcurrentHashMap<>();
|
||||||
new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
private ConcurrentMap<String, OwnCloudClient> mClientsWithUnknownUsername =
|
private ConcurrentMap<String, OwnCloudClient> mClientsWithUnknownUsername = new ConcurrentHashMap<>();
|
||||||
new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws OperationCanceledException,
|
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws OperationCanceledException,
|
||||||
@ -76,9 +75,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
OwnCloudClient client = null;
|
OwnCloudClient client = null;
|
||||||
String accountName = account.getName();
|
String accountName = account.getName();
|
||||||
String sessionName = account.getCredentials() == null ? "" :
|
String sessionName = account.getCredentials() == null ? "" :
|
||||||
AccountUtils.buildAccountName(
|
AccountUtils.buildAccountName(account.getBaseUri(), account.getCredentials().getAuthToken());
|
||||||
account.getBaseUri(),
|
|
||||||
account.getCredentials().getAuthToken());
|
|
||||||
|
|
||||||
if (accountName != null) {
|
if (accountName != null) {
|
||||||
client = mClientsWithKnownUsername.get(accountName);
|
client = mClientsWithKnownUsername.get(accountName);
|
||||||
@ -113,7 +110,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
context.getApplicationContext(),
|
context.getApplicationContext(),
|
||||||
true); // TODO remove dependency on OwnCloudClientFactory
|
true); // TODO remove dependency on OwnCloudClientFactory
|
||||||
client.setAccount(account);
|
client.setAccount(account);
|
||||||
client.setContext(context);
|
HttpClient.setContext(context);
|
||||||
client.setOwnCloudClientManager(this);
|
client.setOwnCloudClientManager(this);
|
||||||
|
|
||||||
account.loadCredentials(context);
|
account.loadCredentials(context);
|
||||||
@ -198,10 +195,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
while (accountNames.hasNext()) {
|
while (accountNames.hasNext()) {
|
||||||
accountName = accountNames.next();
|
accountName = accountNames.next();
|
||||||
account = new Account(accountName, accountType);
|
account = new Account(accountName, accountType);
|
||||||
AccountUtils.saveClient(
|
AccountUtils.saveClient(mClientsWithKnownUsername.get(accountName), account, context);
|
||||||
mClientsWithKnownUsername.get(accountName),
|
|
||||||
account,
|
|
||||||
context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||||
@ -218,7 +212,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
if (am != null && account.getSavedAccount() != null) {
|
if (am != null && account.getSavedAccount() != null) {
|
||||||
String recentCookies = am.getUserData(account.getSavedAccount(), AccountUtils.Constants.KEY_COOKIES);
|
String recentCookies = am.getUserData(account.getSavedAccount(), AccountUtils.Constants.KEY_COOKIES);
|
||||||
String previousCookies = reusedClient.getCookiesString();
|
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);
|
AccountUtils.restoreCookies(account.getSavedAccount(), reusedClient, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,6 @@ public class BearerCredentials {
|
|||||||
* @param token The bearer token
|
* @param token The bearer token
|
||||||
*/
|
*/
|
||||||
public BearerCredentials(String token) {
|
public BearerCredentials(String token) {
|
||||||
/*if (token == null) {
|
|
||||||
throw new IllegalArgumentException("Bearer token may not be null");
|
|
||||||
}*/
|
|
||||||
mAccessToken = (token == null) ? "" : token;
|
mAccessToken = (token == null) ? "" : token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ import java.security.KeyStore;
|
|||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.cert.CertPathValidatorException;
|
import java.security.cert.CertPathValidatorException;
|
||||||
import java.security.cert.CertStoreException;
|
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.CertificateExpiredException;
|
import java.security.cert.CertificateExpiredException;
|
||||||
import java.security.cert.CertificateNotYetValidException;
|
import java.security.cert.CertificateNotYetValidException;
|
||||||
@ -46,20 +45,17 @@ public class AdvancedX509TrustManager implements X509TrustManager {
|
|||||||
|
|
||||||
private static final String TAG = AdvancedX509TrustManager.class.getSimpleName();
|
private static final String TAG = AdvancedX509TrustManager.class.getSimpleName();
|
||||||
|
|
||||||
private X509TrustManager mStandardTrustManager = null;
|
private X509TrustManager mStandardTrustManager;
|
||||||
private KeyStore mKnownServersKeyStore;
|
private KeyStore mKnownServersKeyStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for AdvancedX509TrustManager
|
* Constructor for AdvancedX509TrustManager
|
||||||
*
|
*
|
||||||
* @param knownServersKeyStore Local certificates store with server certificates explicitly trusted by the user.
|
* @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)
|
public AdvancedX509TrustManager(KeyStore knownServersKeyStore) throws NoSuchAlgorithmException, KeyStoreException {
|
||||||
throws NoSuchAlgorithmException, KeyStoreException, CertStoreException {
|
|
||||||
super();
|
super();
|
||||||
TrustManagerFactory factory = TrustManagerFactory
|
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||||
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
|
||||||
factory.init((KeyStore) null);
|
factory.init((KeyStore) null);
|
||||||
mStandardTrustManager = findX509TrustManager(factory);
|
mStandardTrustManager = findX509TrustManager(factory);
|
||||||
|
|
||||||
@ -71,13 +67,12 @@ public class AdvancedX509TrustManager implements X509TrustManager {
|
|||||||
*
|
*
|
||||||
* @param factory TrustManagerFactory to inspect in the search for a X509TrustManager
|
* @param factory TrustManagerFactory to inspect in the search for a X509TrustManager
|
||||||
* @return The first X509TrustManager found in factory.
|
* @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();
|
TrustManager tms[] = factory.getTrustManagers();
|
||||||
for (int i = 0; i < tms.length; i++) {
|
for (TrustManager tm : tms) {
|
||||||
if (tms[i] instanceof X509TrustManager) {
|
if (tm instanceof X509TrustManager) {
|
||||||
return (X509TrustManager) tms[i];
|
return (X509TrustManager) tm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -116,7 +111,7 @@ public class AdvancedX509TrustManager implements X509TrustManager {
|
|||||||
previousCause = cause;
|
previousCause = cause;
|
||||||
cause = cause.getCause();
|
cause = cause.getCause();
|
||||||
}
|
}
|
||||||
if (cause != null && cause instanceof CertPathValidatorException) {
|
if (cause instanceof CertPathValidatorException) {
|
||||||
result.setCertPathValidatorException((CertPathValidatorException) cause);
|
result.setCertPathValidatorException((CertPathValidatorException) cause);
|
||||||
} else {
|
} else {
|
||||||
result.setOtherCertificateException(c);
|
result.setOtherCertificateException(c);
|
||||||
|
@ -28,10 +28,10 @@ import java.util.Collection;
|
|||||||
|
|
||||||
public interface ProgressiveDataTransferer {
|
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;
|
private int mDimension;
|
||||||
|
|
||||||
/**
|
public GetRemoteUserAvatarOperation(int dimension) {
|
||||||
* 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) {
|
|
||||||
mDimension = dimension;
|
mDimension = dimension;
|
||||||
mCurrentEtag = currentEtag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -78,9 +71,7 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation<GetRemoteUserA
|
|||||||
ByteArrayOutputStream bos = null;
|
ByteArrayOutputStream bos = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String url =
|
final String url = client.getBaseUri() + NON_OFFICIAL_AVATAR_PATH + client.getCredentials().getUsername() + "/" + mDimension;
|
||||||
client.getBaseUri() + NON_OFFICIAL_AVATAR_PATH +
|
|
||||||
client.getCredentials().getUsername() + "/" + mDimension;
|
|
||||||
Log_OC.d(TAG, "avatar URI: " + url);
|
Log_OC.d(TAG, "avatar URI: " + url);
|
||||||
|
|
||||||
getMethod = new GetMethod(new URL(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);
|
String contentType = getMethod.getResponseHeader(HttpConstants.CONTENT_TYPE_HEADER);
|
||||||
|
|
||||||
if (contentType == null || !contentType.startsWith("image")) {
|
if (contentType == null || !contentType.startsWith("image")) {
|
||||||
Log_OC.e(
|
Log_OC.e(TAG, "Not an image, failing with no avatar");
|
||||||
TAG, "Not an image, failing with no avatar"
|
|
||||||
);
|
|
||||||
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.FILE_NOT_FOUND);
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.FILE_NOT_FOUND);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -115,12 +104,10 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation<GetRemoteUserA
|
|||||||
bis = new BufferedInputStream(inputStream);
|
bis = new BufferedInputStream(inputStream);
|
||||||
bos = new ByteArrayOutputStream(totalToTransfer);
|
bos = new ByteArrayOutputStream(totalToTransfer);
|
||||||
|
|
||||||
long transferred = 0;
|
|
||||||
byte[] bytes = new byte[4096];
|
byte[] bytes = new byte[4096];
|
||||||
int readResult = 0;
|
int readResult;
|
||||||
while ((readResult = bis.read(bytes)) != -1) {
|
while ((readResult = bis.read(bytes)) != -1) {
|
||||||
bos.write(bytes, 0, readResult);
|
bos.write(bytes, 0, readResult);
|
||||||
transferred += readResult;
|
|
||||||
}
|
}
|
||||||
// TODO check total bytes transferred?
|
// TODO check total bytes transferred?
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user