1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#include "tunnel_client.h"
17c29fa5a6Sopenharmony_ci
18c29fa5a6Sopenharmony_ci#include "if_system_ability_manager.h"
19c29fa5a6Sopenharmony_ci#include "iservice_registry.h"
20c29fa5a6Sopenharmony_ci#include "system_ability_definition.h"
21c29fa5a6Sopenharmony_ci
22c29fa5a6Sopenharmony_ci#include "iremote_broker.h"
23c29fa5a6Sopenharmony_ci#include "iremote_object.h"
24c29fa5a6Sopenharmony_ci
25c29fa5a6Sopenharmony_ci#include "devicestatus_define.h"
26c29fa5a6Sopenharmony_ci
27c29fa5a6Sopenharmony_ci#undef LOG_TAG
28c29fa5a6Sopenharmony_ci#define LOG_TAG "TunnelClient"
29c29fa5a6Sopenharmony_ci
30c29fa5a6Sopenharmony_cinamespace OHOS {
31c29fa5a6Sopenharmony_cinamespace Msdp {
32c29fa5a6Sopenharmony_cinamespace DeviceStatus {
33c29fa5a6Sopenharmony_ci
34c29fa5a6Sopenharmony_ciTunnelClient::~TunnelClient()
35c29fa5a6Sopenharmony_ci{
36c29fa5a6Sopenharmony_ci    if (devicestatusProxy_ != nullptr) {
37c29fa5a6Sopenharmony_ci        auto remoteObject = devicestatusProxy_->AsObject();
38c29fa5a6Sopenharmony_ci        if (remoteObject != nullptr) {
39c29fa5a6Sopenharmony_ci            remoteObject->RemoveDeathRecipient(deathRecipient_);
40c29fa5a6Sopenharmony_ci        }
41c29fa5a6Sopenharmony_ci    }
42c29fa5a6Sopenharmony_ci}
43c29fa5a6Sopenharmony_ci
44c29fa5a6Sopenharmony_ciint32_t TunnelClient::Enable(Intention intention, ParamBase &data, ParamBase &reply)
45c29fa5a6Sopenharmony_ci{
46c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
47c29fa5a6Sopenharmony_ci    MessageParcel dataParcel;
48c29fa5a6Sopenharmony_ci    if (!dataParcel.WriteInterfaceToken(IIntention::GetDescriptor())) {
49c29fa5a6Sopenharmony_ci        FI_HILOGE("WriteInterfaceToken fail");
50c29fa5a6Sopenharmony_ci        return RET_ERR;
51c29fa5a6Sopenharmony_ci    }
52c29fa5a6Sopenharmony_ci    if (!data.Marshalling(dataParcel)) {
53c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Marshalling fail");
54c29fa5a6Sopenharmony_ci        return RET_ERR;
55c29fa5a6Sopenharmony_ci    }
56c29fa5a6Sopenharmony_ci    if (Connect() != RET_OK) {
57c29fa5a6Sopenharmony_ci        FI_HILOGE("Can not connect to IntentionService");
58c29fa5a6Sopenharmony_ci        return RET_ERR;
59c29fa5a6Sopenharmony_ci    }
60c29fa5a6Sopenharmony_ci    MessageParcel replyParcel;
61c29fa5a6Sopenharmony_ci    int32_t ret = devicestatusProxy_->Enable(intention, dataParcel, replyParcel);
62c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
63c29fa5a6Sopenharmony_ci        FI_HILOGE("proxy::Enable fail");
64c29fa5a6Sopenharmony_ci        return RET_ERR;
65c29fa5a6Sopenharmony_ci    }
66c29fa5a6Sopenharmony_ci    if (!reply.Unmarshalling(replyParcel)) {
67c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Unmarshalling fail");
68c29fa5a6Sopenharmony_ci        return RET_ERR;
69c29fa5a6Sopenharmony_ci    }
70c29fa5a6Sopenharmony_ci    return RET_OK;
71c29fa5a6Sopenharmony_ci}
72c29fa5a6Sopenharmony_ci
73c29fa5a6Sopenharmony_ciint32_t TunnelClient::Disable(Intention intention, ParamBase &data, ParamBase &reply)
74c29fa5a6Sopenharmony_ci{
75c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
76c29fa5a6Sopenharmony_ci    MessageParcel dataParcel;
77c29fa5a6Sopenharmony_ci    if (!dataParcel.WriteInterfaceToken(IIntention::GetDescriptor())) {
78c29fa5a6Sopenharmony_ci        FI_HILOGE("WriteInterfaceToken fail");
79c29fa5a6Sopenharmony_ci        return RET_ERR;
80c29fa5a6Sopenharmony_ci    }
81c29fa5a6Sopenharmony_ci    if (!data.Marshalling(dataParcel)) {
82c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Marshalling fail");
83c29fa5a6Sopenharmony_ci        return RET_ERR;
84c29fa5a6Sopenharmony_ci    }
85c29fa5a6Sopenharmony_ci    if (Connect() != RET_OK) {
86c29fa5a6Sopenharmony_ci        FI_HILOGE("Can not connect to IntentionService");
87c29fa5a6Sopenharmony_ci        return RET_ERR;
88c29fa5a6Sopenharmony_ci    }
89c29fa5a6Sopenharmony_ci    MessageParcel replyParcel;
90c29fa5a6Sopenharmony_ci    int32_t ret = devicestatusProxy_->Disable(intention, dataParcel, replyParcel);
91c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
92c29fa5a6Sopenharmony_ci        FI_HILOGE("proxy::Disable fail");
93c29fa5a6Sopenharmony_ci        return RET_ERR;
94c29fa5a6Sopenharmony_ci    }
95c29fa5a6Sopenharmony_ci    if (!reply.Unmarshalling(replyParcel)) {
96c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Unmarshalling fail");
97c29fa5a6Sopenharmony_ci        return RET_ERR;
98c29fa5a6Sopenharmony_ci    }
99c29fa5a6Sopenharmony_ci    return RET_OK;
100c29fa5a6Sopenharmony_ci}
101c29fa5a6Sopenharmony_ci
102c29fa5a6Sopenharmony_ciint32_t TunnelClient::Start(Intention intention, ParamBase &data, ParamBase &reply)
103c29fa5a6Sopenharmony_ci{
104c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
105c29fa5a6Sopenharmony_ci    MessageParcel dataParcel;
106c29fa5a6Sopenharmony_ci    if (!dataParcel.WriteInterfaceToken(IIntention::GetDescriptor())) {
107c29fa5a6Sopenharmony_ci        FI_HILOGE("WriteInterfaceToken fail");
108c29fa5a6Sopenharmony_ci        return RET_ERR;
109c29fa5a6Sopenharmony_ci    }
110c29fa5a6Sopenharmony_ci    if (!data.Marshalling(dataParcel)) {
111c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Marshalling fail");
112c29fa5a6Sopenharmony_ci        return RET_ERR;
113c29fa5a6Sopenharmony_ci    }
114c29fa5a6Sopenharmony_ci    if (Connect() != RET_OK) {
115c29fa5a6Sopenharmony_ci        FI_HILOGE("Can not connect to IntentionService");
116c29fa5a6Sopenharmony_ci        return RET_ERR;
117c29fa5a6Sopenharmony_ci    }
118c29fa5a6Sopenharmony_ci    MessageParcel replyParcel;
119c29fa5a6Sopenharmony_ci    int32_t ret = devicestatusProxy_->Start(intention, dataParcel, replyParcel);
120c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
121c29fa5a6Sopenharmony_ci        FI_HILOGE("proxy::Start fail");
122c29fa5a6Sopenharmony_ci        return ret;
123c29fa5a6Sopenharmony_ci    }
124c29fa5a6Sopenharmony_ci    if (!reply.Unmarshalling(replyParcel)) {
125c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Unmarshalling fail");
126c29fa5a6Sopenharmony_ci        return RET_ERR;
127c29fa5a6Sopenharmony_ci    }
128c29fa5a6Sopenharmony_ci    return RET_OK;
129c29fa5a6Sopenharmony_ci}
130c29fa5a6Sopenharmony_ci
131c29fa5a6Sopenharmony_ciint32_t TunnelClient::Stop(Intention intention, ParamBase &data, ParamBase &reply)
132c29fa5a6Sopenharmony_ci{
133c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
134c29fa5a6Sopenharmony_ci    MessageParcel dataParcel;
135c29fa5a6Sopenharmony_ci    if (!dataParcel.WriteInterfaceToken(IIntention::GetDescriptor())) {
136c29fa5a6Sopenharmony_ci        FI_HILOGE("WriteInterfaceToken fail");
137c29fa5a6Sopenharmony_ci        return RET_ERR;
138c29fa5a6Sopenharmony_ci    }
139c29fa5a6Sopenharmony_ci    if (!data.Marshalling(dataParcel)) {
140c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Marshalling fail");
141c29fa5a6Sopenharmony_ci        return RET_ERR;
142c29fa5a6Sopenharmony_ci    }
143c29fa5a6Sopenharmony_ci    if (Connect() != RET_OK) {
144c29fa5a6Sopenharmony_ci        FI_HILOGE("Can not connect to IntentionService");
145c29fa5a6Sopenharmony_ci        return RET_ERR;
146c29fa5a6Sopenharmony_ci    }
147c29fa5a6Sopenharmony_ci    MessageParcel replyParcel;
148c29fa5a6Sopenharmony_ci    int32_t ret = devicestatusProxy_->Stop(intention, dataParcel, replyParcel);
149c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
150c29fa5a6Sopenharmony_ci        FI_HILOGE("proxy::Stop fail");
151c29fa5a6Sopenharmony_ci        return RET_ERR;
152c29fa5a6Sopenharmony_ci    }
153c29fa5a6Sopenharmony_ci    if (!reply.Unmarshalling(replyParcel)) {
154c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Unmarshalling fail");
155c29fa5a6Sopenharmony_ci        return RET_ERR;
156c29fa5a6Sopenharmony_ci    }
157c29fa5a6Sopenharmony_ci    return RET_OK;
158c29fa5a6Sopenharmony_ci}
159c29fa5a6Sopenharmony_ci
160c29fa5a6Sopenharmony_ciint32_t TunnelClient::AddWatch(Intention intention, uint32_t id, ParamBase &data, ParamBase &reply)
161c29fa5a6Sopenharmony_ci{
162c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
163c29fa5a6Sopenharmony_ci    MessageParcel dataParcel;
164c29fa5a6Sopenharmony_ci    if (!dataParcel.WriteInterfaceToken(IIntention::GetDescriptor())) {
165c29fa5a6Sopenharmony_ci        FI_HILOGE("WriteInterfaceToken fail");
166c29fa5a6Sopenharmony_ci        return RET_ERR;
167c29fa5a6Sopenharmony_ci    }
168c29fa5a6Sopenharmony_ci    if (!data.Marshalling(dataParcel)) {
169c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Marshalling fail");
170c29fa5a6Sopenharmony_ci        return RET_ERR;
171c29fa5a6Sopenharmony_ci    }
172c29fa5a6Sopenharmony_ci    if (Connect() != RET_OK) {
173c29fa5a6Sopenharmony_ci        FI_HILOGE("Can not connect to IntentionService");
174c29fa5a6Sopenharmony_ci        return RET_ERR;
175c29fa5a6Sopenharmony_ci    }
176c29fa5a6Sopenharmony_ci    MessageParcel replyParcel;
177c29fa5a6Sopenharmony_ci    int32_t ret = devicestatusProxy_->AddWatch(intention, id, dataParcel, replyParcel);
178c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
179c29fa5a6Sopenharmony_ci        FI_HILOGE("proxy::AddWatch fail");
180c29fa5a6Sopenharmony_ci        return RET_ERR;
181c29fa5a6Sopenharmony_ci    }
182c29fa5a6Sopenharmony_ci    if (!reply.Unmarshalling(replyParcel)) {
183c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Unmarshalling fail");
184c29fa5a6Sopenharmony_ci        return RET_ERR;
185c29fa5a6Sopenharmony_ci    }
186c29fa5a6Sopenharmony_ci    return RET_OK;
187c29fa5a6Sopenharmony_ci}
188c29fa5a6Sopenharmony_ci
189c29fa5a6Sopenharmony_ciint32_t TunnelClient::RemoveWatch(Intention intention, uint32_t id, ParamBase &data, ParamBase &reply)
190c29fa5a6Sopenharmony_ci{
191c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
192c29fa5a6Sopenharmony_ci    MessageParcel dataParcel;
193c29fa5a6Sopenharmony_ci    if (!dataParcel.WriteInterfaceToken(IIntention::GetDescriptor())) {
194c29fa5a6Sopenharmony_ci        FI_HILOGE("WriteInterfaceToken fail");
195c29fa5a6Sopenharmony_ci        return RET_ERR;
196c29fa5a6Sopenharmony_ci    }
197c29fa5a6Sopenharmony_ci    if (!data.Marshalling(dataParcel)) {
198c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Marshalling fail");
199c29fa5a6Sopenharmony_ci        return RET_ERR;
200c29fa5a6Sopenharmony_ci    }
201c29fa5a6Sopenharmony_ci    if (Connect() != RET_OK) {
202c29fa5a6Sopenharmony_ci        FI_HILOGE("Can not connect to IntentionService");
203c29fa5a6Sopenharmony_ci        return RET_ERR;
204c29fa5a6Sopenharmony_ci    }
205c29fa5a6Sopenharmony_ci    MessageParcel replyParcel;
206c29fa5a6Sopenharmony_ci    int32_t ret = devicestatusProxy_->RemoveWatch(intention, id, dataParcel, replyParcel);
207c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
208c29fa5a6Sopenharmony_ci        FI_HILOGE("proxy::RemoveWatch fail");
209c29fa5a6Sopenharmony_ci        return RET_ERR;
210c29fa5a6Sopenharmony_ci    }
211c29fa5a6Sopenharmony_ci    if (!reply.Unmarshalling(replyParcel)) {
212c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Unmarshalling fail");
213c29fa5a6Sopenharmony_ci        return RET_ERR;
214c29fa5a6Sopenharmony_ci    }
215c29fa5a6Sopenharmony_ci    return RET_OK;
216c29fa5a6Sopenharmony_ci}
217c29fa5a6Sopenharmony_ci
218c29fa5a6Sopenharmony_ciint32_t TunnelClient::SetParam(Intention intention, uint32_t id, ParamBase &data, ParamBase &reply)
219c29fa5a6Sopenharmony_ci{
220c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
221c29fa5a6Sopenharmony_ci    MessageParcel dataParcel;
222c29fa5a6Sopenharmony_ci    if (!dataParcel.WriteInterfaceToken(IIntention::GetDescriptor())) {
223c29fa5a6Sopenharmony_ci        FI_HILOGE("WriteInterfaceToken fail");
224c29fa5a6Sopenharmony_ci        return RET_ERR;
225c29fa5a6Sopenharmony_ci    }
226c29fa5a6Sopenharmony_ci    if (!data.Marshalling(dataParcel)) {
227c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Marshalling fail");
228c29fa5a6Sopenharmony_ci        return RET_ERR;
229c29fa5a6Sopenharmony_ci    }
230c29fa5a6Sopenharmony_ci    if (Connect() != RET_OK) {
231c29fa5a6Sopenharmony_ci        FI_HILOGE("Can not connect to IntentionService");
232c29fa5a6Sopenharmony_ci        return RET_ERR;
233c29fa5a6Sopenharmony_ci    }
234c29fa5a6Sopenharmony_ci    MessageParcel replyParcel;
235c29fa5a6Sopenharmony_ci    int32_t ret = devicestatusProxy_->SetParam(intention, id, dataParcel, replyParcel);
236c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
237c29fa5a6Sopenharmony_ci        FI_HILOGE("proxy::SetParam fail");
238c29fa5a6Sopenharmony_ci        return RET_ERR;
239c29fa5a6Sopenharmony_ci    }
240c29fa5a6Sopenharmony_ci    if (!reply.Unmarshalling(replyParcel)) {
241c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Unmarshalling fail");
242c29fa5a6Sopenharmony_ci        return RET_ERR;
243c29fa5a6Sopenharmony_ci    }
244c29fa5a6Sopenharmony_ci    return RET_OK;
245c29fa5a6Sopenharmony_ci}
246c29fa5a6Sopenharmony_ci
247c29fa5a6Sopenharmony_ciint32_t TunnelClient::GetParam(Intention intention, uint32_t id, ParamBase &data, ParamBase &reply)
248c29fa5a6Sopenharmony_ci{
249c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
250c29fa5a6Sopenharmony_ci    MessageParcel dataParcel;
251c29fa5a6Sopenharmony_ci    if (!dataParcel.WriteInterfaceToken(IIntention::GetDescriptor())) {
252c29fa5a6Sopenharmony_ci        FI_HILOGE("WriteInterfaceToken fail");
253c29fa5a6Sopenharmony_ci        return RET_ERR;
254c29fa5a6Sopenharmony_ci    }
255c29fa5a6Sopenharmony_ci    if (!data.Marshalling(dataParcel)) {
256c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Marshalling fail");
257c29fa5a6Sopenharmony_ci        return RET_ERR;
258c29fa5a6Sopenharmony_ci    }
259c29fa5a6Sopenharmony_ci    if (Connect() != RET_OK) {
260c29fa5a6Sopenharmony_ci        FI_HILOGE("Can not connect to IntentionService");
261c29fa5a6Sopenharmony_ci        return RET_ERR;
262c29fa5a6Sopenharmony_ci    }
263c29fa5a6Sopenharmony_ci    MessageParcel replyParcel;
264c29fa5a6Sopenharmony_ci    int32_t ret = devicestatusProxy_->GetParam(intention, id, dataParcel, replyParcel);
265c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
266c29fa5a6Sopenharmony_ci        FI_HILOGE("proxy::GetParam fail");
267c29fa5a6Sopenharmony_ci        return RET_ERR;
268c29fa5a6Sopenharmony_ci    }
269c29fa5a6Sopenharmony_ci    if (!reply.Unmarshalling(replyParcel)) {
270c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Unmarshalling fail");
271c29fa5a6Sopenharmony_ci        return RET_ERR;
272c29fa5a6Sopenharmony_ci    }
273c29fa5a6Sopenharmony_ci    return RET_OK;
274c29fa5a6Sopenharmony_ci}
275c29fa5a6Sopenharmony_ci
276c29fa5a6Sopenharmony_ciint32_t TunnelClient::Control(Intention intention, uint32_t id, ParamBase &data, ParamBase &reply)
277c29fa5a6Sopenharmony_ci{
278c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
279c29fa5a6Sopenharmony_ci    MessageParcel dataParcel;
280c29fa5a6Sopenharmony_ci    if (!dataParcel.WriteInterfaceToken(IIntention::GetDescriptor())) {
281c29fa5a6Sopenharmony_ci        FI_HILOGE("WriteInterfaceToken fail");
282c29fa5a6Sopenharmony_ci        return RET_ERR;
283c29fa5a6Sopenharmony_ci    }
284c29fa5a6Sopenharmony_ci    if (!data.Marshalling(dataParcel)) {
285c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Marshalling fail");
286c29fa5a6Sopenharmony_ci        return RET_ERR;
287c29fa5a6Sopenharmony_ci    }
288c29fa5a6Sopenharmony_ci    if (Connect() != RET_OK) {
289c29fa5a6Sopenharmony_ci        FI_HILOGE("Can not connect to IntentionService");
290c29fa5a6Sopenharmony_ci        return RET_ERR;
291c29fa5a6Sopenharmony_ci    }
292c29fa5a6Sopenharmony_ci    MessageParcel replyParcel;
293c29fa5a6Sopenharmony_ci    int32_t ret = devicestatusProxy_->Control(intention, id, dataParcel, replyParcel);
294c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
295c29fa5a6Sopenharmony_ci        FI_HILOGE("proxy::Control fail");
296c29fa5a6Sopenharmony_ci        return RET_ERR;
297c29fa5a6Sopenharmony_ci    }
298c29fa5a6Sopenharmony_ci    if (!reply.Unmarshalling(replyParcel)) {
299c29fa5a6Sopenharmony_ci        FI_HILOGE("ParamBase::Unmarshalling fail");
300c29fa5a6Sopenharmony_ci        return RET_ERR;
301c29fa5a6Sopenharmony_ci    }
302c29fa5a6Sopenharmony_ci    return RET_OK;
303c29fa5a6Sopenharmony_ci}
304c29fa5a6Sopenharmony_ci
305c29fa5a6Sopenharmony_ciErrCode TunnelClient::Connect()
306c29fa5a6Sopenharmony_ci{
307c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
308c29fa5a6Sopenharmony_ci    std::lock_guard lock(mutex_);
309c29fa5a6Sopenharmony_ci    if (devicestatusProxy_ != nullptr) {
310c29fa5a6Sopenharmony_ci        return RET_OK;
311c29fa5a6Sopenharmony_ci    }
312c29fa5a6Sopenharmony_ci
313c29fa5a6Sopenharmony_ci    sptr<ISystemAbilityManager> sa = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
314c29fa5a6Sopenharmony_ci    CHKPR(sa, E_DEVICESTATUS_GET_SYSTEM_ABILITY_MANAGER_FAILED);
315c29fa5a6Sopenharmony_ci
316c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remoteObject = sa->CheckSystemAbility(MSDP_DEVICESTATUS_SERVICE_ID);
317c29fa5a6Sopenharmony_ci    CHKPR(remoteObject, E_DEVICESTATUS_GET_SERVICE_FAILED);
318c29fa5a6Sopenharmony_ci
319c29fa5a6Sopenharmony_ci    deathRecipient_ = sptr<DeathRecipient>::MakeSptr(shared_from_this());
320c29fa5a6Sopenharmony_ci    CHKPR(deathRecipient_, ERR_NO_MEMORY);
321c29fa5a6Sopenharmony_ci
322c29fa5a6Sopenharmony_ci    if (remoteObject->IsProxyObject()) {
323c29fa5a6Sopenharmony_ci        if (!remoteObject->AddDeathRecipient(deathRecipient_)) {
324c29fa5a6Sopenharmony_ci            FI_HILOGE("Add death recipient to DeviceStatus service failed");
325c29fa5a6Sopenharmony_ci            return E_DEVICESTATUS_ADD_DEATH_RECIPIENT_FAILED;
326c29fa5a6Sopenharmony_ci        }
327c29fa5a6Sopenharmony_ci    }
328c29fa5a6Sopenharmony_ci
329c29fa5a6Sopenharmony_ci    devicestatusProxy_ = iface_cast<IIntention>(remoteObject);
330c29fa5a6Sopenharmony_ci    FI_HILOGD("Connecting IntentionService success");
331c29fa5a6Sopenharmony_ci    return RET_OK;
332c29fa5a6Sopenharmony_ci}
333c29fa5a6Sopenharmony_ci
334c29fa5a6Sopenharmony_civoid TunnelClient::ResetProxy(const wptr<IRemoteObject> &remote)
335c29fa5a6Sopenharmony_ci{
336c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
337c29fa5a6Sopenharmony_ci    std::lock_guard lock(mutex_);
338c29fa5a6Sopenharmony_ci    CHKPV(devicestatusProxy_);
339c29fa5a6Sopenharmony_ci    auto serviceRemote = devicestatusProxy_->AsObject();
340c29fa5a6Sopenharmony_ci    if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
341c29fa5a6Sopenharmony_ci        serviceRemote->RemoveDeathRecipient(deathRecipient_);
342c29fa5a6Sopenharmony_ci        devicestatusProxy_ = nullptr;
343c29fa5a6Sopenharmony_ci    }
344c29fa5a6Sopenharmony_ci}
345c29fa5a6Sopenharmony_ci
346c29fa5a6Sopenharmony_ciTunnelClient::DeathRecipient::DeathRecipient(std::shared_ptr<TunnelClient> parent)
347c29fa5a6Sopenharmony_ci    : parent_(parent)
348c29fa5a6Sopenharmony_ci{}
349c29fa5a6Sopenharmony_ci
350c29fa5a6Sopenharmony_civoid TunnelClient::DeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
351c29fa5a6Sopenharmony_ci{
352c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
353c29fa5a6Sopenharmony_ci    std::shared_ptr<TunnelClient> parent = parent_.lock();
354c29fa5a6Sopenharmony_ci    CHKPV(parent);
355c29fa5a6Sopenharmony_ci    CHKPV(remote);
356c29fa5a6Sopenharmony_ci    parent->ResetProxy(remote);
357c29fa5a6Sopenharmony_ci    FI_HILOGD("Recv death notice");
358c29fa5a6Sopenharmony_ci}
359c29fa5a6Sopenharmony_ci} // namespace DeviceStatus
360c29fa5a6Sopenharmony_ci} // namespace Msdp
361c29fa5a6Sopenharmony_ci} // namespace OHOS
362