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_ciimport time
185ba71b47Sopenharmony_cifrom devicetest.core.test_case import TestCase, CheckPoint, get_report_dir
195ba71b47Sopenharmony_cifrom hypium import UiDriver
205ba71b47Sopenharmony_cifrom hypium.action.os_hypium.device_logger import DeviceLogger
215ba71b47Sopenharmony_cifrom tools.get_source_path import get_source_path
225ba71b47Sopenharmony_cifrom tools.push_remove_source import push_source, remove_source
235ba71b47Sopenharmony_ci
245ba71b47Sopenharmony_ci
255ba71b47Sopenharmony_ciclass case21_add001(TestCase):
265ba71b47Sopenharmony_ci
275ba71b47Sopenharmony_ci    def __init__(self, configs):
285ba71b47Sopenharmony_ci        self.TAG = self.__class__.__name__
295ba71b47Sopenharmony_ci        TestCase.__init__(self, self.TAG, configs)
305ba71b47Sopenharmony_ci        self.tests = [
315ba71b47Sopenharmony_ci            "test_step"
325ba71b47Sopenharmony_ci        ]
335ba71b47Sopenharmony_ci        self.driver = UiDriver(self.device1)
345ba71b47Sopenharmony_ci        self.sn = self.device1.device_sn
355ba71b47Sopenharmony_ci        self.source_path = {}
365ba71b47Sopenharmony_ci
375ba71b47Sopenharmony_ci    def setup(self):
385ba71b47Sopenharmony_ci        self.log.info("case21_add001 start")
395ba71b47Sopenharmony_ci        need_source = {"cfg": True, "fwk": True, "listen_test": True, "audio_ability": True, "ondemand": True,
405ba71b47Sopenharmony_ci                       "proxy": True, "para": False}
415ba71b47Sopenharmony_ci        self.source_path = get_source_path(need_source=need_source, casename="level0/case21_add001")
425ba71b47Sopenharmony_ci        push_source(source_path=self.source_path, driver=self.driver, sn=self.sn)
435ba71b47Sopenharmony_ci
445ba71b47Sopenharmony_ci    def test_step(self):
455ba71b47Sopenharmony_ci        driver = self.driver
465ba71b47Sopenharmony_ci        driver.Screen.close()
475ba71b47Sopenharmony_ci        time.sleep(20)
485ba71b47Sopenharmony_ci        result = driver.System.execute_command("hidumper -ls")
495ba71b47Sopenharmony_ci        max_wait_time = 5
505ba71b47Sopenharmony_ci        wait_time = 0
515ba71b47Sopenharmony_ci        while ("1494" in result and wait_time <= max_wait_time):
525ba71b47Sopenharmony_ci            wait_time += 1
535ba71b47Sopenharmony_ci            time.sleep(1)
545ba71b47Sopenharmony_ci            result = driver.System.execute_command("hidumper -ls")
555ba71b47Sopenharmony_ci        CheckPoint("Initially, 1494 was not loaded")
565ba71b47Sopenharmony_ci        assert "1494" not in result
575ba71b47Sopenharmony_ci
585ba71b47Sopenharmony_ci        device_logger = DeviceLogger(driver).set_filter_string("01800")
595ba71b47Sopenharmony_ci        device_logger.start_log(get_report_dir() + "//case21_add001.txt")
605ba71b47Sopenharmony_ci        driver.System.execute_command("./system/bin/sa_main /system/profile/listen_test.json")
615ba71b47Sopenharmony_ci        device_logger.stop_log()
625ba71b47Sopenharmony_ci        device_logger.check_log("AddSystemProcessInner PERMISSION DENIED!", EXCEPTION=True)
635ba71b47Sopenharmony_ci
645ba71b47Sopenharmony_ci        result = driver.System.execute_command("hidumper -ls")
655ba71b47Sopenharmony_ci        max_wait_time = 5
665ba71b47Sopenharmony_ci        wait_time = 0
675ba71b47Sopenharmony_ci        while ("1494" in result and wait_time <= max_wait_time):
685ba71b47Sopenharmony_ci            wait_time += 1
695ba71b47Sopenharmony_ci            time.sleep(1)
705ba71b47Sopenharmony_ci            result = driver.System.execute_command("hidumper -ls")
715ba71b47Sopenharmony_ci        CheckPoint("Non native process add intercepted, 1494 not loaded")
725ba71b47Sopenharmony_ci        assert "1494" not in result
735ba71b47Sopenharmony_ci
745ba71b47Sopenharmony_ci    def teardown(self):
755ba71b47Sopenharmony_ci        self.driver.Screen.close()
765ba71b47Sopenharmony_ci        remove_source(source_path=self.source_path, driver=self.driver, sn=self.sn)
775ba71b47Sopenharmony_ci        self.log.info("case21_add001 down")
78