1 package com.android.cts.verifier.nfc.hce;
2 
3 import android.content.ComponentName;
4 import android.content.pm.PackageManager;
5 
6 public final class HceUtils {
7     public static final String ACTION_APDU_SEQUENCE_COMPLETE =
8             "com.android.cts.verifier.nfc.hce.ACTION_APDU_SEQUENCE_COMPLETE";
9     public static final String ACTION_APDU_SEQUENCE_ERROR =
10             "com.android.cts.verifier.nfc.hce.ACTION_APDU_SEQUENCE_ERROR";
11 
12     public static final String EXTRA_COMPONENT = "component";
13     public static final String EXTRA_DURATION = "duration";
14 
15     public static final String PPSE_AID = "325041592E5359532E4444463031";
16     public static final String MC_AID = "A0000000041010";
17     public static final String VISA_AID = "A0000000030000";
18 
19     public static final String TRANSPORT_AID = "F001020304";
20     public static final String ACCESS_AID = "F005060708";
21 
22     public static final String TRANSPORT_PREFIX_AID = "F001020304";
23     public static final String ACCESS_PREFIX_AID = "F005060708";
24 
25     public static final String LARGE_NUM_AIDS_PREFIX = "F00102030414";
26     public static final String LARGE_NUM_AIDS_POSTFIX ="81";
27 
28     public static final String TRANSACTION_EVENT_AID = "A000000476416E64726F696443545341";
29     public static final String HCI_CMD = "0025000000";
30 
enableComponent(PackageManager pm, ComponentName component)31     public static void enableComponent(PackageManager pm, ComponentName component) {
32         pm.setComponentEnabledSetting(
33                 component,
34                 PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
35                 PackageManager.DONT_KILL_APP);
36     }
37 
disableComponent(PackageManager pm, ComponentName component)38     public static void disableComponent(PackageManager pm, ComponentName component) {
39         pm.setComponentEnabledSetting(
40                 component,
41                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
42                 PackageManager.DONT_KILL_APP);
43     }
44 
getHexBytes(String header, byte[] bytes)45     public static String getHexBytes(String header, byte[] bytes) {
46         StringBuilder sb = new StringBuilder();
47         if (header != null) {
48             sb.append(header + ": ");
49         }
50         for (byte b : bytes) {
51             sb.append(String.format("%02X ", b));
52         }
53         return sb.toString();
54     }
55 
hexStringToBytes(String s)56     public static byte[] hexStringToBytes(String s) {
57         if (s == null || s.length() == 0) return null;
58         int len = s.length();
59         if (len % 2 != 0) {
60             s = '0' + s;
61             len++;
62         }
63         byte[] data = new byte[len / 2];
64         for (int i = 0; i < len; i += 2) {
65             data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
66                                  + Character.digit(s.charAt(i+1), 16));
67         }
68         return data;
69     }
70 
buildCommandApdu(String apdu, boolean reachable)71     public static final CommandApdu buildCommandApdu(String apdu, boolean reachable) {
72         return new CommandApdu(apdu, reachable);
73     }
74 
buildSelectApdu(String aid, boolean reachable)75     public static final CommandApdu buildSelectApdu(String aid, boolean reachable) {
76         StringBuilder sb = new StringBuilder();
77         sb.append("00A40400");
78         sb.append(String.format("%02X", aid.length() / 2));
79         sb.append(aid);
80         return new CommandApdu(sb.toString(), reachable);
81     }
82 }
83