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

Commit

Permalink
Finish replacing logOC with timber
Browse files Browse the repository at this point in the history
  • Loading branch information
abelgardep committed Jan 9, 2020
1 parent d6364ba commit df977e4
Show file tree
Hide file tree
Showing 31 changed files with 120 additions and 582 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public class DynamicSessionManager implements OwnCloudClientManager {

@Override
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
throws AccountUtils.AccountNotFoundException,
OperationCanceledException, AuthenticatorException, IOException {
throws OperationCanceledException, AuthenticatorException, IOException {

OwnCloudVersion ownCloudVersion = null;
if (account.getSavedAccount() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

public class OwnCloudClientFactory {

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

/**
* Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud
* client connections.
Expand All @@ -49,4 +47,4 @@ public static OwnCloudClient createOwnCloudClient(Uri uri, Context context,

return client;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,25 @@
import android.content.Context;

import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.utils.Log_OC;
import timber.log.Timber;

import java.io.IOException;

public class SimpleFactoryManager implements OwnCloudClientManager {

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

@Override
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws
OperationCanceledException, AuthenticatorException, IOException {

Log_OC.d(TAG, "getClientFor(OwnCloudAccount ... : ");
Timber.d("getClientFor(OwnCloudAccount ... : ");

OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
account.getBaseUri(),
context.getApplicationContext(),
true);

Log_OC.v(TAG, " new client {" +
(account.getName() != null ?
account.getName() :
AccountUtils.buildAccountName(account.getBaseUri(), "")

) + ", " + client.hashCode() + "}");
Timber.v(" new client {" + (account.getName() != null ? account.getName() :
AccountUtils.buildAccountName(account.getBaseUri(), "")) + ", " + client.hashCode() + "}");

if (account.getCredentials() == null) {
account.loadCredentials(context);
Expand All @@ -75,5 +69,4 @@ public OwnCloudClient removeClientFor(OwnCloudAccount account) {
public void saveAllClients(Context context, String accountType) {
// nothing to do - not taking care of tracking instances!
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
import android.accounts.OperationCanceledException;
import android.content.Context;
import android.net.Uri;
import android.util.Log;

import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.utils.Log_OC;
import timber.log.Timber;

import java.io.IOException;
import java.util.Iterator;
Expand All @@ -54,8 +53,6 @@

public class SingleSessionManager implements OwnCloudClientManager {

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

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

private ConcurrentMap<String, OwnCloudClient> mClientsWithUnknownUsername = new ConcurrentHashMap<>();
Expand All @@ -64,9 +61,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws OperationCanceledException,
AuthenticatorException, IOException {

if (Log.isLoggable(TAG, Log.DEBUG)) {
Log_OC.d(TAG, "getClientFor starting ");
}
Timber.d("getClientFor starting ");
if (account == null) {
throw new IllegalArgumentException("Cannot get an OwnCloudClient for a null account");
}
Expand All @@ -84,21 +79,16 @@ public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) thr
if (accountName != null) {
client = mClientsWithUnknownUsername.remove(sessionName);
if (client != null) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log_OC.v(TAG, "reusing client for session " + sessionName);
}
Timber.v("reusing client for session %s", sessionName);

mClientsWithKnownUsername.put(accountName, client);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log_OC.v(TAG, "moved client to account " + accountName);
}
Timber.v("moved client to account %s", accountName);
}
} else {
client = mClientsWithUnknownUsername.get(sessionName);
}
} else {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log_OC.v(TAG, "reusing client for account " + accountName);
}
Timber.v("reusing client for account %s", accountName);
reusingKnown = true;
}

Expand All @@ -117,37 +107,28 @@ public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) thr

if (accountName != null) {
mClientsWithKnownUsername.put(accountName, client);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log_OC.v(TAG, "new client for account " + accountName);
}
Timber.v("new client for account %s", accountName);

} else {
mClientsWithUnknownUsername.put(sessionName, client);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log_OC.v(TAG, "new client for session " + sessionName);
}
Timber.v("new client for session %s", sessionName);
}
} else {
if (!reusingKnown && Log.isLoggable(TAG, Log.VERBOSE)) {
Log_OC.v(TAG, "reusing client for session " + sessionName);
if (!reusingKnown) {
Timber.v("reusing client for session %s", sessionName);
}

keepCredentialsUpdated(client);
keepCookiesUpdated(context, account, client);
keepUriUpdated(account, client);
}

if (Log.isLoggable(TAG, Log.DEBUG)) {
Log_OC.d(TAG, "getClientFor finishing ");
}
Timber.d("getClientFor finishing ");
return client;
}

@Override
public OwnCloudClient removeClientFor(OwnCloudAccount account) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log_OC.d(TAG, "removeClientFor starting ");
}
Timber.d("removeClientFor starting ");

if (account == null) {
return null;
Expand All @@ -158,31 +139,22 @@ public OwnCloudClient removeClientFor(OwnCloudAccount account) {
if (accountName != null) {
client = mClientsWithKnownUsername.remove(accountName);
if (client != null) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log_OC.v(TAG, "Removed client for account " + accountName);
}
Timber.v("Removed client for account %s", accountName);
return client;
} else {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log_OC.v(TAG, "No client tracked for account " + accountName);
}
Timber.v("No client tracked for account %s", accountName);
}
}

mClientsWithUnknownUsername.clear();

if (Log.isLoggable(TAG, Log.DEBUG)) {
Log_OC.d(TAG, "removeClientFor finishing ");
}
Timber.d("removeClientFor finishing ");
return null;
}

@Override
public void saveAllClients(Context context, String accountType) {

if (Log.isLoggable(TAG, Log.DEBUG)) {
Log_OC.d(TAG, "Saving sessions... ");
}
Timber.d("Saving sessions... ");

Iterator<String> accountNames = mClientsWithKnownUsername.keySet().iterator();
String accountName;
Expand All @@ -193,9 +165,7 @@ public void saveAllClients(Context context, String accountType) {
AccountUtils.saveClient(mClientsWithKnownUsername.get(accountName), account, context);
}

if (Log.isLoggable(TAG, Log.DEBUG)) {
Log_OC.d(TAG, "All sessions saved");
}
Timber.d("All sessions saved");
}

private void keepCredentialsUpdated(OwnCloudClient reusedClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import okhttp3.Cookie;
import timber.log.Timber;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AccountUtils {

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

/**
* Constructs full url to host and webdav resource basing on host version
*
Expand Down Expand Up @@ -104,7 +102,7 @@ public static String getUsernameForAccount(Account account) {
try {
username = account.name.substring(0, account.name.lastIndexOf('@'));
} catch (Exception e) {
Log_OC.e(TAG, "Couldn't get a username for the given account", e);
Timber.e(e, "Couldn't get a username for the given account");
}
return username;
}
Expand All @@ -124,7 +122,7 @@ public static OwnCloudVersion getServerVersionForAccount(Account account, Contex
version = new OwnCloudVersion(versionString);

} catch (Exception e) {
Log_OC.e(TAG, "Couldn't get a the server version for an account", e);
Timber.e(e, "Couldn't get a the server version for an account");
}
return version;
}
Expand Down Expand Up @@ -216,7 +214,7 @@ public static void saveClient(OwnCloudClient client, Account savedAccount, Conte
String cookiesString = client.getCookiesString();
if (!"".equals(cookiesString)) {
ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString);
Log_OC.d(TAG, "Saving Cookies: " + cookiesString);
Timber.d("Saving Cookies: %s", cookiesString);
}
}
}
Expand All @@ -230,10 +228,10 @@ public static void saveClient(OwnCloudClient client, Account savedAccount, Conte
*/
public static void restoreCookies(Account account, OwnCloudClient client, Context context) {
if (account == null) {
Log_OC.d(TAG, "Cannot restore cookie for null account");
Timber.d("Cannot restore cookie for null account");

} else {
Log_OC.d(TAG, "Restoring cookies for " + account.name);
Timber.d("Restoring cookies for %s", account.name);

// Account Manager
AccountManager am = AccountManager.get(context.getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

package com.owncloud.android.lib.common.authentication.oauth;

import com.owncloud.android.lib.common.utils.Log_OC;
import timber.log.Timber;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -61,7 +61,7 @@ public Map<String, String> parse(String query) {
mOAuth2ParsedAuthorizationResponse.put(key, value);
}

Log_OC.v(TAG, "[" + i + "," + j + "] = " + p);
Timber.v("[" + i + "," + j + "] = " + p);
j++;
}
i++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import org.json.JSONObject;
import timber.log.Timber;

import java.net.URL;
import java.util.Map;

public class OAuth2RefreshAccessTokenOperation extends RemoteOperation<Map<String, String>> {

private static final String TAG = OAuth2RefreshAccessTokenOperation.class.getSimpleName();
private final String mAccessTokenEndpointPath;
private final OAuth2ResponseParser mResponseParser;
private String mClientId;
Expand Down Expand Up @@ -96,7 +95,7 @@ protected RemoteOperationResult<Map<String, String>> run(OwnCloudClient client)
switchClientCredentials(oldCredentials);

final String responseData = postMethod.getResponseBodyAsString();
Log_OC.d(TAG, "OAUTH2: raw response from POST TOKEN: " + responseData);
Timber.d("OAUTH2: raw response from POST TOKEN: %s", responseData);

if (responseData != null && responseData.length() > 0) {
final JSONObject tokenJson = new JSONObject(responseData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@

package com.owncloud.android.lib.common.authentication.oauth;

import com.owncloud.android.lib.common.utils.Log_OC;
import timber.log.Timber;

public class OwnCloudOAuth2Provider implements OAuth2Provider {

public static final String NAME = OAuth2Provider.class.getName();

public static final String ACCESS_TOKEN_ENDPOINT_PATH = "index.php/apps/oauth2/api/v1/token";
static final String ACCESS_TOKEN_ENDPOINT_PATH = "index.php/apps/oauth2/api/v1/token";
private static final String AUTHORIZATION_CODE_ENDPOINT_PATH = "index.php/apps/oauth2/authorize";

private String mAuthorizationServerUrl = "";
Expand Down Expand Up @@ -66,26 +64,26 @@ public void setAuthorizationServerUri(String authorizationServerUri) {
mAuthorizationServerUrl = authorizationServerUri;
}

public String getAccessTokenEndpointPath() {
String getAccessTokenEndpointPath() {
return mAccessTokenEndpointPath;
}

public void setAccessTokenEndpointPath(String accessTokenEndpointPath) {
if (accessTokenEndpointPath == null || accessTokenEndpointPath.length() <= 0) {
Log_OC.w(NAME, "Setting invalid access token endpoint path, going on with default");
Timber.w("Setting invalid access token endpoint path, going on with default");
mAccessTokenEndpointPath = ACCESS_TOKEN_ENDPOINT_PATH;
} else {
mAccessTokenEndpointPath = accessTokenEndpointPath;
}
}

public String getAuthorizationCodeEndpointPath() {
String getAuthorizationCodeEndpointPath() {
return mAuthorizationCodeEndpointPath;
}

public void setAuthorizationCodeEndpointPath(String authorizationCodeEndpointPath) {
if (authorizationCodeEndpointPath == null || authorizationCodeEndpointPath.length() <= 0) {
Log_OC.w(NAME, "Setting invalid authorization code endpoint path, going on with default");
Timber.w("Setting invalid authorization code endpoint path, going on with default");
mAuthorizationCodeEndpointPath = AUTHORIZATION_CODE_ENDPOINT_PATH;
} else {
mAuthorizationCodeEndpointPath = authorizationCodeEndpointPath;
Expand Down
Loading

0 comments on commit df977e4

Please sign in to comment.