当前位置: 首页 > 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"}
]

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 前端面试 vue 接口权限控制
  • 【WPF开发】控件介绍-ComboBox
  • 《昇思25天学习打卡营第25天|文本解码原理--以MindNLP为例》
  • lse:一款专为渗透测试和CTF设计的Linux枚举工具
  • #systemverilog# 之 event region 和 timeslot 仿真调度(十)高层次视角看仿真调度事件的发生
  • linux协议栈之FDB表
  • 【Spring Boot 中的 `banner.txt` 和 `logback-spring.xml` 配置】
  • 安装caffe-CPU版本并进行训练
  • 谷粒商城实战笔记-52~53-商品服务-API-三级分类-新增-修改
  • Vuex看这一篇就够了
  • 奇瑞灯控,智照未来 | 经纬恒润AUTOSAR赋能智能车灯新纪元
  • 【Day1415】Bean管理、SpringBoot 原理、总结、Maven 高级
  • concrt140.dll修复丢失的解决办法?一键修复丢失concrt140.dll文件
  • 6、基于Fabirc 2.X 通用电子存证系统部署
  • 学习java第一百三十八天
  • android高仿小视频、应用锁、3种存储库、QQ小红点动画、仿支付宝图表等源码...
  • Consul Config 使用Git做版本控制的实现
  • echarts的各种常用效果展示
  • Effective Java 笔记(一)
  • Linux gpio口使用方法
  • Linux后台研发超实用命令总结
  • nodejs实现webservice问题总结
  • React+TypeScript入门
  • React-生命周期杂记
  • ubuntu 下nginx安装 并支持https协议
  • vue--为什么data属性必须是一个函数
  • 机器学习学习笔记一
  • 使用agvtool更改app version/build
  • 使用Gradle第一次构建Java程序
  • 我有几个粽子,和一个故事
  • 应用生命周期终极 DevOps 工具包
  • 在GitHub多个账号上使用不同的SSH的配置方法
  • ​创新驱动,边缘计算领袖:亚马逊云科技海外服务器服务再进化
  • ​人工智能书单(数学基础篇)
  • # 睡眠3秒_床上这样睡觉的人,睡眠质量多半不好
  • #C++ 智能指针 std::unique_ptr 、std::shared_ptr 和 std::weak_ptr
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • #systemverilog# 之 event region 和 timeslot 仿真调度(十)高层次视角看仿真调度事件的发生
  • (42)STM32——LCD显示屏实验笔记
  • (C语言)二分查找 超详细
  • (附源码)ssm高校社团管理系统 毕业设计 234162
  • (一)Neo4j下载安装以及初次使用
  • (一)utf8mb4_general_ci 和 utf8mb4_unicode_ci 适用排序和比较规则场景
  • (原創) 如何使用ISO C++讀寫BMP圖檔? (C/C++) (Image Processing)
  • (转)Scala的“=”符号简介
  • ***详解账号泄露:全球约1亿用户已泄露
  • .bat批处理(十一):替换字符串中包含百分号%的子串
  • .Net Core 微服务之Consul(二)-集群搭建
  • .Net Core 微服务之Consul(三)-KV存储分布式锁
  • .NET/C# 编译期间能确定的相同字符串,在运行期间是相同的实例
  • .NET8.0 AOT 经验分享 FreeSql/FreeRedis/FreeScheduler 均已通过测试
  • .NET分布式缓存Memcached从入门到实战
  • [ CTF ] WriteUp- 2022年第三届“网鼎杯”网络安全大赛(朱雀组)
  • [].shift.call( arguments ) 和 [].slice.call( arguments )
  • [240527] 谷歌 CEO 承认 AI 编造虚假信息问题难解(此文使用 @gemini 命令二次创作)| ICQ 停止运作