Search in sources :

Example 56 with ProxyInfo

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

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 57 with ProxyInfo

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

the class ConnectivityService method sendProxyBroadcast.

private void sendProxyBroadcast(ProxyInfo proxy) {
    if (proxy == null)
        proxy = new ProxyInfo("", 0, "");
    if (mPacManager.setCurrentProxyScriptUrl(proxy))
        return;
    if (DBG)
        log("sending Proxy Broadcast for " + proxy);
    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
    intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
    intent.putExtra(Proxy.EXTRA_PROXY_INFO, proxy);
    final long ident = Binder.clearCallingIdentity();
    try {
        mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : ProxyInfo(android.net.ProxyInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 58 with ProxyInfo

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

the class ConnectivityService method getProxyForNetwork.

@Override
public ProxyInfo getProxyForNetwork(Network network) {
    if (network == null)
        return getDefaultProxy();
    final ProxyInfo globalProxy = getGlobalProxy();
    if (globalProxy != null)
        return globalProxy;
    if (!NetworkUtils.queryUserAccess(Binder.getCallingUid(), network.netId))
        return null;
    // Don't call getLinkProperties() as it requires ACCESS_NETWORK_STATE permission, which
    // caller may not have.
    final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
    if (nai == null)
        return null;
    synchronized (nai) {
        final ProxyInfo proxyInfo = nai.linkProperties.getHttpProxy();
        if (proxyInfo == null)
            return null;
        return new ProxyInfo(proxyInfo);
    }
}
Also used : ProxyInfo(android.net.ProxyInfo) NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo)

Example 59 with ProxyInfo

use of android.net.ProxyInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ProxySelector method saveToDb.

/**
     * returns true on success, false if the user must correct something
     */
boolean saveToDb() {
    String hostname = mHostnameField.getText().toString().trim();
    String portStr = mPortField.getText().toString().trim();
    String exclList = mExclusionListField.getText().toString().trim();
    int port = 0;
    int result = validate(hostname, portStr, exclList);
    if (result != 0) {
        showDialog(ERROR_DIALOG_ID);
        return false;
    }
    if (portStr.length() > 0) {
        try {
            port = Integer.parseInt(portStr);
        } catch (NumberFormatException ex) {
            // should never happen - caught by validate above
            return false;
        }
    }
    ProxyInfo p = new ProxyInfo(hostname, port, exclList);
    // FIXME: The best solution would be to make a better UI that would
    // disable editing of the text boxes if the user chooses to use the
    // default settings. i.e. checking a box to always use the default
    // carrier. http:/b/issue?id=756480
    // FIXME: If the user types in a proxy that matches the default, should
    // we keep that setting? Can be fixed with a new UI.
    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    cm.setGlobalProxy(p);
    return true;
}
Also used : ProxyInfo(android.net.ProxyInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 60 with ProxyInfo

use of android.net.ProxyInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiConfigController method ipAndProxyFieldsAreValid.

private boolean ipAndProxyFieldsAreValid() {
    mIpAssignment = (mIpSettingsSpinner != null && mIpSettingsSpinner.getSelectedItemPosition() == STATIC_IP) ? IpAssignment.STATIC : IpAssignment.DHCP;
    if (mIpAssignment == IpAssignment.STATIC) {
        mStaticIpConfiguration = new StaticIpConfiguration();
        int result = validateIpConfigFields(mStaticIpConfiguration);
        if (result != 0) {
            return false;
        }
    }
    final int selectedPosition = mProxySettingsSpinner.getSelectedItemPosition();
    mProxySettings = ProxySettings.NONE;
    mHttpProxy = null;
    if (selectedPosition == PROXY_STATIC && mProxyHostView != null) {
        mProxySettings = ProxySettings.STATIC;
        String host = mProxyHostView.getText().toString();
        String portStr = mProxyPortView.getText().toString();
        String exclusionList = mProxyExclusionListView.getText().toString();
        int port = 0;
        int result = 0;
        try {
            port = Integer.parseInt(portStr);
            result = ProxySelector.validate(host, portStr, exclusionList);
        } catch (NumberFormatException e) {
            result = R.string.proxy_error_invalid_port;
        }
        if (result == 0) {
            mHttpProxy = new ProxyInfo(host, port, exclusionList);
        } else {
            return false;
        }
    } else if (selectedPosition == PROXY_PAC && mProxyPacView != null) {
        mProxySettings = ProxySettings.PAC;
        CharSequence uriSequence = mProxyPacView.getText();
        if (TextUtils.isEmpty(uriSequence)) {
            return false;
        }
        Uri uri = Uri.parse(uriSequence.toString());
        if (uri == null) {
            return false;
        }
        mHttpProxy = new ProxyInfo(uri);
    }
    return true;
}
Also used : ProxyInfo(android.net.ProxyInfo) StaticIpConfiguration(android.net.StaticIpConfiguration) Uri(android.net.Uri) AccessPoint(com.android.settingslib.wifi.AccessPoint)

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