• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "permission_manager_adapter.h"
17 #include "accesstoken_kit.h"
18 #include "dlp_dfx_define.h"
19 #include "dlp_permission.h"
20 #include "dlp_permission_log.h"
21 #include "bundle_manager_adapter.h"
22 #include "bundle_mgr_client.h"
23 #include "system_ability_definition.h"
24 #include "iservice_registry.h"
25 #include "ipc_skeleton.h"
26 #include "dlp_permission_service_test.h"
27 
28 namespace OHOS {
29 namespace Security {
30 namespace DlpPermission {
31 using namespace Security::AccessToken;
32 using namespace OHOS::AppExecFwk;
33 
34 static const std::string PERMISSION_ACCESS_DLP_FILE = "ohos.permission.ACCESS_DLP_FILE";
35 static const std::string PERMISSION_ENTERPRISE_ACCESS_DLP_FILE = "ohos.permission.ENTERPRISE_ACCESS_DLP_FILE";
36 static const int32_t TWO = 2;
37 
38 bool DlpPermissionServiceTest::isSandbox = true;
39 bool DlpPermissionServiceTest::isCheckSandbox = true;
40 int32_t DlpPermissionServiceTest::permType = 0;
41 
CheckPermission(const std::string & permission)42 bool PermissionManagerAdapter::CheckPermission(const std::string& permission)
43 {
44     switch (DlpPermissionServiceTest::permType) {
45         case -1:
46             return false;
47         case 0:
48             return true;
49         case 1:
50             if (permission == PERMISSION_ACCESS_DLP_FILE) {
51                 return true;
52             }
53             return false;
54         case TWO:
55             if (permission == PERMISSION_ENTERPRISE_ACCESS_DLP_FILE) {
56                 return true;
57             }
58             return false;
59         default:
60             break;
61     }
62     return true;
63 }
64 
CheckPermissionAndGetAppId(std::string & appId)65 bool PermissionManagerAdapter::CheckPermissionAndGetAppId(std::string& appId)
66 {
67     appId = "6917562860841254665";
68     return true;
69 }
70 
CheckSandboxFlagWithService(AccessToken::AccessTokenID tokenId,bool & sandboxFlag)71 int32_t PermissionManagerAdapter::CheckSandboxFlagWithService(AccessToken::AccessTokenID tokenId, bool& sandboxFlag)
72 {
73     if (!DlpPermissionServiceTest::isCheckSandbox) {
74         return DLP_SERVICE_ERROR_VALUE_INVALID;
75     }
76     sandboxFlag = DlpPermissionServiceTest::isSandbox;
77     return DLP_OK;
78 }
79 }  // namespace DlpPermission
80 }  // namespace Security
81 }  // namespace OHOS