1 /*
2  * Copyright (C) 2016 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.cts.verifier.nfc.hcef;
17 
18 import android.content.BroadcastReceiver;
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.IntentFilter;
23 import android.nfc.NfcAdapter;
24 import android.nfc.cardemulation.NfcFCardEmulation;
25 import android.os.Bundle;
26 
27 import com.android.cts.verifier.PassFailButtons;
28 import com.android.cts.verifier.R;
29 
30 public class HceFEmulatorActivity extends PassFailButtons.Activity{
31     static String ACTION_TEST_SUCCESS = "success";
32 
33     NfcAdapter mAdapter;
34     NfcFCardEmulation mNfcFCardEmulation;
35 
36     final BroadcastReceiver mReceiver = new BroadcastReceiver() {
37         @Override
38         public void onReceive(Context context, Intent intent) {
39             String action = intent.getAction();
40 
41             if (ACTION_TEST_SUCCESS.equals(action)) {
42                 getPassButton().setEnabled(true);
43             }
44         }
45     };
46 
47     @Override
onCreate(Bundle savedInstanceState)48     protected void onCreate(Bundle savedInstanceState) {
49         super.onCreate(savedInstanceState);
50         setContentView(R.layout.pass_fail_text);
51         setPassFailButtonClickListeners();
52         getPassButton().setEnabled(false);
53         mAdapter = NfcAdapter.getDefaultAdapter(this);
54         mNfcFCardEmulation = NfcFCardEmulation.getInstance(mAdapter);
55     }
56 
57     @Override
onResume()58     protected void onResume() {
59         super.onResume();
60         IntentFilter filter = new IntentFilter(ACTION_TEST_SUCCESS);
61         registerReceiver(mReceiver, filter);
62         ComponentName hceFService = new ComponentName("com.android.cts.verifier",
63                 MyHostFelicaService.class.getName());
64         mNfcFCardEmulation.enableService(this, hceFService);
65     }
66 
67     @Override
onPause()68     protected void onPause() {
69         super.onPause();
70         unregisterReceiver(mReceiver);
71     }
72 
73 }
74