Loading src/com/owncloud/android/lib/common/OwnCloudClientManager.java +1 −13 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ package com.owncloud.android.lib.common; import java.io.IOException; import android.accounts.Account; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.content.Context; Loading @@ -45,21 +44,10 @@ public interface OwnCloudClientManager { public OwnCloudClient getClientFor(OwnCloudAccount account, Context context); /* public OwnCloudClient getClientFor(Account savedAccount, Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException; public OwnCloudClient getClientFor( Uri serverBaseUri, OwnCloudCredentials credentials, Context context); */ public OwnCloudClient removeClientFor(OwnCloudAccount account); public void saveAllClients(Context context, String accountType) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException; public OwnCloudClient removeClientFor(Account account, Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException; } src/com/owncloud/android/lib/common/SimpleFactoryManager.java +38 −42 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * Copyright (C) 2014 ownCloud Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.common; import android.accounts.Account; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import com.owncloud.android.lib.common.accounts.AccountUtils; import android.content.Context; import android.net.Uri; import android.util.Log; import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; public class SimpleFactoryManager implements OwnCloudClientManager { private static final String TAG = SimpleFactoryManager.class.getSimpleName(); Loading @@ -22,51 +42,27 @@ public class SimpleFactoryManager implements OwnCloudClientManager { context.getApplicationContext(), true); Log.d(TAG, " new client " + client.hashCode()); client.setCredentials(account.getCredentials()); return client; } /* @Override public OwnCloudClient getClientFor(Account savedAccount, Context context) throws OperationCanceledException, AuthenticatorException, AccountNotFoundException, IOException { Log.d(TAG, "getClientFor(Account ... : "); OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient( savedAccount, context.getApplicationContext()); Log.d(TAG, " new client {" + (account.getName() != null ? account.getName() : AccountUtils.buildAccountName( account.getBaseUri(), account.getCredentials().getAuthToken())) + ", " + client.hashCode() + "}"); Log.d(TAG, " new client " + client.hashCode()); client.setCredentials(account.getCredentials()); return client; } @Override public OwnCloudClient getClientFor(Uri serverBaseUri, OwnCloudCredentials credentials, Context context) { Log.d(TAG, "getClientFor(Uri ... : "); OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient( serverBaseUri, context.getApplicationContext(), true); client.setCredentials(credentials); Log.d(TAG, " new client " + client.hashCode()); return client; public OwnCloudClient removeClientFor(OwnCloudAccount account) { // nothing to do - not taking care of tracking instances! return null; } */ @Override public void saveAllClients(Context context, String accountType) { // TODO Auto-generated method stub } @Override public OwnCloudClient removeClientFor(Account account, Context context) { return null; // nothing to do - not taking care of tracking instances! } } src/com/owncloud/android/lib/common/SingleSessionManager.java +37 −87 Original line number Diff line number Diff line Loading @@ -46,16 +46,12 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce * * TODO check multithreading safety * * TODO better mapping? * * @author David A. Velasco * @author masensio */ public class SingleSessionManager implements OwnCloudClientManager { //private static final String TAG = SingleSessionManager.class.getSimpleName(); private static final String TAG = SingleSessionManager.class.getSimpleName(); private Map<String, Map<OwnCloudCredentials, OwnCloudClient>> mClientsPerServer = Loading Loading @@ -130,94 +126,39 @@ public class SingleSessionManager implements OwnCloudClientManager { return client; } /* @Override public synchronized OwnCloudClient getClientFor(Account savedAccount, Context context) throws OperationCanceledException, AuthenticatorException, AccountNotFoundException, IOException { Uri serverBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount)); OwnCloudCredentials credentials = AccountUtils.getCredentialsForAccount(context, savedAccount); OwnCloudClient client = getClientFor(serverBaseUri, credentials, context); // Restore Cookies ?? AccountUtils.restoreCookies(savedAccount, client, context); return client; } */ /* @Override public synchronized OwnCloudClient getClientFor( Uri serverBaseUri, OwnCloudCredentials credentials, Context context) { Map<OwnCloudCredentials, OwnCloudClient> clientsPerAccount = mClientsPerServer.get(serverBaseUri.toString()); if (clientsPerAccount == null) { clientsPerAccount = new HashMap<OwnCloudCredentials, OwnCloudClient>(); mClientsPerServer.put( serverBaseUri.toString(), clientsPerAccount); } if (credentials == null) { credentials = OwnCloudCredentialsFactory.getAnonymousCredentials(); } /// TODO - CRITERIA FOR MATCH OF KEYS!!! OwnCloudClient client = clientsPerAccount.get(credentials); if (client == null) { client = OwnCloudClientFactory.createOwnCloudClient( serverBaseUri, context.getApplicationContext(), true); // Restore Cookies String accountName = AccountUtils.buildAccountName(serverBaseUri, credentials.getUsername()); AccountUtils.restoreCookies(accountName, client, context); client.setCredentials(credentials); clientsPerAccount.put(credentials, client); public OwnCloudClient removeClientFor(OwnCloudAccount account) { if (account == null) { return null; } OwnCloudClient client = null; String accountName = account.getName(); if (accountName != null) { client = mClientsWithKnownUsername.remove(accountName); if (client != null) { Log.d(TAG, "Removed client {" + accountName + ", " + client.hashCode() + "}"); return client; } else { Log.d(TAG, "No client tracked for {" + accountName + "}"); } */ private void keepCredentialsUpdated(OwnCloudAccount account, OwnCloudClient reusedClient) { OwnCloudCredentials recentCredentials = account.getCredentials(); if (!recentCredentials.getAuthToken().equals( reusedClient.getCredentials().getAuthToken())) { reusedClient.setCredentials(recentCredentials); } String sessionName = AccountUtils.buildAccountName( account.getBaseUri(), account.getCredentials().getAuthToken()); client = mClientsWithUnknownUsername.remove(sessionName); if (client != null) { Log.d(TAG, "Removed client {" + sessionName + ", " + client.hashCode() + "}"); return client; } Log.d(TAG, "No client tracked for {" + sessionName + "}"); @Override public synchronized OwnCloudClient removeClientFor(Account savedAccount, Context context) throws AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException { Uri serverBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount)); Map<OwnCloudCredentials, OwnCloudClient> clientsPerAccount = mClientsPerServer.get(serverBaseUri.toString()); if (clientsPerAccount != null) { OwnCloudCredentials credentials = AccountUtils.getCredentialsForAccount(context, savedAccount); return clientsPerAccount.remove(credentials); } Log.d(TAG, "No client removed"); return null; } Loading Loading @@ -254,4 +195,13 @@ public class SingleSessionManager implements OwnCloudClientManager { } private void keepCredentialsUpdated(OwnCloudAccount account, OwnCloudClient reusedClient) { OwnCloudCredentials recentCredentials = account.getCredentials(); if (!recentCredentials.getAuthToken().equals( reusedClient.getCredentials().getAuthToken())) { reusedClient.setCredentials(recentCredentials); } } } Loading
src/com/owncloud/android/lib/common/OwnCloudClientManager.java +1 −13 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ package com.owncloud.android.lib.common; import java.io.IOException; import android.accounts.Account; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.content.Context; Loading @@ -45,21 +44,10 @@ public interface OwnCloudClientManager { public OwnCloudClient getClientFor(OwnCloudAccount account, Context context); /* public OwnCloudClient getClientFor(Account savedAccount, Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException; public OwnCloudClient getClientFor( Uri serverBaseUri, OwnCloudCredentials credentials, Context context); */ public OwnCloudClient removeClientFor(OwnCloudAccount account); public void saveAllClients(Context context, String accountType) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException; public OwnCloudClient removeClientFor(Account account, Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException; }
src/com/owncloud/android/lib/common/SimpleFactoryManager.java +38 −42 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * Copyright (C) 2014 ownCloud Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.common; import android.accounts.Account; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import com.owncloud.android.lib.common.accounts.AccountUtils; import android.content.Context; import android.net.Uri; import android.util.Log; import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; public class SimpleFactoryManager implements OwnCloudClientManager { private static final String TAG = SimpleFactoryManager.class.getSimpleName(); Loading @@ -22,51 +42,27 @@ public class SimpleFactoryManager implements OwnCloudClientManager { context.getApplicationContext(), true); Log.d(TAG, " new client " + client.hashCode()); client.setCredentials(account.getCredentials()); return client; } /* @Override public OwnCloudClient getClientFor(Account savedAccount, Context context) throws OperationCanceledException, AuthenticatorException, AccountNotFoundException, IOException { Log.d(TAG, "getClientFor(Account ... : "); OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient( savedAccount, context.getApplicationContext()); Log.d(TAG, " new client {" + (account.getName() != null ? account.getName() : AccountUtils.buildAccountName( account.getBaseUri(), account.getCredentials().getAuthToken())) + ", " + client.hashCode() + "}"); Log.d(TAG, " new client " + client.hashCode()); client.setCredentials(account.getCredentials()); return client; } @Override public OwnCloudClient getClientFor(Uri serverBaseUri, OwnCloudCredentials credentials, Context context) { Log.d(TAG, "getClientFor(Uri ... : "); OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient( serverBaseUri, context.getApplicationContext(), true); client.setCredentials(credentials); Log.d(TAG, " new client " + client.hashCode()); return client; public OwnCloudClient removeClientFor(OwnCloudAccount account) { // nothing to do - not taking care of tracking instances! return null; } */ @Override public void saveAllClients(Context context, String accountType) { // TODO Auto-generated method stub } @Override public OwnCloudClient removeClientFor(Account account, Context context) { return null; // nothing to do - not taking care of tracking instances! } }
src/com/owncloud/android/lib/common/SingleSessionManager.java +37 −87 Original line number Diff line number Diff line Loading @@ -46,16 +46,12 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce * * TODO check multithreading safety * * TODO better mapping? * * @author David A. Velasco * @author masensio */ public class SingleSessionManager implements OwnCloudClientManager { //private static final String TAG = SingleSessionManager.class.getSimpleName(); private static final String TAG = SingleSessionManager.class.getSimpleName(); private Map<String, Map<OwnCloudCredentials, OwnCloudClient>> mClientsPerServer = Loading Loading @@ -130,94 +126,39 @@ public class SingleSessionManager implements OwnCloudClientManager { return client; } /* @Override public synchronized OwnCloudClient getClientFor(Account savedAccount, Context context) throws OperationCanceledException, AuthenticatorException, AccountNotFoundException, IOException { Uri serverBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount)); OwnCloudCredentials credentials = AccountUtils.getCredentialsForAccount(context, savedAccount); OwnCloudClient client = getClientFor(serverBaseUri, credentials, context); // Restore Cookies ?? AccountUtils.restoreCookies(savedAccount, client, context); return client; } */ /* @Override public synchronized OwnCloudClient getClientFor( Uri serverBaseUri, OwnCloudCredentials credentials, Context context) { Map<OwnCloudCredentials, OwnCloudClient> clientsPerAccount = mClientsPerServer.get(serverBaseUri.toString()); if (clientsPerAccount == null) { clientsPerAccount = new HashMap<OwnCloudCredentials, OwnCloudClient>(); mClientsPerServer.put( serverBaseUri.toString(), clientsPerAccount); } if (credentials == null) { credentials = OwnCloudCredentialsFactory.getAnonymousCredentials(); } /// TODO - CRITERIA FOR MATCH OF KEYS!!! OwnCloudClient client = clientsPerAccount.get(credentials); if (client == null) { client = OwnCloudClientFactory.createOwnCloudClient( serverBaseUri, context.getApplicationContext(), true); // Restore Cookies String accountName = AccountUtils.buildAccountName(serverBaseUri, credentials.getUsername()); AccountUtils.restoreCookies(accountName, client, context); client.setCredentials(credentials); clientsPerAccount.put(credentials, client); public OwnCloudClient removeClientFor(OwnCloudAccount account) { if (account == null) { return null; } OwnCloudClient client = null; String accountName = account.getName(); if (accountName != null) { client = mClientsWithKnownUsername.remove(accountName); if (client != null) { Log.d(TAG, "Removed client {" + accountName + ", " + client.hashCode() + "}"); return client; } else { Log.d(TAG, "No client tracked for {" + accountName + "}"); } */ private void keepCredentialsUpdated(OwnCloudAccount account, OwnCloudClient reusedClient) { OwnCloudCredentials recentCredentials = account.getCredentials(); if (!recentCredentials.getAuthToken().equals( reusedClient.getCredentials().getAuthToken())) { reusedClient.setCredentials(recentCredentials); } String sessionName = AccountUtils.buildAccountName( account.getBaseUri(), account.getCredentials().getAuthToken()); client = mClientsWithUnknownUsername.remove(sessionName); if (client != null) { Log.d(TAG, "Removed client {" + sessionName + ", " + client.hashCode() + "}"); return client; } Log.d(TAG, "No client tracked for {" + sessionName + "}"); @Override public synchronized OwnCloudClient removeClientFor(Account savedAccount, Context context) throws AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException { Uri serverBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount)); Map<OwnCloudCredentials, OwnCloudClient> clientsPerAccount = mClientsPerServer.get(serverBaseUri.toString()); if (clientsPerAccount != null) { OwnCloudCredentials credentials = AccountUtils.getCredentialsForAccount(context, savedAccount); return clientsPerAccount.remove(credentials); } Log.d(TAG, "No client removed"); return null; } Loading Loading @@ -254,4 +195,13 @@ public class SingleSessionManager implements OwnCloudClientManager { } private void keepCredentialsUpdated(OwnCloudAccount account, OwnCloudClient reusedClient) { OwnCloudCredentials recentCredentials = account.getCredentials(); if (!recentCredentials.getAuthToken().equals( reusedClient.getCredentials().getAuthToken())) { reusedClient.setCredentials(recentCredentials); } } }