• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
enableComponent(PackageManager pm, ComponentName component)28     public static void enableComponent(PackageManager pm, ComponentName component) {
29         pm.setComponentEnabledSetting(
30                 component,
31                 PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
32                 PackageManager.DONT_KILL_APP);
33     }
34 
disableComponent(PackageManager pm, ComponentName component)35     public static void disableComponent(PackageManager pm, ComponentName component) {
36         pm.setComponentEnabledSetting(
37                 component,
38                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
39                 PackageManager.DONT_KILL_APP);
40     }
41 
getHexBytes(String header, byte[] bytes)42     public static String getHexBytes(String header, byte[] bytes) {
43         StringBuilder sb = new StringBuilder();
44         if (header != null) {
45             sb.append(header + ": ");
46         }
47         for (byte b : bytes) {
48             sb.append(String.format("%02X ", b));
49         }
50         return sb.toString();
51     }
52 
hexStringToBytes(String s)53     public static byte[] hexStringToBytes(String s) {
54         if (s == null || s.length() == 0) return null;
55         int len = s.length();
56         if (len % 2 != 0) {
57             s = '0' + s;
58             len++;
59         }
60         byte[] data = new byte[len / 2];
61         for (int i = 0; i < len; i += 2) {
62             data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
63                                  + Character.digit(s.charAt(i+1), 16));
64         }
65         return data;
66     }
67 
buildCommandApdu(String apdu, boolean reachable)68     public static final CommandApdu buildCommandApdu(String apdu, boolean reachable) {
69         return new CommandApdu(apdu, reachable);
70     }
71 
buildSelectApdu(String aid, boolean reachable)72     public static final CommandApdu buildSelectApdu(String aid, boolean reachable) {
73         StringBuilder sb = new StringBuilder();
74         sb.append("00A40400");
75         sb.append(String.format("%02X", aid.length() / 2));
76         sb.append(aid);
77         return new CommandApdu(sb.toString(), reachable);
78     }
79 }
80