1 /* 2 * Copyright (c) 2021-2023 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 DISTRIBUTED_SCHED_PERMISSION_H 17 #define DISTRIBUTED_SCHED_PERMISSION_H 18 19 #include <string> 20 21 #include "distributed_sched_interface.h" 22 #include "nlohmann/json.hpp" 23 #include "single_instance.h" 24 25 namespace OHOS { 26 namespace DistributedSchedule { 27 struct GroupInfo { 28 std::string groupName; 29 std::string groupId; 30 std::string groupOwner; 31 int32_t groupType; 32 int32_t groupVisibility; 33 GroupInfoGroupInfo34 GroupInfo() : groupName(""), groupId(""), groupOwner(""), groupType(0), groupVisibility(0) {} 35 }; 36 37 void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo); 38 39 class DistributedSchedPermission { 40 DECLARE_SINGLE_INSTANCE(DistributedSchedPermission); 41 42 public: 43 using AccountInfo = IDistributedSched::AccountInfo; 44 45 int32_t CheckSendResultPermission(const AAFwk::Want& want, const CallerInfo& callerInfo, 46 const AccountInfo& accountInfo, AppExecFwk::AbilityInfo& targetAbility); 47 int32_t CheckStartPermission(const AAFwk::Want& want, const CallerInfo& callerInfo, 48 const AccountInfo& accountInfo, AppExecFwk::AbilityInfo& targetAbility); 49 int32_t CheckGetCallerPermission(const AAFwk::Want& want, const CallerInfo& callerInfo, 50 const AccountInfo& accountInfo, AppExecFwk::AbilityInfo& targetAbility); 51 bool IsFoundationCall() const; 52 bool IsSceneBoardCall() const; 53 int32_t CheckPermission(uint32_t accessToken, const std::string& permissionName) const; 54 int32_t CheckPermissionAll(uint32_t accessToken, const std::string& permissionName) const; 55 int32_t GetAccountInfo(const std::string& remoteNetworkId, const CallerInfo& callerInfo, 56 AccountInfo& accountInfo); 57 bool GetTargetAbility(const AAFwk::Want& want, AppExecFwk::AbilityInfo& targetAbility, 58 bool needQueryExtension = false) const; 59 void MarkUriPermission(OHOS::AAFwk::Want& want, uint32_t accessToken); 60 61 private: 62 bool GetRelatedGroups(const std::string& udid, const std::vector<std::string>& bundleNames, 63 AccountInfo& accountInfo); 64 bool ParseGroupInfos(const std::string& returnGroupStr, std::vector<GroupInfo>& groupInfos); 65 bool VerifyPermission(uint32_t accessToken, const std::string& permissionName) const; 66 bool CheckAccountAccessPermission(const CallerInfo& callerInfo, 67 const AccountInfo& accountInfo, const std::string& targetBundleName); 68 bool CheckComponentAccessPermission(const AppExecFwk::AbilityInfo& targetAbility, 69 const CallerInfo& callerInfo, const AccountInfo& accountInfo, const AAFwk::Want& want) const; 70 bool CheckStartControlPermission(const AppExecFwk::AbilityInfo& targetAbility, 71 const CallerInfo& callerInfo, const AAFwk::Want& want) const; 72 bool CheckBackgroundPermission(const AppExecFwk::AbilityInfo& targetAbility, 73 const CallerInfo& callerInfo, const AAFwk::Want& want, bool needCheckApiVersion) const; 74 bool CheckMinApiVersion(const AppExecFwk::AbilityInfo& targetAbility, int32_t apiVersion) const; 75 bool CheckDeviceSecurityLevel(const std::string& srcDeviceId, const std::string& dstDeviceId) const; 76 int32_t GetDeviceSecurityLevel(const std::string& udid) const; 77 bool CheckTargetAbilityVisible(const AppExecFwk::AbilityInfo& targetAbility, const CallerInfo& callerInfo) const; 78 bool IsDistributedFile(const std::string& path) const; 79 }; 80 } // namespace DistributedSchedule 81 } // namespace OHOS 82 #endif // DISTRIBUTED_SCHED_PERMISSION_H