1 /*
2 * Copyright (c) 2023-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 "atomic_service_status_callback_proxy.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_capacity_wrap.h"
20
21 namespace OHOS {
22 namespace AAFwk {
23 using OHOS::AAFwk::IAtomicServiceStatusCallback;
24
AtomicServiceStatusCallbackProxy(const sptr<IRemoteObject> & impl)25 AtomicServiceStatusCallbackProxy::AtomicServiceStatusCallbackProxy(const sptr<IRemoteObject>& impl)
26 : IRemoteProxy<IAtomicServiceStatusCallback>(impl)
27 {
28 }
OnInstallFinished(int resultCode,const Want & want,int32_t userId)29 void AtomicServiceStatusCallbackProxy::OnInstallFinished(int resultCode, const Want &want, int32_t userId)
30 {
31 MessageParcel data;
32 MessageParcel reply;
33 MessageOption option;
34 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
35
36 if (!data.WriteInterfaceToken(IAtomicServiceStatusCallback::GetDescriptor())) {
37 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed");
38 return;
39 }
40
41 if (!data.WriteInt32(resultCode)) {
42 TAG_LOGE(AAFwkTag::ABILITYMGR, "write resultCode failed");
43 return;
44 }
45
46 if (!data.WriteParcelable(&want)) {
47 TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
48 return;
49 }
50
51 if (!data.WriteInt32(userId)) {
52 TAG_LOGE(AAFwkTag::ABILITYMGR, "write userId failed");
53 return;
54 }
55
56 int32_t error = SendTransactCmd(IAtomicServiceStatusCallbackCmd::ON_FREE_INSTALL_DONE, data,
57 reply, option);
58 if (error != NO_ERROR) {
59 TAG_LOGE(AAFwkTag::ABILITYMGR, "OnFinished fail, error: %{public}d", error);
60 return;
61 }
62 }
63
OnRemoteInstallFinished(int resultCode,const Want & want,int32_t userId)64 void AtomicServiceStatusCallbackProxy::OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId)
65 {
66 MessageParcel data;
67 MessageParcel reply;
68 MessageOption option;
69 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
70
71 if (!data.WriteInterfaceToken(IAtomicServiceStatusCallback::GetDescriptor())) {
72 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed");
73 return;
74 }
75
76 if (!data.WriteInt32(resultCode)) {
77 TAG_LOGE(AAFwkTag::ABILITYMGR, "write resultCode failed");
78 return;
79 }
80
81 if (!data.WriteParcelable(&want)) {
82 TAG_LOGE(AAFwkTag::ABILITYMGR, "write want error");
83 return;
84 }
85
86 if (!data.WriteInt32(userId)) {
87 TAG_LOGE(AAFwkTag::ABILITYMGR, "write userId failed");
88 return;
89 }
90
91 int32_t error = SendTransactCmd(ON_REMOTE_FREE_INSTALL_DONE, data, reply, option);
92 if (error != NO_ERROR) {
93 TAG_LOGE(AAFwkTag::ABILITYMGR, "OnFinished fail, error: %{public}d", error);
94 return;
95 }
96 }
97
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)98 int32_t AtomicServiceStatusCallbackProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
99 MessageParcel &reply, MessageOption &option)
100 {
101 sptr<IRemoteObject> remote = Remote();
102 if (remote == nullptr) {
103 TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
104 return ERR_NULL_OBJECT;
105 }
106
107 int32_t ret = remote->SendRequest(code, data, reply, option);
108 if (ret != NO_ERROR) {
109 TAG_LOGE(AAFwkTag::ABILITYMGR, "sendRequest failed, code: %{public}d, ret: %{public}d", code, ret);
110 return ret;
111 }
112 return NO_ERROR;
113 }
114 } // namespace AAFwk
115 } // namespace OHOS
116