• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NATIVE_CHILD_EXIT:
42             ret = HandleOnNativeChildExit(data, reply);
43             break;
44 
45         case INativeChildNotify::IPC_ID_ON_ERROR:
46             ret = HandleOnError(data, reply);
47             break;
48 
49         default:
50             TAG_LOGW(AAFwkTag::APPMGR, "NativeChildNotifyStub Unknow ipc call(%{public}u)", code);
51             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
52             break;
53     }
54 
55     TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyStub::OnRemoteRequest end");
56     return ret;
57 }
58 
HandleOnNativeChildStarted(MessageParcel & data,MessageParcel & reply)59 int32_t NativeChildNotifyStub::HandleOnNativeChildStarted(MessageParcel &data, MessageParcel &reply)
60 {
61     sptr<IRemoteObject> cb = data.ReadRemoteObject();
62     OnNativeChildStarted(cb);
63     return ERR_NONE;
64 }
65 
HandleOnNativeChildExit(MessageParcel & data,MessageParcel & reply)66 int32_t NativeChildNotifyStub::HandleOnNativeChildExit(MessageParcel &data, MessageParcel &reply)
67 {
68     int pid = data.ReadInt32();
69     int signal = data.ReadInt32();
70     return OnNativeChildExit(pid, signal);
71 }
72 
HandleOnError(MessageParcel & data,MessageParcel & reply)73 int32_t NativeChildNotifyStub::HandleOnError(MessageParcel &data, MessageParcel &reply)
74 {
75     int32_t err = data.ReadInt32();
76     OnError(err);
77     return ERR_NONE;
78 }
79 
80 } // OHOS
81 } // AppExecFwk
82