Is there a way to set android emulator proxy from adb shell

9,619 views
Skip to first unread message

yankee

unread,
May 24, 2011, 8:23:02 PM5/24/11
to android-platform
hi,

We can set an android emulator proxy at

Settings->Wireless&Networks->Mobile networks->Access Point Names->T-
Mobile US(can also be other name)-> Proxy and Port .

Is there a way to directly set the proxy by an adb shell command?

Like we can load an url in command line by using:

adb shell am start –a android.intent.action.VIEW –d http://www.google.com

Thanks very much for any help!!

Yanke

biAji

unread,
May 25, 2011, 2:39:51 AM5/25/11
to android-...@googlegroups.com

adb shell getprop | grep proxy

get the system properties' name. and use adb shell setprop to set it.

errr~~ if you have root access right.

>
> Thanks very much for any help!!
>
> Yanke
>

> --
> You received this message because you are subscribed to the Google Groups "android-platform" group.
> To post to this group, send email to android-...@googlegroups.com.
> To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
>
>

--

biAji

Tim Bird

unread,
May 25, 2011, 12:59:56 PM5/25/11
to android-...@googlegroups.com

See http://elinux.org/Android_Networking

To quote:

The browser looks at system settings stored in a provider database
for the http proxy.

The value for http_proxy is set in the following sqlite database:
/data/data/com.android.providers.settings/databases/settings.db
the setting goes in the 'system' table in this database, with a key
of 99, a name of 'http_proxy' and a value that is a string containing
your proxy server and port. I don't know if you can use a server name
rather than just an IP address. I haven't done that.

To set this, on target, do the following:
# cd /data/data/com.android.providers.settings/databases
# sqlite3 settings.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> insert into system values(99,'http_proxy','192.168.1.1:80');
sqlite>.exit

Replace '192.168.1.1:80' with the appropriate address and port for
your network configuration.
Since it's only a single line, you can also do this from the command
line. You can check that the value is stored properly by typing the
following:
# sqlite3 settings.db "select * from system;"
This should show output similar to the following (first part omitted):
...
38|volume_ring|4
39|volume_ring_last_audible|4
99|http_proxy|43.131.3.73:80

This change is persistent, and you should only have to make it once.

This worked on some devices I used here at Sony, but I'm not sure
if it works in the emulator, or on different phone models.
-- Tim

=============================
Tim Bird
Architecture Group Chair, CE Workgroup of the Linux Foundation
Senior Staff Engineer, Sony Network Entertainment
=============================

yankee

unread,
May 25, 2011, 3:12:02 PM5/25/11
to android-platform
hi,

Thanks very much,

I tried this while emulator is running. I can change the value of
net.gprs.http-proxy, but when the android browser goes to some page,
it doesn't go through the proxy.

My android version is 2.2 froyo..

On May 24, 11:39 pm, biAji <biaji...@gmail.com> wrote:
> On Wed, May 25, 2011 at 8:23 AM, yankee <huya...@gmail.com> wrote:
> > hi,
>
> > We can set an android emulator proxy at
>
> >  Settings->Wireless&Networks->Mobile networks->Access Point Names->T-
> > Mobile US(can also be other name)-> Proxy and Port .
>
> > Is there a way to directly set the proxy by anadbshell command?
>
> > Like we can load an url in command line by using:
>
> >adbshell am start –a android.intent.action.VIEW –dhttp://www.google.com
>
> adbshell getprop | grep proxy
>
> get the system properties' name.  and useadbshell setprop to set it.

yankee

unread,
May 25, 2011, 3:18:04 PM5/25/11
to android-platform
hi,

Thanks very much.

I tried this while the emulator is running, it can add an item like 99|
http_proxy|43.131.3.73:80 into the database. But when I use android
browser to go to some page, it still doesn't go through the proxy.

My android version is 2.2 froyo.

Actually, there is a way to go to the proxy setting view by:

Adb shell am start –n com.android.settings/
com.android.settings.ProxySelector

But you still need to manually input http proxy and port and then
save.

I hope I can find a way to get all this done by just using command
line input.

Thanks again!!

On May 25, 9:59 am, Tim Bird <tim.b...@am.sony.com> wrote:
> On 05/24/2011 05:23 PM, yankee wrote:
>
> > hi,
>
> > We can set an android emulator proxy at
>
> >  Settings->Wireless&Networks->Mobile networks->Access Point Names->T-
> > Mobile US(can also be other name)-> Proxy and Port .
>
> > Is there a way to directly set the proxy by anadbshell command?
>
> > Like we can load an url in command line by using:
>
> >adbshell am start a android.intent.action.VIEW dhttp://www.google.com
>
> Seehttp://elinux.org/Android_Networking

David Turner

unread,
May 25, 2011, 9:58:01 PM5/25/11
to android-...@googlegroups.com
If you're using the emulator, simply start it with the -http-proxy option instead, no need to modify the system.
For the rest, how the proxy setting is stored is an implementation detail, and may vary between platforms.

yankee

unread,
May 26, 2011, 1:13:24 PM5/26/11
to android-platform
Thank you.

But I tried emulator -http-proxy before, it sometimes works, sometimes
not work.

The only way of setting proxy works perfectly is :

Settings->Wireless&Networks->Mobile networks->Access Point Names->T-
Mobile US(can also be other name)-> Proxy and Port .

or

Adb shell am start –n com.android.settings/
com.android.settings.ProxySelector

But both of them involves some manual step. I hope I can find a way
to get all these done by commandline so I can use it in a program.

Anyway, thanks very much.

Yanke

biAji

unread,
May 26, 2011, 9:48:09 PM5/26/11
to android-...@googlegroups.com
On Fri, May 27, 2011 at 1:13 AM, yankee <huy...@gmail.com> wrote:
> Thank you.
>
> But I tried emulator -http-proxy before, it sometimes works, sometimes
> not work.
>
> The only way of setting proxy works perfectly is :
>
> Settings->Wireless&Networks->Mobile networks->Access Point Names->T-
> Mobile US(can also be other name)-> Proxy and Port .

adb shell sqlite3
/data/data/com.android.providers.telephony/databases/telephony.db
"update carriers set proxy=''xxx', port='xx' where id=xxx "

--

biAji

yankee

unread,
May 27, 2011, 4:10:01 PM5/27/11
to android-platform
hi,biAji,

Thanks very much for your answer! It makes every sense we should
"update carriers set proxy=''xxx', port='xx' where id=xxx " like you
said.

But I just tried , and it seems still not work...

On the other hand, after I set the proxy by:

Settings->Wireless&Networks->Mobile networks->Access Point Names->T-
Mobile US(can also be other name)-> Proxy and Port .

or

Adb shell am start –n com.android.settings/
com.android.settings.ProxySelector

The values in the carriers table of /data/data/
com.android.providers.telephony/databases/telephony.db doesn't
change any...

Maybe the proxy value will directly take effect , and not pass to
databases ?

Thanks very much anyway!!

On May 26, 6:48 pm, biAji <biaji...@gmail.com> wrote:
> On Fri, May 27, 2011 at 1:13 AM, yankee <huya...@gmail.com> wrote:
> > Thank you.
>
> > But I tried emulator -http-proxybefore, it sometimes works, sometimes
> > not work.
>
> > The only way of settingproxyworks perfectly is :
>
> > Settings->Wireless&Networks->Mobile networks->Access Point Names->T-
> > Mobile US(can also be other name)->Proxyand Port .
>
> adbshell sqlite3
> /data/data/com.android.providers.telephony/databases/telephony.db
> "update carriers setproxy=''xxx', port='xx' where id=xxx "
>
>
>
>
>
>
>
>
>
>
>
> > or
>
> >Adbshell am start –n com.android.settings/
> > com.android.settings.ProxySelector
>
> > But both of them involves some manual step.  I hope I can find a way
> > to get all these done by commandline so I can use it in a program.
>
> > Anyway, thanks very much.
>
> > Yanke
>
> > On May 25, 6:58 pm, David Turner <di...@android.com> wrote:
> >> If you're using the emulator, simply start it with the -http-proxyoption
> >> instead, no need to modify the system.
> >> For the rest, how theproxysetting is stored is an implementation detail,
> >> and may vary between platforms.
>
> >> On Wed, May 25, 2011 at 12:18 PM, yankee <huya...@gmail.com> wrote:
> >> > hi,
>
> >> > Thanks very much.
>
> >> > I tried this while the emulator is running, it can add an item like 99|
> >> > http_proxy|43.131.3.73:80  into the database. But when I use android
> >> > browser to go to some page, it still doesn't go through theproxy.
>
> >> > My android version is 2.2 froyo.
>
> >> > Actually, there is a way to go to theproxysetting view by:
>
> >> >Adbshell am start –n com.android.settings/
> >> > com.android.settings.ProxySelector
>
> >> > But you still need to manually input httpproxyand port and then
> >> > save.
>
> >> > I hope I can find a way to get all this done by just using command
> >> > line input.
>
> >> > Thanks again!!
>
> >> > On May 25, 9:59 am, Tim Bird <tim.b...@am.sony.com> wrote:
> >> > > On 05/24/2011 05:23 PM, yankee wrote:
>
> >> > > > hi,
>
> >> > > > We can set an android emulatorproxyat
>
> >> > > >  Settings->Wireless&Networks->Mobile networks->Access Point Names->T-
> >> > > > Mobile US(can also be other name)->Proxyand Port .
>
> >> > > > Is there a way to directly set theproxyby anadbshell command?
>
> >> > > > Like we can load an url in command line by using:
>
> >> > > >adbshell am start a android.intent.action.VIEW dhttp://www.google.com
>
> >> > > Seehttp://elinux.org/Android_Networking
>
> >> > > To quote:
>
> >> > > The browser looks at system settings stored in a provider database
> >> > > for the httpproxy.
>
> >> > > The value for http_proxy is set in the following sqlite database:
> >> > > /data/data/com.android.providers.settings/databases/settings.db
> >> > > the setting goes in the 'system' table in this database, with a key
> >> > > of 99, a name of 'http_proxy' and a value that is a string containing
> >> > > yourproxyserver and port. I don't know if you can use a server name

biAji

unread,
May 29, 2011, 9:52:02 PM5/29/11
to android-...@googlegroups.com
Here is the source code that takes effect:

Settings.Secure.putString(res, Settings.Secure.HTTP_PROXY, hostname);
sendBroadcast(new Intent(Proxy.PROXY_CHANGE_ACTION));

--

biAji

Reply all
Reply to author
Forward
0 new messages