Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android's proxy confusing documentation resources

It seems to me that there is a lot of confusing resources regarding the proxy topic on Android.

First of all, it seems that all the methods of the Proxy class are declared deprecated and it's suggested to:

"Use standard java vm proxy values to find the host, port and exclusion list. This call ignores the exclusion list."

The official java vm proxy values can be accessed in the following way:

System.getProperty("http.proxyHost")
System.getProperty("http.proxyPort")
System.getProperty("http.nonProxyHosts")

This could seem confirmed by the documentation of the ProxySelector class.

But trying on a real device or an emulator, these values seems to me always empty. After looking to the Android source code of the hidden ProxySelector activity, it seems that the proxy is saved into the secure settings of the system in the following way:

Settings.Secure.putString(res, Settings.Secure.HTTP_PROXY, hostname);

And only an application signed by the OS provider can write to the secure settings. Developers can access these settings only in read mode in the following way:

Settings.Secure.getString(getApplicationContext().getContentResolver(),Settings.Secure.HTTP_PROXY);

Someone can clarify if this is the correct reading of how can be access the proxy settings into Android? (At least it seems to work). If this is the correct intepretation, why the documentation is so full of errors?

like image 828
lechuckcaptain Avatar asked Feb 17 '12 17:02

lechuckcaptain


2 Answers

For getting proxy values, accessing the System properties as you have done should work; it should not be necessary to access secure settings. If you cannot use the System properties to read proxy settings that were made through the normal device UI, then there is a problem. Proxies are per network type, so the APN and WiFi will have separate proxy settings.

like image 169
Sparky Avatar answered Nov 04 '22 13:11

Sparky


I don't know if it's the "right" way to access the proxy settings but it's the right and only way you should access the system "secure settings".

Maybe this is also interesting, looks like it makes things easier, especially if there are Wifi proxys (does Android support something like this?). At least it looks like great abstraction for the various android versions.

like image 42
Luminger Avatar answered Nov 04 '22 13:11

Luminger