• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_stub.h"
17 
18 #include "hilog_wrapper.h"
19 #include "ipc_types.h"
20 #include "message_parcel.h"
21 
22 namespace OHOS {
23 namespace AbilityRuntime {
ConnectionObserverStub()24 ConnectionObserverStub::ConnectionObserverStub()
25 {
26     vecMemberFunc_.resize(IConnectionObserver::CMD_MAX);
27     vecMemberFunc_[ON_EXTENSION_CONNECTED] = &ConnectionObserverStub::OnExtensionConnectedInner;
28     vecMemberFunc_[ON_EXTENSION_DISCONNECTED] = &ConnectionObserverStub::OnExtensionDisconnectedInner;
29     vecMemberFunc_[ON_DLP_ABILITY_OPENED] = &ConnectionObserverStub::OnDlpAbilityOpenedInner;
30     vecMemberFunc_[ON_DLP_ABILITY_CLOSED] = &ConnectionObserverStub::OnDlpAbilityClosedInner;
31 }
32 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int ConnectionObserverStub::OnRemoteRequest(
34     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
35 {
36     std::u16string descriptor = ConnectionObserverStub::GetDescriptor();
37     std::u16string remoteDescriptor = data.ReadInterfaceToken();
38     if (descriptor != remoteDescriptor) {
39         HILOG_INFO("ConnectionObserverStub Local descriptor is not equal to remote.");
40         return ERR_INVALID_STATE;
41     }
42 
43     if (code < IConnectionObserver::CMD_MAX && code >= 0) {
44         auto memberFunc = vecMemberFunc_[code];
45         return (this->*memberFunc)(data, reply);
46     }
47 
48     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49 }
50 
OnExtensionConnectedInner(MessageParcel & data,MessageParcel & reply)51 int ConnectionObserverStub::OnExtensionConnectedInner(MessageParcel &data, MessageParcel &reply)
52 {
53     std::unique_ptr<ConnectionData> connectionData(data.ReadParcelable<ConnectionData>());
54     if (!connectionData) {
55         HILOG_ERROR("OnExensionConnected ReadParcelable<ConnectionData> failed");
56         return ERR_INVALID_VALUE;
57     }
58 
59     OnExtensionConnected(*connectionData);
60     return NO_ERROR;
61 }
62 
OnExtensionDisconnectedInner(MessageParcel & data,MessageParcel & reply)63 int ConnectionObserverStub::OnExtensionDisconnectedInner(MessageParcel &data, MessageParcel &reply)
64 {
65     std::unique_ptr<ConnectionData> connectionData(data.ReadParcelable<ConnectionData>());
66     if (!connectionData) {
67         HILOG_ERROR("OnExtensionDisconnected ReadParcelable<ConnectionData> failed");
68         return ERR_INVALID_VALUE;
69     }
70 
71     OnExtensionDisconnected(*connectionData);
72     return NO_ERROR;
73 }
74 
OnDlpAbilityOpenedInner(MessageParcel & data,MessageParcel & reply)75 int ConnectionObserverStub::OnDlpAbilityOpenedInner(MessageParcel &data, MessageParcel &reply)
76 {
77     std::unique_ptr<DlpStateData> dlpData(data.ReadParcelable<DlpStateData>());
78     if (!dlpData) {
79         HILOG_ERROR("OnDlpAbilityOpened ReadParcelable<DlpStateData> failed");
80         return ERR_INVALID_VALUE;
81     }
82 
83     OnDlpAbilityOpened(*dlpData);
84     return NO_ERROR;
85 }
86 
OnDlpAbilityClosedInner(MessageParcel & data,MessageParcel & reply)87 int ConnectionObserverStub::OnDlpAbilityClosedInner(MessageParcel &data, MessageParcel &reply)
88 {
89     std::unique_ptr<DlpStateData> dlpData(data.ReadParcelable<DlpStateData>());
90     if (!dlpData) {
91         HILOG_ERROR("OnDlpAbilityClosed ReadParcelable<DlpStateData> failed");
92         return ERR_INVALID_VALUE;
93     }
94 
95     OnDlpAbilityClosed(*dlpData);
96     return NO_ERROR;
97 }
98 }  // namespace AbilityRuntime
99 }  // namespace OHOS
100