Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**WIFI PROXY*/
- public static Object getField(Object obj, String name)
- throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
- Field f = obj.getClass().getField(name);
- Object out = f.get(obj);
- return out;
- }
- public static Object getDeclaredField(Object obj, String name)
- throws SecurityException, NoSuchFieldException,
- IllegalArgumentException, IllegalAccessException {
- Field f = obj.getClass().getDeclaredField(name);
- f.setAccessible(true);
- Object out = f.get(obj);
- return out;
- }
- public static void setEnumField(Object obj, String value, String name)
- throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
- Field f = obj.getClass().getField(name);
- f.set(obj, Enum.valueOf((Class<Enum>) f.getType(), value));
- }
- public static void setProxySettings(String assign , WifiConfiguration wifiConf)
- throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException{
- setEnumField(wifiConf, assign, "proxySettings");
- }
- void setWifiProxySettings()
- {
- if(null == conf)
- return;
- try
- {
- //get the link properties from the wifi configuration
- Object linkProperties = getDeclaredField(conf, "linkProperties");
- if(null == linkProperties)
- return;
- //get the setHttpProxy method for LinkProperties
- Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties");
- Class[] setHttpProxyParams = new Class[1];
- setHttpProxyParams[0] = proxyPropertiesClass;
- Class lpClass = Class.forName("android.net.LinkProperties");
- Method setHttpProxy = lpClass.getDeclaredMethod("setHttpProxy", setHttpProxyParams);
- setHttpProxy.setAccessible(true);
- //get ProxyProperties constructor
- Class[] proxyPropertiesCtorParamTypes = new Class[3];
- proxyPropertiesCtorParamTypes[0] = String.class;
- proxyPropertiesCtorParamTypes[1] = int.class;
- proxyPropertiesCtorParamTypes[2] = String.class;
- Constructor proxyPropertiesCtor = proxyPropertiesClass.getConstructor(proxyPropertiesCtorParamTypes);
- //create the parameters for the constructor
- Object[] proxyPropertiesCtorParams = new Object[3];
- proxyPropertiesCtorParams[0] = "orion.ucf.edu.cu";
- proxyPropertiesCtorParams[1] = 3128;
- proxyPropertiesCtorParams[2] = "*.ucf.edu.cu";
- //create a new object using the params
- Object proxySettings = proxyPropertiesCtor.newInstance(proxyPropertiesCtorParams);
- //pass the new object to setHttpProxy
- Object[] params = new Object[1];
- params[0] = proxySettings;
- setHttpProxy.invoke(linkProperties, params);
- setProxySettings("DHCP", conf);
- //save the settings
- wifiManager.updateNetwork(conf);
- /*wifiManager.disconnect();
- wifiManager.reconnect();*/
- }
- catch(Exception e)
- {
- Log.d("Porque se jodio", e.getMessage());
- }
- }
- final Dialog builder = new Dialog(this);
- View v = LayoutInflater.from(this).inflate(R.layout.login_show_eap, null);
- builder.setContentView(v);
- TextView textView = (TextView) v.findViewById(R.id.red_info);
- final TextInputEditText textUser = (TextInputEditText) v.findViewById(R.id.user_name_eap);
- final TextInputEditText textPassw = (TextInputEditText) v.findViewById(R.id.user_passw_eap);
- Button btnAccept = (Button) v.findViewById(R.id.btnLoginShowEap);
- textView.setText(scanResult.SSID);
- final String[] identity = new String[1];
- final String[] passw = new String[1];
- btnAccept.setOnClickListener(new View.OnClickListener() {
- @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
- @Override
- public void onClick(View view) {
- if (textUser.getText().toString().isEmpty()) {
- textUser.setError(getString(R.string.error_field_required));
- } else if (textPassw.getText().toString().isEmpty()) {
- textPassw.setError(getString(R.string.error_field_required));
- } else {
- passw[0] = textPassw.getText().toString();
- identity[0] = textUser.getText().toString();
- networkPass = passw[0];
- networkIdentity = identity[0];
- builder.dismiss();
- helperConnect(scanResult);
- }
- }
- });
- builder.show();
- }
Add Comment
Please, Sign In to add comment