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