• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#-*- coding: utf-8 -*-
3
4# Copyright (c) 2025 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
17
18def push_source(source_path, driver, sn, update_param=False):
19    """
20    @func: push resources to devices
21    @param source_path: the path of resources required by a case
22    @param driver: the device
23    @param sn: device sn
24    """
25    driver.shell("kill -9 `pidof listen_test`")
26    driver.hdc("target mount")
27    driver.shell("rm -r /data/log/hilog")
28    driver.shell("hilog -d /system/bin/samgr")
29    if "sa_listen_cfg_path" in source_path:
30        driver.Storage.push_file(local_path=source_path["sa_listen_cfg_path"], device_path="/system/etc/init")
31        driver.shell("chmod 644 /system/etc/init/listen_test.cfg")
32        driver.Storage.push_file(local_path=source_path["sa_listen_json_path"], device_path="/system/profile/")
33        driver.shell("chmod 644 /system/profile/listen_test.json")
34
35    if "sa_lib_listen_test_path" in source_path:
36        driver.Storage.push_file(local_path=source_path["sa_lib_listen_test_path"], device_path="/system/lib/")
37        driver.shell("chmod 644 /system/lib/liblisten_test.z.so")
38
39    if "sa_proxy_path" in source_path:
40        driver.Storage.push_file(local_path=source_path["sa_proxy_path"], device_path="/system/lib/")
41        driver.shell("chmod 644 /system/lib/libtest_sa_proxy.z.so")
42
43
44    if "sa_lib_audio_ability" in source_path:
45        driver.Storage.push_file(local_path=source_path["sa_lib_audio_ability"], device_path="/system/lib/")
46        driver.shell("chmod 644 /system/lib/libtest_audio_ability.z.so")
47
48    if "sa_ondemand_path" in source_path:
49        driver.Storage.push_file(local_path=source_path["sa_ondemand_path"], device_path="/system/bin/")
50        driver.shell("chmod 755 /system/bin/ondemand")
51
52    if "sa_para_path" in source_path:
53        driver.Storage.push_file(local_path=source_path["sa_para_path"], device_path="/system/etc/param/")
54        driver.shell("chmod 755 /system/etc/param/samgr.para")
55        driver.Storage.push_file(local_path=source_path["sa_para_dac_path"], device_path="/system/etc/param/")
56        driver.shell("chmod 755 /system/etc/param/samgr.para.dac")
57    if update_param:
58        driver.System.execute_command("ondemand param true")
59    driver.System.reboot()
60
61
62def remove_source(source_path, driver, sn):
63    """
64    @func: push resources from devices
65    @param source_path: the path of resources required by a case
66    @param driver: the device
67    @param sn: device sn
68    """
69    driver.shell("kill -9 `pidof listen_test`")
70    driver.shell("target mount")
71    if "sa_listen_cfg_path" in source_path:
72        driver.Storage.remove_file("/system/etc/init/listen_test.cfg")
73        driver.Storage.remove_file("/system/etc/init/listen_test.json")
74
75    if "sa_para_path" in source_path:
76        driver.Storage.remove_file("/system/etc/param/samgr.para")
77        driver.Storage.remove_file("/system/etc/param/samgr.para.dac")
78        driver.Storage.push_file(local_path=source_path["sa_para_origin"], device_path="/system/etc/param/")
79        driver.Storage.push_file(local_path=source_path["sa_para_dac_origin"], device_path="/system/etc/param/")
80