diff --git a/src/main/java/com/owncloud/android/utils/ConnectivityUtils.java b/src/main/java/com/owncloud/android/utils/ConnectivityUtils.java index be429c4f2a..3588e5f149 100644 --- a/src/main/java/com/owncloud/android/utils/ConnectivityUtils.java +++ b/src/main/java/com/owncloud/android/utils/ConnectivityUtils.java @@ -28,6 +28,7 @@ import android.content.Context; import com.evernote.android.job.JobRequest; import com.evernote.android.job.util.Device; +import com.owncloud.android.MainApp; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.utils.Log_OC; @@ -37,10 +38,9 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; +import java.net.HttpURLConnection; import java.net.URL; -import javax.net.ssl.HttpsURLConnection; - public class ConnectivityUtils { private final static String TAG = ConnectivityUtils.class.getName(); @@ -49,34 +49,37 @@ public class ConnectivityUtils { if (!Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY)) { try { Account account = AccountUtils.getCurrentOwnCloudAccount(context); - OwnCloudAccount ocAccount = new OwnCloudAccount(account, context); - OwnCloudVersion serverVersion = AccountUtils.getServerVersion(account); + if (account != null) { + OwnCloudAccount ocAccount = new OwnCloudAccount(account, context); + OwnCloudVersion serverVersion = AccountUtils.getServerVersion(account); - URL url; - if (serverVersion.compareTo(OwnCloudVersion.nextcloud_13) > 0) { - url = new URL(ocAccount.getBaseUri() + "/index.php/204"); - } else { - url = new URL(ocAccount.getBaseUri() + "/status.php"); - } - HttpsURLConnection urlc = (HttpsURLConnection) (url.openConnection()); - urlc.setRequestProperty("User-Agent", "Android"); - urlc.setRequestProperty("Connection", "close"); - urlc.setConnectTimeout(2500); - urlc.connect(); + URL url; + if (serverVersion.compareTo(OwnCloudVersion.nextcloud_13) > 0) { + url = new URL(ocAccount.getBaseUri() + "/index.php/204"); + } else { + url = new URL(ocAccount.getBaseUri() + "/status.php"); + } + + HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); + urlc.setRequestProperty("User-Agent", MainApp.getUserAgent()); + urlc.setRequestProperty("Connection", "close"); + urlc.setConnectTimeout(2500); + urlc.connect(); - if (serverVersion.compareTo(OwnCloudVersion.nextcloud_13) > 0) { - return !(urlc.getResponseCode() == 204 && urlc.getContentLength() == 0); - } else { - if (urlc.getResponseCode() == 200) { - // try parsing json to verify response - try { - new JSONObject(urlc.getResponseMessage()); - return false; - } catch (JSONException e) { + if (serverVersion.compareTo(OwnCloudVersion.nextcloud_13) > 0) { + return !(urlc.getResponseCode() == 204 && urlc.getContentLength() == 0); + } else { + if (urlc.getResponseCode() == 200) { + // try parsing json to verify response + try { + new JSONObject(urlc.getResponseMessage()); + return false; + } catch (JSONException e) { + return true; + } + } else { return true; } - } else { - return true; } } } catch (IOException e) { @@ -84,8 +87,6 @@ public class ConnectivityUtils { } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) { Log_OC.e(TAG, "Account not found", e); } - } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) { - Log_OC.d(TAG, "No account found"); } return true; diff --git a/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java b/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java index 8cc6e8b52d..133939a7ed 100644 --- a/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java +++ b/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java @@ -229,10 +229,12 @@ public class FilesSyncHelper { } } - if (!Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY) && - !ConnectivityUtils.isInternetWalled(context)) { - uploadRequester.retryFailedUploads(context, null, null); - } + new Thread(() -> { + if (!Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY) && + !ConnectivityUtils.isInternetWalled(context)) { + uploadRequester.retryFailedUploads(context, null, null); + } + }).start(); } @RequiresApi(api = Build.VERSION_CODES.N)