• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "NfcStatsUtil.h"
18 
19 #include <android-base/stringprintf.h>
20 #include <base/logging.h>
21 #include <log/log.h>
22 #include <statslog_nfc.h>
23 
24 #include "nfc_api.h"
25 
26 using android::base::StringPrintf;
27 
28 extern bool nfc_debug_enabled;
29 
30 /*******************************************************************************
31 **
32 ** Function:        logNfcTagType
33 **
34 ** Description:     determine Nfc tag type from given protocol and log
35 ** accordingly
36 **                  protocol: tag protocol
37 **                  discoveryMode: tag discovery mode
38 **
39 ** Returns:         None
40 **
41 *******************************************************************************/
logNfcTagType(int protocol,int discoveryMode)42 void NfcStatsUtil::logNfcTagType(int protocol, int discoveryMode) {
43   static const char fn[] = "NfcStatsUtil::logNfcTagType";
44   DLOG_IF(INFO, nfc_debug_enabled)
45       << StringPrintf("%s: protocol %d, mode %d", fn, protocol, discoveryMode);
46   int tagType = nfc::stats::NFC_TAG_TYPE_OCCURRED__TYPE__TAG_UNKNOWN;
47   if (protocol == NFC_PROTOCOL_T1T) {
48     tagType = nfc::stats::NFC_TAG_TYPE_OCCURRED__TYPE__TAG_TYPE_1;
49   } else if (protocol == NFC_PROTOCOL_T2T) {
50     tagType = nfc::stats::NFC_TAG_TYPE_OCCURRED__TYPE__TAG_TYPE_2;
51   } else if (protocol == NFC_PROTOCOL_T3T) {
52     tagType = nfc::stats::NFC_TAG_TYPE_OCCURRED__TYPE__TAG_TYPE_3;
53   } else if (protocol == NFC_PROTOCOL_MIFARE) {
54     tagType = nfc::stats::NFC_TAG_TYPE_OCCURRED__TYPE__TAG_MIFARE_CLASSIC;
55   } else if (protocol == NFC_PROTOCOL_ISO_DEP) {
56     if ((discoveryMode == NFC_DISCOVERY_TYPE_POLL_A) ||
57         (discoveryMode == NFC_DISCOVERY_TYPE_POLL_A_ACTIVE) ||
58         (discoveryMode == NFC_DISCOVERY_TYPE_LISTEN_A) ||
59         (discoveryMode == NFC_DISCOVERY_TYPE_LISTEN_A_ACTIVE)) {
60       tagType = nfc::stats::NFC_TAG_TYPE_OCCURRED__TYPE__TAG_TYPE_4A;
61     } else if ((discoveryMode == NFC_DISCOVERY_TYPE_POLL_B) ||
62                (discoveryMode == NFC_DISCOVERY_TYPE_POLL_B_PRIME) ||
63                (discoveryMode == NFC_DISCOVERY_TYPE_LISTEN_B) ||
64                (discoveryMode == NFC_DISCOVERY_TYPE_LISTEN_B_PRIME)) {
65       tagType = nfc::stats::NFC_TAG_TYPE_OCCURRED__TYPE__TAG_TYPE_4B;
66     }
67   } else if (protocol == NFC_PROTOCOL_T5T) {
68     tagType = nfc::stats::NFC_TAG_TYPE_OCCURRED__TYPE__TAG_TYPE_5;
69   } else if (protocol == NFC_PROTOCOL_KOVIO) {
70     tagType = nfc::stats::NFC_TAG_TYPE_OCCURRED__TYPE__TAG_KOVIO_BARCODE;
71   }
72   writeNfcStatsTagTypeOccurred(tagType);
73 }
74 
75 /*******************************************************************************
76 **
77 ** Function:        writeNfcStatsTagTypeOccurred
78 **
79 ** Description:     stats_write TagTypeOccurred atom with provided type
80 **                  tagType: NfcTagType defined in
81 ** frameworks/proto_logging/stats/enums/nfc/enums.proto
82 **
83 ** Returns:         None
84 **
85 *******************************************************************************/
writeNfcStatsTagTypeOccurred(int tagType)86 void NfcStatsUtil::writeNfcStatsTagTypeOccurred(int tagType) {
87   static const char fn[] = "NfcStatsUtil::writeNfcStatsTagTypeOccurred";
88   DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: %d", fn, tagType);
89 
90   nfc::stats::stats_write(nfc::stats::NFC_TAG_TYPE_OCCURRED, tagType);
91 }
92