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 "dms_free_install_callback_proxy.h"
17 
18 #include "dtbschedmgr_log.h"
19 #include "ipc_types.h"
20 #include "message_parcel.h"
21 
22 namespace OHOS {
23 namespace DistributedSchedule {
24 namespace {
25 const std::string TAG = "DmsFreeInstallCallbackProxy";
26 }
27 using OHOS::DistributedSchedule::IDmsFreeInstallCallback;
DmsFreeInstallCallbackProxy(const sptr<IRemoteObject> & impl)28 DmsFreeInstallCallbackProxy::DmsFreeInstallCallbackProxy(const sptr<IRemoteObject>& impl)
29     : IRemoteProxy<IDmsFreeInstallCallback>(impl)
30 {
31 }
32 
OnInstallFinished(const OHOS::AAFwk::Want & want,int32_t requestCode,int32_t resultCode)33 void DmsFreeInstallCallbackProxy::OnInstallFinished(
34     const OHOS::AAFwk::Want& want, int32_t requestCode, int32_t resultCode)
35 {
36     MessageParcel data;
37     MessageParcel reply;
38     MessageOption option;
39 
40     if (!data.WriteInterfaceToken(IDmsFreeInstallCallback::GetDescriptor())) {
41         HILOGE("Write interface token failed.");
42         return;
43     }
44 
45     if (!data.WriteInt32(resultCode)) {
46         HILOGE("Write resultCode error.");
47         return;
48     }
49 
50     if (!data.WriteParcelable(&want)) {
51         HILOGE("want write failed.");
52         return;
53     }
54 
55     if (!data.WriteInt32(requestCode)) {
56         HILOGE("requestCode write failed.");
57         return;
58     }
59 
60     sptr<IRemoteObject> remote = Remote();
61     if (remote == nullptr) {
62         HILOGE("remote service null");
63         return;
64     }
65     int32_t error = remote->SendRequest(static_cast<uint32_t>
66         (IDRreeInstallCallbackInterfaceCode::ON_FREE_INSTALL_DONE), data, reply, option);
67     if (error != NO_ERROR) {
68         HILOGE("OnFinished fail, error: %{public}d", error);
69         return;
70     }
71 }
72 }  // namespace DistributedSchedule
73 }  // namespace OHOS
74