• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "update_callback_proxy.h"
17 #include "securec.h"
18 #include "update_helper.h"
19 
20 namespace OHOS {
21 namespace update_engine {
OnCheckVersionDone(const VersionInfo & info)22 void UpdateCallbackProxy::OnCheckVersionDone(const VersionInfo &info)
23 {
24     ENGINE_LOGI("UpdateCallbackProxy::OnCheckVersionDone");
25     MessageParcel data;
26     MessageParcel reply;
27     MessageOption option { MessageOption::TF_SYNC };
28 
29     if (!data.WriteInterfaceToken(GetDescriptor())) {
30         ENGINE_LOGI("UpdateCallbackProxy WriteInterfaceToken fail");
31         return;
32     }
33 
34     auto remote = Remote();
35     ENGINE_CHECK(remote != nullptr, return, "Can not get remote");
36 
37     int32_t result = UpdateHelper::WriteVersionInfo(data, info);
38     ENGINE_CHECK(result == 0, return, "Can not WriteVersionInfo");
39 
40     result = remote->SendRequest(CHECK_VERSION, data, reply, option);
41     ENGINE_CHECK(result == ERR_OK, return, "Can not SendRequest");
42     return;
43 }
44 
OnDownloadProgress(const Progress & progress)45 void UpdateCallbackProxy::OnDownloadProgress(const Progress &progress)
46 {
47     ENGINE_LOGI("UpdateCallbackProxy::OnDownloadProgress");
48     MessageParcel data;
49     MessageParcel reply;
50     MessageOption option { MessageOption::TF_SYNC };
51 
52     if (!data.WriteInterfaceToken(GetDescriptor())) {
53         ENGINE_LOGI("UpdateCallbackProxy WriteInterfaceToken fail");
54         return;
55     }
56 
57     auto remote = Remote();
58     ENGINE_CHECK(remote != nullptr, return, "Can not get remote");
59 
60     int32_t result = UpdateHelper::WriteUpdateProgress(data, progress);
61     ENGINE_CHECK(result == 0, return, "Can not WriteUpdateProgress");
62 
63     result = remote->SendRequest(DOWNLOAD, data, reply, option);
64     ENGINE_CHECK(result == ERR_OK, return, "Can not SendRequest %d", result);
65     return;
66 }
67 
OnUpgradeProgress(const Progress & progress)68 void UpdateCallbackProxy::OnUpgradeProgress(const Progress &progress)
69 {
70     ENGINE_LOGI("UpdateCallbackProxy::OnUpgradeProgress");
71     MessageParcel data;
72     MessageParcel reply;
73     MessageOption option { MessageOption::TF_SYNC };
74 
75     if (!data.WriteInterfaceToken(GetDescriptor())) {
76         ENGINE_LOGI("UpdateCallbackProxy WriteInterfaceToken fail");
77         return;
78     }
79 
80     auto remote = Remote();
81     ENGINE_CHECK(remote != nullptr, return, "Can not get remote");
82 
83     int32_t result = UpdateHelper::WriteUpdateProgress(data, progress);
84     ENGINE_CHECK(result == 0, return, "Can not WriteUpdateProgress");
85 
86     result = remote->SendRequest(UPGRADE, data, reply, option);
87     ENGINE_CHECK(result == ERR_OK, return, "Can not SendRequest");
88     return;
89 }
90 }
91 } // namespace OHOS
92