• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "ui_service_proxy.h"
17 
18 #include "ui_service_hilog.h"
19 
20 namespace OHOS {
21 namespace Ace {
UIServiceProxy(const sptr<IRemoteObject> & remote)22 UIServiceProxy::UIServiceProxy(const sptr<IRemoteObject>& remote) : IRemoteProxy<IUIService>(remote) {}
~UIServiceProxy()23 UIServiceProxy::~UIServiceProxy() {}
24 
OnPushCallBack(const AAFwk::Want & want,const std::string & name,const std::string & jsonPath,const std::string & data,const std::string & extraData)25 void UIServiceProxy::OnPushCallBack(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
26     const std::string& data, const std::string& extraData)
27 {
28     auto remote = Remote();
29     if (remote == nullptr) {
30         return;
31     }
32 
33     OHOS::MessageParcel dataParcel;
34     OHOS::MessageParcel reply;
35     OHOS::MessageOption option(MessageOption::TF_ASYNC);
36 
37     if (!dataParcel.WriteInterfaceToken(UIServiceProxy::GetDescriptor())) {
38         LOGW("%{public}s dataParcel.WriteInterfaceToken(GetDescriptor()) return false",
39             __func__);
40         return;
41     }
42     if (!dataParcel.WriteParcelable(&want)) {
43         return;
44     }
45     if (!dataParcel.WriteString(name)) {
46         return;
47     }
48     if (!dataParcel.WriteString(jsonPath)) {
49         return;
50     }
51     if (!dataParcel.WriteString(data)) {
52         return;
53     }
54     if (!dataParcel.WriteString(extraData)) {
55         return;
56     }
57     int32_t result = remote->SendRequest(IUIService::UI_SERVICE_PUSH_CALL_BACK, dataParcel, reply, option);
58     if (result == ERR_NONE) {
59         LOGI("%{public}s SendRequest ok, retval is %d", __func__, reply.ReadInt32());
60         return;
61     } else {
62         LOGW("%{public}s SendRequest error, result=%{public}d", __func__, result);
63         return;
64     }
65 }
66 
OnRequestCallBack(const AAFwk::Want & want,const std::string & name,const std::string & data)67 void UIServiceProxy::OnRequestCallBack(const AAFwk::Want& want, const std::string& name, const std::string& data)
68 {
69     auto remote = Remote();
70     if (remote == nullptr) {
71         return;
72     }
73 
74     OHOS::MessageParcel dataParcel;
75     OHOS::MessageParcel reply;
76     OHOS::MessageOption option(MessageOption::TF_ASYNC);
77 
78     if (!dataParcel.WriteInterfaceToken(UIServiceProxy::GetDescriptor())) {
79         LOGW("%{public}s dataParcel.WriteInterfaceToken(GetDescriptor()) return false",
80             __func__);
81         return;
82     }
83     if (!dataParcel.WriteParcelable(&want)) {
84         return;
85     }
86     if (!dataParcel.WriteString(name)) {
87         return;
88     }
89     if (!dataParcel.WriteString(data)) {
90         return;
91     }
92     int32_t result = remote->SendRequest(IUIService::UI_SERVICE_REQUEST_CALL_BACK, dataParcel, reply, option);
93     if (result == ERR_NONE) {
94         LOGI("%{public}s SendRequest ok, retval is %d", __func__, reply.ReadInt32());
95         return;
96     } else {
97         LOGW("%{public}s SendRequest error, result=%{public}d", __func__, result);
98         return;
99     }
100 }
101 
OnReturnRequest(const AAFwk::Want & want,const std::string & source,const std::string & data,const std::string & extraData)102 void UIServiceProxy::OnReturnRequest(
103     const AAFwk::Want& want, const std::string& source, const std::string& data, const std::string& extraData)
104 {
105     auto remote = Remote();
106     if (remote == nullptr) {
107         return;
108     }
109 
110     OHOS::MessageParcel dataParcel;
111     OHOS::MessageParcel reply;
112     OHOS::MessageOption option(MessageOption::TF_ASYNC);
113 
114     if (!dataParcel.WriteInterfaceToken(UIServiceProxy::GetDescriptor())) {
115         LOGW("%{public}s dataParcel.WriteInterfaceToken(GetDescriptor()) return false",
116             __func__);
117         return;
118     }
119     if (!dataParcel.WriteParcelable(&want)) {
120         return;
121     }
122     if (!dataParcel.WriteString(source)) {
123         return;
124     }
125     if (!dataParcel.WriteString(data)) {
126         return;
127     }
128     if (!dataParcel.WriteString(extraData)) {
129         return;
130     }
131     int32_t result = remote->SendRequest(IUIService::UI_SERVICE_RETURN_REQUEST, dataParcel, reply, option);
132     if (result == ERR_NONE) {
133         LOGI("%{public}s SendRequest ok, retval is %d", __func__, reply.ReadInt32());
134         return;
135     } else {
136         LOGW("%{public}s SendRequest error, result=%{public}d", __func__, result);
137         return;
138     }
139 }
140 } // namespace Ace
141 } // namespace OHOS
142