1 /*
2 * Copyright (c) 2022-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 "connection_observer_stub.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_types.h"
20 #include "message_parcel.h"
21
22 namespace OHOS {
23 namespace AbilityRuntime {
ConnectionObserverStub()24 ConnectionObserverStub::ConnectionObserverStub() {}
25
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int ConnectionObserverStub::OnRemoteRequest(
27 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
28 {
29 std::u16string descriptor = ConnectionObserverStub::GetDescriptor();
30 std::u16string remoteDescriptor = data.ReadInterfaceToken();
31 if (descriptor != remoteDescriptor) {
32 TAG_LOGI(AAFwkTag::CONNECTION, "invalid descriptor");
33 return ERR_INVALID_STATE;
34 }
35 if (code < IConnectionObserver::CMD_MAX && code >= 0) {
36 switch (code) {
37 case ON_EXTENSION_CONNECTED:
38 return OnExtensionConnectedInner(data, reply);
39 case ON_EXTENSION_DISCONNECTED:
40 return OnExtensionDisconnectedInner(data, reply);
41 #ifdef WITH_DLP
42 case ON_DLP_ABILITY_OPENED:
43 return OnDlpAbilityOpenedInner(data, reply);
44 case ON_DLP_ABILITY_CLOSED:
45 return OnDlpAbilityClosedInner(data, reply);
46 #endif // WITH_DLP
47 }
48 }
49 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51
OnExtensionConnectedInner(MessageParcel & data,MessageParcel & reply)52 int ConnectionObserverStub::OnExtensionConnectedInner(MessageParcel &data, MessageParcel &reply)
53 {
54 std::unique_ptr<ConnectionData> connectionData(data.ReadParcelable<ConnectionData>());
55 if (!connectionData) {
56 TAG_LOGE(AAFwkTag::CONNECTION, "error connectionData");
57 return ERR_INVALID_VALUE;
58 }
59
60 OnExtensionConnected(*connectionData);
61 return NO_ERROR;
62 }
63
OnExtensionDisconnectedInner(MessageParcel & data,MessageParcel & reply)64 int ConnectionObserverStub::OnExtensionDisconnectedInner(MessageParcel &data, MessageParcel &reply)
65 {
66 std::unique_ptr<ConnectionData> connectionData(data.ReadParcelable<ConnectionData>());
67 if (!connectionData) {
68 TAG_LOGE(AAFwkTag::CONNECTION, "error connectionData");
69 return ERR_INVALID_VALUE;
70 }
71
72 OnExtensionDisconnected(*connectionData);
73 return NO_ERROR;
74 }
75
76 #ifdef WITH_DLP
OnDlpAbilityOpenedInner(MessageParcel & data,MessageParcel & reply)77 int ConnectionObserverStub::OnDlpAbilityOpenedInner(MessageParcel &data, MessageParcel &reply)
78 {
79 std::unique_ptr<DlpStateData> dlpData(data.ReadParcelable<DlpStateData>());
80 if (!dlpData) {
81 TAG_LOGE(AAFwkTag::CONNECTION, "error dlpData");
82 return ERR_INVALID_VALUE;
83 }
84
85 OnDlpAbilityOpened(*dlpData);
86 return NO_ERROR;
87 }
88
OnDlpAbilityClosedInner(MessageParcel & data,MessageParcel & reply)89 int ConnectionObserverStub::OnDlpAbilityClosedInner(MessageParcel &data, MessageParcel &reply)
90 {
91 std::unique_ptr<DlpStateData> dlpData(data.ReadParcelable<DlpStateData>());
92 if (!dlpData) {
93 TAG_LOGE(AAFwkTag::CONNECTION, "error dlpData");
94 return ERR_INVALID_VALUE;
95 }
96
97 OnDlpAbilityClosed(*dlpData);
98 return NO_ERROR;
99 }
100 #endif // WITH_DLP
101 } // namespace AbilityRuntime
102 } // namespace OHOS
103