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 LOG(ERROR) << "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 case static_cast<uint32_t>(SysInstallerCallbackInterfaceCode::STREAM_UPDATE_RESULT): {
47 int updateStatus = data.ReadInt32();
48 int dealLen = data.ReadInt32();
49 OnUpgradeDealLen(static_cast<UpdateStatus>(updateStatus), dealLen, data.ReadString());
50 break;
51 }
52 default: {
53 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
54 }
55 }
56 return 0;
57 }
58
OnUpgradeProgress(UpdateStatus updateStatus,int percent,const std::string & resultMsg)59 void SysInstallerCallback::OnUpgradeProgress(UpdateStatus updateStatus, int percent,
60 const std::string &resultMsg)
61 {
62 LOG(INFO) << "updateStatus: " << updateStatus << " percent:" << percent << " msg:" << resultMsg;
63 if (callback_ != nullptr) {
64 callback_->OnUpgradeProgress(updateStatus, percent, resultMsg);
65 }
66 }
67
OnUpgradeDealLen(UpdateStatus updateStatus,int dealLen,const std::string & resultMsg)68 void SysInstallerCallback::OnUpgradeDealLen(UpdateStatus updateStatus, int dealLen,
69 const std::string &resultMsg)
70 {
71 LOG(INFO) << "updateStatus: " << updateStatus << " dealLen:" << dealLen << " msg:" << resultMsg;
72 if (callback_ != nullptr) {
73 callback_->OnUpgradeDealLen(updateStatus, dealLen, resultMsg);
74 }
75 }
76
RegisterCallback(sptr<ISysInstallerCallbackFunc> callback)77 void SysInstallerCallback::RegisterCallback(sptr<ISysInstallerCallbackFunc> callback)
78 {
79 callback_ = callback;
80 }
81 }
82 } // namespace OHOS
83