1 /*
2 * Copyright (c) 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 "kia_interceptor_proxy.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_capacity_wrap.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
WriteInterfaceToken(MessageParcel & data)23 bool KiaInterceptorProxy::WriteInterfaceToken(MessageParcel &data)
24 {
25 if (!data.WriteInterfaceToken(KiaInterceptorProxy::GetDescriptor())) {
26 TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed");
27 return false;
28 }
29 return true;
30 }
31
OnIntercept(AAFwk::Want & want)32 int KiaInterceptorProxy::OnIntercept(AAFwk::Want &want)
33 {
34 MessageParcel data;
35 MessageParcel reply;
36 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
37 MessageOption option(MessageOption::TF_SYNC);
38 if (!WriteInterfaceToken(data)) {
39 return ERR_INVALID_VALUE;
40 }
41 data.WriteParcelable(&want);
42 sptr<IRemoteObject> remote = Remote();
43 if (remote == nullptr) {
44 TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL");
45 return ERR_INVALID_VALUE;
46 }
47 int32_t ret = remote->SendRequest(static_cast<uint32_t>(IKiaInterceptor::KIA_INTERCEPTOR_ON_INTERCEPT),
48 data, reply, option);
49 if (ret != NO_ERROR) {
50 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d.", ret);
51 return ret;
52 }
53 int resultCode = reply.ReadInt32();
54 if (resultCode != ERR_OK) {
55 TAG_LOGE(AAFwkTag::APPMGR, "OnIntercept failed, resultCode=%{public}d.", resultCode);
56 return resultCode;
57 }
58 sptr<AAFwk::Want> resultWant = reply.ReadParcelable<AAFwk::Want>();
59 if (resultWant == nullptr) {
60 TAG_LOGE(AAFwkTag::APPMGR, "resultWant is nullptr.");
61 return ERR_INVALID_VALUE;
62 }
63 want = *resultWant;
64 return resultCode;
65 }
66 } // namespace AppExecFwk
67 } // namespace OHOS
68