Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3031)

Unified Diff: build/android/pylib/fake_dns.py

Issue 10689132: [android] Upstream / sync most of build/android and build/android/pylib. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/debug_info.py ('k') | build/android/pylib/forwarder.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/fake_dns.py
diff --git a/build/android/pylib/fake_dns.py b/build/android/pylib/fake_dns.py
new file mode 100644
index 0000000000000000000000000000000000000000..4079c31df74a32bf1fcba9ba2a8e547dee598ffe
--- /dev/null
+++ b/build/android/pylib/fake_dns.py
@@ -0,0 +1,61 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import android_commands
+import constants
+import logging
+import os
+import subprocess
+import time
+
+
+class FakeDns(object):
+ """Wrapper class for the fake_dns tool."""
+ _FAKE_DNS_PATH = '/data/local/tmp/fake_dns'
+
+ def __init__(self, adb):
+ """
+ Args:
+ adb: the AndroidCommands to use.
+ """
+ self._adb = adb
+ self._fake_dns = None
+ self._original_dns = None
+
+ def _PushAndStartFakeDns(self):
+ """Starts the fake_dns server that replies all name queries 127.0.0.1.
+
+ Returns:
+ subprocess instance connected to the fake_dns process on the device.
+ """
+ self._adb.PushIfNeeded(
+ os.path.join(constants.CHROME_DIR, 'out', 'Release', 'fake_dns'),
+ FakeDns._FAKE_DNS_PATH)
+ return subprocess.Popen(
+ ['adb', '-s', self._adb._adb.GetSerialNumber(),
+ 'shell', '%s -D' % FakeDns._FAKE_DNS_PATH])
+
+ def SetUp(self):
+ """Configures the system to point to a DNS server that replies 127.0.0.1.
+
+ This can be used in combination with the forwarder to forward all web
+ traffic to a replay server.
+
+ The TearDown() method will perform all cleanup.
+ """
+ self._adb.RunShellCommand('ip route add 8.8.8.0/24 via 127.0.0.1 dev lo')
+ self._fake_dns = self._PushAndStartFakeDns()
+ self._original_dns = self._adb.RunShellCommand('getprop net.dns1')[0]
+ self._adb.RunShellCommand('setprop net.dns1 127.0.0.1')
+ time.sleep(2) # Time for server to start and the setprop to take effect.
+
+ def TearDown(self):
+ """Shuts down the fake_dns."""
+ if self._fake_dns:
+ if not self._original_dns or self._original_dns == '127.0.0.1':
+ logging.warning('Bad original DNS, falling back to Google DNS.')
+ self._original_dns = '8.8.8.8'
+ self._adb.RunShellCommand('setprop net.dns1 %s' % self._original_dns)
+ self._fake_dns.kill()
+ self._adb.RunShellCommand('ip route del 8.8.8.0/24 via 127.0.0.1 dev lo')
« no previous file with comments | « build/android/pylib/debug_info.py ('k') | build/android/pylib/forwarder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698