1 /*
2 * Copyright (c) 2021-2024 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 #include "ability_connection_wrapper_proxy.h"
17
18 #include "dtbschedmgr_log.h"
19 #include "ipc_object_proxy.h"
20 #include "ipc_types.h"
21 #include "parcel_helper.h"
22
23 namespace OHOS {
24 namespace DistributedSchedule {
25 namespace {
26 const std::u16string CONNECTION_CALLBACK_INTERFACE_TOKEN = u"ohos.abilityshell.DistributedConnection";
27 const std::string TAG = "AbilityConnectionWrapperProxy";
28 }
29
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)30 void AbilityConnectionWrapperProxy::OnAbilityConnectDone(const AppExecFwk::ElementName& element,
31 const sptr<IRemoteObject>& remoteObject, int32_t resultCode)
32 {
33 HILOGD("AbilityConnectionWrapperProxy::OnAbilityConnectDone called");
34 MessageParcel data;
35 if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
36 return;
37 }
38
39 MessageParcel reply;
40 MessageOption option;
41 PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
42 PARCEL_WRITE_HELPER_NORET(data, RemoteObject, remoteObject);
43 PARCEL_WRITE_HELPER_NORET(data, Int32, resultCode);
44
45 sptr<IRemoteObject> remote = Remote();
46 if (remote == nullptr) {
47 HILOGE("remote service null");
48 return;
49 }
50 int32_t errCode = remote->SendRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
51 HILOGD("AbilityConnectionWrapperProxy::OnAbilityConnectDone result %{public}d", errCode);
52 }
53
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)54 void AbilityConnectionWrapperProxy::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int32_t resultCode)
55 {
56 HILOGD("AbilityConnectionWrapperProxy::OnAbilityDisconnectDone called");
57 MessageParcel data;
58 if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
59 return;
60 }
61
62 MessageParcel reply;
63 MessageOption option;
64 PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
65 PARCEL_WRITE_HELPER_NORET(data, Int32, resultCode);
66 sptr<IRemoteObject> remote = Remote();
67 if (remote == nullptr) {
68 HILOGE("remote service null");
69 return;
70 }
71 int32_t errCode = remote->SendRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
72 HILOGD("AbilityConnectionWrapperProxy::OnAbilityDisconnectDone result %{public}d", errCode);
73 }
74 } // namespace DistributedSchedule
75 } // namespace OHOS