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