工厂手机电话测试Python 脚本

# coding:utf-8
import os
import time


def readDevicesList():
    p = os.popen('adb devices')
    devicesList = p.read()
    p.close()
    lists = devicesList.split("\n")
    devicesNames = []
    for item in lists:
        if (item.strip() == ""):
            continue
        elif (item.startswith("List of")):
            continue
        else:
            devicesNames.append(item.split("\t")[0])
    return devicesNames


def getRealDeviceName(deviceId):
    p = os.popen('adb -s ' + deviceId + ' shell getprop ro.product.manufacturer')
    manufacturer = p.read()
    p.close()
    p = os.popen('adb -s ' + deviceId + ' shell getprop ro.product.model')
    model = p.read()
    p.close()
    return manufacturer.strip() + " " + model.strip()


def getPhoneState(deviceId):
    # adb shell 后的命令用双引号,否则执行出错!!!!
    p = os.popen('adb -s ' + deviceId + ' shell "dumpsys telephony.registry|grep \"mCallState\""')
    res = p.read().splitlines()[0].split('=')[1]
    p.close()
    if res == '0':
        res = 'idle'
    elif res == '1':
        res = 'ringing'
    elif res == '2':
        res = 'calling'
    return res.strip()


def callPhone():
    call = os.popen('adb shell am start -a android.intent.action.CALL -d tel:18620332060')
    call.close()


def answerPhone():
    answer = os.popen('adb shell input keyevent 5')
    answer.close()


def offHookPhone():
    off = os.popen('adb shell input keyevent 6')
    off.close()


sleep_time = 1.0
while 1:
    answerPhone()
    time.sleep(sleep_time)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值