• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "atomic_service_status_callback_proxy.h"
17 
18 #include "hilog_wrapper.h"
19 #include "ipc_types.h"
20 #include "message_parcel.h"
21 
22 namespace OHOS {
23 namespace AAFwk {
24 using OHOS::AAFwk::IAtomicServiceStatusCallback;
25 
AtomicServiceStatusCallbackProxy(const sptr<IRemoteObject> & impl)26 AtomicServiceStatusCallbackProxy::AtomicServiceStatusCallbackProxy(const sptr<IRemoteObject>& impl)
27     : IRemoteProxy<IAtomicServiceStatusCallback>(impl)
28 {
29 }
OnInstallFinished(int resultCode,const Want & want,int32_t userId)30 void AtomicServiceStatusCallbackProxy::OnInstallFinished(int resultCode, const Want &want, int32_t userId)
31 {
32     MessageParcel data;
33     MessageParcel reply;
34     MessageOption option;
35 
36     if (!data.WriteInterfaceToken(IAtomicServiceStatusCallback::GetDescriptor())) {
37         HILOG_ERROR("Write interface token failed.");
38         return;
39     }
40 
41     if (!data.WriteInt32(resultCode)) {
42         HILOG_ERROR("Write resultCode failed.");
43         return;
44     }
45 
46     if (!data.WriteParcelable(&want)) {
47         HILOG_ERROR("Write want failed.");
48         return;
49     }
50 
51     if (!data.WriteInt32(userId)) {
52         HILOG_ERROR("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         HILOG_ERROR("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 
70     if (!data.WriteInterfaceToken(IAtomicServiceStatusCallback::GetDescriptor())) {
71         HILOG_ERROR("Write interface token failed.");
72         return;
73     }
74 
75     if (!data.WriteInt32(resultCode)) {
76         HILOG_ERROR("Write resultCode failed.");
77         return;
78     }
79 
80     if (!data.WriteParcelable(&want)) {
81         HILOG_ERROR("Write want error.");
82         return;
83     }
84 
85     if (!data.WriteInt32(userId)) {
86         HILOG_ERROR("Write userId failed.");
87         return;
88     }
89 
90     int32_t error = SendTransactCmd(ON_REMOTE_FREE_INSTALL_DONE, data, reply, option);
91     if (error != NO_ERROR) {
92         HILOG_ERROR("OnFinished fail, error: %{public}d", error);
93         return;
94     }
95 }
96 
OnRemoveTimeoutTask(const Want & want)97 void AtomicServiceStatusCallbackProxy::OnRemoveTimeoutTask(const Want &want)
98 {
99     MessageParcel data;
100     MessageParcel reply;
101     MessageOption option;
102 
103     if (!data.WriteInterfaceToken(IAtomicServiceStatusCallback::GetDescriptor())) {
104         HILOG_ERROR("Write interface token failed.");
105         return;
106     }
107 
108     if (!data.WriteParcelable(&want)) {
109         HILOG_ERROR("Write want error.");
110         return;
111     }
112 
113     int32_t error = SendTransactCmd(ON_REMOVE_TIMEOUT_TASK, data, reply, option);
114     if (error != NO_ERROR) {
115         HILOG_ERROR("OnFinished fail, error: %{public}d", error);
116         return;
117     }
118 }
119 
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)120 int32_t AtomicServiceStatusCallbackProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
121     MessageParcel &reply, MessageOption &option)
122 {
123     sptr<IRemoteObject> remote = Remote();
124     if (remote == nullptr) {
125         HILOG_ERROR("remote object is nullptr.");
126         return ERR_NULL_OBJECT;
127     }
128 
129     int32_t ret = remote->SendRequest(code, data, reply, option);
130     if (ret != NO_ERROR) {
131         HILOG_ERROR("SendRequest failed. code is %{public}d, ret is %{public}d.", code, ret);
132         return ret;
133     }
134     return NO_ERROR;
135 }
136 }  // namespace AAFwk
137 }  // namespace OHOS
138