1 /*
2 * Copyright (c) 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 #include "connection_observer_proxy.h"
17
18 #include "hilog_wrapper.h"
19 #include "ipc_types.h"
20 #include "message_parcel.h"
21
22 namespace OHOS {
23 namespace AbilityRuntime {
OnExtensionConnected(const ConnectionData & connectionData)24 void ConnectionObserverProxy::OnExtensionConnected(const ConnectionData& connectionData)
25 {
26 MessageParcel data;
27 MessageParcel reply;
28 MessageOption option(MessageOption::TF_ASYNC);
29
30 HILOG_INFO("ConnectionObserverProxy OnExtensionConnected.");
31 if (!data.WriteInterfaceToken(IConnectionObserver::GetDescriptor())) {
32 HILOG_ERROR("Write interface token failed.");
33 return;
34 }
35
36 if (!data.WriteParcelable(&connectionData)) {
37 HILOG_ERROR("Write ConnectionData error.");
38 return;
39 }
40
41 int error = Remote()->SendRequest(IConnectionObserver::ON_EXTENSION_CONNECTED, data, reply, option);
42 if (error != NO_ERROR) {
43 HILOG_ERROR("OnExtensionConnected sned request fail, error: %{public}d", error);
44 return;
45 }
46 }
47
OnExtensionDisconnected(const ConnectionData & connectionData)48 void ConnectionObserverProxy::OnExtensionDisconnected(const ConnectionData& connectionData)
49 {
50 MessageParcel data;
51 MessageParcel reply;
52 MessageOption option(MessageOption::TF_ASYNC);
53
54 HILOG_INFO("ConnectionObserverProxy OnExtensionDisconnected.");
55 if (!data.WriteInterfaceToken(IConnectionObserver::GetDescriptor())) {
56 HILOG_ERROR("Write interface token failed.");
57 return;
58 }
59
60 if (!data.WriteParcelable(&connectionData)) {
61 HILOG_ERROR("Write ConnectionData error.");
62 return;
63 }
64
65 int error = Remote()->SendRequest(IConnectionObserver::ON_EXTENSION_DISCONNECTED, data, reply, option);
66 if (error != NO_ERROR) {
67 HILOG_ERROR("OnExtensionDisconnected send request fail, error: %{public}d", error);
68 return;
69 }
70 }
71
OnDlpAbilityOpened(const DlpStateData & dlpData)72 void ConnectionObserverProxy::OnDlpAbilityOpened(const DlpStateData& dlpData)
73 {
74 MessageParcel data;
75 MessageParcel reply;
76 MessageOption option(MessageOption::TF_ASYNC);
77
78 HILOG_INFO("ConnectionObserverProxy OnDlpAbilityOpened.");
79 if (!data.WriteInterfaceToken(IConnectionObserver::GetDescriptor())) {
80 HILOG_ERROR("Write interface token failed.");
81 return;
82 }
83
84 if (!data.WriteParcelable(&dlpData)) {
85 HILOG_ERROR("Write DlpStateData error.");
86 return;
87 }
88
89 int error = Remote()->SendRequest(IConnectionObserver::ON_DLP_ABILITY_OPENED, data, reply, option);
90 if (error != NO_ERROR) {
91 HILOG_ERROR("OnDlpAbilityOpened send request fail, error: %{public}d", error);
92 return;
93 }
94 }
95
OnDlpAbilityClosed(const DlpStateData & dlpData)96 void ConnectionObserverProxy::OnDlpAbilityClosed(const DlpStateData& dlpData)
97 {
98 MessageParcel data;
99 MessageParcel reply;
100 MessageOption option(MessageOption::TF_ASYNC);
101
102 HILOG_INFO("ConnectionObserverProxy OnDlpAbilityClosed.");
103 if (!data.WriteInterfaceToken(IConnectionObserver::GetDescriptor())) {
104 HILOG_ERROR("Write interface token failed.");
105 return;
106 }
107
108 if (!data.WriteParcelable(&dlpData)) {
109 HILOG_ERROR("Write DlpStateData error.");
110 return;
111 }
112
113 int error = Remote()->SendRequest(IConnectionObserver::ON_DLP_ABILITY_CLOSED, data, reply, option);
114 if (error != NO_ERROR) {
115 HILOG_ERROR("OnDlpAbilityClosed send request fail, error: %{public}d", error);
116 return;
117 }
118 }
119 } // namespace AAFwk
120 } // namespace OHOS
121