1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (C) 2024 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15import subprocess
16import time
17
18def IsLogVersion():
19    output = subprocess.check_output("hdc shell param get const.product.software.version", shell=True, text=True, encoding="utf-8").strip()
20    return "log" in output
21
22def IsRootVersion():
23    output = subprocess.check_output("hdc shell param get const.debuggable", shell=True, text=True, encoding="utf-8").strip()
24    return output == "1"
25
26def IsOpenHarmonyVersion():
27    output = subprocess.check_output("hdc shell param get const.product.software.version", shell=True, text=True, encoding="utf-8").strip()
28    return "OpenHarmony" in output
29
30def pytest_sessionstart(session):
31    if not IsRootVersion():
32        print("device is no root version")
33        subprocess.check_call("hdc install testModule/resource/entry-default-signed.hap", shell=True)
34    else:
35        print("device is root version")
36
37def pytest_sessionfinish(session, exitstatus):
38    if not IsRootVersion():
39        subprocess.check_call("hdc uninstall com.example.myapplication", shell=True)