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 "service_center_status_callback_stub.h"
17
18 #include "app_log_tag_wrapper.h"
19 #include "bundle_memory_guard.h"
20 #include "free_install_params.h"
21
22 namespace OHOS {
23 namespace AppExecFwk {
24 namespace {
25 const std::u16string SEEVICE_CENTER_CALLBACK_TOKEN = u"abilitydispatcherhm.openapi.hapinstall.IHapInstallCallback";
26 }
27
ServiceCenterStatusCallbackStub()28 ServiceCenterStatusCallbackStub::ServiceCenterStatusCallbackStub()
29 {
30 LOG_I(BMS_TAG_DEFAULT, "ServiceCenterStatusCallbackStub is created");
31 }
32
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int32_t ServiceCenterStatusCallbackStub::OnRemoteRequest(
34 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
35 {
36 BundleMemoryGuard memoryGuard;
37 if (data.ReadInterfaceToken() != SEEVICE_CENTER_CALLBACK_TOKEN) {
38 LOG_E(BMS_TAG_DEFAULT, "verify interface token failed");
39 return -1;
40 }
41
42 auto result = data.ReadString16();
43 LOG_D(BMS_TAG_DEFAULT, "OnRemoteRequest:code:%{public}d, result:%{public}s",
44 code, Str16ToStr8(result).c_str());
45 if (code == ServiceCenterFunction::CONNECT_DELAYED_HEARTBEAT) {
46 return OnDelayedHeartbeat(Str16ToStr8(result));
47 }
48 if (DISCONNECT_ABILITY_FUNC.find(static_cast<ServiceCenterFunction>(code)) != DISCONNECT_ABILITY_FUNC.end()) {
49 return OnServiceCenterReceived(Str16ToStr8(result));
50 }
51 return OnInstallFinished(Str16ToStr8(result));
52 }
53 } // namespace AppExecFwk
54 } // namespace OHOS
55