Search in sources :

Example 46 with ProxyInfo

use of android.net.ProxyInfo in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityService method updateProxy.

// If the proxy has changed from oldLp to newLp, resend proxy broadcast with default proxy.
// This method gets called when any network changes proxy, but the broadcast only ever contains
// the default proxy (even if it hasn't changed).
// TODO: Deprecate the broadcast extras as they aren't necessarily applicable in a multi-network
// world where an app might be bound to a non-default network.
private void updateProxy(LinkProperties newLp, LinkProperties oldLp, NetworkAgentInfo nai) {
    ProxyInfo newProxyInfo = newLp == null ? null : newLp.getHttpProxy();
    ProxyInfo oldProxyInfo = oldLp == null ? null : oldLp.getHttpProxy();
    if (!proxyInfoEqual(newProxyInfo, oldProxyInfo)) {
        sendProxyBroadcast(getDefaultProxy());
    }
}
Also used : ProxyInfo(android.net.ProxyInfo)

Example 47 with ProxyInfo

use of android.net.ProxyInfo in project android_frameworks_base by DirtyUnicorns.

the class NetworkMonitor method isCaptivePortal.

@VisibleForTesting
protected CaptivePortalProbeResult isCaptivePortal() {
    if (!mIsCaptivePortalCheckEnabled) {
        validationLog("Validation disabled.");
        return new CaptivePortalProbeResult(204);
    }
    URL pacUrl = null, httpsUrl = null, httpUrl = null, fallbackUrl = null;
    // On networks with a PAC instead of fetching a URL that should result in a 204
    // response, we instead simply fetch the PAC script.  This is done for a few reasons:
    // 1. At present our PAC code does not yet handle multiple PACs on multiple networks
    //    until something like https://android-review.googlesource.com/#/c/115180/ lands.
    //    Network.openConnection() will ignore network-specific PACs and instead fetch
    //    using NO_PROXY.  If a PAC is in place, the only fetch we know will succeed with
    //    NO_PROXY is the fetch of the PAC itself.
    // 2. To proxy the generate_204 fetch through a PAC would require a number of things
    //    happen before the fetch can commence, namely:
    //        a) the PAC script be fetched
    //        b) a PAC script resolver service be fired up and resolve the captive portal
    //           server.
    //    Network validation could be delayed until these prerequisities are satisifed or
    //    could simply be left to race them.  Neither is an optimal solution.
    // 3. PAC scripts are sometimes used to block or restrict Internet access and may in
    //    fact block fetching of the generate_204 URL which would lead to false negative
    //    results for network validation.
    final ProxyInfo proxyInfo = mNetworkAgentInfo.linkProperties.getHttpProxy();
    if (proxyInfo != null && !Uri.EMPTY.equals(proxyInfo.getPacFileUrl())) {
        pacUrl = makeURL(proxyInfo.getPacFileUrl().toString());
        if (pacUrl == null) {
            return CaptivePortalProbeResult.FAILED;
        }
    }
    if (pacUrl == null) {
        httpsUrl = makeURL(getCaptivePortalServerHttpsUrl(mContext));
        httpUrl = makeURL(getCaptivePortalServerHttpUrl(mContext));
        fallbackUrl = makeURL(getCaptivePortalFallbackUrl(mContext));
        if (httpUrl == null || httpsUrl == null) {
            return CaptivePortalProbeResult.FAILED;
        }
    }
    long startTime = SystemClock.elapsedRealtime();
    final CaptivePortalProbeResult result;
    if (pacUrl != null) {
        result = sendDnsAndHttpProbes(null, pacUrl, ValidationProbeEvent.PROBE_PAC);
    } else if (mUseHttps) {
        result = sendParallelHttpProbes(proxyInfo, httpsUrl, httpUrl, fallbackUrl);
    } else {
        result = sendDnsAndHttpProbes(proxyInfo, httpUrl, ValidationProbeEvent.PROBE_HTTP);
    }
    long endTime = SystemClock.elapsedRealtime();
    sendNetworkConditionsBroadcast(true, /* response received */
    result.isPortal(), /* isCaptivePortal */
    startTime, endTime);
    return result;
}
Also used : ProxyInfo(android.net.ProxyInfo) URL(java.net.URL) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 48 with ProxyInfo

use of android.net.ProxyInfo in project android_frameworks_base by DirtyUnicorns.

the class PacManager method sendProxyIfNeeded.

private synchronized void sendProxyIfNeeded() {
    if (!mHasDownloaded || (mLastPort == -1)) {
        return;
    }
    if (!mHasSentBroadcast) {
        sendPacBroadcast(new ProxyInfo(mPacUrl, mLastPort));
        mHasSentBroadcast = true;
    }
}
Also used : ProxyInfo(android.net.ProxyInfo)

Example 49 with ProxyInfo

use of android.net.ProxyInfo in project android_frameworks_base by DirtyUnicorns.

the class IpConfigStore method writeConfig.

private boolean writeConfig(DataOutputStream out, int configKey, IpConfiguration config) throws IOException {
    boolean written = false;
    try {
        switch(config.ipAssignment) {
            case STATIC:
                out.writeUTF(IP_ASSIGNMENT_KEY);
                out.writeUTF(config.ipAssignment.toString());
                StaticIpConfiguration staticIpConfiguration = config.staticIpConfiguration;
                if (staticIpConfiguration != null) {
                    if (staticIpConfiguration.ipAddress != null) {
                        LinkAddress ipAddress = staticIpConfiguration.ipAddress;
                        out.writeUTF(LINK_ADDRESS_KEY);
                        out.writeUTF(ipAddress.getAddress().getHostAddress());
                        out.writeInt(ipAddress.getPrefixLength());
                    }
                    if (staticIpConfiguration.gateway != null) {
                        out.writeUTF(GATEWAY_KEY);
                        // Default route.
                        out.writeInt(0);
                        // Have a gateway.
                        out.writeInt(1);
                        out.writeUTF(staticIpConfiguration.gateway.getHostAddress());
                    }
                    for (InetAddress inetAddr : staticIpConfiguration.dnsServers) {
                        out.writeUTF(DNS_KEY);
                        out.writeUTF(inetAddr.getHostAddress());
                    }
                }
                written = true;
                break;
            case DHCP:
                out.writeUTF(IP_ASSIGNMENT_KEY);
                out.writeUTF(config.ipAssignment.toString());
                written = true;
                break;
            case UNASSIGNED:
                /* Ignore */
                break;
            default:
                loge("Ignore invalid ip assignment while writing");
                break;
        }
        switch(config.proxySettings) {
            case STATIC:
                ProxyInfo proxyProperties = config.httpProxy;
                String exclusionList = proxyProperties.getExclusionListAsString();
                out.writeUTF(PROXY_SETTINGS_KEY);
                out.writeUTF(config.proxySettings.toString());
                out.writeUTF(PROXY_HOST_KEY);
                out.writeUTF(proxyProperties.getHost());
                out.writeUTF(PROXY_PORT_KEY);
                out.writeInt(proxyProperties.getPort());
                if (exclusionList != null) {
                    out.writeUTF(EXCLUSION_LIST_KEY);
                    out.writeUTF(exclusionList);
                }
                written = true;
                break;
            case PAC:
                ProxyInfo proxyPacProperties = config.httpProxy;
                out.writeUTF(PROXY_SETTINGS_KEY);
                out.writeUTF(config.proxySettings.toString());
                out.writeUTF(PROXY_PAC_FILE);
                out.writeUTF(proxyPacProperties.getPacFileUrl().toString());
                written = true;
                break;
            case NONE:
                out.writeUTF(PROXY_SETTINGS_KEY);
                out.writeUTF(config.proxySettings.toString());
                written = true;
                break;
            case UNASSIGNED:
                /* Ignore */
                break;
            default:
                loge("Ignore invalid proxy settings while writing");
                break;
        }
        if (written) {
            out.writeUTF(ID_KEY);
            out.writeInt(configKey);
        }
    } catch (NullPointerException e) {
        loge("Failure in writing " + config + e);
    }
    out.writeUTF(EOS);
    return written;
}
Also used : LinkAddress(android.net.LinkAddress) ProxyInfo(android.net.ProxyInfo) StaticIpConfiguration(android.net.StaticIpConfiguration) InetAddress(java.net.InetAddress)

Example 50 with ProxyInfo

use of android.net.ProxyInfo in project android_frameworks_base by AOSPA.

the class NetworkMonitor method isCaptivePortal.

@VisibleForTesting
protected CaptivePortalProbeResult isCaptivePortal() {
    if (!mIsCaptivePortalCheckEnabled) {
        validationLog("Validation disabled.");
        return new CaptivePortalProbeResult(204);
    }
    URL pacUrl = null, httpsUrl = null, httpUrl = null, fallbackUrl = null;
    // On networks with a PAC instead of fetching a URL that should result in a 204
    // response, we instead simply fetch the PAC script.  This is done for a few reasons:
    // 1. At present our PAC code does not yet handle multiple PACs on multiple networks
    //    until something like https://android-review.googlesource.com/#/c/115180/ lands.
    //    Network.openConnection() will ignore network-specific PACs and instead fetch
    //    using NO_PROXY.  If a PAC is in place, the only fetch we know will succeed with
    //    NO_PROXY is the fetch of the PAC itself.
    // 2. To proxy the generate_204 fetch through a PAC would require a number of things
    //    happen before the fetch can commence, namely:
    //        a) the PAC script be fetched
    //        b) a PAC script resolver service be fired up and resolve the captive portal
    //           server.
    //    Network validation could be delayed until these prerequisities are satisifed or
    //    could simply be left to race them.  Neither is an optimal solution.
    // 3. PAC scripts are sometimes used to block or restrict Internet access and may in
    //    fact block fetching of the generate_204 URL which would lead to false negative
    //    results for network validation.
    final ProxyInfo proxyInfo = mNetworkAgentInfo.linkProperties.getHttpProxy();
    if (proxyInfo != null && !Uri.EMPTY.equals(proxyInfo.getPacFileUrl())) {
        pacUrl = makeURL(proxyInfo.getPacFileUrl().toString());
        if (pacUrl == null) {
            return CaptivePortalProbeResult.FAILED;
        }
    }
    if (pacUrl == null) {
        httpsUrl = makeURL(getCaptivePortalServerHttpsUrl(mContext));
        httpUrl = makeURL(getCaptivePortalServerHttpUrl(mContext));
        fallbackUrl = makeURL(getCaptivePortalFallbackUrl(mContext));
        if (httpUrl == null || httpsUrl == null) {
            return CaptivePortalProbeResult.FAILED;
        }
    }
    long startTime = SystemClock.elapsedRealtime();
    final CaptivePortalProbeResult result;
    if (pacUrl != null) {
        result = sendDnsAndHttpProbes(null, pacUrl, ValidationProbeEvent.PROBE_PAC);
    } else if (mUseHttps) {
        result = sendParallelHttpProbes(proxyInfo, httpsUrl, httpUrl, fallbackUrl);
    } else {
        result = sendDnsAndHttpProbes(proxyInfo, httpUrl, ValidationProbeEvent.PROBE_HTTP);
    }
    long endTime = SystemClock.elapsedRealtime();
    sendNetworkConditionsBroadcast(true, /* response received */
    result.isPortal(), /* isCaptivePortal */
    startTime, endTime);
    return result;
}
Also used : ProxyInfo(android.net.ProxyInfo) URL(java.net.URL) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

ProxyInfo (android.net.ProxyInfo)66 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 StaticIpConfiguration (android.net.StaticIpConfiguration)11 ContentResolver (android.content.ContentResolver)10 LinkAddress (android.net.LinkAddress)10 IOException (java.io.IOException)10 InetAddress (java.net.InetAddress)10 Intent (android.content.Intent)8 PendingIntent (android.app.PendingIntent)7 ApplicationInfo (android.content.pm.ApplicationInfo)7 RemoteException (android.os.RemoteException)7 ProxySettings (android.net.IpConfiguration.ProxySettings)6 ComponentName (android.content.ComponentName)5 Context (android.content.Context)5 IPackageManager (android.content.pm.IPackageManager)5 InstrumentationInfo (android.content.pm.InstrumentationInfo)5 IpConfiguration (android.net.IpConfiguration)5 IpAssignment (android.net.IpConfiguration.IpAssignment)5 RouteInfo (android.net.RouteInfo)5 SparseArray (android.util.SparseArray)5