1 /*
2 * Copyright (c) 2024 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<Uri> &uriVec, uint32_t mode = 0, const std::string &callerBundleName = "",
43         const std::string &targetBundleName = "");
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 SetContentUriCheckResult(const std::vector<bool> &contentUriResult);
49 
50     void SetMediaUriCheckResult(const std::vector<bool> &mediaUriResult);
51 
52     void SetOtherUriCheckResult(const std::vector<bool> &otherUriResult);
53 
54     void GetNeedCheckProxyPermissionURI(std::vector<PolicyInfo> &proxyUrisByPolicy, std::vector<Uri> &proxyUrisByMap);
55 
56     void SetCheckProxyByMapResult(std::vector<bool> &proxyResultByMap);
57 
58     void SetCheckProxyByPolicyResult(std::vector<bool> &proxyResultByPolicy);
59 
60     int32_t GetUriToGrantByMap(std::vector<std::string> &uriVec);
61 
62     void SelectPermissionedUri(std::vector<Uri> &uris, std::vector<int32_t> &indexs, std::vector<std::string> &uriVec);
63 
64     int32_t GetUriToGrantByPolicy(std::vector<PolicyInfo> &docsPolicyInfoVec,
65         std::vector<PolicyInfo> &bundlePolicyInfoVec);
66 
67     int32_t GetPermissionedUriCount();
68 
69     std::string targetAppName;
70 
71     // media uri
72     std::vector<Uri> mediaUris;
73     std::vector<int32_t> mediaIndexs;
74 
75     // content uri
76     std::vector<Uri> contentUris;
77     std::vector<int32_t> contentIndexs;
78 
79     // docs and bundle uri
80     std::vector<Uri> otherUris;
81     std::vector<int32_t> otherIndexs;
82     std::vector<PolicyInfo> otherPolicyInfos;
83 
84     // caller's uri
85     std::vector<PolicyInfo> selfBundlePolicyInfos;
86 
87     // for check proxy uri permission
88     std::vector<int32_t> proxyIndexsByMap;
89     std::vector<int32_t> proxyIndexsByPolicy;
90 
91     // result of CheckUriPermission
92     std::vector<bool> result;
93     std::vector<bool> isDocsUriVec;
94 
95     // target's uri
96     int32_t targetBundleUriCount = 0;
97     std::vector<bool> isTargetBundleUri;
98 
99     int32_t validUriCount = 0;
100     int32_t totalUriCount = 0;
101 };
102 } // OHOS
103 } // AAFwk
104 #endif // OHOS_ABILITY_RUNTIME_BATCH_URI_H