Search in sources :

Example 16 with ProxyInfo

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

the class ConnectivityService method handleDeprecatedGlobalHttpProxy.

private void handleDeprecatedGlobalHttpProxy() {
    String proxy = Settings.Global.getString(mContext.getContentResolver(), Settings.Global.HTTP_PROXY);
    if (!TextUtils.isEmpty(proxy)) {
        String[] data = proxy.split(":");
        if (data.length == 0) {
            return;
        }
        String proxyHost = data[0];
        int proxyPort = 8080;
        if (data.length > 1) {
            try {
                proxyPort = Integer.parseInt(data[1]);
            } catch (NumberFormatException e) {
                return;
            }
        }
        ProxyInfo p = new ProxyInfo(data[0], proxyPort, "");
        setGlobalProxy(p);
    }
}
Also used : ProxyInfo(android.net.ProxyInfo) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString)

Example 17 with ProxyInfo

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

the class ConnectivityService method setGlobalProxy.

public void setGlobalProxy(ProxyInfo proxyProperties) {
    enforceConnectivityInternalPermission();
    synchronized (mProxyLock) {
        if (proxyProperties == mGlobalProxy)
            return;
        if (proxyProperties != null && proxyProperties.equals(mGlobalProxy))
            return;
        if (mGlobalProxy != null && mGlobalProxy.equals(proxyProperties))
            return;
        String host = "";
        int port = 0;
        String exclList = "";
        String pacFileUrl = "";
        if (proxyProperties != null && (!TextUtils.isEmpty(proxyProperties.getHost()) || !Uri.EMPTY.equals(proxyProperties.getPacFileUrl()))) {
            if (!proxyProperties.isValid()) {
                if (DBG)
                    log("Invalid proxy properties, ignoring: " + proxyProperties.toString());
                return;
            }
            mGlobalProxy = new ProxyInfo(proxyProperties);
            host = mGlobalProxy.getHost();
            port = mGlobalProxy.getPort();
            exclList = mGlobalProxy.getExclusionListAsString();
            if (!Uri.EMPTY.equals(proxyProperties.getPacFileUrl())) {
                pacFileUrl = proxyProperties.getPacFileUrl().toString();
            }
        } else {
            mGlobalProxy = null;
        }
        ContentResolver res = mContext.getContentResolver();
        final long token = Binder.clearCallingIdentity();
        try {
            Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, host);
            Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, port);
            Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, exclList);
            Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC, pacFileUrl);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        if (mGlobalProxy == null) {
            proxyProperties = mDefaultProxy;
        }
        sendProxyBroadcast(proxyProperties);
    }
}
Also used : ProxyInfo(android.net.ProxyInfo) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString) ContentResolver(android.content.ContentResolver)

Example 18 with ProxyInfo

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

the class DevicePolicyManagerService method saveGlobalProxyLocked.

private void saveGlobalProxyLocked(String proxySpec, String exclusionList) {
    if (exclusionList == null) {
        exclusionList = "";
    }
    if (proxySpec == null) {
        proxySpec = "";
    }
    // Remove white spaces
    proxySpec = proxySpec.trim();
    String[] data = proxySpec.split(":");
    int proxyPort = 8080;
    if (data.length > 1) {
        try {
            proxyPort = Integer.parseInt(data[1]);
        } catch (NumberFormatException e) {
        }
    }
    exclusionList = exclusionList.trim();
    ProxyInfo proxyProperties = new ProxyInfo(data[0], proxyPort, exclusionList);
    if (!proxyProperties.isValid()) {
        Slog.e(LOG_TAG, "Invalid proxy properties, ignoring: " + proxyProperties.toString());
        return;
    }
    mInjector.settingsGlobalPutString(Settings.Global.GLOBAL_HTTP_PROXY_HOST, data[0]);
    mInjector.settingsGlobalPutInt(Settings.Global.GLOBAL_HTTP_PROXY_PORT, proxyPort);
    mInjector.settingsGlobalPutString(Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, exclusionList);
}
Also used : ProxyInfo(android.net.ProxyInfo) ParcelableString(com.android.internal.util.ParcelableString)

Example 19 with ProxyInfo

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

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

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

the class ProxySelector method populateFields.

void populateFields() {
    final Activity activity = getActivity();
    String hostname = "";
    int port = -1;
    String exclList = "";
    // Use the last setting given by the user
    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    ProxyInfo proxy = cm.getGlobalProxy();
    if (proxy != null) {
        hostname = proxy.getHost();
        port = proxy.getPort();
        exclList = proxy.getExclusionListAsString();
    }
    if (hostname == null) {
        hostname = "";
    }
    mHostnameField.setText(hostname);
    String portStr = port == -1 ? "" : Integer.toString(port);
    mPortField.setText(portStr);
    mExclusionListField.setText(exclList);
    final Intent intent = activity.getIntent();
    String buttonLabel = intent.getStringExtra("button-label");
    if (!TextUtils.isEmpty(buttonLabel)) {
        mOKButton.setText(buttonLabel);
    }
    String title = intent.getStringExtra("title");
    if (!TextUtils.isEmpty(title)) {
        activity.setTitle(title);
    }
}
Also used : ProxyInfo(android.net.ProxyInfo) ConnectivityManager(android.net.ConnectivityManager) Activity(android.app.Activity) Intent(android.content.Intent)

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