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 import android.util.Log;
22 
23 import com.android.nfc.service.TransportService2;
24 import com.android.nfc.utils.HceUtils;
25 import com.android.nfc.service.PrefixAccessService;
26 import com.android.nfc.service.PrefixTransportService1;
27 
28 import java.util.ArrayList;
29 
30 public class DualNonPaymentPrefixEmulatorActivity extends BaseEmulatorActivity {
31     public static final String TAG = "DualNonPaymentEm";
32 
33     @Override
onCreate(Bundle savedInstanceState)34     protected void onCreate(Bundle savedInstanceState) {
35         super.onCreate(savedInstanceState);
36         Log.d(TAG, "onCreate");
37         setupServices(PrefixTransportService1.COMPONENT, PrefixAccessService.COMPONENT);
38     }
39 
40     @Override
onResume()41     protected void onResume() {
42         super.onResume();
43         mCardEmulation.setPreferredService(
44                 this, PrefixAccessService.COMPONENT);
45     }
46 
47     @Override
onPause()48     protected void onPause() {
49         super.onPause();
50         mCardEmulation.unsetPreferredService(this);
51     }
52 
53     @Override
onServicesSetup()54     protected void onServicesSetup() {
55         // Do dynamic AID registration
56         ArrayList<String> service1_aids = new ArrayList<>();
57         service1_aids.add(HceUtils.TRANSPORT_PREFIX_AID + "*");
58         ArrayList<String> service2_aids = new ArrayList<>();
59         service2_aids.add(HceUtils.ACCESS_PREFIX_AID + "*");
60         mCardEmulation.registerAidsForService(
61                 PrefixTransportService1.COMPONENT,
62                 CardEmulation.CATEGORY_OTHER,
63                 service1_aids);
64         mCardEmulation.registerAidsForService(
65                 PrefixAccessService.COMPONENT,
66                 CardEmulation.CATEGORY_OTHER,
67                 service2_aids);
68     }
69 
70     @Override
onApduSequenceComplete(ComponentName component, long duration)71     protected void onApduSequenceComplete(ComponentName component, long duration) {
72         if (component.equals(PrefixAccessService.COMPONENT)) {
73             setTestPassed();
74         }
75     }
76 
77     @Override
getPreferredServiceComponent()78     public ComponentName getPreferredServiceComponent(){
79         return PrefixAccessService.COMPONENT;
80     }
81 }
82