• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "appspawn_mount_permission.h"
17 #include "sandbox_utils.h"
18 #include "appspawn_adapter.h"
19 namespace OHOS {
20 namespace AppSpawn {
21 
22 bool AppspawnMountPermission::g_IsLoad = false;
23 
GetMountPermissionList()24 std::set<std::string> AppspawnMountPermission::GetMountPermissionList()
25 {
26     if (!AppspawnMountPermission::g_IsLoad) {
27         LoadAppSandboxConfig();
28         APPSPAWN_LOGI("GetMountPermissionList LoadAppSandboxConfig");
29         AppspawnMountPermission::g_IsLoad = true;
30     }
31     return SandboxUtils::GetMountPermissionNames();
32 }
33 
GenPermissionCode(const std::set<std::string> & permissions)34 uint32_t AppspawnMountPermission::GenPermissionCode(const std::set<std::string> &permissions)
35 {
36     uint32_t result = 0;
37     if (permissions.size() == 0) {
38         return result;
39     }
40     uint32_t flagIndex = 1;
41     for (std::string mountPermission : GetMountPermissionList()) {
42         for (std::string inputPermission : permissions) {
43             if (mountPermission.compare(inputPermission) == 0) {
44                 result |= flagIndex;
45             }
46         }
47         flagIndex <<= 1;
48     }
49     return result;
50 }
51 
IsMountPermission(uint32_t code,const std::string permission)52 bool AppspawnMountPermission::IsMountPermission(uint32_t code, const std::string permission)
53 {
54     for (std::string mountPermission : SandboxUtils::GetMountPermissionNames()) {
55         if (mountPermission.compare(permission) == 0) {
56             return code & 1;
57         }
58         code >>= 1;
59     }
60     return false;
61 } // AppSpawn
62 } // OHOS
63 }
64