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

Unverified Commit 591eeb21 authored by tobiasKaminsky's avatar tobiasKaminsky
Browse files

use nextcloud user agent for E2e calls

parent 272f024c
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -26,20 +26,25 @@ public class DynamicSessionManager implements OwnCloudClientManager {

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

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

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

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

+9 −2
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class OwnCloudClient extends HttpClient {
    /**
     * Constructor
     */
    public OwnCloudClient(Uri baseUri, HttpConnectionManager connectionMgr) {
    public OwnCloudClient(Uri baseUri, HttpConnectionManager connectionMgr, boolean useNextcloudUserAgent) {
        super(connectionMgr);
        
        if (baseUri == null) {
@@ -85,7 +85,14 @@ public class OwnCloudClient extends HttpClient {
        mInstanceNumber = sIntanceCounter++;
        Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");

        String userAgent = OwnCloudClientManagerFactory.getUserAgent();
        String userAgent;

        if (useNextcloudUserAgent) {
            userAgent = OwnCloudClientManagerFactory.getNextcloudUserAgent();
        } else {
            userAgent = OwnCloudClientManagerFactory.getUserAgent();
        }
        
        getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
        getParams().setParameter(
        		PARAM_PROTOCOL_VERSION,
+8 −5
Original line number Diff line number Diff line
@@ -209,8 +209,8 @@ public class OwnCloudClientFactory {
     * @param context   Android context where the OwnCloudClient is being created.
     * @return          A OwnCloudClient object ready to be used
     */
    public static OwnCloudClient createOwnCloudClient(Uri uri, Context context,
                                                      boolean followRedirects) {
    public static OwnCloudClient createOwnCloudClient(Uri uri, Context context, boolean followRedirects,
                                                      boolean useNextcloudUserAgent) {
        try {
            NetworkUtils.registerAdvancedSslContext(true, context);
        }  catch (GeneralSecurityException e) {
@@ -222,12 +222,15 @@ public class OwnCloudClientFactory {
                    " in the system will be used for HTTPS connections", e);
        }

        OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager());
        OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager(),
                useNextcloudUserAgent);
        client.setDefaultTimeouts(DEFAULT_DATA_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
        client.setFollowRedirects(followRedirects);
        
        return client;
    }


    public static OwnCloudClient createOwnCloudClient(Uri uri, Context context, boolean followRedirects) {
        return createOwnCloudClient(uri, context, followRedirects, false);
    }
}
+7 −3
Original line number Diff line number Diff line
@@ -24,14 +24,14 @@

package com.owncloud.android.lib.common;

import java.io.IOException;

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

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

import java.io.IOException;


/**
 * Manager to create and reuse OwnCloudClient instances to access remote OC servers. 
@@ -42,6 +42,10 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce

public interface OwnCloudClientManager {

    public OwnCloudClient getClientFor(OwnCloudAccount account, Context context, boolean useNextcloudUserAgent)
            throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
            IOException;

    public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
            throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
            IOException;
+9 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ public class OwnCloudClientManagerFactory {
	private static OwnCloudClientManager sDefaultSingleton;

    private static String sUserAgent;
    private static String sNextcloudUserAgent;

	public static OwnCloudClientManager newDefaultOwnCloudClientManager() {
		return newOwnCloudClientManager(sDefaultPolicy);
@@ -86,6 +87,14 @@ public class OwnCloudClientManagerFactory {
        return sUserAgent;
    }

    public static void setNextcloudUserAgent(String userAgent) {
        sNextcloudUserAgent = userAgent;
    }

    public static String getNextcloudUserAgent() {
        return sNextcloudUserAgent;
    }

	private static boolean defaultSingletonMustBeUpdated(Policy policy) {
		if (sDefaultSingleton == null) {
			return false;
Loading