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_stub.h"
17
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AppExecFwk {
KiaInterceptorStub()22 KiaInterceptorStub::KiaInterceptorStub() {}
23
~KiaInterceptorStub()24 KiaInterceptorStub::~KiaInterceptorStub() {}
25
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int KiaInterceptorStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
27 {
28 TAG_LOGD(AAFwkTag::APPMGR, "cmd=%{public}d,flags=%{public}d", code, option.GetFlags());
29 std::u16string descriptor = KiaInterceptorStub::GetDescriptor();
30 std::u16string remoteDescriptor = data.ReadInterfaceToken();
31 if (descriptor != remoteDescriptor) {
32 TAG_LOGI(AAFwkTag::APPMGR, "local descriptor is not equal to remote");
33 return ERR_INVALID_STATE;
34 }
35
36 if (code == KIA_INTERCEPTOR_ON_INTERCEPT) {
37 return OnInterceptInner(data, reply);
38 }
39 TAG_LOGW(AAFwkTag::APPMGR, "KiaInterceptorStub::OnRemoteRequest, default case, need check.");
40 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
41 }
42
OnInterceptInner(MessageParcel & data,MessageParcel & reply)43 int KiaInterceptorStub::OnInterceptInner(MessageParcel &data, MessageParcel &reply)
44 {
45 sptr<AAFwk::Want> want = data.ReadParcelable<AAFwk::Want>();
46 int resultCode = OnIntercept(*want);
47 if (!reply.WriteInt32(resultCode)) {
48 TAG_LOGE(AAFwkTag::APPMGR, "write resultCode failed.");
49 return ERR_INVALID_VALUE;
50 }
51 if (!reply.WriteParcelable(want)) {
52 TAG_LOGE(AAFwkTag::APPMGR, "write want failed.");
53 return ERR_INVALID_VALUE;
54 }
55
56 return NO_ERROR;
57 }
58 } // namespace AppExecFwk
59 } // namespace OHOS
60