net-test: when running under Android run inside netns if possible

Will hopefully reduce flake rate...

Bug: 185330868
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I233e79c637cb62a145bcf9eaeab08c219a7bd5df
diff --git a/net/test/all_tests.py b/net/test/all_tests.py
index 17d9701..2305354 100755
--- a/net/test/all_tests.py
+++ b/net/test/all_tests.py
@@ -15,6 +15,7 @@
 # limitations under the License.
 
 import importlib
+import os
 import sys
 import unittest
 
@@ -48,8 +49,9 @@
 ]
 
 if __name__ == '__main__':
-  # Check whether ADB over TCP is occupying TCP port 5555.
-  if namespace.HasEstablishedTcpSessionOnPort(5555):
+  # Check whether ADB over TCP is occupying TCP port 5555,
+  # or if we're on a real Android device
+  if os.path.isdir('/system') or namespace.HasEstablishedTcpSessionOnPort(5555):
     namespace.IfPossibleEnterNewNetworkNamespace()
   # First, run InjectTests on all modules, to ensure that any parameterized
   # tests in those modules are injected.