1 /*
2  * Copyright (c) 2023 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 "form_host_delegate_stub.h"
17 
18 #include "appexecfwk_errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_mgr_errors.h"
21 #include "ipc_types.h"
22 #include "iremote_object.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
FormHostDelegateStub()26 FormHostDelegateStub::FormHostDelegateStub()
27 {}
28 
~FormHostDelegateStub()29 FormHostDelegateStub::~FormHostDelegateStub()
30 {}
31 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t FormHostDelegateStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
33     MessageParcel &reply, MessageOption &option)
34 {
35     HILOG_INFO("code:%{public}u,flags:%{public}d", code, option.GetFlags());
36     std::u16string descriptor = FormHostDelegateStub::GetDescriptor();
37     std::u16string remoteDescriptor = data.ReadInterfaceToken();
38     if (descriptor != remoteDescriptor) {
39         HILOG_ERROR("local descriptor not equal to remote");
40         return ERR_APPEXECFWK_FORM_INVALID_PARAM;
41     }
42 
43     switch (code) {
44         case static_cast<uint32_t>(IFormHostDelegate::Message::FORM_ROUTER_PROXY_MGR):
45             return HandleRouterEvent(data, reply);
46         default:
47             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48     }
49 }
50 
HandleRouterEvent(MessageParcel & data,MessageParcel & reply)51 int32_t FormHostDelegateStub::HandleRouterEvent(MessageParcel &data, MessageParcel &reply)
52 {
53     HILOG_DEBUG("call");
54     int64_t formId = data.ReadInt64();
55     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
56     if (!want) {
57         HILOG_ERROR("ReadParcelable<Want> failed");
58         return ERR_APPEXECFWK_PARCEL_ERROR;
59     }
60 
61     auto result = RouterEvent(formId, *want);
62     reply.WriteInt32(result);
63     return result;
64 }
65 } // namespace AppExecFwk
66 } // namespace OHOS