• 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_URI_UTILS_H
17 #define OHOS_ABILITY_RUNTIME_URI_UTILS_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "ability_record.h"
23 #include "nocopyable.h"
24 #include "uri.h"
25 #include "want.h"
26 
27 namespace OHOS {
28 namespace AAFwk {
29 class UriUtils {
30 public:
31     static UriUtils &GetInstance();
32 
33     std::vector<Uri> GetPermissionedUriList(const std::vector<std::string> &uriVec,
34         const std::vector<bool> &checkResults, uint32_t callerTokenId,
35         const std::string &targetBundleName, Want &want);
36 
37     bool GetUriListFromWant(Want &want, std::vector<std::string> &uriVec);
38 
39 #ifdef SUPPORT_UPMS
40     bool IsGrantUriPermissionFlag(const Want &want);
41 #endif // SUPPORT_UPMS
42 
43     bool IsServiceExtensionType(AppExecFwk::ExtensionAbilityType extensionAbilityType);
44 
45 #ifdef SUPPORT_UPMS
46     void GrantDmsUriPermission(Want &want, uint32_t callerTokenId, std::string targetBundleName, int32_t appIndex);
47 
48     bool GrantUriPermissionForServiceExtension(const AbilityRequest &abilityRequest);
49 
50     bool GrantUriPermissionForUIOrServiceExtension(const AbilityRequest &abilityRequest);
51 
52     void GrantUriPermission(Want &want, std::string targetBundleName, int32_t appIndex,
53         bool isSandboxApp, uint32_t callerTokenId, int32_t collaboratorType);
54 
55     void CheckUriPermission(uint32_t callerTokenId, Want &want);
56 
57     void GrantUriPermission(const std::vector<std::string> &uriVec, int32_t flag,
58         const std::string &targetBundleName, int32_t appIndex, uint32_t initiatorTokenId);
59 #endif // SUPPORT_UPMS
60 private:
61     UriUtils();
62     ~UriUtils();
63 
64 #ifdef SUPPORT_UPMS
65     bool GrantShellUriPermission(const std::vector<std::string> &strUriVec, uint32_t flag,
66         const std::string &targetPkg, int32_t appIndex);
67 
68     bool GrantUriPermissionInner(std::vector<std::string> uriVec, uint32_t callerTokenId,
69         const std::string &targetBundleName, int32_t appIndex, Want &want);
70 #endif // SUPPORT_UPMS
71 
72     bool IsDmsCall(uint32_t fromTokenId);
73 
74     bool IsSandboxApp(uint32_t tokenId);
75 
76     std::vector<Uri> GetUriListFromWantDms(Want &want);
77 
78     void PublishFileOpenEvent(const Want &want);
79 
80     bool IsInAncoAppIdentifier(const std::string &bundleName);
81 
82     bool CheckIsInAncoAppIdentifier(const std::string &identifier, const std::string &bundleName);
83 
84     void ProcessUDMFKey(Want &want);
85 
86     bool ProcessWantUri(bool checkResult, int32_t apiVersion, Want &want, std::vector<Uri> &permissionedUris);
87 
88     bool GetCallerNameAndApiVersion(uint32_t tokenId, std::string &callerName, int32_t &apiVersion);
89 
90     bool SendGrantUriPermissionEvent(const std::string &callerBundleName, const std::string &targetBundleName,
91         const std::string &oriUri, int32_t apiVersion, const std::string &eventType);
92 
93     DISALLOW_COPY_AND_MOVE(UriUtils);
94 };
95 } // namespace AAFwk
96 } // namespace OHOS
97 #endif // OHOS_ABILITY_RUNTIME_URI_UTILS_H