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 
17 package com.android.nfc.emulator;
18 
19 import android.content.ComponentName;
20 import android.os.Bundle;
21 import android.util.Log;
22 
23 import com.android.nfc.utils.HceUtils;
24 import com.android.nfc.service.ThroughputService;
25 
26 public class ThroughputEmulatorActivity extends BaseEmulatorActivity {
27     private static final String TAG = "ThroughputEm";
28 
29     @Override
onCreate(Bundle savedInstanceState)30     protected void onCreate(Bundle savedInstanceState) {
31         super.onCreate(savedInstanceState);
32     }
33 
34     @Override
onResume()35     protected void onResume() {
36         super.onResume();
37         Log.d(TAG, "onResume");
38         setupServices(ThroughputService.COMPONENT);
39     }
40 
41     @Override
getPreferredServiceComponent()42     public ComponentName getPreferredServiceComponent(){
43         return ThroughputService.COMPONENT;
44     }
45 
46     @Override
onApduSequenceComplete(ComponentName component, long duration)47     public void onApduSequenceComplete(ComponentName component, long duration) {
48         if (component.equals(ThroughputService.COMPONENT)) {
49             if (duration < 1000) {
50                 setTestPassed();
51             } else {
52                 long timePerApdu =
53                         duration
54                                 / HceUtils.COMMAND_APDUS_BY_SERVICE.get(
55                                                 ThroughputService.class.getName())
56                                         .length;
57                 Log.e(
58                         TAG,
59                         "\"Test Failed. Requires <= 60 ms per APDU round trip. Received \"  "
60                                 + timePerApdu
61                                 + " ms per round trip.\"");
62             }
63         }
64     }
65 }
66