@SuppressLint("NewApi") private void showProxyFields() { WifiConfiguration config = null; mView.findViewById(R.id.proxy_settings_fields).setVisibility(View.VISIBLE); if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) { config = mAccessPoint.getConfig(); } if (mProxySettingsSpinner.getSelectedItemPosition() == PROXY_STATIC) { mView.findViewById(R.id.proxy_warning_limited_support).setVisibility(View.VISIBLE); mView.findViewById(R.id.proxy_fields).setVisibility(View.VISIBLE); if (mProxyHostView == null) { mProxyHostView = (TextView) mView.findViewById(R.id.proxy_hostname); mProxyHostView.addTextChangedListener(this); mProxyPortView = (TextView) mView.findViewById(R.id.proxy_port); mProxyPortView.addTextChangedListener(this); mProxyExclusionListView = (TextView) mView.findViewById(R.id.proxy_exclusionlist); mProxyExclusionListView.addTextChangedListener(this); } if (config != null) { ProxyProperties proxyProperties = config.linkProperties.getHttpProxy(); if (proxyProperties != null) { mProxyHostView.setText(proxyProperties.getHost()); mProxyPortView.setText(Integer.toString(proxyProperties.getPort())); mProxyExclusionListView.setText(proxyProperties.getExclusionList()); } } } else { mView.findViewById(R.id.proxy_warning_limited_support).setVisibility(View.GONE); mView.findViewById(R.id.proxy_fields).setVisibility(View.GONE); } }
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); ProxyProperties proxy = cm.getGlobalProxy(); if (proxy != null) { hostname = proxy.getHost(); port = proxy.getPort(); exclList = proxy.getExclusionList(); } 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); } }
/** * 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; } } ProxyProperties p = new ProxyProperties(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; }
public LinkProperties createFromParcel(Parcel in) { LinkProperties netProp = new LinkProperties(); String iface = in.readString(); if (iface != null) { netProp.setInterfaceName(iface); } int addressCount = in.readInt(); for (int i=0; i<addressCount; i++) { netProp.addLinkAddress((LinkAddress)in.readParcelable(null)); } addressCount = in.readInt(); for (int i=0; i<addressCount; i++) { try { netProp.addDns(InetAddress.getByAddress(in.createByteArray())); } catch (UnknownHostException e) { } } netProp.setDomains(in.readString()); netProp.setMtu(in.readInt()); addressCount = in.readInt(); for (int i=0; i<addressCount; i++) { netProp.addRoute((RouteInfo)in.readParcelable(null)); } if (in.readByte() == 1) { netProp.setHttpProxy((ProxyProperties)in.readParcelable(null)); } ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>(); in.readList(stackedLinks, LinkProperties.class.getClassLoader()); for (LinkProperties stackedLink: stackedLinks) { netProp.addStackedLink(stackedLink); } return netProp; }
public LinkProperties(LinkProperties source) { if (source != null) { mIfaceName = source.getInterfaceName(); for (LinkAddress l : source.getLinkAddresses()) mLinkAddresses.add(l); for (InetAddress i : source.getDnses()) mDnses.add(i); for (RouteInfo r : source.getRoutes()) mRoutes.add(r); mHttpProxy = (source.getHttpProxy() == null) ? null : new ProxyProperties(source.getHttpProxy()); } }
private void handleProxyBroadcast(Intent intent) { ProxyProperties props = (ProxyProperties)intent.getExtra(Proxy.EXTRA_PROXY_INFO); if (props == null || props.getHost() == null) { updateProxyConfig(null); } else { updateProxyConfig(props); } }
public void setHttpProxy(ProxyProperties proxy) { mHttpProxy = proxy; }
public ProxyProperties getHttpProxy() { return mHttpProxy; }
private native void updateProxyConfig(ProxyProperties props);