• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,
27     const std::string &resultMsg)
28 {
29     LOG(INFO) << "OnUpgradeProgress";
30     MessageParcel data;
31     MessageParcel reply;
32     MessageOption option { MessageOption::TF_SYNC };
33 
34     if (!data.WriteInterfaceToken(GetDescriptor())) {
35         LOG(INFO) << "UpdateCallbackProxy WriteInterfaceToken fail";
36         return;
37     }
38 
39     auto remote = Remote();
40     if (remote == nullptr) {
41         LOG(ERROR) << "Can not get remote";
42         return;
43     }
44 
45     data.WriteInt32(updateStatus);
46     data.WriteInt32(percent);
47     data.WriteString(resultMsg);
48     int32_t result = remote->SendRequest(
49         static_cast<uint32_t>(SysInstallerCallbackInterfaceCode::UPDATE_RESULT), data, reply, option);
50     if (result != ERR_OK) {
51         LOG(ERROR) << "Can not SendRequest " << result;
52     }
53 }
54 
OnUpgradeDealLen(UpdateStatus updateStatus,int dealLen,const std::string & resultMsg)55 void SysInstallerCallbackProxy::OnUpgradeDealLen(UpdateStatus updateStatus, int dealLen,
56     const std::string &resultMsg)
57 {
58     LOG(INFO) << "OnUpgradeDealLen";
59     MessageParcel data;
60     MessageParcel reply;
61     MessageOption option { MessageOption::TF_SYNC };
62 
63     if (!data.WriteInterfaceToken(GetDescriptor())) {
64         LOG(INFO) << "UpdateCallbackProxy WriteInterfaceToken fail";
65         return;
66     }
67 
68     auto remote = Remote();
69     if (remote == nullptr) {
70         LOG(ERROR) << "Can not get remote";
71         return;
72     }
73 
74     data.WriteInt32(updateStatus);
75     data.WriteInt32(dealLen);
76     data.WriteString(resultMsg);
77     int32_t result = remote->SendRequest(
78         static_cast<uint32_t>(SysInstallerCallbackInterfaceCode::STREAM_UPDATE_RESULT), data, reply, option);
79     if (result != ERR_OK) {
80         LOG(ERROR) << "Can not SendRequest " << result;
81     }
82 }
83 }
84 } // namespace OHOS
85