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 package com.android.nfc.service; 17 18 import android.content.ComponentName; 19 import android.content.Intent; 20 import android.nfc.NfcAdapter; 21 import android.os.Bundle; 22 23 public class AccessServiceTurnObserveModeOnProcessApdu extends AccessService { 24 public static final ComponentName COMPONENT = 25 new ComponentName( 26 "com.android.nfc.emulator", 27 AccessServiceTurnObserveModeOnProcessApdu.class.getName()); 28 29 public static final String OBSERVE_MODE_FALSE = "com.android.nfc.service.OBSERVE_MODE_FALSE"; 30 31 @Override getComponent()32 public ComponentName getComponent() { 33 return AccessServiceTurnObserveModeOnProcessApdu.COMPONENT; 34 } 35 36 @Override processCommandApdu(byte[] arg0, Bundle arg1)37 public byte[] processCommandApdu(byte[] arg0, Bundle arg1) { 38 if (mApduIndex == 1) { 39 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); 40 41 if (adapter != null && !adapter.setObserveModeEnabled(true)) { 42 sendBroadcast(new Intent(OBSERVE_MODE_FALSE)); 43 } 44 } 45 return super.processCommandApdu(arg0, arg1); 46 } 47 } 48