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_URI_PERMISSION_EVENT_H
17 #define OHOS_ABILITY_RUNTIME_URI_PERMISSION_EVENT_H
18 
19 #include "event_report.h"
20 #include "bundle_mgr_helper.h"
21 
22 namespace OHOS {
23 namespace AAFwk {
24 
25 class UPMSUtils {
26 public:
27     static bool SendShareUnPrivilegeUriEvent(uint32_t callTokenId, uint32_t targetTokenId);
28     static bool SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId,
29         const std::vector<std::string> &uriVec, const std::vector<int32_t> &resVec);
30     static int32_t GetCurrentAccountId();
31     static bool IsFoundationCall();
32     static bool IsSAOrSystemAppCall();
33     static bool IsSystemAppCall(uint32_t tokenId);
34     static bool CheckIsSystemAppByTokenId(uint32_t tokenId);
35     static bool GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName);
36     static bool GetBundleNameByTokenId(uint32_t tokenId, std::string &bundleName);
37     static bool GetAlterableBundleNameByTokenId(uint32_t tokenId, std::string &bundleName);
38     static int32_t GetAppIdByBundleName(const std::string &bundleName, std::string &appId);
39     static int32_t GetTokenIdByBundleName(const std::string &bundleName, int32_t appIndex, uint32_t &tokenId);
40     static bool IsDocsCloudUri(Uri &uri);
41 
42 private:
43     static std::shared_ptr<AppExecFwk::BundleMgrHelper> ConnectManagerHelper();
44     static bool CheckAndCreateEventInfo(uint32_t callerTokenId, uint32_t targetTokenId, EventInfo &eventInfo);
45     static bool CheckIsSystemAppByBundleName(std::string &bundleName);
46 
47 private:
48     static std::shared_ptr<AppExecFwk::BundleMgrHelper> bundleMgrHelper_;
49 };
50 } // OHOS
51 } // AAFwk
52 #endif  // OHOS_ABILITY_RUNTIME_URI_PERMISSION_EVENT_H