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 "native_child_notify_proxy.h"
17 #include "hilog_tag_wrapper.h"
18 #include "ipc_types.h"
19
20 namespace OHOS {
21 namespace AppExecFwk {
22
NativeChildNotifyProxy(const sptr<IRemoteObject> & impl)23 NativeChildNotifyProxy::NativeChildNotifyProxy(const sptr<IRemoteObject> &impl)
24 : IRemoteProxy<INativeChildNotify>(impl)
25 {
26 }
27
WriteInterfaceToken(MessageParcel & data)28 bool NativeChildNotifyProxy::WriteInterfaceToken(MessageParcel &data)
29 {
30 if (!data.WriteInterfaceToken(NativeChildNotifyProxy::GetDescriptor())) {
31 TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy write interface token failed");
32 return false;
33 }
34
35 return true;
36 }
37
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int32_t NativeChildNotifyProxy::SendRequest(uint32_t code, MessageParcel &data,
39 MessageParcel &reply, MessageOption& option)
40 {
41 sptr<IRemoteObject> remote = Remote();
42 if (!remote) {
43 TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy get remote object failed");
44 return ERR_NULL_OBJECT;
45 }
46
47 int32_t ret = remote->SendRequest(code, data, reply, option);
48 if (ret != NO_ERROR) {
49 TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy SendRequest failed(%{public}d)", ret);
50 return ret;
51 }
52
53 return NO_ERROR;
54 }
55
OnNativeChildStarted(const sptr<IRemoteObject> & nativeChild)56 void NativeChildNotifyProxy::OnNativeChildStarted(const sptr<IRemoteObject> &nativeChild)
57 {
58 TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyProxy OnNativeChildStarted");
59 MessageParcel data;
60 MessageParcel reply;
61 MessageOption option(MessageOption::TF_ASYNC);
62 if (!WriteInterfaceToken(data)) {
63 return;
64 }
65
66 if (!data.WriteRemoteObject(nativeChild)) {
67 TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy write native child ipc object failed.");
68 return;
69 }
70
71 SendRequest(INativeChildNotify::IPC_ID_ON_NATIVE_CHILD_STARTED, data, reply, option);
72 }
73
OnError(int32_t errCode)74 void NativeChildNotifyProxy::OnError(int32_t errCode)
75 {
76 TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyProxy OnError(%{public}d)", errCode);
77 MessageParcel data;
78 MessageParcel reply;
79 MessageOption option(MessageOption::TF_ASYNC);
80 if (!WriteInterfaceToken(data)) {
81 return;
82 }
83
84 if (!data.WriteInt32(errCode)) {
85 TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy write error code failed.");
86 return;
87 }
88
89 SendRequest(INativeChildNotify::IPC_ID_ON_ERROR, data, reply, option);
90 }
91
92 } // OHOS
93 } // AppExecFwk