From 6c9f80ff76e79d81bb1d7cdb8dd1492f5a997d89 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Thu, 28 Nov 2019 09:23:41 +0000 Subject: [PATCH] target: get model form platform Move the resolution of the model name from targets into Platform's _set_model_from_target() (which was already attempting to do that via dmidecode method). --- devlib/platform/__init__.py | 11 ++++++++++- devlib/target.py | 23 ++++------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/devlib/platform/__init__.py b/devlib/platform/__init__.py index 3fdc775..205b5c6 100644 --- a/devlib/platform/__init__.py +++ b/devlib/platform/__init__.py @@ -78,7 +78,16 @@ class Platform(object): def _set_model_from_target(self, target): if target.os == 'android': - self.model = target.getprop('ro.product.model') + try: + self.model = target.getprop(prop='ro.product.device') + except KeyError: + self.model = target.getprop('ro.product.model') + elif target.file_exists("/proc/device-tree/model"): + # There is currently no better way to do this cross platform. + # ARM does not have dmidecode + raw_model = target.execute("cat /proc/device-tree/model") + device_model_to_return = '_'.join(raw_model.split()[:2]) + return device_model_to_return.rstrip(' \t\r\n\0') elif target.is_rooted: try: self.model = target.execute('dmidecode -s system-version', diff --git a/devlib/target.py b/devlib/target.py index 95561fe..2086433 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -136,6 +136,10 @@ class Target(object): def os_version(self): # pylint: disable=no-self-use return {} + @property + def model(self): + return self.platform.model + @property def abi(self): # pylint: disable=no-self-use return None @@ -980,17 +984,6 @@ class LinuxTarget(Target): os_version[name] = convert_new_lines(output.strip()).replace('\n', ' ') return os_version - @property - @memoized - # There is currently no better way to do this cross platform. - # ARM does not have dmidecode - def model(self): - if self.file_exists("/proc/device-tree/model"): - raw_model = self.execute("cat /proc/device-tree/model") - device_model_to_return = '_'.join(raw_model.split()[:2]) - return device_model_to_return.rstrip(' \t\r\n\0') - return None - @property @memoized def system_id(self): @@ -1163,14 +1156,6 @@ class AndroidTarget(Target): output = self.execute('content query --uri content://settings/secure --projection value --where "name=\'android_id\'"').strip() return output.split('value=')[-1] - @property - @memoized - def model(self): - try: - return self.getprop(prop='ro.product.device') - except KeyError: - return None - @property @memoized def system_id(self):