Home | History | Annotate | Download | only in hce
      1 package com.android.cts.verifier.nfc.hce;
      2 
      3 import android.annotation.TargetApi;
      4 import android.content.ComponentName;
      5 import android.content.Context;
      6 import android.content.Intent;
      7 import android.nfc.cardemulation.CardEmulation;
      8 import android.os.Bundle;
      9 import android.util.Log;
     10 
     11 import com.android.cts.verifier.R;
     12 import com.android.cts.verifier.nfc.NfcDialogs;
     13 
     14 @TargetApi(19)
     15 public class ForegroundPaymentEmulatorActivity extends BaseEmulatorActivity {
     16 
     17     @Override
     18     protected void onCreate(Bundle savedInstanceState) {
     19         super.onCreate(savedInstanceState);
     20         setContentView(R.layout.pass_fail_text);
     21         setPassFailButtonClickListeners();
     22         getPassButton().setEnabled(false);
     23     }
     24 
     25     @Override
     26     protected void onResume() {
     27         super.onResume();
     28         if (!mCardEmulation.categoryAllowsForegroundPreference(CardEmulation.CATEGORY_PAYMENT)) {
     29             // Launch tap&pay settings
     30             NfcDialogs.createChangeForegroundDialog(this).show();
     31         } else {
     32             setupServices(this, PaymentService2.COMPONENT, PaymentService1.COMPONENT);
     33         }
     34     }
     35 
     36     @Override
     37     void onServicesSetup(boolean result) {
     38         if (!makePaymentDefault(PaymentService1.COMPONENT,
     39                 R.string.nfc_hce_change_preinstalled_wallet)) {
     40             mCardEmulation.setPreferredService(this, PaymentService2.COMPONENT);
     41             NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_foreground_payment_help)).show();
     42         } // else, wait for callback
     43     }
     44 
     45     @Override
     46     void onPaymentDefaultResult(ComponentName component, boolean success) {
     47         if (success) {
     48             NfcDialogs.createHceTapReaderDialog(this, null).show();
     49         }
     50     }
     51 
     52     @Override
     53     protected void onPause() {
     54         super.onPause();
     55         mCardEmulation.unsetPreferredService(this);
     56     }
     57 
     58     public static Intent buildReaderIntent(Context context) {
     59         Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
     60         readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
     61                 PaymentService2.APDU_COMMAND_SEQUENCE);
     62         readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES,
     63                 PaymentService2.APDU_RESPOND_SEQUENCE);
     64         readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
     65                 context.getString(R.string.nfc_hce_foreground_payment_reader));
     66         return readerIntent;
     67     }
     68 
     69     @Override
     70     void onApduSequenceComplete(ComponentName component, long duration) {
     71         if (component.equals(PaymentService2.COMPONENT)) {
     72             getPassButton().setEnabled(true);
     73         }
     74     }
     75 }
     76