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_manager_callback_stub.h"
17
18 #include "app_log_wrapper.h"
19 #include "bundle_framework_services_ipc_interface_code.h"
20 #include "bundle_memory_guard.h"
21 #include "string_ex.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
BundleManagerCallbackStub()25 BundleManagerCallbackStub::BundleManagerCallbackStub()
26 {
27 APP_LOGI("BundleManagerCallbackStub is created");
28 }
29
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int32_t BundleManagerCallbackStub::OnRemoteRequest(
31 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
32 {
33 BundleMemoryGuard memoryGuard;
34 APP_LOGI("bundle mgr callback onReceived message, message code %{public}u", code);
35 std::u16string descriptor = BundleManagerCallbackStub::GetDescriptor();
36 std::u16string token = data.ReadInterfaceToken();
37 if (descriptor != token) {
38 APP_LOGE("OnRemoteRequest token is invalid");
39 return OBJECT_NULL;
40 }
41 switch (code) {
42 case static_cast<uint32_t>(BundleManagerCallbackInterfaceCode::QUERY_RPC_ID_CALLBACK):
43 return HandleQueryRpcIdCallBack(data, reply);
44 default:
45 APP_LOGW("BundleManagerCallbackStub receives unknown code %{public}d", code);
46 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
47 }
48 return NO_ERROR;
49 }
50
HandleQueryRpcIdCallBack(MessageParcel & data,MessageParcel & reply)51 int32_t BundleManagerCallbackStub::HandleQueryRpcIdCallBack(MessageParcel &data, MessageParcel &reply)
52 {
53 std::string queryRpcIdResult = Str16ToStr8(data.ReadString16());
54 return OnQueryRpcIdFinished(queryRpcIdResult);
55 }
56 } // namespace AppExecFwk
57 } // namespace OHOS