1 /*
2  * Copyright (c) 2022-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 "free_install_status_callback_proxy.h"
17 #include "fms_log_wrapper.h"
18 #include "ipc_types.h"
19 #include "message_parcel.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
FreeInstallStatusCallBackProxy(const sptr<IRemoteObject> & impl)23 FreeInstallStatusCallBackProxy::FreeInstallStatusCallBackProxy(const sptr<IRemoteObject>& impl)
24     : IRemoteProxy<IFreeInstallStatusCallBack>(impl)
25 {
26 }
27 
OnInstallFinished(int32_t resultCode,const Want & want,int32_t userId)28 void FreeInstallStatusCallBackProxy::OnInstallFinished(int32_t resultCode, const Want &want, int32_t userId)
29 {
30     MessageParcel data;
31     MessageParcel reply;
32     MessageOption option;
33 
34     if (!data.WriteInterfaceToken(IFreeInstallStatusCallBack::GetDescriptor())) {
35         HILOG_ERROR("Write interface token failed");
36         return;
37     }
38 
39     if (!data.WriteInt32(resultCode)) {
40         HILOG_ERROR("Write resultCode error");
41         return;
42     }
43 
44     if (!data.WriteParcelable(&want)) {
45         HILOG_ERROR("Write want error");
46         return;
47     }
48 
49     if (!data.WriteInt32(userId)) {
50         HILOG_ERROR("Write userId error");
51         return;
52     }
53 
54     sptr<IRemoteObject> remote = Remote();
55     if (remote == nullptr) {
56         HILOG_ERROR("null remote");
57         return;
58     }
59 
60     int32_t error = remote->SendRequest(IFreeInstallStatusCallBackCmd::ON_FREE_INSTALL_DONE, data,
61         reply, option);
62     if (error != NO_ERROR) {
63         HILOG_ERROR("OnFinished fail, error:%{public}d", error);
64         return;
65     }
66 }
67 } // namespace AppExecFwk
68 } // namespace OHOS
69