• 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
17import json
18import time
19
20class PermissionUtils:
21    systemPermissionList = []
22    userPermissionList = []
23
24    def __init__(self):
25        self.systemPermissionList.clear()
26        self.userPermissionList.clear()
27        self.getAllPermissions()
28
29    def isInPermissionList(self, permission):
30        return permission in self.permissionList
31
32    def getAllPermissions(self):
33        with open('./testcases/module.json', 'r') as f:
34            permissionData = json.load(f)['module']['definePermissions']
35        for permissionInfo in permissionData:
36            if 'grantMode' in permissionInfo and permissionInfo['grantMode'] == 'system_grant':
37                self.systemPermissionList.append(permissionInfo['name'])
38            elif 'grantMode' in permissionInfo and permissionInfo['grantMode'] == 'user_grant':
39                self.userPermissionList.append(permissionInfo['name'])
40
41    def getDevicePermissionList(self, permissionBundleInfo):
42        permissionBundleInfo = permissionBundleInfo[permissionBundleInfo.index('\n') + 1 :]
43        time.sleep(1)
44        permissionBundleInfoObj = json.loads(permissionBundleInfo)
45        devicePermissions = []
46        if 'defPermissions' in permissionBundleInfoObj:
47            devicePermissions = permissionBundleInfoObj['defPermissions']
48        return devicePermissions