dont set cache value when base server address is empty

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-09-10 14:49:42 +02:00 committed by Alper Öztürk
parent 53e70282b1
commit 25f75114fb
2 changed files with 13 additions and 25 deletions

View file

@ -90,28 +90,23 @@ class ConnectivityServiceImpl implements ConnectivityService {
if (cachedValue != null) {
return cachedValue;
} else {
Server server = accountManager.getUser().getServer();
String baseServerAddress = server.getUri().toString();
boolean result;
Connectivity c = getConnectivity();
if (c.isConnected() && c.isWifi() && !c.isMetered()) {
if (c.isConnected() && c.isWifi() && !c.isMetered() && !baseServerAddress.isEmpty()) {
GetMethod get = requestBuilder.invoke(baseServerAddress + CONNECTIVITY_CHECK_ROUTE);
PlainClient client = clientFactory.createPlainClient();
Server server = accountManager.getUser().getServer();
String baseServerAddress = server.getUri().toString();
if (baseServerAddress.isEmpty()) {
result = true;
} else {
int status = get.execute(client);
GetMethod get = requestBuilder.invoke(baseServerAddress + CONNECTIVITY_CHECK_ROUTE);
PlainClient client = clientFactory.createPlainClient();
int status = get.execute(client);
// Content-Length is not available when using chunked transfer encoding, so check for -1 as well
result = !(status == HttpStatus.SC_NO_CONTENT && get.getResponseContentLength() <= 0);
get.releaseConnection();
if (result) {
Log_OC.w(TAG, "isInternetWalled(): Failed to GET " + CONNECTIVITY_CHECK_ROUTE + "," +
" assuming connectivity is impaired");
}
// Content-Length is not available when using chunked transfer encoding, so check for -1 as well
result = !(status == HttpStatus.SC_NO_CONTENT && get.getResponseContentLength() <= 0);
get.releaseConnection();
if (result) {
Log_OC.w(TAG, "isInternetWalled(): Failed to GET " + CONNECTIVITY_CHECK_ROUTE + "," +
" assuming connectivity is impaired");
}
} else {
result = !c.isConnected();

View file

@ -182,8 +182,6 @@ public abstract class FileActivity extends DrawerActivity
private NetworkChangeReceiver networkChangeReceiver;
private static boolean clearConnectivityCacheValue = true;
private void registerNetworkChangeReceiver() {
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(networkChangeReceiver, filter);
@ -242,11 +240,6 @@ public abstract class FileActivity extends DrawerActivity
bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection,
Context.BIND_AUTO_CREATE);
registerNetworkChangeReceiver();
if (clearConnectivityCacheValue) {
connectivityService.clearCachedResult();
clearConnectivityCacheValue = false;
}
}
@Override