• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2024-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 #ifndef OHOS_ABILITY_RUNTIME_BATCH_URI_H
17 #define OHOS_ABILITY_RUNTIME_BATCH_URI_H
18 
19 #include <sys/types.h>
20 #include <vector>
21 
22 #ifdef ABILITY_RUNTIME_FEATURE_SANDBOXMANAGER
23 #include "policy_info.h"
24 #else
25 #include "upms_policy_info.h"
26 #endif
27 
28 #include "uri.h"
29 
30 namespace OHOS {
31 namespace AAFwk {
32 namespace {
33 #ifdef ABILITY_RUNTIME_FEATURE_SANDBOXMANAGER
34 using PolicyInfo = AccessControl::SandboxManager::PolicyInfo;
35 #endif
36 }
37 
38 class BatchUri {
39 public:
BatchUri()40     BatchUri() {}
41 
42     int32_t Init(const std::vector<std::string> &uriVec, uint32_t mode = 0,
43         const std::string &callerAlterBundleName = "", const std::string &targetAlterBundleName = "");
44 
45     void InitFileUriInfo(Uri &uriInner, uint32_t index, const uint32_t mode = 0,
46         const std::string &callerBundleName = "", const std::string &targetBundleName = "");
47 
48     void SetMediaUriCheckResult(const std::vector<bool> &mediaUriResult);
49 
50     void SetOtherUriCheckResult(const std::vector<bool> &otherUriResult);
51 
52     void GetNeedCheckProxyPermissionURI(std::vector<PolicyInfo> &proxyUrisByPolicy, std::vector<Uri> &proxyUrisByMap);
53 
54     void SetCheckProxyByMapResult(std::vector<bool> &proxyResultByMap);
55 
56     void SetCheckProxyByPolicyResult(std::vector<bool> &proxyResultByPolicy);
57 
58     int32_t GetUriToGrantByMap(std::vector<std::string> &uriVec);
59 
60     void SelectPermissionedUri(std::vector<Uri> &uris, std::vector<int32_t> &indexs, std::vector<std::string> &uriVec);
61 
62     int32_t GetUriToGrantByPolicy(std::vector<PolicyInfo> &docsPolicyInfoVec,
63         std::vector<PolicyInfo> &bundlePolicyInfoVec);
64 
65     bool GetUriToGrantByPolicy(std::vector<PolicyInfo> &policyVec);
66 
67     int32_t GetPermissionedUriCount();
68 
69     // media
70     int32_t GetMediaUriToGrant(std::vector<std::string> &uriVec);
71 
72     bool IsAllUriValid();
73 
74     bool IsAllUriPermissioned();
75 
76     // media uri
77     std::vector<std::string> mediaUris;
78     std::vector<int32_t> mediaIndexes;
79 
80     // docs and bundle uri
81     std::vector<Uri> otherUris;
82     std::vector<int32_t> otherIndexes;
83     std::vector<PolicyInfo> otherPolicyInfos;
84 
85     // caller's uri
86     std::vector<PolicyInfo> selfBundlePolicyInfos;
87 
88     // for check proxy uri permission
89     std::vector<int32_t> proxyIndexesByMap;
90     std::vector<int32_t> proxyIndexesByPolicy;
91 
92     // result of CheckUriPermission
93     std::vector<bool> checkResult;
94     std::vector<bool> isDocsUriVec;
95 
96     // target's uri
97     int32_t targetBundleUriCount = 0;
98     std::vector<bool> isTargetBundleUri;
99 
100     int32_t validUriCount = 0;
101     int32_t totalUriCount = 0;
102 };
103 
104 struct BatchStringUri {
105     std::vector<std::string> uriStrVec;
106     std::vector<std::string> contentUris;
107     std::vector<std::string> mediaUriVec;
108     std::vector<PolicyInfo> policyVec;
109 };
110 } // OHOS
111 } // AAFwk
112 #endif // OHOS_ABILITY_RUNTIME_BATCH_URI_H