1 /*
2  * Copyright (c) 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 #ifndef OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_COLLABORATOR_PROXY_H
16 #define OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_COLLABORATOR_PROXY_H
17 
18 #include "iability_manager_collaborator.h"
19 #include "iremote_proxy.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
23 class AbilityManagerCollaboratorProxy : public IRemoteProxy<IAbilityManagerCollaborator> {
24 public:
AbilityManagerCollaboratorProxy(const sptr<IRemoteObject> & impl)25     explicit AbilityManagerCollaboratorProxy(const sptr<IRemoteObject> &impl)
26         : IRemoteProxy<IAbilityManagerCollaborator>(impl)
27     {}
28     virtual ~AbilityManagerCollaboratorProxy() = default;
29 
30     /**
31      * @brief Notify collaborator to StartAbility.
32      * @param AbilityInfo ability info from bms
33      * @param userId userId.
34      * @param want targert info, will modify by collaborator.
35      * @param accessTokenIDEx accessToken
36      * @return 0 when notify start ability success or else failed.
37      */
38     virtual int32_t NotifyStartAbility(const AppExecFwk::AbilityInfo &abilityInfo,
39         int32_t userId, Want &want, uint64_t accessTokenIDEx) override;
40 
41     /**
42      * @brief Notify collaborator to app preload.
43      * @param bundleName bundlName.
44      * @return 0 means success or else failed.
45      */
46     virtual int32_t NotifyPreloadAbility(const std::string &bundleName) override;
47 
48     /**
49      * @brief Notify when mission is created.
50      * @param missionId missionId.
51      * @param want target info.
52      * @return 0 when notify mission created success or else failed.
53      */
54     virtual int32_t NotifyMissionCreated(int32_t missionId, const Want &want) override;
55 
56     /**
57      * @brief Notify when mission is created.
58      * @param sessionInfo sessionInfo.
59      * @return 0 when notify mission created success or else failed.
60      */
61     virtual int32_t NotifyMissionCreated(const sptr<SessionInfo> &sessionInfo) override;
62 
63     /**
64      * @brief Notify when start loading ability record.
65      * @param AbilityInfo ability info from bms.
66      * @param missionId missionId.
67      * @param want target info.
68      * @return 0 when notify load ability success or else failed.
69      */
70     virtual int32_t NotifyLoadAbility(const AppExecFwk::AbilityInfo &abilityInfo,
71         int32_t missionId, const Want &want) override;
72 
73     /**
74      * @brief Notify when start loading ability record.
75      * @param AbilityInfo ability info from bms.
76      * @param sessionInfo sessionInfo.
77      * @return 0 when notify load ability success or else failed.
78     */
79     virtual int32_t NotifyLoadAbility(
80         const AppExecFwk::AbilityInfo &abilityInfo, const sptr<SessionInfo> &sessionInfo) override;
81 
82     /**
83      * @brief Notify when notify app to background.
84      * @param missionId missionId.
85      * @return 0 when notify move mission to background success or else failed.
86      */
87     virtual int32_t NotifyMoveMissionToBackground(int32_t missionId) override;
88 
89     /**
90      * @brief Notify when notify app to foreground.
91      * @param missionId missionId.
92      * @return 0 when notify move mission to foreground success or else failed.
93      */
94     virtual int32_t NotifyMoveMissionToForeground(int32_t missionId) override;
95 
96     /**
97      * @brief Notify when notify ability is terminated, but mission is not cleared.
98      * @param missionId missionId.
99      * @return 0 when notify terminate mission success or else failed.
100      */
101     virtual int32_t NotifyTerminateMission(int32_t missionId) override;
102 
103     /**
104      * @brief Notify to broker when clear mission.
105      * @param missionId missionId.
106      * @return 0 when notify clear mission success or else failed.
107      */
108     virtual int32_t NotifyClearMission(int32_t missionId) override;
109 
110     /**
111      * @brief Notify to broker when clear mission.
112      * @param pid pid of shell process.
113      * @param type died type.
114      * @param reason addational message for died reason.
115      * @return 0 when notify remove shell process success or else failed.
116      */
117     virtual int32_t NotifyRemoveShellProcess(int32_t pid, int32_t type, const std::string &reason) override;
118 
119     /**
120      * @brief Update mission info to real element by broker.
121      * @param info info of mission.
122      */
123     virtual void UpdateMissionInfo(InnerMissionInfoDto &info) override;
124 
125     /**
126      * @brief Update mission info to real element by broker.
127      * @param sessionInfo sessionInfo.
128      */
129     virtual void UpdateMissionInfo(sptr<SessionInfo> &sessionInfo) override;
130 
131     /**
132      * @brief Check the call permission from shell assistant.
133      * @param want target info.
134      * @return 0 when check permission success or else failed.
135      */
136     virtual int32_t CheckCallAbilityPermission(const Want &want) override;
137 
138     /**
139      * @brief Notify application update system environment changes.
140      * @param config System environment change parameters.
141      * @param userId userId Designation User ID.
142      * @return Return true to notify changes successfully, or false to failed.
143      */
144     virtual bool UpdateConfiguration(const AppExecFwk::Configuration &config, int32_t userId) override;
145 
146     /**
147      * @brief Open file by uri.
148      * @param uri The file uri.
149      * @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
150      * @return int The file descriptor.
151      */
152     virtual int OpenFile(const Uri& uri, uint32_t flag) override;
153 
154     virtual void NotifyMissionBindPid(int32_t missionId, int32_t pid) override;
155 
156     virtual int32_t CheckStaticCfgPermission(const Want &want, bool isImplicit) override;
157 private:
158     static inline BrokerDelegator<AbilityManagerCollaboratorProxy> delegator_;
159     int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
160 };
161 }   // namespace AAFWK
162 }   // namespace OHOS
163 #endif // OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_COLLABORATOR_PROXY_H
164