1 /*
2  * Copyright (c) 2023-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 "insight_intent_execute_callback_stub.h"
17 #include "insight_intent_host_client.h"
18 #include "hilog_tag_wrapper.h"
19 
20 namespace OHOS {
21 namespace AAFwk {
22 
InsightIntentExecuteCallbackStub()23 InsightIntentExecuteCallbackStub::InsightIntentExecuteCallbackStub() {}
24 
~InsightIntentExecuteCallbackStub()25 InsightIntentExecuteCallbackStub::~InsightIntentExecuteCallbackStub() {}
26 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int32_t InsightIntentExecuteCallbackStub::OnRemoteRequest(
28     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
29 {
30     if (data.ReadInterfaceToken() != IInsightIntentExecuteCallback::GetDescriptor()) {
31         TAG_LOGE(AAFwkTag::INTENT, "InterfaceToken not equal");
32         return ERR_INVALID_STATE;
33     }
34 
35     if (code == ON_INSIGHT_INTENT_EXECUTE_DONE) {
36         return OnExecuteDoneInner(data, reply);
37     }
38     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
39 }
40 
OnExecuteDoneInner(MessageParcel & data,MessageParcel & reply)41 int32_t InsightIntentExecuteCallbackStub::OnExecuteDoneInner(MessageParcel &data, MessageParcel &reply)
42 {
43     TAG_LOGD(AAFwkTag::INTENT, "called");
44     uint64_t key = data.ReadUint64();
45     int32_t resultCode = data.ReadInt32();
46     std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> executeResult(
47         data.ReadParcelable<AppExecFwk::InsightIntentExecuteResult>());
48     if (executeResult == nullptr) {
49         TAG_LOGE(AAFwkTag::INTENT, "null executeResult");
50         return ERR_INVALID_VALUE;
51     }
52     OnExecuteDone(key, resultCode, *executeResult);
53     return ERR_OK;
54 }
55 } // namespace AAFwk
56 } // namespace OHOS
57