1 /*
2 * Copyright (c) 2022-2023 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 "bundle_event_callback_host.h"
17
18 #include "app_log_wrapper.h"
19 #include "bundle_framework_core_ipc_interface_code.h"
20 #include "bundle_memory_guard.h"
21 #include "ipc_types.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
BundleEventCallbackHost()25 BundleEventCallbackHost::BundleEventCallbackHost()
26 {
27 APP_LOGD("create BundleEventCallbackHost");
28 }
29
~BundleEventCallbackHost()30 BundleEventCallbackHost::~BundleEventCallbackHost()
31 {
32 APP_LOGD("destroy BundleEventCallbackHost");
33 }
34
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)35 int BundleEventCallbackHost::OnRemoteRequest(
36 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
37 {
38 BundleMemoryGuard memoryGuard;
39 APP_LOGD("BundleEventCallbackHost OnRemoteRequest, code : %{public}u", code);
40 std::u16string descriptor = BundleEventCallbackHost::GetDescriptor();
41 std::u16string remoteDescriptor = data.ReadInterfaceToken();
42 if (descriptor != remoteDescriptor) {
43 APP_LOGE("verify descriptor failed");
44 return OBJECT_NULL;
45 }
46
47 switch (code) {
48 case static_cast<uint32_t>(BundleEventCallbackInterfaceCode::ON_RECEIVE_EVENT): {
49 std::unique_ptr<EventFwk::CommonEventData> dataPtr(data.ReadParcelable<EventFwk::CommonEventData>());
50 if (dataPtr == nullptr) {
51 APP_LOGE("get CommonEventData failed");
52 return OBJECT_NULL;
53 }
54 OnReceiveEvent(*(dataPtr.get()));
55 break;
56 }
57 default:
58 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
59 }
60 return NO_ERROR;
61 }
62 } // namespace AppExecFwk
63 } // namespace OHOS
64