1 /*
2 * Copyright (c) 2024 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 "render_state_observer_proxy.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_types.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
23 namespace {
24 const int32_t ERR_INVALID_STUB = 32;
25 }
RenderStateObserverProxy(const sptr<IRemoteObject> & impl)26 RenderStateObserverProxy::RenderStateObserverProxy(
27 const sptr<IRemoteObject> &impl) : IRemoteProxy<IRenderStateObserver>(impl)
28 {}
29
WriteInterfaceToken(MessageParcel & data)30 bool RenderStateObserverProxy::WriteInterfaceToken(MessageParcel &data)
31 {
32 if (!data.WriteInterfaceToken(RenderStateObserverProxy::GetDescriptor())) {
33 TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed.");
34 return false;
35 }
36 return true;
37 }
38
OnRenderStateChanged(const RenderStateData & renderStateData)39 void RenderStateObserverProxy::OnRenderStateChanged(const RenderStateData &renderStateData)
40 {
41 MessageParcel data;
42 MessageParcel reply;
43 MessageOption option(MessageOption::TF_ASYNC);
44 if (!WriteInterfaceToken(data)) {
45 return;
46 }
47
48 if (!data.WriteParcelable(&renderStateData)) {
49 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write renderStateData");
50 return;
51 }
52
53 sptr<IRemoteObject> remote = Remote();
54 if (remote == nullptr) {
55 TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL");
56 return;
57 }
58 int32_t ret = SendTransactCmd(
59 static_cast<uint32_t>(IRenderStateObserver::ON_RENDER_STATE_CHANGED),
60 data, reply, option);
61 if (ret != NO_ERROR || ret != ERR_INVALID_STUB) {
62 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
63 return;
64 }
65 }
66
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)67 int32_t RenderStateObserverProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
68 MessageParcel &reply, MessageOption &option)
69 {
70 sptr<IRemoteObject> remote = Remote();
71 if (remote == nullptr) {
72 TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
73 return ERR_NULL_OBJECT;
74 }
75
76 return remote->SendRequest(code, data, reply, option);
77 }
78 } // namespace AppExecFwk
79 } // namespace OHOS