1 /*
2 * Copyright (c) 2022 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 "sys_installer_callback.h"
17
18 #include "if_system_ability_manager.h"
19 #include "iservice_registry.h"
20 #include "log/log.h"
21 #include "securec.h"
22 #include "utils.h"
23
24 #include "isys_installer_callback.h"
25 #include "sys_installer_common.h"
26 #include "sys_installer_sa_ipc_interface_code.h"
27
28 namespace OHOS {
29 namespace SysInstaller {
30 using namespace Updater;
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t SysInstallerCallbackStub::OnRemoteRequest(uint32_t code,
33 MessageParcel &data, MessageParcel &reply, MessageOption &option)
34 {
35 if (data.ReadInterfaceToken() != GetDescriptor()) {
36 printf("ReadInterfaceToken fail");
37 return -1;
38 }
39 switch (code) {
40 case static_cast<uint32_t>(SysInstallerCallbackInterfaceCode::UPDATE_RESULT): {
41 int updateStatus = data.ReadInt32();
42 int percent = data.ReadInt32();
43 OnUpgradeProgress(static_cast<UpdateStatus>(updateStatus), percent, data.ReadString());
44 break;
45 }
46 default: {
47 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48 }
49 }
50 return 0;
51 }
52
OnUpgradeProgress(UpdateStatus updateStatus,int percent,const std::string & resultMsg)53 void SysInstallerCallback::OnUpgradeProgress(UpdateStatus updateStatus, int percent, const std::string &resultMsg)
54 {
55 LOG(INFO) << "progress: " << updateStatus << " percent:" << percent << " msg:" << resultMsg;
56 if (callback_ != nullptr) {
57 callback_->OnUpgradeProgress(updateStatus, percent, resultMsg);
58 }
59 }
60
RegisterCallback(sptr<ISysInstallerCallbackFunc> callback)61 void SysInstallerCallback::RegisterCallback(sptr<ISysInstallerCallbackFunc> callback)
62 {
63 callback_ = callback;
64 }
65 }
66 } // namespace OHOS
67