Skip to content

Commit

Permalink
Enabled proxy on Android emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
budtmo committed Jul 5, 2019
1 parent de07332 commit 19e26a0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README_CUSTOM_CONFIG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Proxy
-----

You can enable proxy inside container by passing following environment variables:
You can enable proxy inside container and Android emulator by passing following environment variables:

- HTTP_PROXY="\<docker\_bridge\_ip\_address>"
- HTTPS_PROXY="\<docker\_bridge\_ip\_address>"
- HTTP_PROXY="http://\<docker\_bridge\_ip>:<port>"
- HTTPS_PROXY=""http://\<docker\_bridge\_ip>:<port>"
- NO_PROXY="localhost"
- ENABLE_PROXY_ON_EMULATOR=true

Language
--------
Expand Down
4 changes: 2 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ def run():
cfg.write('\ndisk.dataPartition.size={dp}'.format(dp=dp_size))

if is_first_run:
cmd = 'emulator/emulator @{name} -gpu swiftshader_indirect -accel on -wipe-data -verbose {custom_args}'.format(name=avd_name, custom_args=custom_args)
cmd = 'emulator/emulator @{name} -gpu swiftshader_indirect -accel on -wipe-data -writable-system -verbose {custom_args}'.format(name=avd_name, custom_args=custom_args)
else:
cmd = 'emulator/emulator @{name} -gpu swiftshader_indirect -accel on -verbose {custom_args}'.format(name=avd_name, custom_args=custom_args)
cmd = 'emulator/emulator @{name} -gpu swiftshader_indirect -accel on -verbose -writable-system {custom_args}'.format(name=avd_name, custom_args=custom_args)
appium = convert_str_to_bool(str(os.getenv('APPIUM', False)))
if appium:
subprocess.Popen(cmd.split())
Expand Down
39 changes: 39 additions & 0 deletions src/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,45 @@ function disable_animation () {
adb shell "settings put global animator_duration_scale 0.0"
}

function enable_proxy_if_needed () {
if [ "$ENABLE_PROXY_ON_EMULATOR" = true ]; then
if [ ! -z "${HTTP_PROXY// }" ]; then
if [[ $HTTP_PROXY == *"http"* ]]; then
protocol="$(echo $HTTP_PROXY | grep :// | sed -e's,^\(.*://\).*,\1,g')"
proxy="$(echo ${HTTP_PROXY/$protocol/})"
echo "[EMULATOR] - Proxy: $proxy"

IFS=':' read -r -a p <<< "$proxy"

echo "[EMULATOR] - Proxy-IP: ${p[0]}"
echo "[EMULATOR] - Proxy-Port: ${p[1]}"

wait_emulator_to_be_ready
echo "Enable proxy on Android emulator. Please make sure that docker-container has internet access!"
adb root

echo "Mount system to read write access"
adb shell "mount -o rw,remount /system"

echo "Updateing Proxy"

adb shell "content update --uri content://telephony/carriers --bind proxy:s:"${p[0]}" --bind port:s:"${p[1]}" --where "mcc=310" --where "mnc=260""

echo "remount system back to read only"
adb shell "mount -o ro,remount /system"
adb unroot
else
echo "Please use http:// in the beginning!"
fi
else
echo "$HTTP_PROXY is not given! Please pass it through environment variable!"
exit 1
fi
fi
}

enable_proxy_if_needed
sleep 1
change_language_if_needed
sleep 1
install_google_play
Expand Down

0 comments on commit 19e26a0

Please sign in to comment.