Android's proxy confusing documentation resources - android

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?

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.

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.

Related

How can my Android app get method tracing of another process/app on a phone that has enabled developer options?

I would like to write an Android app (not a PC program) that has a subset features of Android Device Monitor (ADM), ie. select a process and trace its method calls, with detailed information (all the information that ADM can get, like stack trace and time), while the phone is not connected to any computer nor does it have any network access.
I've searched into android.os.Debug.startMethodTracing*, but it seems can only trace current process and the result can only be written into a file (I need the info in memory).
Digging its implementation, I found dalvik.system.VMDebug.startMethodTracing*, but it seems cannot be used by apps and I didn't find a way to specify pids, neither. Looks like it's calling JNI functions, but I didn't find the implementation.
Maybe I can get the information by lower level way by using Linux perf events (perf_event_open(2)). But before doing that, I would like to know if such kind of feature possible to implement purely in Java (maybe by talking to some "system manager" process or "debugging server" process, or by calling some CLI tools then get its stdout)?
These capabilities can only be accessed by the shell user (the user that adb runs as), or the root user of course. By design, a normal android application cannot access these features, because this would completely break the application sandbox that is the basis of the application security model in Android.

Equivalent of WifiEnterpriseConfig before Android OS 4.3

In my Android application, I let the user choose a Wifi connection for the device. Using WifiConfiguration, I am able to deal with WEP as well as WPA2-PSK networks. However, it appears WPA2-EAP requires one more field - username. Browsing the net, I came across a system class WifiEnterpriseConfig that seems promising. However, this API is available only for OS 4.3+. I am wondering if there is any other way to achieve saving EAP network config that would work for 4.1 and above. Any pointer is appreciated. Regards.
You can just copypaste source code of this class into your project, it should resolve your problem.

How to set a proxy in a WebView on Lollipop 5.0

My app has a WebView and I want to configure it to use a proxy. Apparently Android doesn't have an API that I can use to achieve this but I found some a couple of articles on StackOverflow showing how to do it via reflection:
WebView android proxy
Android WebView set proxy programmatically on Android-L
Unfortunately the methods in the first article only work up to KitKat 4.4 and the Android L/5.0 way of doing it requires setting the application-wide proxy settings (via System.setProperty("http.proxyHost", ...) and System.setProperty("http.proxyPort", ...) which affects more than just the WebView. For example, the Apache HTTP client seems to pick up these settings too.
Is there a way to set proxy settings just for WebViews without affecting other components of the app?
In API>21 lollipop, it does not allow setting proxy settings in webviews. The methods have been removed.
So the only way now is to set system wide proxy as you mentioned, then clear the proxy on onPause and onStop methods of your activity.
The clear can be done by:
System.clearProperty("http.proxyHost");
System.clearProperty("http.proxyPort");
Hope you find this helpful.

How to enable/disable 3G/2G in Android SDK

I am just wondering how to enable/disable 3G/2G using the Android SDK and not just intenting to the 3G settings page. Thanks. Also is there a way to do the same thing, but with GPS. Thanks!
There is no exported to the SDK functionality to switch between 2G and 3G. For a given device you could probably figure out the private functionality, but it wouldn't work unless the app was signed with the system key.
You can disable the radios though, by turning on airplane mode.
And you might be able to make a shortcut to open the appropriate settings activity directly, instead of going through a few levels of menus to get there.
If you make your own build, you can presumably add the capability you really want, but that's likely not useful to anyone but yourself.
Edit: further detail - to understand how it works, look at the settings menu code (default version, a given device will differ):
http://android.git.kernel.org/?p=platform/packages/apps/Phone.git;a=blob;f=src/com/android/phone/Settings.java;hb=HEAD
Edit: AOSP is no longer served from kernel.org. A browsable mirror of
the current phone repository is at
https://github.com/android/platform_packages_apps_phone however due to
evolution of code organization there is no longer a Settings.java
there. One might either use git to reconstruct the version above from
this repository, or else try to figure out where the code has migrated
to in current releases.
You would need to find out the implementation specific set of NT_MODE_ constants you wish to toggle between. And you need to be able to write to secure settings, which requires being signed with the system key. Unless it's a custom build, you probably don't have access to that.
You cannot enable or disable any of these from an SDK application.

Spoofing Location

I've got an application in the browser that's customized to use Android's browser geolocation APIs. I'd like to find a way to fake the lat/lng that's sent to the browser so I can type in arbitrary coordinates.
In doing some research I came across DDMS - http://developer.android.com/guide/developing/tools/ddms.html - which seems to do what I want, but seems to require the IDE or an emulator. I don't want to use an emulator because I want to test on the device and I don't have the IDE set up for Android.
Does anyone know if there's a way to send mock location data to an Android device without loading up the IDE (or doing it through the emulator)?
I do not believe this is possible -- sorry!
Also the DDMS and IDE solutions are one and the same and only work with the emulator.
Just in case someone stumbles across this question like I did, here is some info about how to mock the LocationProvider on a physical device. Marking this as community wiki because I didn't come up with the original answer. Code is listed in diffract.me/2009/11/android-location-provider-mock (looks like domain is expired as of 9/29/2010, I used Google's cache of the page) & from stackoverflow.com/.../android-mock-location-on-device.

Categories

Resources