Connectivity check: no need to use owncloudClient (#4344)

Connectivity check: no need to use owncloudClient
This commit is contained in:
Tobias Kaminsky 2019-08-21 07:57:00 +02:00 committed by GitHub
commit 66a889825e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 15 deletions

View file

@ -1 +1 @@
413
412

View file

@ -145,7 +145,8 @@ public class UserAccountManagerImpl implements UserAccountManager {
try {
Account currentPlatformAccount = getCurrentAccount();
return new OwnCloudAccount(currentPlatformAccount, context);
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException ex) {
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException |
IllegalArgumentException ex) {
return null;
}
}

View file

@ -29,6 +29,8 @@ import android.net.Uri;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import org.apache.commons.httpclient.HttpClient;
import java.io.IOException;
public interface ClientFactory {
@ -46,4 +48,6 @@ public interface ClientFactory {
boolean useNextcloudUserAgent);
OwnCloudClient create(Uri uri, boolean followRedirects);
HttpClient createPlainClient();
}

View file

@ -31,6 +31,8 @@ import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import org.apache.commons.httpclient.HttpClient;
import java.io.IOException;
class ClientFactoryImpl implements ClientFactory {
@ -64,4 +66,9 @@ class ClientFactoryImpl implements ClientFactory {
public OwnCloudClient create(Uri uri, boolean followRedirects) {
return OwnCloudClientFactory.createOwnCloudClient(uri, context, followRedirects);
}
@Override
public HttpClient createPlainClient() {
return new HttpClient();
}
}

View file

@ -21,18 +21,16 @@
package com.nextcloud.client.network;
import android.accounts.Account;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.evernote.android.job.JobRequest;
import com.nextcloud.client.account.UserAccountManager;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.json.JSONObject;
@ -73,8 +71,8 @@ class ConnectivityServiceImpl implements ConnectivityService {
if (isOnlineWithWifi()) {
try {
Account account = accountManager.getCurrentAccount();
if (account != null) {
OwnCloudAccount ocAccount = accountManager.getCurrentOwnCloudAccount();
OwnCloudAccount ocAccount = accountManager.getCurrentOwnCloudAccount();
if (account != null && ocAccount != null) {
OwnCloudVersion serverVersion = accountManager.getServerVersion(account);
String url;
@ -85,7 +83,7 @@ class ConnectivityServiceImpl implements ConnectivityService {
}
GetMethod get = requestBuilder.invoke(url);
OwnCloudClient client = clientFactory.create(account);
HttpClient client = clientFactory.createPlainClient();
int status = client.executeMethod(get);
@ -110,10 +108,6 @@ class ConnectivityServiceImpl implements ConnectivityService {
}
} catch (IOException e) {
Log_OC.e(TAG, "Error checking internet connection", e);
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
Log_OC.e(TAG, "Account not found", e);
} catch (OperationCanceledException | AuthenticatorException e) {
Log_OC.e(TAG, e.getMessage());
}
} else {
return getActiveNetworkType() == JobRequest.NetworkType.ANY;

View file

@ -29,8 +29,8 @@ import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import com.owncloud.android.lib.common.OwnCloudAccount
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.resources.status.OwnCloudVersion
import org.apache.commons.httpclient.HttpClient
import org.apache.commons.httpclient.HttpStatus
import org.apache.commons.httpclient.methods.GetMethod
import org.junit.Assert.assertFalse
@ -77,7 +77,7 @@ class ConnectivityServiceTest {
lateinit var clientFactory: ClientFactory
@Mock
lateinit var client: OwnCloudClient
lateinit var client: HttpClient
@Mock
lateinit var getRequest: GetMethod
@ -107,7 +107,7 @@ class ConnectivityServiceTest {
)
whenever(platformConnectivityManager.activeNetworkInfo).thenReturn(networkInfo)
whenever(requestBuilder.invoke(any())).thenReturn(getRequest)
whenever(clientFactory.create(any())).thenReturn(client)
whenever(clientFactory.createPlainClient()).thenReturn(client)
whenever(accountManager.currentOwnCloudAccount).thenReturn(ownCloudAccount)
whenever(accountManager.currentAccount).thenReturn(platformAccount)
whenever(baseServerUri.toString()).thenReturn(SERVER_BASE_URL)