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 20 import java.util.List; 21 import java.util.Objects; 22 23 public class SimpleEmulatorActivity extends BaseEmulatorActivity { 24 protected static final String TAG = "SimpleEmulatorActivity"; 25 26 public static final String EXTRA_SERVICES = "EXTRA_SERVICES"; 27 public static final String EXTRA_IS_PAYMENT_ACTIVITY = "EXTRA_IS_PAYMENT_ACTIVITY"; 28 public static final String EXTRA_PREFERRED_SERVICE = "EXTRA_PREFERRED_SERVICE"; 29 public static final String EXTRA_EXPECTED_SERVICE = "EXTRA_EXPECTED_SERVICE"; 30 31 private ComponentName mPreferredService = null; 32 33 @Override onResume()34 protected void onResume() { 35 super.onResume(); 36 37 List<ComponentName> components = 38 getIntent().getExtras().getParcelableArrayList(EXTRA_SERVICES, ComponentName.class); 39 if (components != null) { 40 setupServices(components.toArray(new ComponentName[0])); 41 } 42 43 if (getIntent().getBooleanExtra(EXTRA_IS_PAYMENT_ACTIVITY, false)) { 44 makeDefaultWalletRoleHolder(); 45 } 46 47 mPreferredService = 48 getIntent().getExtras().getParcelable(EXTRA_PREFERRED_SERVICE, ComponentName.class); 49 50 if (mPreferredService != null) { 51 mCardEmulation.setPreferredService(this, mPreferredService); 52 } 53 } 54 55 @Override onPause()56 protected void onPause() { 57 super.onPause(); 58 mCardEmulation.unsetPreferredService(this); 59 } 60 61 @Override onApduSequenceComplete(ComponentName component, long duration)62 protected void onApduSequenceComplete(ComponentName component, long duration) { 63 if (component.equals( 64 Objects.requireNonNull(getIntent().getExtras()) 65 .getParcelable(EXTRA_EXPECTED_SERVICE, ComponentName.class))) { 66 setTestPassed(); 67 } 68 } 69 70 @Override getPreferredServiceComponent()71 public ComponentName getPreferredServiceComponent() { 72 return mPreferredService; 73 } 74 } 75