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_proxy.h"
17 #include "sys_installer_sa_ipc_interface_code.h"
18
19 #include "log/log.h"
20 #include "securec.h"
21
22 namespace OHOS {
23 namespace SysInstaller {
24 using namespace Updater;
25
OnUpgradeProgress(UpdateStatus updateStatus,int percent,const std::string & resultMsg)26 void SysInstallerCallbackProxy::OnUpgradeProgress(UpdateStatus updateStatus, int percent, const std::string &resultMsg)
27 {
28 LOG(INFO) << "OnUpgradeProgress";
29 MessageParcel data;
30 MessageParcel reply;
31 MessageOption option { MessageOption::TF_SYNC };
32
33 if (!data.WriteInterfaceToken(GetDescriptor())) {
34 LOG(INFO) << "UpdateCallbackProxy WriteInterfaceToken fail";
35 return;
36 }
37
38 auto remote = Remote();
39 if (remote == nullptr) {
40 LOG(ERROR) << "Can not get remote";
41 return;
42 }
43
44 data.WriteInt32(updateStatus);
45 data.WriteInt32(percent);
46 data.WriteString(resultMsg);
47 int32_t result = remote->SendRequest(
48 static_cast<uint32_t>(SysInstallerCallbackInterfaceCode::UPDATE_RESULT), data, reply, option);
49 if (result != ERR_OK) {
50 LOG(ERROR) << "Can not SendRequest " << result;
51 }
52 }
53 }
54 } // namespace OHOS
55