• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4Copyright (c) 2024 Huawei Device Co., Ltd.
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9    http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Description: Preload before run test cases.
18"""
19
20from devicetest.core.test_case import TestCase, Step
21from xdevice import platform_logger
22
23from hypium import UiExplorer, BY
24
25log = platform_logger("Preload")
26
27
28# 类名必须是Preload
29class Preload(TestCase):
30    def __init__(self, configs):
31        self.tag = self.__class__.__name__
32        TestCase.__init__(self, self.tag, configs)
33
34    def setup(self):
35        Step("预置")
36
37    def process(self):
38        log.info("message {}".format(self.configs.get("testargs").get("pass_through", {})))
39        # 任务可能使用多个设备,需逐一进行初始化
40        for device in self.devices:
41            d = UiExplorer(device)
42            Step("********处理打卡软件和日志********")
43            out_message1 = d.hdc("shell ls /sys_prod/app/MSPES")
44            out_message2 = d.hdc("shell param get persist.sys.hilog.binary.on")
45            flag = 0
46            if "MSPES" in out_message1:
47                log.info("********打卡软件处理********")
48                d.Storage.remount("/sys_prod")
49                d.hdc("shell rm /sys_prod/app/MSPES/MSPES.hap")
50                flag = 1
51            if "true" in out_message2:
52                log.info("********日志处理********")
53                d.hdc("shell param set persist.sys.hilog.binary.on false")
54                flag = 1
55            if flag == 1:
56                log.info("********设备重启********")
57                d.System.reboot()
58                d.System.wait_for_boot_complete()
59                d.shell("power-shell setmode 602")
60                d.Screen.wake_up()
61                d.ScreenLock.unlock()
62                d.wait(5)
63                has_dialog_usb0 = d.find_component(BY.type("Dialog"))
64                if has_dialog_usb0:
65                    d.touch(BY.text("取消"))
66                d.wait(5)
67            else:
68                log.info("********打卡软件和日志都已处理********")
69
70            Step("********清理锁屏密码********")
71            d.ScreenLock.clear_password("123456", EXCEPTION=False)
72            d.wait(5)
73
74            out_message3 = d.hdc("shell aa dump -l")
75            if "hwstartupguide" in out_message3:
76                Step("********跳过开机向导********")
77                d.AppManager.disable_startup_guide()
78                d.wait(5)
79            else:
80                log.info("********已跳过开机向导********")
81
82            Step("********处理代码签名后亮屏解锁处理小艺输入法********")
83            d.shell("mount -o rw,remount /")
84            d.hdc("target mount")
85            d.wait(1)
86            d.shell('sed -i "s%/proc/sys/kernel/xpm/xpm_mode 4%/proc/sys/kernel/xpm/xpm_mode 0%g" '
87                    '/system/etc/init/key_enable.cfg')
88            d.shell('sed -i "s%/proc/sys/kernel/xpm/xpm_mode 4%/proc/sys/kernel/xpm/xpm_mode 0%g" '
89                    '/system/etc/init/key_enable.enable_xxpm.cfg')
90            d.wait(1)
91            d.System.reboot()
92            d.System.wait_for_boot_complete()
93            d.shell("power-shell setmode 602")
94            d.Screen.wake_up()
95            d.ScreenLock.unlock()
96            d.wait(5)
97            has_dialog_usb1 = d.find_component(BY.type("Dialog"))
98            if has_dialog_usb1:
99                d.touch(BY.text("取消"))
100            d.shell("sysctl -w kernel.xpm.xpm_mode=0")
101            # 使用时需手动修改下方bundle_name
102            bundle_name = ""
103            d.start_app(bundle_name, "MainAbility")
104            if d.find_component(BY.text("同意")) is not None:
105                d.touch(BY.text("同意"))
106            if d.find_component(BY.text("用于允许不同设备间的数据交换")) is not None:
107                d.touch(BY.text("允许"))
108            if d.find_component(BY.id("createNote")) is not None:
109                d.touch(BY.id("createNote"))
110            if d.find_component(BY.text("小艺输入法")) is not None:
111                d.touch(BY.text("同意"))
112            if d.find_component(BY.text("下一步")) is not None:
113                d.touch(BY.text("下一步"))
114            d.AppManager.clear_recent_app()
115            d.wait(5)
116
117            Step("********关闭wifi********")
118            result = d.Wifi.disable()
119            log.info("********关闭wifi********" + str(result))
120
121    def tear_down(self):
122        Step("收尾")