• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     public static final String EXTRA_SHOULD_DISABLE_SERVICES_ON_DESTROY = "EXTRA_SHOULD_DISABLE_SERVICES_ON_DESTROY";
31 
32     private ComponentName mPreferredService = null;
33 
34     @Override
onResume()35     protected void onResume() {
36         super.onResume();
37 
38         List<ComponentName> components =
39                 getIntent().getExtras().getParcelableArrayList(EXTRA_SERVICES, ComponentName.class);
40         if (components != null) {
41             setupServices(components.toArray(new ComponentName[0]));
42         }
43 
44         if (getIntent().getBooleanExtra(EXTRA_IS_PAYMENT_ACTIVITY, false)) {
45             makeDefaultWalletRoleHolder();
46         }
47 
48         mPreferredService =
49                 getIntent().getExtras().getParcelable(EXTRA_PREFERRED_SERVICE, ComponentName.class);
50 
51         if (mPreferredService != null) {
52             mCardEmulation.setPreferredService(this, mPreferredService);
53         }
54         mShouldDisableServicesOnDestroy =
55                 getIntent().getBooleanExtra(EXTRA_SHOULD_DISABLE_SERVICES_ON_DESTROY, true);
56     }
57 
58     @Override
onPause()59     protected void onPause() {
60         super.onPause();
61         if (mPreferredService != null) {
62             mCardEmulation.unsetPreferredService(this);
63         }
64     }
65 
66     @Override
onApduSequenceComplete(ComponentName component, long duration)67     protected void onApduSequenceComplete(ComponentName component, long duration) {
68         if (component.equals(
69                 Objects.requireNonNull(getIntent().getExtras())
70                         .getParcelable(EXTRA_EXPECTED_SERVICE, ComponentName.class))) {
71             setTestPassed();
72         }
73     }
74 
75     @Override
getPreferredServiceComponent()76     public ComponentName getPreferredServiceComponent() {
77         return mPreferredService;
78     }
79 }
80