1 
2 /*
3  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "appexecfwk_errors.h"
18 #include "fms_log_wrapper.h"
19 #include "ipc_types.h"
20 #include "message_parcel.h"
21 #include "provider_connect_stub.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 /**
26  * @brief handle remote request.
27  * @param data input param.
28  * @param reply output param.
29  * @param option message option.
30  * @return Returns ERR_OK on success, others on failure.
31  */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int ProviderConnectStub::OnRemoteRequest(
33     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
34 {
35     std::u16string descriptor = ProviderConnectStub::GetDescriptor();
36     std::u16string remoteDescriptor = data.ReadInterfaceToken();
37     if (descriptor != remoteDescriptor) {
38         HILOG_INFO("fail,localDescriptor not equal to remote");
39         return ERR_INVALID_STATE;
40     }
41 
42     auto element = data.ReadParcelable<AppExecFwk::ElementName>();
43     switch (code) {
44         case IAbilityConnection::ON_ABILITY_CONNECT_DONE: {
45             if (element == nullptr) {
46                 HILOG_ERROR("null element");
47                 return ERR_APPEXECFWK_PARCEL_ERROR;
48             }
49             sptr<IRemoteObject> remoteObject = nullptr;
50             if (data.ReadBool()) {
51                 remoteObject = data.ReadRemoteObject();
52             }
53             auto resultCode = data.ReadInt32();
54             OnAbilityConnectDone(*element, remoteObject, resultCode);
55             delete element;
56             return ERR_OK;
57         }
58         case IAbilityConnection::ON_ABILITY_DISCONNECT_DONE: {
59             if (element == nullptr) {
60                 HILOG_ERROR("null element");
61                 return ERR_APPEXECFWK_PARCEL_ERROR;
62             }
63             auto resultCode = data.ReadInt32();
64             OnAbilityDisconnectDone(*element, resultCode);
65             delete element;
66             return ERR_OK;
67         }
68         default: {
69             if (element != nullptr) {
70                 delete element;
71             }
72             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
73         }
74     }
75 }
76 }  // namespace AppExecFwk
77 }  // namespace OHOS
78