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 "query_app_info_callback_proxy.h"
17
18 #include "nfc_service_ipc_interface_code.h"
19 #include "loghelper.h"
20
21 namespace OHOS {
22 namespace NFC {
23 static const int MAX_HAP_LIST_LEN = 1000;
24
QueryAppInfoCallbackProxy(const sptr<IRemoteObject> & remote)25 QueryAppInfoCallbackProxy::QueryAppInfoCallbackProxy(const sptr<IRemoteObject> &remote)
26 : IRemoteProxy<IQueryAppInfoCallback>(remote)
27 {}
28
OnQueryAppInfo(std::string type,std::vector<int> techList,std::vector<AAFwk::Want> & hceAppList,std::vector<AppExecFwk::ElementName> & elementNameList)29 bool QueryAppInfoCallbackProxy::OnQueryAppInfo(std::string type, std::vector<int> techList,
30 std::vector<AAFwk::Want> &hceAppList, std::vector<AppExecFwk::ElementName> &elementNameList)
31 {
32 MessageOption option = {MessageOption::TF_SYNC};
33 MessageParcel data;
34 MessageParcel reply;
35 if (!data.WriteInterfaceToken(GetDescriptor())) {
36 ErrorLog("OnQueryAppInfo:WriteInterfaceToken token error");
37 return false;
38 }
39 data.WriteInt32(0);
40 data.WriteString(type);
41 DebugLog("query %{pubic}s app.", type.c_str());
42 if (type.compare(KEY_TAG_APP) == 0) {
43 data.WriteInt32Vector(techList);
44 int error = Remote()->SendRequest(
45 static_cast<uint32_t>(NfcServiceIpcInterfaceCode::COMMAND_QUERY_APP_INFO_MSG_CALLBACK),
46 data, reply, option);
47 if (error != ERR_NONE) {
48 ErrorLog("QueryAppInfoCallbackProxy::OnQueryAppInfo, Set Attr error: %{public}d", error);
49 return false;
50 }
51 int elementNameListLen = reply.ReadInt32();
52 InfoLog("QueryAppInfoCallbackProxy::OnQueryAppInfo recv %{public}d app need to add", elementNameListLen);
53 if (elementNameListLen > MAX_HAP_LIST_LEN) {
54 return false;
55 }
56 for (int i = 0; i < elementNameListLen; i++) {
57 elementNameList.push_back(*AppExecFwk::ElementName::Unmarshalling(reply));
58 }
59 return true;
60 } else if (type.compare(KEY_HCE_APP) == 0) {
61 int error = Remote()->SendRequest(
62 static_cast<uint32_t>(NfcServiceIpcInterfaceCode::COMMAND_QUERY_APP_INFO_MSG_CALLBACK),
63 data, reply, option);
64 if (error != ERR_NONE) {
65 ErrorLog("QueryAppInfoCallbackProxy::OnQueryAppInfo, Set Attr error: %{public}d", error);
66 return false;
67 }
68 int appLen = reply.ReadInt32();
69 InfoLog("QueryAppInfoCallbackProxy::OnQueryAppInfo recv %{public}d app need to add", appLen);
70 if (appLen > MAX_HAP_LIST_LEN) {
71 return false;
72 }
73 for (int i = 0; i < appLen; i++) {
74 hceAppList.push_back(*(AAFwk::Want::Unmarshalling(reply)));
75 }
76 return true;
77 }
78 return false;
79 }
80 } // namespace NFC
81 } // namespace OHOS
82