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_stub.h"
17 #include "hilog_tag_wrapper.h"
18 #include "ipc_types.h"
19
20 namespace OHOS {
21 namespace AppExecFwk {
22
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)23 int NativeChildNotifyStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
24 MessageParcel &reply, MessageOption &option)
25 {
26 TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyStub::OnRemoteRequest, code=%{public}u, flags=%{public}d.",
27 code, option.GetFlags());
28 std::u16string descriptor = NativeChildNotifyStub::GetDescriptor();
29 std::u16string remoteDesc = data.ReadInterfaceToken();
30 if (descriptor != remoteDesc) {
31 TAG_LOGE(AAFwkTag::APPMGR, "A local descriptor is not equivalent to a remote");
32 return ERR_INVALID_STATE;
33 }
34
35 int32_t ret;
36 switch (code) {
37 case INativeChildNotify::IPC_ID_ON_NATIVE_CHILD_STARTED:
38 ret = HandleOnNativeChildStarted(data, reply);
39 break;
40
41 case INativeChildNotify::IPC_ID_ON_ERROR:
42 ret = HandleOnError(data, reply);
43 break;
44
45 default:
46 TAG_LOGW(AAFwkTag::APPMGR, "NativeChildNotifyStub Unknow ipc call(%{public}u)", code);
47 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48 break;
49 }
50
51 TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyStub::OnRemoteRequest end");
52 return ret;
53 }
54
HandleOnNativeChildStarted(MessageParcel & data,MessageParcel & reply)55 int32_t NativeChildNotifyStub::HandleOnNativeChildStarted(MessageParcel &data, MessageParcel &reply)
56 {
57 sptr<IRemoteObject> cb = data.ReadRemoteObject();
58 OnNativeChildStarted(cb);
59 return ERR_NONE;
60 }
61
HandleOnError(MessageParcel & data,MessageParcel & reply)62 int32_t NativeChildNotifyStub::HandleOnError(MessageParcel &data, MessageParcel &reply)
63 {
64 int32_t err = data.ReadInt32();
65 OnError(err);
66 return ERR_NONE;
67 }
68
69 } // OHOS
70 } // AppExecFwk
71