当前位置: 首页 > news >正文

Django+vue自动化测试平台(28)-- ADB获取设备信息

概述

adb的全称为Android Debug Bridge,就是起到调试桥的作用。通过adb可以在Eclipse中通过DDMS来调试Android程序,说白了就是调试工具。
adb的工作方式比较特殊,采用监听Socket TCP 5554等端口的方式让IDE和Qemu通讯,默认情况下adb会daemon相关的网络端口,所以当我们运行Eclipse时adb进程就会自动运行。
adb是android sdk里的一个工具, 用这个工具可以直接操作管理android模拟器或者真实的android设备(如G1手机).  它的主要功能有:

  • 运行设备的shell(命令行)
  • 管理模拟器或设备的端口映射
  • 计算机和设备之间上传/下载文件
  • 将本地apk软件安装至模拟器或android设备
    ADB是一个 客户端-服务器端 程序, 其中客户端是你用来操作的电脑, 服务器端是android设备.

代码实现:

def get_device_info():version = ""cmd = 'tidevice list --json'device_info_list = []ios_result = os.popen(cmd).read().replace("\\n", "").replace("\u001b[0m", "")if eval(ios_result):for i in eval(ios_result):if i["market_name"] == "-":name = i["name"]else:name = i["market_name"]ios = {}ios["deviceName"] = i["udid"]ios["device_name"] = nameios["os_type"] = "ios"ios["version"] = i["product_version"]   device_info_list.append(ios)else:device_info_list = []devices_output = subprocess.check_output("adb devices", shell=True).decode().strip()if devices_output != "List of devices attached":devices_list = devices_output.split('\n')[1:]for device in devices_list:device_id = device.split('\t')[0]device_info_output = subprocess.check_output(f"adb -s {device_id} shell getprop",shell=True).decode().strip()brand = get_property(device_info_output, 'ro.product.brand')if brand == "OPPO":if get_property(device_info_output, 'ro.oppo.market.name') == "":device_name = get_property(device_info_output, 'ro.vendor.oplus.market.name')else:device_name = get_property(device_info_output, 'ro.oppo.market.name')version = str(get_property(device_info_output, "ro.product.build.version.release"))elif brand == "HUAWEI":# 鸿蒙系统version = "Harmony OS " + str(get_property(device_info_output, "hw_sc.build.platform.version"))device_name = get_property(device_info_output, 'ro.config.marketing_name')elif brand == "Redmi":device_name = get_property(device_info_output, 'ro.product.marketname')version = str(get_property(device_info_output, "ro.product.build.version.release"))elif brand == "SG":device_name = get_property(device_info_output, 'ro.sh.brand')version = str(get_property(device_info_output, "ro.system.build.version.release"))elif brand == "XIAOMI":device_name = get_property(device_info_output, 'ro.product.model')version = str(get_property(device_info_output, "ro.product.build.version.release"))elif brand == "OnePlus":device_name = get_property(device_info_output, 'ro.product.device')version = str(get_property(device_info_output, "ro.product.build.version.release"))elif brand == "google":device_name = get_property(device_info_output, 'ro.product.model')version = str(get_property(device_info_output, "ro.product.build.version.release"))elif brand == "HONOR":device_name = get_property(device_info_output, 'ro.config.marketing_name')version = str(get_property(device_info_output, "ro.product.build.version.release"))elif brand == "samsung":device_name = get_property(device_info_output, 'ro.product.model')version = str(get_property(device_info_output, "ro.product.build.version.release"))else:device_name = get_property(device_info_output, 'ro.product.brand')version = "未知操作系统版本"device_info_list.append({'deviceName': get_property(device_info_output, 'ro.serialno'),'device_name': device_name,"os_type": "android","version": version,})else:return device_info_listreturn device_info_list

结果:

[{"deviceName": "00008110-000C49623C99801E","device_name": "iPhone 13 Pro","os_type": "ios","version": "15.1.1"},{"deviceName": "6faf7764","device_name": "OPPO K9 5G","os_type": "android","version": "12"}
]
http://www.lryc.cn/news/403481.html

相关文章:

  • RESTful API设计指南:构建高效、可扩展和易用的API
  • npm下载的依赖包版本号怎么看
  • css前端面试题
  • Vue从零到实战
  • 【Chatgpt大语言模型医学领域中如何应用】
  • ES6 正则的扩展(十九)
  • <数据集>钢铁缺陷检测数据集<目标检测>
  • Kafka系列之:Kafka存储数据相关重要参数理解
  • Template execution failed: ReferenceError: name is not defined
  • CVE-2024-24549 Apache Tomcat - Denial of Service
  • Linux下如何安装配置Graylog日志管理工具
  • 「MQTT over QUIC」与「MQTT over TCP」与 「TCP 」通信测试报告
  • 获取磁盘剩余容量-----c++
  • AI算法24-决策树C4.5算法
  • 【云原生】Prometheus整合Alertmanager告警规则使用详解
  • C++ :友元类
  • 【整理了一些关于使用swoole使用的解决方案】
  • python selenium4 EdgeDriver动态页面爬取
  • 【一次记一句:SQL】从 information_schema.TABLES中查询数据库表中记录数据量
  • NXP i.MX8系列平台开发讲解 - 3.19 Linux TTY子系统(二)
  • FPGA资源容量
  • Zabbix介绍和架构
  • 打造智慧图书馆:AI视频技术助力图书馆安全与秩序管理
  • Go的数据结构与实现【LinkedList】
  • Ubuntu22.04安装CUDA+CUDNN+Conda+PyTorch
  • 当“广撒网”遇上“精准定点”的鱼叉式网络钓鱼
  • svn ldap认证临时切换到本地认证
  • 极狐GitLab如何配置使用独立数据库?
  • TCP状态转换详解
  • SimMIM:一个类BERT的计算机视觉的预训练框架