mirror of
https://github.com/owncloud/android-library.git
synced 2026-08-17 11:22:54 +00:00
Add Log_OC class and update the log references
This commit is contained in:
@@ -44,11 +44,11 @@ import org.apache.http.HttpStatus;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
public class OwnCloudClient extends HttpClient {
|
||||
|
||||
@@ -79,7 +79,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
mBaseUri = baseUri;
|
||||
|
||||
mInstanceNumber = sIntanceCounter++;
|
||||
Log.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
|
||||
|
||||
getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
|
||||
getParams().setParameter(
|
||||
@@ -125,7 +125,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
HeadMethod head = new HeadMethod(getWebdavUri() + WebdavUtils.encodePath(path));
|
||||
try {
|
||||
int status = executeMethod(head);
|
||||
Log.d(TAG, "HEAD to " + path + " finished with HTTP status " + status +
|
||||
Log_OC.d(TAG, "HEAD to " + path + " finished with HTTP status " + status +
|
||||
((status != HttpStatus.SC_OK)?"(FAIL)":""));
|
||||
exhaustResponse(head.getResponseBodyAsStream());
|
||||
return (status == HttpStatus.SC_OK);
|
||||
@@ -185,7 +185,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
customRedirectionNeeded = mFollowRedirects;
|
||||
}
|
||||
|
||||
Log.d(TAG + " #" + mInstanceNumber, "REQUEST " +
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
|
||||
method.getName() + " " + method.getPath());
|
||||
|
||||
// logCookiesAtRequest(method.getRequestHeaders(), "before");
|
||||
@@ -204,7 +204,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
return status;
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG + " #" + mInstanceNumber, "Exception occured", e);
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber, "Exception occured", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -222,14 +222,14 @@ public class OwnCloudClient extends HttpClient {
|
||||
location = method.getResponseHeader("location");
|
||||
}
|
||||
if (location != null) {
|
||||
Log.d(TAG + " #" + mInstanceNumber,
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber,
|
||||
"Location to redirect: " + location.getValue());
|
||||
method.setURI(new URI(location.getValue(), true));
|
||||
status = super.executeMethod(method);
|
||||
redirectionsCount++;
|
||||
|
||||
} else {
|
||||
Log.d(TAG + " #" + mInstanceNumber, "No location to redirect!");
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber, "No location to redirect!");
|
||||
status = HttpStatus.SC_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
responseBodyAsStream.close();
|
||||
|
||||
} catch (IOException io) {
|
||||
Log.e(TAG, "Unexpected exception while exhausting not interesting HTTP response;" +
|
||||
Log_OC.e(TAG, "Unexpected exception while exhausting not interesting HTTP response;" +
|
||||
" will be IGNORED", io);
|
||||
}
|
||||
}
|
||||
@@ -306,24 +306,24 @@ public class OwnCloudClient extends HttpClient {
|
||||
int counter = 0;
|
||||
for (int i=0; i<headers.length; i++) {
|
||||
if (headers[i].getName().toLowerCase().equals("cookie")) {
|
||||
Log.d(TAG + " #" + mInstanceNumber,
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber,
|
||||
"Cookies at request (" + when + ") (" + counter++ + "): " +
|
||||
headers[i].getValue());
|
||||
}
|
||||
}
|
||||
if (counter == 0) {
|
||||
Log.d(TAG + " #" + mInstanceNumber, "No cookie at request before");
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at request before");
|
||||
}
|
||||
}
|
||||
|
||||
private void logCookiesAtState(String string) {
|
||||
Cookie[] cookies = getState().getCookies();
|
||||
if (cookies.length == 0) {
|
||||
Log.d(TAG + " #" + mInstanceNumber, "No cookie at STATE before");
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at STATE before");
|
||||
} else {
|
||||
Log.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (before)");
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (before)");
|
||||
for (int i=0; i<cookies.length; i++) {
|
||||
Log.d(TAG + " #" + mInstanceNumber, " (" + i + "):" +
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber, " (" + i + "):" +
|
||||
"\n name: " + cookies[i].getName() +
|
||||
"\n value: " + cookies[i].getValue() +
|
||||
"\n domain: " + cookies[i].getDomain() +
|
||||
@@ -337,12 +337,12 @@ public class OwnCloudClient extends HttpClient {
|
||||
int counter = 0;
|
||||
for (int i=0; i<headers.length; i++) {
|
||||
if (headers[i].getName().toLowerCase().equals("set-cookie")) {
|
||||
Log.d(TAG + " #" + mInstanceNumber,
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber,
|
||||
"Set-Cookie (" + counter++ + "): " + headers[i].getValue());
|
||||
}
|
||||
}
|
||||
if (counter == 0) {
|
||||
Log.d(TAG + " #" + mInstanceNumber, "No set-cookie");
|
||||
Log_OC.d(TAG + " #" + mInstanceNumber, "No set-cookie");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -369,15 +369,15 @@ public class OwnCloudClient extends HttpClient {
|
||||
}
|
||||
|
||||
private void logCookie(Cookie cookie) {
|
||||
Log.d(TAG, "Cookie name: "+ cookie.getName() );
|
||||
Log.d(TAG, " value: "+ cookie.getValue() );
|
||||
Log.d(TAG, " domain: "+ cookie.getDomain());
|
||||
Log.d(TAG, " path: "+ cookie.getPath() );
|
||||
Log.d(TAG, " version: "+ cookie.getVersion() );
|
||||
Log.d(TAG, " expiryDate: " +
|
||||
Log_OC.d(TAG, "Cookie name: "+ cookie.getName() );
|
||||
Log_OC.d(TAG, " value: "+ cookie.getValue() );
|
||||
Log_OC.d(TAG, " domain: "+ cookie.getDomain());
|
||||
Log_OC.d(TAG, " path: "+ cookie.getPath() );
|
||||
Log_OC.d(TAG, " version: "+ cookie.getVersion() );
|
||||
Log_OC.d(TAG, " expiryDate: " +
|
||||
(cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--"));
|
||||
Log.d(TAG, " comment: "+ cookie.getComment() );
|
||||
Log.d(TAG, " secure: "+ cookie.getSecure() );
|
||||
Log_OC.d(TAG, " comment: "+ cookie.getComment() );
|
||||
Log_OC.d(TAG, " secure: "+ cookie.getSecure() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,11 +27,6 @@ package com.owncloud.android.lib.common;
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||
import com.owncloud.android.lib.common.network.NetworkUtils;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerFuture;
|
||||
@@ -41,7 +36,12 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||
import com.owncloud.android.lib.common.network.NetworkUtils;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
public class OwnCloudClientFactory {
|
||||
|
||||
@@ -192,10 +192,10 @@ public class OwnCloudClientFactory {
|
||||
try {
|
||||
NetworkUtils.registerAdvancedSslContext(true, context);
|
||||
} catch (GeneralSecurityException e) {
|
||||
Log.e(TAG, "Advanced SSL Context could not be loaded. Default SSL management in the system will be used for HTTPS connections", e);
|
||||
Log_OC.e(TAG, "Advanced SSL Context could not be loaded. Default SSL management in the system will be used for HTTPS connections", e);
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "The local server truststore could not be read. Default SSL management in the system will be used for HTTPS connections", e);
|
||||
Log_OC.e(TAG, "The local server truststore could not be read. Default SSL management in the system will be used for HTTPS connections", e);
|
||||
}
|
||||
|
||||
OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager());
|
||||
|
||||
@@ -25,10 +25,10 @@
|
||||
package com.owncloud.android.lib.common;
|
||||
|
||||
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||
|
||||
@@ -36,13 +36,13 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||
|
||||
@Override
|
||||
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
|
||||
Log.d(TAG, "getClientFor(OwnCloudAccount ... : ");
|
||||
Log_OC.d(TAG, "getClientFor(OwnCloudAccount ... : ");
|
||||
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
|
||||
account.getBaseUri(),
|
||||
context.getApplicationContext(),
|
||||
true);
|
||||
|
||||
Log.d(TAG, " new client {" +
|
||||
Log_OC.d(TAG, " new client {" +
|
||||
(account.getName() != null ?
|
||||
account.getName() :
|
||||
AccountUtils.buildAccountName(
|
||||
|
||||
@@ -36,12 +36,10 @@ import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
/**
|
||||
* Implementation of {@link OwnCloudClientManager}
|
||||
@@ -65,7 +63,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
|
||||
@Override
|
||||
public synchronized OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
|
||||
Log.d(TAG, "getClientFor(OwnCloudAccount ... : ");
|
||||
Log_OC.d(TAG, "getClientFor(OwnCloudAccount ... : ");
|
||||
if (account == null) {
|
||||
throw new IllegalArgumentException("Cannot get an OwnCloudClient for a null account");
|
||||
}
|
||||
@@ -84,17 +82,17 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
if (accountName != null) {
|
||||
client = mClientsWithUnknownUsername.remove(sessionName);
|
||||
if (client != null) {
|
||||
Log.d(TAG, " reusing client {" + sessionName + ", " +
|
||||
Log_OC.d(TAG, " reusing client {" + sessionName + ", " +
|
||||
client.hashCode() + "}");
|
||||
mClientsWithKnownUsername.put(accountName, client);
|
||||
Log.d(TAG, " moved client to {" + accountName + ", " +
|
||||
Log_OC.d(TAG, " moved client to {" + accountName + ", " +
|
||||
client.hashCode() + "}");
|
||||
}
|
||||
} else {
|
||||
client = mClientsWithUnknownUsername.get(sessionName);
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, " reusing client {" + accountName + ", " + client.hashCode() + "}");
|
||||
Log_OC.d(TAG, " reusing client {" + accountName + ", " + client.hashCode() + "}");
|
||||
reusingKnown = true;
|
||||
}
|
||||
|
||||
@@ -114,15 +112,15 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
client.setCredentials(account.getCredentials());
|
||||
if (accountName != null) {
|
||||
mClientsWithKnownUsername.put(accountName, client);
|
||||
Log.d(TAG, " new client {" + accountName + ", " + client.hashCode() + "}");
|
||||
Log_OC.d(TAG, " new client {" + accountName + ", " + client.hashCode() + "}");
|
||||
|
||||
} else {
|
||||
mClientsWithUnknownUsername.put(sessionName, client);
|
||||
Log.d(TAG, " new client {" + sessionName + ", " + client.hashCode() + "}");
|
||||
Log_OC.d(TAG, " new client {" + sessionName + ", " + client.hashCode() + "}");
|
||||
}
|
||||
} else {
|
||||
if (!reusingKnown) {
|
||||
Log.d(TAG, " reusing client {" + sessionName + ", " + client.hashCode() + "}");
|
||||
Log_OC.d(TAG, " reusing client {" + sessionName + ", " + client.hashCode() + "}");
|
||||
}
|
||||
keepCredentialsUpdated(account, client);
|
||||
keepUriUpdated(account, client);
|
||||
@@ -144,10 +142,10 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
if (accountName != null) {
|
||||
client = mClientsWithKnownUsername.remove(accountName);
|
||||
if (client != null) {
|
||||
Log.d(TAG, "Removed client {" + accountName + ", " + client.hashCode() + "}");
|
||||
Log_OC.d(TAG, "Removed client {" + accountName + ", " + client.hashCode() + "}");
|
||||
return client;
|
||||
} else {
|
||||
Log.d(TAG, "No client tracked for {" + accountName + "}");
|
||||
Log_OC.d(TAG, "No client tracked for {" + accountName + "}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,12 +154,12 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
account.getCredentials().getAuthToken());
|
||||
client = mClientsWithUnknownUsername.remove(sessionName);
|
||||
if (client != null) {
|
||||
Log.d(TAG, "Removed client {" + sessionName + ", " + client.hashCode() + "}");
|
||||
Log_OC.d(TAG, "Removed client {" + sessionName + ", " + client.hashCode() + "}");
|
||||
return client;
|
||||
}
|
||||
Log.d(TAG, "No client tracked for {" + sessionName + "}");
|
||||
Log_OC.d(TAG, "No client tracked for {" + sessionName + "}");
|
||||
|
||||
Log.d(TAG, "No client removed");
|
||||
Log_OC.d(TAG, "No client removed");
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
||||
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
public class AccountUtils {
|
||||
@@ -220,7 +220,7 @@ public class AccountUtils {
|
||||
String cookiesString = client.getCookiesString();
|
||||
if (cookiesString != "") {
|
||||
ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString);
|
||||
// Log.d(TAG, "Saving Cookies: "+ cookiesString );
|
||||
// Log_OC.d(TAG, "Saving Cookies: "+ cookiesString );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public class AccountUtils {
|
||||
*/
|
||||
public static void restoreCookies(Account account, OwnCloudClient client, Context context) {
|
||||
|
||||
Log.d(TAG, "Restoring cookies for " + account.name);
|
||||
Log_OC.d(TAG, "Restoring cookies for " + account.name);
|
||||
|
||||
// Account Manager
|
||||
AccountManager am = AccountManager.get(context.getApplicationContext());
|
||||
@@ -267,7 +267,7 @@ public class AccountUtils {
|
||||
* @param context
|
||||
*/
|
||||
public static void restoreCookies(String accountName, OwnCloudClient client, Context context) {
|
||||
Log.d(TAG, "Restoring cookies for " + accountName);
|
||||
Log_OC.d(TAG, "Restoring cookies for " + accountName);
|
||||
|
||||
// Account Manager
|
||||
AccountManager am = AccountManager.get(context.getApplicationContext());
|
||||
|
||||
@@ -30,15 +30,12 @@ import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
//import java.security.Provider;
|
||||
import java.security.cert.X509Certificate;
|
||||
//import java.util.Enumeration;
|
||||
|
||||
import javax.net.SocketFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.net.ssl.SSLHandshakeException;
|
||||
//import javax.net.ssl.SSLParameters;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
@@ -48,8 +45,7 @@ import org.apache.commons.httpclient.params.HttpConnectionParams;
|
||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
||||
|
||||
//import android.os.Build;
|
||||
import android.util.Log;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
|
||||
|
||||
@@ -97,39 +93,39 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
|
||||
/*
|
||||
private void logSslInfo() {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
|
||||
Log.v(TAG, "SUPPORTED SSL PARAMETERS");
|
||||
Log_OCv(TAG, "SUPPORTED SSL PARAMETERS");
|
||||
logSslParameters(mSslContext.getSupportedSSLParameters());
|
||||
Log.v(TAG, "DEFAULT SSL PARAMETERS");
|
||||
Log_OCv(TAG, "DEFAULT SSL PARAMETERS");
|
||||
logSslParameters(mSslContext.getDefaultSSLParameters());
|
||||
Log.i(TAG, "CURRENT PARAMETERS");
|
||||
Log.i(TAG, "Protocol: " + mSslContext.getProtocol());
|
||||
Log_OCi(TAG, "CURRENT PARAMETERS");
|
||||
Log_OCi(TAG, "Protocol: " + mSslContext.getProtocol());
|
||||
}
|
||||
Log.i(TAG, "PROVIDER");
|
||||
Log_OCi(TAG, "PROVIDER");
|
||||
logSecurityProvider(mSslContext.getProvider());
|
||||
}
|
||||
|
||||
private void logSecurityProvider(Provider provider) {
|
||||
Log.i(TAG, "name: " + provider.getName());
|
||||
Log.i(TAG, "version: " + provider.getVersion());
|
||||
Log.i(TAG, "info: " + provider.getInfo());
|
||||
Log_OCi(TAG, "name: " + provider.getName());
|
||||
Log_OCi(TAG, "version: " + provider.getVersion());
|
||||
Log_OCi(TAG, "info: " + provider.getInfo());
|
||||
Enumeration<?> keys = provider.propertyNames();
|
||||
String key;
|
||||
while (keys.hasMoreElements()) {
|
||||
key = (String) keys.nextElement();
|
||||
Log.i(TAG, " property " + key + " : " + provider.getProperty(key));
|
||||
Log_OCi(TAG, " property " + key + " : " + provider.getProperty(key));
|
||||
}
|
||||
}
|
||||
|
||||
private void logSslParameters(SSLParameters params) {
|
||||
Log.v(TAG, "Cipher suites: ");
|
||||
Log_OCv(TAG, "Cipher suites: ");
|
||||
String [] elements = params.getCipherSuites();
|
||||
for (int i=0; i<elements.length ; i++) {
|
||||
Log.v(TAG, " " + elements[i]);
|
||||
Log_OCv(TAG, " " + elements[i]);
|
||||
}
|
||||
Log.v(TAG, "Protocols: ");
|
||||
Log_OCv(TAG, "Protocols: ");
|
||||
elements = params.getProtocols();
|
||||
for (int i=0; i<elements.length ; i++) {
|
||||
Log.v(TAG, " " + elements[i]);
|
||||
Log_OCv(TAG, " " + elements[i]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -154,7 +150,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
|
||||
final InetAddress localAddress, final int localPort,
|
||||
final HttpConnectionParams params) throws IOException,
|
||||
UnknownHostException, ConnectTimeoutException {
|
||||
Log.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" + localPort + ", params: " + params);
|
||||
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" + localPort + ", params: " + params);
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("Parameters may not be null");
|
||||
}
|
||||
@@ -163,7 +159,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
|
||||
//logSslInfo();
|
||||
|
||||
SocketFactory socketfactory = mSslContext.getSocketFactory();
|
||||
Log.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout());
|
||||
Log_OC.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout());
|
||||
Socket socket = socketfactory.createSocket();
|
||||
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
|
||||
SocketAddress remoteaddr = new InetSocketAddress(host, port);
|
||||
@@ -180,7 +176,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
|
||||
*/
|
||||
public Socket createSocket(String host, int port) throws IOException,
|
||||
UnknownHostException {
|
||||
Log.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);
|
||||
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);
|
||||
Socket socket = mSslContext.getSocketFactory().createSocket(host, port);
|
||||
verifyPeerIdentity(host, port, socket);
|
||||
return socket;
|
||||
|
||||
@@ -38,7 +38,7 @@ import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import android.util.Log;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class AdvancedX509TrustManager implements X509TrustManager {
|
||||
try {
|
||||
return (mKnownServersKeyStore.getCertificateAlias(cert) != null);
|
||||
} catch (KeyStoreException e) {
|
||||
Log.d(TAG, "Fail while checking certificate in the known-servers store");
|
||||
Log_OC.d(TAG, "Fail while checking certificate in the known-servers store");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.apache.commons.httpclient.auth.AuthenticationException;
|
||||
import org.apache.commons.httpclient.auth.InvalidCredentialsException;
|
||||
import org.apache.commons.httpclient.auth.MalformedChallengeException;
|
||||
|
||||
import android.util.Log;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
|
||||
* @deprecated Use {@link #authenticate(Credentials, HttpMethod)}
|
||||
*/
|
||||
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException {
|
||||
Log.d(TAG, "enter BearerScheme.authenticate(Credentials, String, String)");
|
||||
Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, String, String)");
|
||||
|
||||
BearerCredentials bearer = null;
|
||||
try {
|
||||
@@ -164,7 +164,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
|
||||
* @return a basic authorization string
|
||||
*/
|
||||
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
|
||||
Log.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");
|
||||
Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");
|
||||
|
||||
if (method == null) {
|
||||
throw new IllegalArgumentException("Method may not be null");
|
||||
@@ -208,7 +208,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
|
||||
* @since 3.0
|
||||
*/
|
||||
public static String authenticate(BearerCredentials credentials, String charset) {
|
||||
Log.d(TAG, "enter BearerAuthScheme.authenticate(BearerCredentials, String)");
|
||||
Log_OC.d(TAG, "enter BearerAuthScheme.authenticate(BearerCredentials, String)");
|
||||
|
||||
if (credentials == null) {
|
||||
throw new IllegalArgumentException("Credentials may not be null");
|
||||
|
||||
@@ -36,8 +36,7 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.httpclient.methods.RequestEntity;
|
||||
|
||||
|
||||
import android.util.Log;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
|
||||
/**
|
||||
@@ -142,7 +141,7 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres
|
||||
}
|
||||
|
||||
} catch (IOException io) {
|
||||
Log.e(TAG, io.getMessage());
|
||||
Log_OC.e(TAG, io.getMessage());
|
||||
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.httpclient.methods.RequestEntity;
|
||||
|
||||
import android.util.Log;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ public class FileRequestEntity implements RequestEntity, ProgressiveDataTransfer
|
||||
}
|
||||
|
||||
} catch (IOException io) {
|
||||
Log.e("FileRequestException", io.getMessage());
|
||||
Log_OC.e("FileRequestException", io.getMessage());
|
||||
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
|
||||
|
||||
} finally {
|
||||
|
||||
@@ -45,7 +45,8 @@ import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
public class NetworkUtils {
|
||||
|
||||
@@ -133,7 +134,7 @@ public class NetworkUtils {
|
||||
//mKnownServersStore = KeyStore.getInstance("BKS");
|
||||
mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
File localTrustStoreFile = new File(context.getFilesDir(), LOCAL_TRUSTSTORE_FILENAME);
|
||||
Log.d(TAG, "Searching known-servers store at " + localTrustStoreFile.getAbsolutePath());
|
||||
Log_OC.d(TAG, "Searching known-servers store at " + localTrustStoreFile.getAbsolutePath());
|
||||
if (localTrustStoreFile.exists()) {
|
||||
InputStream in = new FileInputStream(localTrustStoreFile);
|
||||
try {
|
||||
@@ -175,7 +176,7 @@ public class NetworkUtils {
|
||||
public static boolean isCertInKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
|
||||
|
||||
KeyStore knownServers = getKnownServersStore(context);
|
||||
Log.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "
|
||||
Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "
|
||||
+ Boolean.toString(knownServers.isCertificateEntry(Integer.toString(cert.hashCode()))));
|
||||
return knownServers.isCertificateEntry(Integer.toString(cert.hashCode()));
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import android.util.Log;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
|
||||
/**
|
||||
@@ -80,19 +80,19 @@ public class ServerNameIndicator {
|
||||
if (setHostnameMethod != null) {
|
||||
try {
|
||||
setHostnameMethod.invoke(sslSocket, hostname);
|
||||
Log.i(TAG, "SNI done, hostname: " + hostname);
|
||||
Log_OC.i(TAG, "SNI done, hostname: " + hostname);
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
||||
Log_OC.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
||||
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
||||
Log_OC.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
||||
|
||||
} catch (InvocationTargetException e) {
|
||||
Log.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
||||
Log_OC.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "SNI not supported");
|
||||
Log_OC.i(TAG, "SNI not supported");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,15 +134,15 @@ public class ServerNameIndicator {
|
||||
* @return Method to call to indicate the server name of interest to the server.
|
||||
*/
|
||||
private static Method initFrom(Class<?> sslSocketClass) {
|
||||
Log.i(TAG, "SSLSocket implementation: " + sslSocketClass.getCanonicalName());
|
||||
Log_OC.i(TAG, "SSLSocket implementation: " + sslSocketClass.getCanonicalName());
|
||||
Method setHostnameMethod = null;
|
||||
try {
|
||||
setHostnameMethod = sslSocketClass.getMethod(METHOD_NAME, String.class);
|
||||
} catch (SecurityException e) {
|
||||
Log.e(TAG, "Could not access to SSLSocket#setHostname(String) method ", e);
|
||||
Log_OC.e(TAG, "Could not access to SSLSocket#setHostname(String) method ", e);
|
||||
|
||||
} catch (NoSuchMethodException e) {
|
||||
Log.i(TAG, "Could not find SSLSocket#setHostname(String) method - SNI not supported");
|
||||
Log_OC.i(TAG, "Could not find SSLSocket#setHostname(String) method - SNI not supported");
|
||||
}
|
||||
mSingleInstance.set(new ServerNameIndicator(sslSocketClass, setHostnameMethod));
|
||||
return setHostnameMethod;
|
||||
|
||||
@@ -33,7 +33,8 @@ import org.apache.jackrabbit.webdav.property.DavPropertySet;
|
||||
import org.apache.jackrabbit.webdav.xml.Namespace;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
public class WebdavEntry {
|
||||
private static final String NAMESPACE_OC = "http://owncloud.org/ns";
|
||||
@@ -125,7 +126,7 @@ public class WebdavEntry {
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.e("WebdavEntry",
|
||||
Log_OC.e("WebdavEntry",
|
||||
"General fuckup, no status for webdav response");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,13 @@ package com.owncloud.android.lib.common.operations;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountsException;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
@@ -33,16 +40,7 @@ import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
|
||||
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountsException;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
|
||||
/**
|
||||
@@ -110,7 +108,7 @@ public abstract class RemoteOperation implements Runnable {
|
||||
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, mContext);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
||||
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
||||
return new RemoteOperationResult(e);
|
||||
}
|
||||
return run(mClient);
|
||||
@@ -266,11 +264,11 @@ public abstract class RemoteOperation implements Runnable {
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error while trying to access to " + mAccount.name, new AccountsException("I/O exception while trying to authorize the account", e));
|
||||
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, new AccountsException("I/O exception while trying to authorize the account", e));
|
||||
result = new RemoteOperationResult(e);
|
||||
|
||||
} catch (AccountsException e) {
|
||||
Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
||||
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
||||
result = new RemoteOperationResult(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,10 @@ import org.json.JSONException;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountsException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
|
||||
/**
|
||||
@@ -148,7 +148,7 @@ public class RemoteOperationResult implements Serializable {
|
||||
break;
|
||||
default:
|
||||
mCode = ResultCode.UNHANDLED_HTTP_CODE;
|
||||
Log.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
|
||||
Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.owncloud.android.lib.common.utils;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class Log_OC {
|
||||
private static final String SIMPLE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";
|
||||
private static final String OWNCLOUD_DATA_FOLDER = "owncloud";
|
||||
private static final long MAX_FILE_SIZE = 1000000; // 1MB
|
||||
|
||||
private static File mLogFile;
|
||||
private static File mFolder;
|
||||
private static BufferedWriter mBuf;
|
||||
|
||||
private static String[] mLogFileNames = {"currentLog.txt", "olderLog.txt"};
|
||||
private static String mLogPath = Environment.getExternalStorageDirectory() + File.separator +
|
||||
OWNCLOUD_DATA_FOLDER + File.separator + "log";
|
||||
|
||||
private static boolean isMaxFileSizeReached = false;
|
||||
|
||||
public static void i(String TAG, String message){
|
||||
|
||||
// Write the log message to the file
|
||||
appendLog(TAG+" : "+ message);
|
||||
}
|
||||
|
||||
public static void d(String TAG, String message){
|
||||
Log.d(TAG, message);
|
||||
appendLog(TAG + " : " + message);
|
||||
}
|
||||
public static void d(String TAG, String message, Exception e) {
|
||||
Log.d(TAG, message, e);
|
||||
appendLog(TAG + " : " + message + " Exception : "+ e.getStackTrace());
|
||||
}
|
||||
public static void e(String TAG, String message){
|
||||
Log.e(TAG, message);
|
||||
appendLog(TAG + " : " + message);
|
||||
}
|
||||
|
||||
public static void e(String TAG, String message, Throwable e) {
|
||||
Log.e(TAG, message, e);
|
||||
appendLog(TAG+" : " + message +" Exception : " + e.getStackTrace());
|
||||
}
|
||||
|
||||
public static void v(String TAG, String message){
|
||||
Log.v(TAG, message);
|
||||
appendLog(TAG+" : "+ message);
|
||||
}
|
||||
|
||||
public static void w(String TAG, String message) {
|
||||
Log.w(TAG,message);
|
||||
appendLog(TAG+" : "+ message);
|
||||
}
|
||||
|
||||
public static void wtf(String TAG, String message) {
|
||||
Log.wtf(TAG,message);
|
||||
appendLog(TAG+" : "+ message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start doing logging
|
||||
* @param logPath : path of log file
|
||||
*/
|
||||
public static void startLogging(String logPath) {
|
||||
mFolder = new File(logPath);
|
||||
mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);
|
||||
|
||||
boolean isFileCreated = false;
|
||||
|
||||
if (!mFolder.exists()) {
|
||||
mFolder.mkdirs();
|
||||
isFileCreated = true;
|
||||
Log_OC.d("LOG_OC", "Log file created");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (isMaxFileSizeReached) {
|
||||
|
||||
// Move current log file info to another file (old logs)
|
||||
File olderFile = new File(mFolder + File.separator + mLogFileNames[1]);
|
||||
if (mLogFile.exists()) {
|
||||
mLogFile.renameTo(olderFile);
|
||||
}
|
||||
|
||||
// Construct a new file for current log info
|
||||
mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);
|
||||
isMaxFileSizeReached = false;
|
||||
}
|
||||
|
||||
// Create the current log file if does not exist
|
||||
mLogFile.createNewFile();
|
||||
mBuf = new BufferedWriter(new FileWriter(mLogFile, true));
|
||||
if (isFileCreated) {
|
||||
appendPhoneInfo();
|
||||
}
|
||||
|
||||
// Check if current log file size is bigger than the max file size defined
|
||||
if (mLogFile.length() > MAX_FILE_SIZE) {
|
||||
isMaxFileSizeReached = true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete history logging
|
||||
*/
|
||||
public static void deleteHistoryLogging() {
|
||||
File folderLogs = new File(mFolder + File.separator);
|
||||
if(folderLogs.isDirectory()){
|
||||
String[] myFiles = folderLogs.list();
|
||||
for (int i=0; i<myFiles.length; i++) {
|
||||
File myFile = new File(folderLogs, myFiles[i]);
|
||||
myFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the info of the device
|
||||
*/
|
||||
private static void appendPhoneInfo() {
|
||||
appendLog("Model : " + android.os.Build.MODEL);
|
||||
appendLog("Brand : " + android.os.Build.BRAND);
|
||||
appendLog("Product : " + android.os.Build.PRODUCT);
|
||||
appendLog("Device : " + android.os.Build.DEVICE);
|
||||
appendLog("Version-Codename : " + android.os.Build.VERSION.CODENAME);
|
||||
appendLog("Version-Release : " + android.os.Build.VERSION.RELEASE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to the log file the info passed
|
||||
* @param text : text for adding to the log file
|
||||
*/
|
||||
private static void appendLog(String text) {
|
||||
startLogging(mLogPath);
|
||||
String timeStamp = new SimpleDateFormat(SIMPLE_DATE_FORMAT).format(Calendar.getInstance().getTime());
|
||||
|
||||
try {
|
||||
mBuf = new BufferedWriter(new FileWriter(mLogFile, true));
|
||||
mBuf.newLine();
|
||||
mBuf.write(timeStamp);
|
||||
mBuf.newLine();
|
||||
mBuf.write(text);
|
||||
mBuf.newLine();
|
||||
mBuf.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] getLogFileNames() {
|
||||
return mLogFileNames;
|
||||
}
|
||||
|
||||
public static void setmLogFileNames(String[] logFileNames) {
|
||||
Log_OC.mLogFileNames = logFileNames;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user