• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             case ON_EXTENSION_SUSPENDED:
42                 return OnExtensionSuspendedInner(data, reply);
43             case ON_EXTENSION_RESUMED:
44                 return OnExtensionResumedInner(data, reply);
45 #ifdef WITH_DLP
46             case ON_DLP_ABILITY_OPENED:
47                 return OnDlpAbilityOpenedInner(data, reply);
48             case ON_DLP_ABILITY_CLOSED:
49                 return OnDlpAbilityClosedInner(data, reply);
50 #endif // WITH_DLP
51         }
52     }
53     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
54 }
55 
OnExtensionConnectedInner(MessageParcel & data,MessageParcel & reply)56 int ConnectionObserverStub::OnExtensionConnectedInner(MessageParcel &data, MessageParcel &reply)
57 {
58     std::unique_ptr<ConnectionData> connectionData(data.ReadParcelable<ConnectionData>());
59     if (!connectionData) {
60         TAG_LOGE(AAFwkTag::CONNECTION, "error connectionData");
61         return ERR_INVALID_VALUE;
62     }
63 
64     OnExtensionConnected(*connectionData);
65     return NO_ERROR;
66 }
67 
OnExtensionDisconnectedInner(MessageParcel & data,MessageParcel & reply)68 int ConnectionObserverStub::OnExtensionDisconnectedInner(MessageParcel &data, MessageParcel &reply)
69 {
70     std::unique_ptr<ConnectionData> connectionData(data.ReadParcelable<ConnectionData>());
71     if (!connectionData) {
72         TAG_LOGE(AAFwkTag::CONNECTION, "error connectionData");
73         return ERR_INVALID_VALUE;
74     }
75 
76     OnExtensionDisconnected(*connectionData);
77     return NO_ERROR;
78 }
79 
OnExtensionSuspendedInner(MessageParcel & data,MessageParcel & reply)80 int ConnectionObserverStub::OnExtensionSuspendedInner(MessageParcel &data, MessageParcel &reply)
81 {
82     std::unique_ptr<ConnectionData> connectionData(data.ReadParcelable<ConnectionData>());
83     if (!connectionData) {
84         TAG_LOGE(AAFwkTag::CONNECTION, "error connectionData");
85         return ERR_INVALID_VALUE;
86     }
87 
88     OnExtensionSuspended(*connectionData);
89     return NO_ERROR;
90 }
91 
OnExtensionResumedInner(MessageParcel & data,MessageParcel & reply)92 int ConnectionObserverStub::OnExtensionResumedInner(MessageParcel &data, MessageParcel &reply)
93 {
94     std::unique_ptr<ConnectionData> connectionData(data.ReadParcelable<ConnectionData>());
95     if (!connectionData) {
96         TAG_LOGE(AAFwkTag::CONNECTION, "error connectionData");
97         return ERR_INVALID_VALUE;
98     }
99 
100     OnExtensionResumed(*connectionData);
101     return NO_ERROR;
102 }
103 
104 #ifdef WITH_DLP
OnDlpAbilityOpenedInner(MessageParcel & data,MessageParcel & reply)105 int ConnectionObserverStub::OnDlpAbilityOpenedInner(MessageParcel &data, MessageParcel &reply)
106 {
107     std::unique_ptr<DlpStateData> dlpData(data.ReadParcelable<DlpStateData>());
108     if (!dlpData) {
109         TAG_LOGE(AAFwkTag::CONNECTION, "error dlpData");
110         return ERR_INVALID_VALUE;
111     }
112 
113     OnDlpAbilityOpened(*dlpData);
114     return NO_ERROR;
115 }
116 
OnDlpAbilityClosedInner(MessageParcel & data,MessageParcel & reply)117 int ConnectionObserverStub::OnDlpAbilityClosedInner(MessageParcel &data, MessageParcel &reply)
118 {
119     std::unique_ptr<DlpStateData> dlpData(data.ReadParcelable<DlpStateData>());
120     if (!dlpData) {
121         TAG_LOGE(AAFwkTag::CONNECTION, "error dlpData");
122         return ERR_INVALID_VALUE;
123     }
124 
125     OnDlpAbilityClosed(*dlpData);
126     return NO_ERROR;
127 }
128 #endif // WITH_DLP
129 }  // namespace AbilityRuntime
130 }  // namespace OHOS
131