• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_FORM_FWK_FORM_ABILITY_CONNECTION_H
17 #define OHOS_FORM_FWK_FORM_ABILITY_CONNECTION_H
18 
19 #include "provider_connect_stub.h"
20 #include "want.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 using WantParams = OHOS::AAFwk::WantParams;
25 
26 /**
27  * @class FormAbilityConnection
28  * Form Ability Connection Stub.
29  */
30 class FormAbilityConnection : public ProviderConnectStub {
31 public:
32     FormAbilityConnection() = default;
33     virtual ~FormAbilityConnection() = default;
34 
35     /**
36      * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect.
37      * @param element service ability's ElementName.
38      * @param remoteObject the session proxy of service ability.
39      * @param resultCode ERR_OK on success, others on failure.
40      */
41     virtual void OnAbilityConnectDone(
42         const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
43 
44     /**
45      * @brief OnAbilityDisconnectDone, AbilityMs notify caller ability the result of disconnect.
46      * @param element service ability's ElementName.
47      * @param resultCode ERR_OK on success, others on failure.
48      */
49     virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
50 
51     /**
52      * @brief remote object died event.
53      * @param remoteObject the remote object of service ability.
54      */
55     void OnConnectDied(const wptr<IRemoteObject> &remoteObject);
56 
57     /**
58      * @brief Get connectId.
59      * @return The ability connection id.
60      */
61     int32_t GetConnectId() const;
62 
63     /**
64      * @brief Set connectId.
65      * @param connectId The ability connection id.
66      */
67     void SetConnectId(int32_t connectId);
68     /**
69      * @brief Get the provider Key
70      *
71      * @return The provider Key
72      */
73     std::string GetProviderKey() const;
74     /**
75      * @brief Set the Provider Key
76      *
77      * @param bundleName bundleName
78      * @param abilityName abilityName
79      */
80     void SetProviderKey(const std::string &bundleName, const std::string &abilityName);
81 
82     /**
83      * @brief Set free install true or false.
84      *
85      * @param isFreeInstall Indicates the free install flag is true or false.
86      */
87     void SetFreeInstall(bool isFreeInstall);
88 
89     /**
90      * @brief Set form ID.
91      *
92      * @param formId Indicates the form ID.
93      */
94     void SetFormId(int64_t formId);
95 
96     /**
97      * @brief Get form ID.
98      */
99     int64_t GetFormId() const;
100 
101     /**
102      * @brief Set host token.
103      * @param hostToken Indicates the host token.
104      */
105     void SetHostToken(const sptr<IRemoteObject> hostToken);
106 
107     /**
108      * @brief Get host token.
109      */
110     sptr<IRemoteObject> GetHostToken() const;
111 
112     /**
113      * @brief Set provider token.
114      * @param hostToken Indicates the provider token.
115      */
116     void SetProviderToken(const sptr<IRemoteObject> providerToken);
117 
118     /**
119      * @brief Get provider token.
120      */
121     sptr<IRemoteObject> GetProviderToken() const;
122 
123     /**
124      * @brief Add death recipient.
125      */
126     void AddHostDeathRecipient();
127 private:
128     int64_t formId_ = -1;
129     std::string deviceId_ = "";
130     std::string bundleName_ = "";
131     std::string abilityName_ = "";
132     bool isFreeInstall_ = false;
133     int32_t connectId_ = 0;
134     sptr<IRemoteObject> hostToken_ = nullptr;
135     sptr<IRemoteObject> providerToken_ = nullptr;
136 
137     DISALLOW_COPY_AND_MOVE(FormAbilityConnection);
138 };
139 }  // namespace AppExecFwk
140 }  // namespace OHOS
141 
142 #endif // OHOS_FORM_FWK_FORM_ABILITY_CONNECTION_H
143