Search in sources :

Example 1 with PlainClient

use of com.nextcloud.common.PlainClient in project android by nextcloud.

the class ConnectivityServiceImpl method isInternetWalled.

@Override
public boolean isInternetWalled() {
    Connectivity c = getConnectivity();
    if (c.isConnected() && c.isWifi() && !c.isMetered()) {
        Server server = accountManager.getUser().getServer();
        String baseServerAddress = server.getUri().toString();
        if (baseServerAddress.isEmpty()) {
            return true;
        }
        GetMethod get = requestBuilder.invoke(baseServerAddress + "/index.php/204");
        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
        boolean result = !(status == HttpStatus.SC_NO_CONTENT && get.getResponseContentLength() <= 0);
        get.releaseConnection();
        return result;
    } else {
        return !c.isConnected();
    }
}
Also used : Server(com.nextcloud.client.account.Server) PlainClient(com.nextcloud.common.PlainClient) GetMethod(com.nextcloud.operations.GetMethod)

Aggregations

Server (com.nextcloud.client.account.Server)1 PlainClient (com.nextcloud.common.PlainClient)1 GetMethod (com.nextcloud.operations.GetMethod)1