Guest User

Untitled

a guest
Apr 23rd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. /**WIFI PROXY*/
  2.  
  3. public static Object getField(Object obj, String name)
  4. throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
  5. Field f = obj.getClass().getField(name);
  6. Object out = f.get(obj);
  7. return out;
  8. }
  9.  
  10. public static Object getDeclaredField(Object obj, String name)
  11. throws SecurityException, NoSuchFieldException,
  12. IllegalArgumentException, IllegalAccessException {
  13. Field f = obj.getClass().getDeclaredField(name);
  14. f.setAccessible(true);
  15. Object out = f.get(obj);
  16. return out;
  17. }
  18.  
  19. public static void setEnumField(Object obj, String value, String name)
  20. throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
  21. Field f = obj.getClass().getField(name);
  22. f.set(obj, Enum.valueOf((Class<Enum>) f.getType(), value));
  23. }
  24.  
  25. public static void setProxySettings(String assign , WifiConfiguration wifiConf)
  26. throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException{
  27. setEnumField(wifiConf, assign, "proxySettings");
  28. }
  29.  
  30. void setWifiProxySettings()
  31. {
  32. if(null == conf)
  33. return;
  34.  
  35. try
  36. {
  37. //get the link properties from the wifi configuration
  38. Object linkProperties = getDeclaredField(conf, "linkProperties");
  39. if(null == linkProperties)
  40. return;
  41.  
  42. //get the setHttpProxy method for LinkProperties
  43. Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties");
  44. Class[] setHttpProxyParams = new Class[1];
  45. setHttpProxyParams[0] = proxyPropertiesClass;
  46. Class lpClass = Class.forName("android.net.LinkProperties");
  47. Method setHttpProxy = lpClass.getDeclaredMethod("setHttpProxy", setHttpProxyParams);
  48. setHttpProxy.setAccessible(true);
  49.  
  50. //get ProxyProperties constructor
  51. Class[] proxyPropertiesCtorParamTypes = new Class[3];
  52. proxyPropertiesCtorParamTypes[0] = String.class;
  53. proxyPropertiesCtorParamTypes[1] = int.class;
  54. proxyPropertiesCtorParamTypes[2] = String.class;
  55.  
  56. Constructor proxyPropertiesCtor = proxyPropertiesClass.getConstructor(proxyPropertiesCtorParamTypes);
  57.  
  58. //create the parameters for the constructor
  59. Object[] proxyPropertiesCtorParams = new Object[3];
  60. proxyPropertiesCtorParams[0] = "orion.ucf.edu.cu";
  61. proxyPropertiesCtorParams[1] = 3128;
  62. proxyPropertiesCtorParams[2] = "*.ucf.edu.cu";
  63.  
  64. //create a new object using the params
  65. Object proxySettings = proxyPropertiesCtor.newInstance(proxyPropertiesCtorParams);
  66.  
  67. //pass the new object to setHttpProxy
  68. Object[] params = new Object[1];
  69. params[0] = proxySettings;
  70. setHttpProxy.invoke(linkProperties, params);
  71.  
  72. setProxySettings("DHCP", conf);
  73.  
  74. //save the settings
  75. wifiManager.updateNetwork(conf);
  76. /*wifiManager.disconnect();
  77. wifiManager.reconnect();*/
  78. }
  79. catch(Exception e)
  80. {
  81. Log.d("Porque se jodio", e.getMessage());
  82. }
  83. }
  84.  
  85. final Dialog builder = new Dialog(this);
  86. View v = LayoutInflater.from(this).inflate(R.layout.login_show_eap, null);
  87. builder.setContentView(v);
  88.  
  89. TextView textView = (TextView) v.findViewById(R.id.red_info);
  90. final TextInputEditText textUser = (TextInputEditText) v.findViewById(R.id.user_name_eap);
  91. final TextInputEditText textPassw = (TextInputEditText) v.findViewById(R.id.user_passw_eap);
  92. Button btnAccept = (Button) v.findViewById(R.id.btnLoginShowEap);
  93.  
  94. textView.setText(scanResult.SSID);
  95.  
  96. final String[] identity = new String[1];
  97. final String[] passw = new String[1];
  98.  
  99. btnAccept.setOnClickListener(new View.OnClickListener() {
  100. @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
  101. @Override
  102. public void onClick(View view) {
  103. if (textUser.getText().toString().isEmpty()) {
  104. textUser.setError(getString(R.string.error_field_required));
  105. } else if (textPassw.getText().toString().isEmpty()) {
  106. textPassw.setError(getString(R.string.error_field_required));
  107. } else {
  108. passw[0] = textPassw.getText().toString();
  109. identity[0] = textUser.getText().toString();
  110. networkPass = passw[0];
  111. networkIdentity = identity[0];
  112. builder.dismiss();
  113. helperConnect(scanResult);
  114. }
  115. }
  116. });
  117. builder.show();
  118. }
Add Comment
Please, Sign In to add comment