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