1 /*
2 * Copyright (c) 2021 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 #include "ui_service_stub.h"
16 #include "hilog_wrapper.h"
17
18 namespace OHOS {
19 namespace Ace {
UIServiceStub()20 UIServiceStub::UIServiceStub()
21 {
22 requestFuncMap_[UI_SERVICE_PUSH_CALL_BACK] = &UIServiceStub::OnPushCallBackInner;
23 requestFuncMap_[UI_SERVICE_REQUEST_CALL_BACK] = &UIServiceStub::OnRequestCallBackInner;
24 requestFuncMap_[UI_SERVICE_RETURN_REQUEST] = &UIServiceStub::OnReturnRequestInner;
25 }
26
~UIServiceStub()27 UIServiceStub::~UIServiceStub()
28 {
29 requestFuncMap_.clear();
30 }
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t UIServiceStub::OnRemoteRequest(
33 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
34 {
35 HILOG_DEBUG("UIServiceStub::%{public}s, cmd = %{public}d, flags= %{public}d, code=%{public}d",
36 __func__, code, option.GetFlags(), code);
37 std::u16string descriptor = UIServiceStub::GetDescriptor();
38 std::u16string remoteDescriptor = data.ReadInterfaceToken();
39 if (descriptor != remoteDescriptor) {
40 HILOG_INFO("local descriptor is not equal to remote");
41 return ERR_INVALID_STATE;
42 }
43
44 auto itFunc = requestFuncMap_.find(code);
45 if (itFunc != requestFuncMap_.end()) {
46 auto requestFunc = itFunc->second;
47 if (requestFunc != nullptr) {
48 return (this->*requestFunc)(data, reply);
49 }
50 }
51 HILOG_WARN("%{public}s, default case, need check.", __func__);
52 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
53 }
54
OnPushCallBackInner(MessageParcel & data,MessageParcel & reply)55 int32_t UIServiceStub::OnPushCallBackInner(MessageParcel& data, MessageParcel& reply)
56 {
57 std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
58 if (want == nullptr) {
59 HILOG_ERROR("OnPushCallBackInner want is nullptr");
60 return ERR_INVALID_VALUE;
61 }
62 const std::string& name = data.ReadString();
63 const std::string& jsonPath = data.ReadString();
64 const std::string& dataStr = data.ReadString();
65 const std::string& extraData = data.ReadString();
66 OnPushCallBack(*want, name, jsonPath, dataStr, extraData);
67 return ERR_NONE;
68 }
69
OnReturnRequestInner(MessageParcel & data,MessageParcel & reply)70 int32_t UIServiceStub::OnReturnRequestInner(MessageParcel& data, MessageParcel& reply)
71 {
72 std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
73 if (want == nullptr) {
74 HILOG_ERROR("OnReturnRequestInner want is nullptr");
75 return ERR_INVALID_VALUE;
76 }
77 const std::string& source = data.ReadString();
78 const std::string& dataStr = data.ReadString();
79 const std::string& extraData = data.ReadString();
80 OnReturnRequest(*want, source, dataStr, extraData);
81 return ERR_NONE;
82 }
83
OnRequestCallBackInner(MessageParcel & data,MessageParcel & reply)84 int32_t UIServiceStub::OnRequestCallBackInner(MessageParcel& data, MessageParcel& reply)
85 {
86 std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
87 if (want == nullptr) {
88 HILOG_ERROR("OnRequestCallBackInner want is nullptr");
89 return ERR_INVALID_VALUE;
90 }
91 const std::string& name = data.ReadString();
92 const std::string& dataStr = data.ReadString();
93 OnRequestCallBack(*want, name, dataStr);
94 return ERR_NONE;
95 }
96
OnRemoteDied(const wptr<IRemoteObject> & remote)97 void UIServiceCallbackRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
98 {
99 HILOG_ERROR("recv UIServiceCallbackRecipient death notice");
100
101 if (handler_) {
102 handler_(remote);
103 }
104 }
105
UIServiceCallbackRecipient(RemoteDiedHandler handler)106 UIServiceCallbackRecipient::UIServiceCallbackRecipient(RemoteDiedHandler handler) : handler_(handler) {}
107
108 UIServiceCallbackRecipient::~UIServiceCallbackRecipient() = default;
109 } // namespace Ace
110 } // namespace OHOS
111