1 /*
2 * Copyright (c) 2022-2024 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 "quick_fix_callback_proxy.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "message_parcel.h"
20 #include "parcel_macro_base.h"
21
22 namespace OHOS {
23 namespace AppExecFwk {
OnLoadPatchDone(int32_t resultCode,int32_t recordId)24 void QuickFixCallbackProxy::OnLoadPatchDone(int32_t resultCode, int32_t recordId)
25 {
26 TAG_LOGD(AAFwkTag::APPMGR, "called");
27
28 MessageParcel data;
29 MessageParcel reply;
30 WRITE_PARCEL_AND_RETURN(InterfaceToken, data, QuickFixCallbackProxy::GetDescriptor());
31 WRITE_PARCEL_AND_RETURN(Int32, data, resultCode);
32 WRITE_PARCEL_AND_RETURN(Int32, data, recordId);
33 if (!SendRequestWithCmd(IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_LOAD_PATCH, data, reply)) {
34 return;
35 }
36
37 TAG_LOGD(AAFwkTag::APPMGR, "function finished.");
38 return;
39 }
40
OnUnloadPatchDone(int32_t resultCode,int32_t recordId)41 void QuickFixCallbackProxy::OnUnloadPatchDone(int32_t resultCode, int32_t recordId)
42 {
43 TAG_LOGD(AAFwkTag::APPMGR, "called");
44
45 MessageParcel data;
46 MessageParcel reply;
47 WRITE_PARCEL_AND_RETURN(InterfaceToken, data, QuickFixCallbackProxy::GetDescriptor());
48 WRITE_PARCEL_AND_RETURN(Int32, data, resultCode);
49 WRITE_PARCEL_AND_RETURN(Int32, data, recordId);
50 if (!SendRequestWithCmd(IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_UNLOAD_PATCH, data, reply)) {
51 return;
52 }
53
54 TAG_LOGD(AAFwkTag::APPMGR, "function finished.");
55 return;
56 }
57
OnReloadPageDone(int32_t resultCode,int32_t recordId)58 void QuickFixCallbackProxy::OnReloadPageDone(int32_t resultCode, int32_t recordId)
59 {
60 TAG_LOGD(AAFwkTag::APPMGR, "called");
61
62 MessageParcel data;
63 MessageParcel reply;
64 WRITE_PARCEL_AND_RETURN(InterfaceToken, data, QuickFixCallbackProxy::GetDescriptor());
65 WRITE_PARCEL_AND_RETURN(Int32, data, resultCode);
66 WRITE_PARCEL_AND_RETURN(Int32, data, recordId);
67 if (!SendRequestWithCmd(IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_RELOAD_PAGE, data, reply)) {
68 return;
69 }
70
71 TAG_LOGD(AAFwkTag::APPMGR, "function finished.");
72 return;
73 }
74
SendRequestWithCmd(uint32_t code,MessageParcel & data,MessageParcel & reply)75 bool QuickFixCallbackProxy::SendRequestWithCmd(uint32_t code, MessageParcel &data, MessageParcel &reply)
76 {
77 sptr<IRemoteObject> remote = Remote();
78 if (remote == nullptr) {
79 TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
80 return false;
81 }
82
83 MessageOption option(MessageOption::TF_SYNC);
84 auto ret = remote->SendRequest(code, data, reply, option);
85 if (ret != 0) {
86 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error %{public}d.", ret);
87 return false;
88 }
89
90 return true;
91 }
92 } // namespace AppExecFwk
93 } // namespace OHOS
94