Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 1ff7cfd9 authored by tobiasKaminsky's avatar tobiasKaminsky
Browse files

use grey theme if no theming of elements is possible

parent 8c20873b
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
package com.owncloud.android.lib.common;

import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;

import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;

import java.io.IOException;

/**
 * Dynamic implementation of {@link OwnCloudClientManager}.
 * <p>
 * Wraps instances of {@link SingleSessionManager} and {@link SimpleFactoryManager} and delegates on one
 * or the other depending on the known version of the server corresponding to the {@link OwnCloudAccount}
 *
 * @author David A. Velasco
 */

public class DynamicSessionManager implements OwnCloudClientManager {

    private SimpleFactoryManager mSimpleFactoryManager = new SimpleFactoryManager();

    private SingleSessionManager mSingleSessionManager = new SingleSessionManager();

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

        OwnCloudVersion ownCloudVersion = null;
        if (account.getSavedAccount() != null) {
            ownCloudVersion = AccountUtils.getServerVersionForAccount(
                    account.getSavedAccount(), context
            );
        }

        if (ownCloudVersion != null && ownCloudVersion.isPreemptiveAuthenticationPreferred()) {
            return mSingleSessionManager.getClientFor(account, context);
        } else {
            return mSimpleFactoryManager.getClientFor(account, context);
        }
    }

    @Override
    public OwnCloudClient removeClientFor(OwnCloudAccount account) {
        OwnCloudClient clientRemovedFromFactoryManager = mSimpleFactoryManager.removeClientFor(account);
        OwnCloudClient clientRemovedFromSingleSessionManager = mSingleSessionManager.removeClientFor(account);
        if (clientRemovedFromSingleSessionManager != null) {
            return clientRemovedFromSingleSessionManager;
        } else {
            return clientRemovedFromFactoryManager;
        }
        // clientRemoved and clientRemoved2 should not be != null at the same time
    }

    @Override
    public void saveAllClients(Context context, String accountType)
            throws AccountUtils.AccountNotFoundException,
            AuthenticatorException, IOException, OperationCanceledException {
        mSimpleFactoryManager.saveAllClients(context, accountType);
        mSingleSessionManager.saveAllClients(context, accountType);
    }

}
 No newline at end of file
+9 −5
Original line number Diff line number Diff line
@@ -25,11 +25,6 @@
package com.owncloud.android.lib.common;


import java.io.IOException;

import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
@@ -37,6 +32,11 @@ import android.accounts.OperationCanceledException;
import android.content.Context;
import android.net.Uri;

import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;

import java.io.IOException;

/**
 * OwnCloud Account
 * 
@@ -139,6 +139,10 @@ public class OwnCloudAccount {
    	return mSavedAccountName;
    }

    public Account getSavedAccount() {
        return mSavedAccount;
    }

    public String getDisplayName() {
        if (mDisplayName != null && mDisplayName.length() > 0) {
            return mDisplayName;
+36 −31
Original line number Diff line number Diff line
@@ -23,35 +23,40 @@
 */
package com.owncloud.android.lib.common;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthPolicy;
import org.apache.commons.httpclient.auth.AuthScope;

import java.util.ArrayList;
import java.util.List;

public class OwnCloudBasicCredentials implements OwnCloudCredentials {

    private String mUsername;
    private String mPassword;
    private boolean mAuthenticationPreemptive;

    public OwnCloudBasicCredentials(String username, String password) {
        mUsername = username != null ? username : "";
        mPassword = password != null ? password : "";
        mAuthenticationPreemptive = true;
    }

    public OwnCloudBasicCredentials(String username, String password, boolean preemptiveMode) {
        mUsername = username != null ? username : "";
        mPassword = password != null ? password : "";
        mAuthenticationPreemptive = preemptiveMode;
    }

    @Override
    public void applyTo(OwnCloudClient client) {
        List<String> authPrefs = new ArrayList<String>(1);
        authPrefs.add(AuthPolicy.BASIC);
        client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);        

        client.getParams().setAuthenticationPreemptive(true);
        client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
        client.getParams().setAuthenticationPreemptive(mAuthenticationPreemptive);
        client.getParams().setCredentialCharset(OwnCloudCredentialsFactory.CREDENTIAL_CHARSET);
        client.getState().setCredentials(
        		AuthScope.ANY, 
        		new UsernamePasswordCredentials(mUsername, mPassword)
		);
        client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(mUsername, mPassword));
    }

    @Override
+6 −7
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpStatus;
@@ -149,7 +148,7 @@ public class OwnCloudClient extends HttpClient {
     * @throws  	Exception   When the existence could not be determined
     */
    @Deprecated
    public boolean existsFile(String path) throws IOException, HttpException {
    public boolean existsFile(String path) throws IOException {
        HeadMethod head = new HeadMethod(getWebdavUri() + WebdavUtils.encodePath(path));
        try {
            int status = executeMethod(head);
@@ -387,16 +386,16 @@ public class OwnCloudClient extends HttpClient {
        	}
        }
        if (counter == 0) {
    		Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at request before");
            Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at request (" + when + ")");
        }
	}

    private void logCookiesAtState(String string) {
    private void logCookiesAtState(String when) {
        Cookie[] cookies = getState().getCookies();
        if (cookies.length == 0) {
    		Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at STATE before");
            Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at STATE " + when);
        } else {
    		Log_OC.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (before)");
            Log_OC.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (" + when + ")");
            for (int i=0; i<cookies.length; i++) {
	    		Log_OC.d(TAG + " #" + mInstanceNumber, "    (" + i + "):" +
	    				"\n        name: " + cookies[i].getName() +
+17 −12
Original line number Diff line number Diff line
@@ -24,9 +24,6 @@

package com.owncloud.android.lib.common;

import java.io.IOException;
import java.security.GeneralSecurityException;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerFuture;
@@ -42,6 +39,10 @@ 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;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;

import java.io.IOException;
import java.security.GeneralSecurityException;

public class OwnCloudClientFactory {
    
@@ -105,16 +106,17 @@ public class OwnCloudClientFactory {
    		);

        } else {
            //String password = am.getPassword(account);
            String password = am.blockingGetAuthToken(
            		account, 
            		AccountTypeUtils.getAuthTokenTypePass(account.type), 
            		false);

            client.setCredentials(
            		OwnCloudCredentialsFactory.newBasicCredentials(username, password)
    		);
            OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext);

            OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(
                    username, password, (version != null && version.isPreemptiveAuthenticationPreferred()));

            client.setCredentials(credentials);
        }
        
        // Restore cookies
@@ -185,9 +187,12 @@ public class OwnCloudClientFactory {
            
            Bundle result = future.getResult();
            String password = result.getString(AccountManager.KEY_AUTHTOKEN);
            client.setCredentials(
            		OwnCloudCredentialsFactory.newBasicCredentials(username, password)
    		);

            OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext);
            OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(
                    username, password, (version != null && version.isPreemptiveAuthenticationPreferred()));

            client.setCredentials(credentials);
        }
        
        // Restore cookies
Loading