Fix casting

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-12-06 10:41:29 +01:00 committed by tobiaskaminsky
parent 626f2b68a2
commit c3889f2afc
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 35 additions and 32 deletions

View file

@ -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;

View file

@ -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)