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
18 #include "message_parcel_helper.h"
19 #include "update_helper.h"
20 #include "update_log.h"
21
22 namespace OHOS {
23 namespace UpdateEngine {
OnCheckVersionDone(const BusinessError & businessError,const CheckResult & checkResult)24 void UpdateCallbackProxy::OnCheckVersionDone(const BusinessError &businessError, const CheckResult &checkResult)
25 {
26 ENGINE_LOGI("UpdateCallbackProxy::OnCheckVersionDone");
27 MessageParcel data;
28 MessageParcel reply;
29 MessageOption option { MessageOption::TF_SYNC };
30
31 if (!data.WriteInterfaceToken(GetDescriptor())) {
32 ENGINE_LOGE("UpdateCallbackProxy WriteInterfaceToken fail");
33 return;
34 }
35
36 auto remote = Remote();
37 ENGINE_CHECK(remote != nullptr, return, "Can not get remote");
38
39 int32_t result = MessageParcelHelper::WriteBusinessError(data, businessError);
40 ENGINE_CHECK(result == 0, return, "Can not WriteBusinessError");
41
42 result = MessageParcelHelper::WriteCheckResult(data, checkResult);
43 ENGINE_CHECK(result == 0, return, "Can not WriteCheckResult");
44
45 result = remote->SendRequest(CHECK_VERSION, data, reply, option);
46 ENGINE_CHECK(result == ERR_OK, return, "Can not SendRequest");
47 return;
48 }
49
OnEvent(const EventInfo & eventInfo)50 void UpdateCallbackProxy::OnEvent(const EventInfo &eventInfo)
51 {
52 ENGINE_LOGI("UpdateCallbackProxy::OnEvent");
53 MessageParcel data;
54 MessageParcel reply;
55 MessageOption option { MessageOption::TF_SYNC };
56
57 if (!data.WriteInterfaceToken(GetDescriptor())) {
58 ENGINE_LOGE("UpdateCallbackProxy WriteInterfaceToken fail");
59 return;
60 }
61
62 auto remote = Remote();
63 ENGINE_CHECK(remote != nullptr, return, "Can not get remote");
64
65 int32_t result = MessageParcelHelper::WriteEventInfo(data, eventInfo);
66 ENGINE_CHECK(result == 0, return, "Can not WriteEventInfo");
67
68 result = remote->SendRequest(ON_EVENT, data, reply, option);
69 ENGINE_CHECK(result == ERR_OK, return, "Can not SendRequest");
70 return;
71 }
72 } // namespace UpdateEngine
73 } // namespace OHOS
74