summaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/utils.py b/utils.py
index 38efdce..65b2eee 100644
--- a/utils.py
+++ b/utils.py
@@ -18,8 +18,11 @@
# TODO(b/147454897): Keep the logic in sync with
# test/vts/utils/python/controllers/android_device.py until
# it is removed.
+import gzip
import logging
+import os
import subprocess
+import tempfile
class AndroidDevice(object):
"""This class controls the device via adb commands."""
@@ -141,6 +144,51 @@ class AndroidDevice(object):
"""Gets the VNDK version that the vendor partition requests."""
return self._GetProp("ro.vndk.version")
+ def GetKernelConfig(self, config_name):
+ """Gets kernel config from the device.
+
+ Args:
+ config_name: A string, the name of the configuration.
+
+ Returns:
+ "y" or "m" if the config is set.
+ "" if the config is not set.
+ None if fails to read config.
+ """
+ line_prefix = config_name + "="
+ with tempfile.NamedTemporaryFile(delete=False) as temp_file:
+ config_path = temp_file.name
+ try:
+ logging.debug("Pull config.gz to %s", config_path)
+ self.AdbPull("/proc/config.gz", config_path)
+ with gzip.open(config_path, "rt") as config_file:
+ for line in config_file:
+ if line.strip().startswith(line_prefix):
+ logging.debug("Found config: %s", line)
+ return line.strip()[len(line_prefix):]
+ logging.debug("%s is not set.", config_name)
+ return ""
+ except (subprocess.CalledProcessError, IOError) as e:
+ logging.exception("Cannot read kernel config.", e)
+ return None
+ finally:
+ os.remove(config_path)
+
+ def GetBinderBitness(self):
+ """Returns the value of BINDER_IPC_32BIT in kernel config.
+
+ Returns:
+ 32 or 64, binder bitness of the device.
+ None if fails to read config.
+ """
+ config_value = self.GetKernelConfig("CONFIG_ANDROID_BINDER_IPC_32BIT")
+ if config_value is None:
+ return None
+ elif config_value:
+ return 32
+ else:
+ return 64
+
def IsRoot(self):
"""Returns whether adb has root privilege on the device."""
out, err, return_code = self.Execute("id")