• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "ui_service_mgr_stub.h"
17 
18 #include "errors.h"
19 #include "string_ex.h"
20 #include "ui_service_mgr_errors.h"
21 #include "ui_service_proxy.h"
22 #include "ui_service_stub.h"
23 
24 namespace OHOS::Ace {
UIServiceMgrStub()25 UIServiceMgrStub::UIServiceMgrStub()
26 {
27     requestFuncMap_[REGISTER_CALLBACK] = &UIServiceMgrStub::RegisterCallBackInner;
28     requestFuncMap_[UNREGISTER_CALLBACK] = &UIServiceMgrStub::UnregisterCallBackInner;
29     requestFuncMap_[PUSH] = &UIServiceMgrStub::PushInner;
30     requestFuncMap_[REQUEST] = &UIServiceMgrStub::RequestInner;
31     requestFuncMap_[RETURN_REQUEST] = &UIServiceMgrStub::ReturnRequestInner;
32 }
33 
~UIServiceMgrStub()34 UIServiceMgrStub::~UIServiceMgrStub()
35 {
36     requestFuncMap_.clear();
37 }
38 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int32_t UIServiceMgrStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
40     MessageOption& option)
41 {
42     HILOG_DEBUG("UIServiceMgrStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags());
43     std::u16string descriptor = UIServiceMgrStub::GetDescriptor();
44     std::u16string remoteDescriptor = data.ReadInterfaceToken();
45     if (descriptor != remoteDescriptor) {
46         HILOG_INFO("local descriptor is not equal to remote");
47         return ERR_INVALID_STATE;
48     }
49     auto itFunc = requestFuncMap_.find(code);
50     if (itFunc != requestFuncMap_.end()) {
51         auto requestFunc = itFunc->second;
52         if (requestFunc != nullptr) {
53             return (this->*requestFunc)(data, reply);
54         }
55     }
56     HILOG_WARN("UIServiceMgrStub::OnRemoteRequest, default case, need check.");
57     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
58 }
59 
RegisterCallBackInner(MessageParcel & data,MessageParcel & reply)60 int32_t UIServiceMgrStub::RegisterCallBackInner(MessageParcel& data, MessageParcel& reply)
61 {
62     std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
63     if (want == nullptr) {
64         HILOG_ERROR("RegisterCallBackInner want is nullptr");
65         return ERR_INVALID_VALUE;
66     }
67 
68     auto object = data.ReadRemoteObject();
69     if (object == nullptr) {
70         HILOG_ERROR("RegisterCallBackInner read remote object failed");
71         return ERR_INVALID_VALUE;
72     }
73 
74     auto uiService = iface_cast<IUIService>(object);
75     int32_t result = RegisterCallBack(*want, uiService);
76     reply.WriteInt32(result);
77     return NO_ERROR;
78 }
79 
UnregisterCallBackInner(MessageParcel & data,MessageParcel & reply)80 int32_t UIServiceMgrStub::UnregisterCallBackInner(MessageParcel& data, MessageParcel& reply)
81 {
82     std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
83     if (want == nullptr) {
84         HILOG_ERROR("UnregisterCallBackInner want is nullptr");
85         return ERR_INVALID_VALUE;
86     }
87     int32_t result = UnregisterCallBack(*want);
88     reply.WriteInt32(result);
89     return NO_ERROR;
90 }
91 
PushInner(MessageParcel & data,MessageParcel & reply)92 int32_t UIServiceMgrStub::PushInner(MessageParcel& data, MessageParcel& reply)
93 {
94     std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
95     if (want == nullptr) {
96         HILOG_ERROR("PushInner want is nullptr");
97         return ERR_INVALID_VALUE;
98     }
99     const std::string& name = data.ReadString();
100     const std::string& jsonPath = data.ReadString();
101     const std::string& dataStr = data.ReadString();
102     const std::string& extraData = data.ReadString();
103 
104     int32_t result = Push(*want, name, jsonPath, dataStr, extraData);
105     reply.WriteInt32(result);
106     return NO_ERROR;
107 }
108 
RequestInner(MessageParcel & data,MessageParcel & reply)109 int32_t UIServiceMgrStub::RequestInner(MessageParcel& data, MessageParcel& reply)
110 {
111     std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
112     if (want == nullptr) {
113         HILOG_ERROR("RequestInner want is nullptr");
114         return ERR_INVALID_VALUE;
115     }
116     const std::string& name = data.ReadString();
117     const std::string& dataStr = data.ReadString();
118     int32_t result = Request(*want, name, dataStr);
119     reply.WriteInt32(result);
120     return NO_ERROR;
121 }
122 
ReturnRequestInner(MessageParcel & data,MessageParcel & reply)123 int32_t UIServiceMgrStub::ReturnRequestInner(MessageParcel& data, MessageParcel& reply)
124 {
125     std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
126     if (want == nullptr) {
127         HILOG_ERROR("ReturnRequestInner want is nullptr");
128         return ERR_INVALID_VALUE;
129     }
130     const std::string& source = data.ReadString();
131     const std::string& dataStr = data.ReadString();
132     const std::string& extraData = data.ReadString();
133     int32_t result = ReturnRequest(*want, source, dataStr, extraData);
134     reply.WriteInt32(result);
135     return NO_ERROR;
136 }
137 }
138