adb判断锁屏,屏幕点亮

 1.判断是否锁屏

def is_screen_lock(id):
    # ----------------------
    # 检测屏幕是否被锁,不同于屏幕点亮, 判断亮屏请使用 adbutils.is_screen_on
    # ----------------------
    try:
        cmd_1 = os.popen('adb -s ' + id + ' shell dumpsys window policy^|grep isStatusBarKeyguard').read()
        cmd_2 = os.popen('adb -s ' + id + ' shell dumpsys window policy^|grep mShowingLockscreen').read()
        if "isStatusBarKeyguard=true".strip() in cmd_1:
            return True
        elif "mShowingLockscreen=true".strip() in cmd_2:
            return True
        elif len(cmd_1) == 0 or len(cmd_2) == 0:
            command = 'adb -s ' + id + " shell dumpsys window policy"
            result = os.popen(command)
            lines = result.readlines()
            loc_flag = 0
            for i in range(len(lines)):
                # print('KeyguardServiceDelegate'.strip())
                if 'KeyguardServiceDelegate'.strip() in lines[i]:
                    loc_flag = i + 1
                    # print(lines[i])
            # print(lines[loc_flag])
            if 'showing=true' in lines[loc_flag] and loc_flag != 0:
                return True
            else:
                return False

        else:
            return False
    except Exception as e:
        print('获取手机lock状态异常',e)
        return False

2.判断是否点亮

 

####第一种方法
def is_screenState(id):
    try:
        cmd = 'adb -s ' + id + ' shell dumpsys power | find "Display Power: state="'
        res = os.popen(cmd).read()
        print(res)
        if "state=ON" in res:
            return True
        else:
            return False

    except Exception as e:
        print('获取手机屏幕点亮状态异常',e)
        return False

####第二种方法

def is_screenState_bake(id):
    try:
        command = 'adb -s ' + id + " shell dumpsys window policy"
        result = os.popen(command)
        lines = result.readlines()
        #print(lines)
        loc_flag = 0
        for i in range(len(lines)):
            #print('KeyguardServiceDelegate'.strip())
            if 'screenState'.strip() in lines[i]:
                loc_flag = i
                #print(lines[i])
        #print(lines[loc_flag])
        if 'screenState=SCREEN_STATE_ON' in lines[loc_flag] or 'screenState=2' in lines[loc_flag]:
            return True
        else:
            return False

    except Exception as e:
        print('获取手机屏幕点亮状态异常',e)
        return False

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值