Search in sources :

Example 6 with ProxyProperties

use of android.net.ProxyProperties in project android_frameworks_base by ParanoidAndroid.

the class WifiConfigStore method writeIpAndProxyConfigurationsOnChange.

/* Compare current and new configuration and write to file on change */
private NetworkUpdateResult writeIpAndProxyConfigurationsOnChange(WifiConfiguration currentConfig, WifiConfiguration newConfig) {
    boolean ipChanged = false;
    boolean proxyChanged = false;
    LinkProperties linkProperties = null;
    switch(newConfig.ipAssignment) {
        case STATIC:
            Collection<LinkAddress> currentLinkAddresses = currentConfig.linkProperties.getLinkAddresses();
            Collection<LinkAddress> newLinkAddresses = newConfig.linkProperties.getLinkAddresses();
            Collection<InetAddress> currentDnses = currentConfig.linkProperties.getDnses();
            Collection<InetAddress> newDnses = newConfig.linkProperties.getDnses();
            Collection<RouteInfo> currentRoutes = currentConfig.linkProperties.getRoutes();
            Collection<RouteInfo> newRoutes = newConfig.linkProperties.getRoutes();
            boolean linkAddressesDiffer = (currentLinkAddresses.size() != newLinkAddresses.size()) || !currentLinkAddresses.containsAll(newLinkAddresses);
            boolean dnsesDiffer = (currentDnses.size() != newDnses.size()) || !currentDnses.containsAll(newDnses);
            boolean routesDiffer = (currentRoutes.size() != newRoutes.size()) || !currentRoutes.containsAll(newRoutes);
            if ((currentConfig.ipAssignment != newConfig.ipAssignment) || linkAddressesDiffer || dnsesDiffer || routesDiffer) {
                ipChanged = true;
            }
            break;
        case DHCP:
            if (currentConfig.ipAssignment != newConfig.ipAssignment) {
                ipChanged = true;
            }
            break;
        case UNASSIGNED:
            /* Ignore */
            break;
        default:
            loge("Ignore invalid ip assignment during write");
            break;
    }
    switch(newConfig.proxySettings) {
        case STATIC:
            ProxyProperties newHttpProxy = newConfig.linkProperties.getHttpProxy();
            ProxyProperties currentHttpProxy = currentConfig.linkProperties.getHttpProxy();
            if (newHttpProxy != null) {
                proxyChanged = !newHttpProxy.equals(currentHttpProxy);
            } else {
                proxyChanged = (currentHttpProxy != null);
            }
            break;
        case NONE:
            if (currentConfig.proxySettings != newConfig.proxySettings) {
                proxyChanged = true;
            }
            break;
        case UNASSIGNED:
            /* Ignore */
            break;
        default:
            loge("Ignore invalid proxy configuration during write");
            break;
    }
    if (!ipChanged) {
        linkProperties = copyIpSettingsFromConfig(currentConfig);
    } else {
        currentConfig.ipAssignment = newConfig.ipAssignment;
        linkProperties = copyIpSettingsFromConfig(newConfig);
        log("IP config changed SSID = " + currentConfig.SSID + " linkProperties: " + linkProperties.toString());
    }
    if (!proxyChanged) {
        linkProperties.setHttpProxy(currentConfig.linkProperties.getHttpProxy());
    } else {
        currentConfig.proxySettings = newConfig.proxySettings;
        linkProperties.setHttpProxy(newConfig.linkProperties.getHttpProxy());
        log("proxy changed SSID = " + currentConfig.SSID);
        if (linkProperties.getHttpProxy() != null) {
            log(" proxyProperties: " + linkProperties.getHttpProxy().toString());
        }
    }
    if (ipChanged || proxyChanged) {
        currentConfig.linkProperties = linkProperties;
        writeIpAndProxyConfigurations();
        sendConfiguredNetworksChangedBroadcast(currentConfig, WifiManager.CHANGE_REASON_CONFIG_CHANGE);
    }
    return new NetworkUpdateResult(ipChanged, proxyChanged);
}
Also used : LinkAddress(android.net.LinkAddress) ProxyProperties(android.net.ProxyProperties) NetworkUpdateResult(android.net.wifi.NetworkUpdateResult) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 7 with ProxyProperties

use of android.net.ProxyProperties in project android_frameworks_base by ParanoidAndroid.

the class WifiConfigStore method clearLinkProperties.

/**
     * clear IP configuration for a given network id
     * @param network id
     */
void clearLinkProperties(int netId) {
    WifiConfiguration config = mConfiguredNetworks.get(netId);
    if (config != null && config.linkProperties != null) {
        // Clear everything except proxy
        ProxyProperties proxy = config.linkProperties.getHttpProxy();
        config.linkProperties.clear();
        config.linkProperties.setHttpProxy(proxy);
    }
}
Also used : ProxyProperties(android.net.ProxyProperties)

Example 8 with ProxyProperties

use of android.net.ProxyProperties in project XobotOS by xamarin.

the class WebView method handleProxyBroadcast.

private static void handleProxyBroadcast(Intent intent) {
    ProxyProperties proxyProperties = (ProxyProperties) intent.getExtra(Proxy.EXTRA_PROXY_INFO);
    if (proxyProperties == null || proxyProperties.getHost() == null) {
        WebViewCore.sendStaticMessage(EventHub.PROXY_CHANGED, null);
        return;
    }
    WebViewCore.sendStaticMessage(EventHub.PROXY_CHANGED, proxyProperties);
}
Also used : ProxyProperties(android.net.ProxyProperties)

Example 9 with ProxyProperties

use of android.net.ProxyProperties in project XobotOS by xamarin.

the class Proxy method getProxy.

/**
     * Return the proxy object to be used for the URL given as parameter.
     * @param ctx A Context used to get the settings for the proxy host.
     * @param url A URL to be accessed. Used to evaluate exclusion list.
     * @return Proxy (java.net) object containing the host name. If the
     *         user did not set a hostname it returns the default host.
     *         A null value means that no host is to be used.
     * {@hide}
     */
public static final java.net.Proxy getProxy(Context ctx, String url) {
    String host = "";
    if (url != null) {
        URI uri = URI.create(url);
        host = uri.getHost();
    }
    if (!isLocalHost(host)) {
        if (sConnectivityManager == null) {
            sConnectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
        }
        if (sConnectivityManager == null)
            return java.net.Proxy.NO_PROXY;
        ProxyProperties proxyProperties = sConnectivityManager.getProxy();
        if (proxyProperties != null) {
            if (!proxyProperties.isExcluded(host)) {
                return proxyProperties.makeProxy();
            }
        }
    }
    return java.net.Proxy.NO_PROXY;
}
Also used : ProxyProperties(android.net.ProxyProperties) URI(java.net.URI)

Example 10 with ProxyProperties

use of android.net.ProxyProperties in project XobotOS by xamarin.

the class WifiConfigStore method clearIpConfiguration.

/**
     * clear IP configuration for a given network id
     */
static void clearIpConfiguration(int netId) {
    synchronized (sConfiguredNetworks) {
        WifiConfiguration config = sConfiguredNetworks.get(netId);
        if (config != null && config.linkProperties != null) {
            // Clear everything except proxy
            ProxyProperties proxy = config.linkProperties.getHttpProxy();
            config.linkProperties.clear();
            config.linkProperties.setHttpProxy(proxy);
        }
    }
}
Also used : ProxyProperties(android.net.ProxyProperties)

Aggregations

ProxyProperties (android.net.ProxyProperties)20 LinkAddress (android.net.LinkAddress)5 LinkProperties (android.net.LinkProperties)5 RouteInfo (android.net.RouteInfo)5 IOException (java.io.IOException)5 InetAddress (java.net.InetAddress)5 RemoteException (android.os.RemoteException)4 PendingIntent (android.app.PendingIntent)3 Intent (android.content.Intent)3 EOFException (java.io.EOFException)3 UnknownHostException (java.net.UnknownHostException)3 ComponentName (android.content.ComponentName)2 ContentResolver (android.content.ContentResolver)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 IPackageManager (android.content.pm.IPackageManager)2 InstrumentationInfo (android.content.pm.InstrumentationInfo)2 PackageManager (android.content.pm.PackageManager)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)2 ProviderInfo (android.content.pm.ProviderInfo)2 ResolveInfo (android.content.pm.ResolveInfo)2