• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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     int32_t CheckPermission(uint32_t accessToken, const std::string& permissionName) const;
53     int32_t GetAccountInfo(const std::string& remoteNetworkId, const CallerInfo& callerInfo,
54         AccountInfo& accountInfo);
55     bool GetTargetAbility(const AAFwk::Want& want, AppExecFwk::AbilityInfo& targetAbility,
56         bool needQueryExtension = false) const;
57 
58 private:
59     bool GetRelatedGroups(const std::string& udid, const std::vector<std::string>& bundleNames,
60         AccountInfo& accountInfo);
61     bool ParseGroupInfos(const std::string& returnGroupStr, std::vector<GroupInfo>& groupInfos);
62     bool IsNativeCall(uint32_t accessToken) const;
63     bool VerifyPermission(uint32_t accessToken, const std::string& permissionName) const;
64     bool CheckAccountAccessPermission(const CallerInfo& callerInfo,
65         const AccountInfo& accountInfo, const std::string& targetBundleName);
66     bool CheckComponentAccessPermission(const AppExecFwk::AbilityInfo& targetAbility,
67         const CallerInfo& callerInfo, const AccountInfo& accountInfo, const AAFwk::Want& want) const;
68     bool CheckCustomPermission(const AppExecFwk::AbilityInfo& targetAbility,
69         const CallerInfo& callerInfo) 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 CheckTargetAbilityVisible(const AppExecFwk::AbilityInfo& targetAbility, const CallerInfo& callerInfo) const;
76 };
77 } // namespace DistributedSchedule
78 } // namespace OHOS
79 #endif // DISTRIBUTED_SCHED_PERMISSION_H