15ba71b47Sopenharmony_ci#!/usr/bin/env python3
25ba71b47Sopenharmony_ci#-*- coding: utf-8 -*-
35ba71b47Sopenharmony_ci
45ba71b47Sopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd.
55ba71b47Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
65ba71b47Sopenharmony_ci# you may not use this file except in compliance with the License.
75ba71b47Sopenharmony_ci# You may obtain a copy of the License at
85ba71b47Sopenharmony_ci#
95ba71b47Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
105ba71b47Sopenharmony_ci#
115ba71b47Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
125ba71b47Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
135ba71b47Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145ba71b47Sopenharmony_ci# See the License for the specific language governing permissions and
155ba71b47Sopenharmony_ci# limitations under the License.
165ba71b47Sopenharmony_ci
175ba71b47Sopenharmony_cifrom hypium.action.host import host
185ba71b47Sopenharmony_ci
195ba71b47Sopenharmony_ci
205ba71b47Sopenharmony_cidef push_source(source_path, driver, sn, update_param=False):
215ba71b47Sopenharmony_ci    """
225ba71b47Sopenharmony_ci    @func: push resources to devices
235ba71b47Sopenharmony_ci    @param source_path: the path of resources required by a case
245ba71b47Sopenharmony_ci    @param driver: the device
255ba71b47Sopenharmony_ci    @param sn: device sn
265ba71b47Sopenharmony_ci    """
275ba71b47Sopenharmony_ci    host.shell("hdc -t {} shell kill -9 `pidof listen_test`".format(sn))
285ba71b47Sopenharmony_ci    host.shell("hdc -t {} target mount".format(sn))
295ba71b47Sopenharmony_ci    host.shell("hdc -t {} shell rm -r /data/log/hilog".format(sn))
305ba71b47Sopenharmony_ci    host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(sn))
315ba71b47Sopenharmony_ci    if "sa_listen_cfg_path" in source_path:
325ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_listen_cfg_path"], device_path="/system/etc/init")
335ba71b47Sopenharmony_ci        host.shell("hdc -t {} shell chmod 644 /system/etc/init/listen_test.cfg".format(sn))
345ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_listen_json_path"], device_path="/system/profile/")
355ba71b47Sopenharmony_ci        host.shell("hdc -t {} shell chmod 644 /system/profile/listen_test.json".format(sn))
365ba71b47Sopenharmony_ci
375ba71b47Sopenharmony_ci    if "sa_lib_listen_test_path" in source_path:
385ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_lib_listen_test_path"], device_path="/system/lib/")
395ba71b47Sopenharmony_ci        host.shell("hdc -t {} shell chmod 644 /system/lib/liblisten_test.z.so".format(sn))
405ba71b47Sopenharmony_ci
415ba71b47Sopenharmony_ci    if "sa_proxy_path" in source_path:
425ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_proxy_path"], device_path="/system/lib/")
435ba71b47Sopenharmony_ci        host.shell("hdc -t {} shell chmod 644 /system/lib/libtest_sa_proxy.z.so".format(sn))
445ba71b47Sopenharmony_ci
455ba71b47Sopenharmony_ci    if "sa_lib_fwk_path" in source_path:
465ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_lib_fwk_path"], device_path="/system/lib/")
475ba71b47Sopenharmony_ci        host.shell("hdc -t {} shell chmod 644 /system/lib/libsystem_ability_fwk.z.so".format(sn))
485ba71b47Sopenharmony_ci
495ba71b47Sopenharmony_ci    if "sa_lib_audio_ability" in source_path:
505ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_lib_audio_ability"], device_path="/system/lib/")
515ba71b47Sopenharmony_ci        host.shell("hdc -t {} shell chmod 644 /system/lib/libtest_audio_ability.z.so".format(sn))
525ba71b47Sopenharmony_ci
535ba71b47Sopenharmony_ci    if "sa_ondemand_path" in source_path:
545ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_ondemand_path"], device_path="/system/bin/")
555ba71b47Sopenharmony_ci        host.shell("hdc -t {} shell chmod 755 /system/bin/ondemand".format(sn))
565ba71b47Sopenharmony_ci
575ba71b47Sopenharmony_ci    if "sa_para_path" in source_path:
585ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_para_path"], device_path="/system/etc/param/")
595ba71b47Sopenharmony_ci        host.shell("hdc -t {} shell chmod 755 /system/etc/param/samgr.para".format(sn))
605ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_para_dac_path"], device_path="/system/etc/param/")
615ba71b47Sopenharmony_ci        host.shell("hdc -t {} shell chmod 755 /system/etc/param/samgr.para.dac".format(sn))
625ba71b47Sopenharmony_ci    if update_param:
635ba71b47Sopenharmony_ci        driver.System.execute_command("ondemand param true")
645ba71b47Sopenharmony_ci    driver.System.reboot()
655ba71b47Sopenharmony_ci
665ba71b47Sopenharmony_ci
675ba71b47Sopenharmony_cidef remove_source(source_path, driver, sn):
685ba71b47Sopenharmony_ci    """
695ba71b47Sopenharmony_ci    @func: push resources from devices
705ba71b47Sopenharmony_ci    @param source_path: the path of resources required by a case
715ba71b47Sopenharmony_ci    @param driver: the device
725ba71b47Sopenharmony_ci    @param sn: device sn
735ba71b47Sopenharmony_ci    """
745ba71b47Sopenharmony_ci    host.shell("hdc -t {} shell kill -9 `pidof listen_test`".format(sn))
755ba71b47Sopenharmony_ci    host.shell("hdc -t {} target mount".format(sn))
765ba71b47Sopenharmony_ci    if "sa_listen_cfg_path" in source_path:
775ba71b47Sopenharmony_ci        driver.Storage.remove_file("/system/etc/init/listen_test.cfg")
785ba71b47Sopenharmony_ci        driver.Storage.remove_file("/system/etc/init/listen_test.json")
795ba71b47Sopenharmony_ci
805ba71b47Sopenharmony_ci    if "sa_lib_listen_test_path" in source_path:
815ba71b47Sopenharmony_ci        driver.Storage.remove_file("/system/lib/liblisten_test.z.so")
825ba71b47Sopenharmony_ci
835ba71b47Sopenharmony_ci    if "sa_proxy_path" in source_path:
845ba71b47Sopenharmony_ci        driver.Storage.remove_file("/system/lib/libtest_sa_proxy.z.so")
855ba71b47Sopenharmony_ci
865ba71b47Sopenharmony_ci    if "sa_lib_fwk_path" in source_path:
875ba71b47Sopenharmony_ci        driver.Storage.remove_file("/system/lib/libsystem_ability_fwk.z.so")
885ba71b47Sopenharmony_ci
895ba71b47Sopenharmony_ci    if "sa_lib_audio_ability" in source_path:
905ba71b47Sopenharmony_ci        driver.Storage.remove_file("/system/lib/libtest_audio_ability.z.so")
915ba71b47Sopenharmony_ci
925ba71b47Sopenharmony_ci    if "sa_ondemand_path" in source_path:
935ba71b47Sopenharmony_ci        driver.Storage.remove_file("/system/bin/ondemand")
945ba71b47Sopenharmony_ci
955ba71b47Sopenharmony_ci    if "sa_para_path" in source_path:
965ba71b47Sopenharmony_ci        driver.Storage.remove_file("/system/etc/param/samgr.para")
975ba71b47Sopenharmony_ci        driver.Storage.remove_file("/system/etc/param/samgr.para.dac")
985ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_para_origin"], device_path="/system/etc/param/")
995ba71b47Sopenharmony_ci        driver.Storage.push_file(local_path=source_path["sa_para_dac_origin"], device_path="/system/etc/param/")
100