24

I am writing system app, which sets global http proxy via

Settings.Global.putString(getContentResolver(), Settings.Global.HTTP_PROXY, "127.0.0.1");

How can I revert this change?
This don't work:

Settings.Global.putString(getContentResolver(), Settings.Global.HTTP_PROXY, null);

Any ideas?
Thanks in advance

Artur Latoszewski
  • 735
  • 1
  • 10
  • 21

6 Answers6

109

Andrews answer works but only for rooted devices, here's my solution for non-rooted devices.

I added the proxy with the following command:

adb shell settings put global http_proxy <ip>:<port>

Update: To remove it you can use the following command (thanks to Rohit Patel for providing this):

adb shell settings put global http_proxy :0 

To remove it I used these commands:

adb shell settings delete global http_proxy
adb shell settings delete global global_http_proxy_host
adb shell settings delete global global_http_proxy_port

Restart the device and you should be good to go

Scott Cooper
  • 2,779
  • 2
  • 23
  • 29
  • Works Great !! Thanks :) – Neeraj May 23 '18 at 08:43
  • Thanks a lot. Had to do a lot of google for the correct solution to reset the proxy settings changed by the adb command. Worked well. ! – Neetesh Dadwariya Aug 09 '18 at 16:31
  • 2
    There is only tow options put&get in android 4.4 – Majid Sep 13 '18 at 06:14
  • 7
    Is there a way to undo the proxy in real time, without restarting? Adding the proxy happens in real time but not removing it. – user1118764 Jan 23 '19 at 09:56
  • Does it support proxy credentials? And is it possible to use a SOCKS proxy instead of an HTTP proxy? Otherwise we would have to use workarounds by using an upstream proxy with other proxies. – baptx Sep 07 '19 at 11:09
  • For rooted devices you can call `am broadcast -a android.intent.action.PROXY_CHANGE` to force proxy refresh without having to reboot. – Pedro Oliveira Sep 09 '19 at 11:37
  • See answer from Rohit Patel below for an approach that obviates the need to restart device or broadcast PROXY_CHANGE: `adb shell settings put global http_proxy :0` – Mark McClelland Jul 28 '20 at 18:10
  • Okay, how to set proxy with authentication? adb shell settings put global http_proxy ::: - it's not working – anarbus Sep 05 '20 at 19:02
  • FYI: these settings do not show up if you manually go to your phones' proxy setting ;-) – Someone Somewhere Feb 09 '22 at 21:49
  • Didn't work for me. Android 9. When I check through the Wifi, It still has no proxy set. – Dr.jacky Jan 08 '23 at 15:26
18

Below is the normal command to remove proxy settings which will be applied without device reboot. You can use it in your script or app relatively.

adb shell settings put global http_proxy :0

You don't need to run all three of those commands. It will work with just the one command above. All proxy settings will be removed instantly.

Simon Notley
  • 2,070
  • 3
  • 12
  • 18
Rohit Patel
  • 181
  • 1
  • 2
3

I know this is an old question, but I had a hell of a time undoing my proxy hack so I figured I'd share.

I passed permissions to the device using ADB that would let me change the values to my proxy settings with my own custom application.

The problem is once I used my app with

Settings.Secure.putString(getContentResolver(), Settings.Secure.HTTP_PROXY, "127.0.0.1:8007");

It wouldn't let me set it back to default (No Proxy) no matter what I tried (null, blank, "NONE") basically if I wasn't connected through the proxy it wouldn't talk to the outside world. Even after restart.

SOLUTION I FOUND:

These settings are stored in a SQL database so when the phone restarts it applies them. You just need to go into the database and delete these rows from the table. What I did:

~user$ adb shell
shell@cinco:/ $ su -

FYI...Not sure if you need super user but it can't hurt right . . .

root@cinco:/ $ sqlite3 /data/data/com.android.providers.settings/databases/settings.db

you can see the full list of what's in the global table by doing:

sqlite> select * from global;

in the list you should be able to see the values you wrote in for http_proxy, global_http_proxy_host, and global_http_proxy_port, maybe you know what magic values to set these to so that it works properly, but I do not... my solution, just delete them:

sqlite> delete from global where name="global_http_proxy_host";
sqlite> delete from global where name="global_http_proxy_port";
sqlite> delete from global where name="http_proxy"; 

restart the phone and like magic there is no more proxy and I get the interwebs!!

Andrew R
  • 31
  • 2
2

Andrew R's method is very constructive, because it shows that when you change the key "HTTP_PROXY", the system will automatically add two additional keys. But when you delete "HTTP_PROXY", the system won't automatically delete the additional keys, so when you only delete "HTTP_PROXY" it's not work.

Now that we know the cause, we can use following commands to remove proxy completely:

adb shell
$ su
# settings delete global http_proxy
# settings delete global global_http_proxy_host
# settings delete global global_http_proxy_port

I think it's a feature(bug) of android.

Rilomilo
  • 21
  • 2
1

use like this

Settings.Secure.putString(getContentResolver(), 
            Settings.Secure.HTTP_PROXY, "127.0.0.1:8007");

note 'Settings.Secure.putString()'

Raghavendra
  • 3,530
  • 1
  • 17
  • 18
0

Another way instead of using root commands (you still need root though) and using the method of

Settings.Global.putString(getContentResolver(), Settings.Global.HTTP_PROXY, "127.0.0.1");

is to set the value to :0 so it would look like this

Settings.Global.putString(activity!!.contentResolver, Settings.Global.HTTP_PROXY, ":0")

I didn't have to reboot either for the changes to take effect

tyczj
  • 71,600
  • 54
  • 194
  • 296