1 2 /* 3 * Copyright (C) 2014 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.nfc.service; 19 20 import android.content.Intent; 21 import android.nfc.cardemulation.PollingFrame; 22 import android.util.Log; 23 24 import com.android.nfc.utils.HceUtils; 25 import android.content.ComponentName; 26 27 import java.util.ArrayList; 28 import java.util.List; 29 30 public class PollingLoopService2 extends HceService { 31 public static final ComponentName COMPONENT = 32 new ComponentName( 33 "com.android.nfc.emulator", PollingLoopService2.class.getName()); 34 35 public static final String POLLING_FRAME_ACTION = 36 "com.android.nfc.service.POLLING_FRAME_ACTION"; 37 public static final String POLLING_FRAME_EXTRA = "POLLING_FRAME_EXTRA"; 38 public static final String SERVICE_NAME_EXTRA = "SERVICE_NAME_EXTRA"; 39 public static final String TAG = "PollingLoopService2"; 40 PollingLoopService2()41 public PollingLoopService2() { 42 super( 43 HceUtils.COMMAND_APDUS_BY_SERVICE.get(PollingLoopService.class.getName()), 44 HceUtils.RESPONSE_APDUS_BY_SERVICE.get(PollingLoopService.class.getName())); 45 } 46 @Override getComponent()47 public ComponentName getComponent() { 48 return PollingLoopService2.COMPONENT; 49 } 50 51 @Override processPollingFrames(List<PollingFrame> frames)52 public void processPollingFrames(List<PollingFrame> frames) { 53 Log.d(TAG, "processPollingFrames of size " + frames.size()); 54 Intent pollingFrameIntent = new Intent(POLLING_FRAME_ACTION); 55 pollingFrameIntent.putExtra(EXTRA_COMPONENT, getComponent()); 56 pollingFrameIntent.putExtra( 57 EXTRA_DURATION, System.currentTimeMillis() - mStartTime); 58 pollingFrameIntent.putExtra(POLLING_FRAME_EXTRA, new ArrayList<PollingFrame>(frames)); 59 pollingFrameIntent.putExtra(SERVICE_NAME_EXTRA, this.getClass().getName()); 60 sendBroadcast(pollingFrameIntent); 61 } 62 } 63