• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#-*- coding: utf-8 -*-
3
4# Copyright (c) 2024 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from hypium.action.host import host
18
19
20def push_source(source_path, driver, sn, update_param=False):
21    """
22    @func: push resources to devices
23    @param source_path: the path of resources required by a case
24    @param driver: the device
25    @param sn: device sn
26    """
27    host.shell("hdc -t {} shell kill -9 `pidof listen_test`".format(sn))
28    host.shell("hdc -t {} target mount".format(sn))
29    host.shell("hdc -t {} shell rm -r /data/log/hilog".format(sn))
30    host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(sn))
31    if "sa_listen_cfg_path" in source_path:
32        driver.Storage.push_file(local_path=source_path["sa_listen_cfg_path"], device_path="/system/etc/init")
33        host.shell("hdc -t {} shell chmod 644 /system/etc/init/listen_test.cfg".format(sn))
34        driver.Storage.push_file(local_path=source_path["sa_listen_json_path"], device_path="/system/profile/")
35        host.shell("hdc -t {} shell chmod 644 /system/profile/listen_test.json".format(sn))
36
37    if "sa_lib_listen_test_path" in source_path:
38        driver.Storage.push_file(local_path=source_path["sa_lib_listen_test_path"], device_path="/system/lib/")
39        host.shell("hdc -t {} shell chmod 644 /system/lib/liblisten_test.z.so".format(sn))
40
41    if "sa_proxy_path" in source_path:
42        driver.Storage.push_file(local_path=source_path["sa_proxy_path"], device_path="/system/lib/")
43        host.shell("hdc -t {} shell chmod 644 /system/lib/libtest_sa_proxy.z.so".format(sn))
44
45    if "sa_lib_fwk_path" in source_path:
46        driver.Storage.push_file(local_path=source_path["sa_lib_fwk_path"], device_path="/system/lib/")
47        host.shell("hdc -t {} shell chmod 644 /system/lib/libsystem_ability_fwk.z.so".format(sn))
48
49    if "sa_lib_audio_ability" in source_path:
50        driver.Storage.push_file(local_path=source_path["sa_lib_audio_ability"], device_path="/system/lib/")
51        host.shell("hdc -t {} shell chmod 644 /system/lib/libtest_audio_ability.z.so".format(sn))
52
53    if "sa_ondemand_path" in source_path:
54        driver.Storage.push_file(local_path=source_path["sa_ondemand_path"], device_path="/system/bin/")
55        host.shell("hdc -t {} shell chmod 755 /system/bin/ondemand".format(sn))
56
57    if "sa_para_path" in source_path:
58        driver.Storage.push_file(local_path=source_path["sa_para_path"], device_path="/system/etc/param/")
59        host.shell("hdc -t {} shell chmod 755 /system/etc/param/samgr.para".format(sn))
60        driver.Storage.push_file(local_path=source_path["sa_para_dac_path"], device_path="/system/etc/param/")
61        host.shell("hdc -t {} shell chmod 755 /system/etc/param/samgr.para.dac".format(sn))
62    if update_param:
63        driver.System.execute_command("ondemand param true")
64    driver.System.reboot()
65
66
67def remove_source(source_path, driver, sn):
68    """
69    @func: push resources from devices
70    @param source_path: the path of resources required by a case
71    @param driver: the device
72    @param sn: device sn
73    """
74    host.shell("hdc -t {} shell kill -9 `pidof listen_test`".format(sn))
75    host.shell("hdc -t {} target mount".format(sn))
76    if "sa_listen_cfg_path" in source_path:
77        driver.Storage.remove_file("/system/etc/init/listen_test.cfg")
78        driver.Storage.remove_file("/system/etc/init/listen_test.json")
79
80    if "sa_lib_listen_test_path" in source_path:
81        driver.Storage.remove_file("/system/lib/liblisten_test.z.so")
82
83    if "sa_proxy_path" in source_path:
84        driver.Storage.remove_file("/system/lib/libtest_sa_proxy.z.so")
85
86    if "sa_lib_fwk_path" in source_path:
87        driver.Storage.remove_file("/system/lib/libsystem_ability_fwk.z.so")
88
89    if "sa_lib_audio_ability" in source_path:
90        driver.Storage.remove_file("/system/lib/libtest_audio_ability.z.so")
91
92    if "sa_ondemand_path" in source_path:
93        driver.Storage.remove_file("/system/bin/ondemand")
94
95    if "sa_para_path" in source_path:
96        driver.Storage.remove_file("/system/etc/param/samgr.para")
97        driver.Storage.remove_file("/system/etc/param/samgr.para.dac")
98        driver.Storage.push_file(local_path=source_path["sa_para_origin"], device_path="/system/etc/param/")
99        driver.Storage.push_file(local_path=source_path["sa_para_dac_origin"], device_path="/system/etc/param/")
100