1 /* 2 * Copyright (C) 2024 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 package com.android.nfc.emulator; 17 18 import android.content.ComponentName; 19 import android.nfc.cardemulation.CardEmulation; 20 import android.os.Bundle; 21 22 import com.android.nfc.utils.HceUtils; 23 import com.android.nfc.service.PrefixTransportService1; 24 import com.android.nfc.service.PrefixTransportService2; 25 26 import java.util.ArrayList; 27 28 public class ConflictingNonPaymentPrefixEmulatorActivity extends BaseEmulatorActivity { 29 30 private String mAidConflictOccurred = null; 31 32 private CardEmulation.NfcEventListener mEventListener = new CardEmulation.NfcEventListener() { 33 @Override 34 public void onAidConflictOccurred(String aid) { 35 mAidConflictOccurred = aid; 36 } 37 }; 38 39 @Override onCreate(Bundle savedInstanceState)40 public void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 setupServices( 43 PrefixTransportService1.COMPONENT, PrefixTransportService2.COMPONENT); 44 45 registerEventListener(mEventListener); 46 } 47 48 @Override onServicesSetup()49 protected void onServicesSetup() { 50 // Do dynamic AID registration 51 ArrayList<String> service_aids = new ArrayList<>(); 52 service_aids.add(HceUtils.TRANSPORT_PREFIX_AID + "*"); 53 mCardEmulation.registerAidsForService( 54 PrefixTransportService1.COMPONENT, 55 CardEmulation.CATEGORY_OTHER, 56 service_aids); 57 mCardEmulation.registerAidsForService( 58 PrefixTransportService2.COMPONENT, 59 CardEmulation.CATEGORY_OTHER, 60 service_aids); 61 } 62 63 @Override onApduSequenceComplete(ComponentName component, long duration)64 public void onApduSequenceComplete(ComponentName component, long duration) { 65 if (component.equals(PrefixTransportService2.COMPONENT)) { 66 if (android.nfc.Flags.nfcEventListener()) { 67 if (mAidConflictOccurred.startsWith(HceUtils.TRANSPORT_AID)) { 68 setTestPassed(); 69 } 70 } else { 71 setTestPassed(); 72 } 73 } 74 } 75 onDestroy()76 protected void onDestroy() { 77 super.onDestroy(); 78 mCardEmulation.unregisterNfcEventListener(mEventListener); 79 } 80 81 @Override getPreferredServiceComponent()82 public ComponentName getPreferredServiceComponent(){ 83 return PrefixTransportService2.COMPONENT; 84 } 85 } 86