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