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