1 /*
2 * Copyright (c) 2023 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 "ability_manager_errors.h"
17 #include "acquire_share_data_callback_proxy.h"
18 #include "hilog_wrapper.h"
19 #include "iremote_object.h"
20 #include "message_parcel.h"
21 #include "peer_holder.h"
22 #include "want_params.h"
23
24 namespace OHOS {
25 namespace AAFwk {
WriteInterfaceToken(MessageParcel & data)26 bool AcquireShareDataCallbackProxy::WriteInterfaceToken(MessageParcel &data)
27 {
28 if (!data.WriteInterfaceToken(AcquireShareDataCallbackProxy::GetDescriptor())) {
29 HILOG_ERROR("write interface tokern failed.");
30 return false;
31 }
32 return true;
33 }
34
AcquireShareDataDone(int32_t resultCode,WantParams & wantParam)35 int32_t AcquireShareDataCallbackProxy::AcquireShareDataDone(int32_t resultCode, WantParams &wantParam)
36 {
37 HILOG_INFO("AcquireShareDataDone start.");
38 MessageParcel data;
39 MessageParcel reply;
40 MessageOption option(MessageOption::TF_ASYNC);
41 if (!WriteInterfaceToken(data)) {
42 HILOG_ERROR("write interface token failed");
43 return INNER_ERR;
44 }
45
46 if (!data.WriteInt32(resultCode)) {
47 HILOG_ERROR("resultCode write failed.");
48 return INNER_ERR;
49 }
50 if (!data.WriteParcelable(&wantParam)) {
51 HILOG_ERROR("wantParam write failed.");
52 return INNER_ERR;
53 }
54 auto remote = Remote();
55 if (!remote) {
56 HILOG_ERROR("remote object is nullptr.");
57 return INNER_ERR;
58 }
59 int32_t ret = remote->SendRequest(IAcquireShareDataCallback::ACQUIRE_SHARE_DATA_DONE, data, reply, option);
60 if (ret != NO_ERROR) {
61 HILOG_ERROR("AcquireShareDataDone fail to Send request, err: %{public}d.", ret);
62 }
63 HILOG_INFO("AcquireShareDataDone end.");
64 return ret;
65 }
66 }
67 }