Fix product name finder

This commit is contained in:
Antonio J. Delgado 2025-07-14 21:26:25 +03:00
parent 29e47d2a5c
commit 978b2c135d

View file

@ -59,7 +59,18 @@ class AndroidManager:
dev['object'] = device_object
try:
dev['properties'] = device_object.get_properties()
dev['name'] = dev['properties']['ro.semc.product.name']
if 'ro.semc.product.name' in dev['properties']:
dev['name'] = dev['properties']['ro.semc.product.name']
elif 'ro.vendor.oplus.market.name' in dev['properties']:
dev['name'] = dev['properties']['ro.vendor.oplus.market.name']
elif 'ro.product.name' in dev['properties']:
dev['name'] = dev['properties']['ro.product.name']
else:
with open('/tmp/tmp.properties.json', 'w', encoding='utf-8') as debug_file:
debug_file.write(json.dumps(dev['properties'], indent=2))
self._log.warning(
"Device product name not found. Check the /tmp/tmp.properties.json file for the right property to get a product name and notify the developer."
)
device_object.shell('dumpsys bluetooth_manager', handler=self._handle_output)
for line in self.lines:
match = re.search(r'^ Name: (.*)$', line)
@ -361,8 +372,9 @@ class AndroidManager:
@click_config_file.configuration_option()
@click.pass_context
def cli(ctx, **kwargs):
'''CLI function'''
ctx.ensure_object(dict)
ctx.obj['debug_level'] = kwargs['debug_level']
ctx.obj['config'] = kwargs
ctx.obj['android_manager'] = AndroidManager(**kwargs)
@cli.command()
@ -387,9 +399,5 @@ def restore_apps(ctx, backup_text_file, device_product_name):
'''Restore Android apps'''
ctx.obj['android_manager'].restore_apps(backup_text_file, device_product_name)
def __main__(**kwargs):
obj = AndroidManager(**kwargs)
obj.close()
if __name__ == "__main__":
__main__()
cli(obj={})