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.emulator; 17 18 import android.content.ComponentName; 19 import android.os.Bundle; 20 21 import com.android.nfc.service.OffHostService; 22 import com.android.nfc.service.PollingLoopService; 23 24 public class OffHostEmulatorActivity extends BaseEmulatorActivity { 25 public static final String EXTRA_ENABLE_OBSERVE_MODE = "EXTRA_ENABLE_OBSERVE_MODE"; 26 27 @Override onCreate(Bundle savedInstanceState)28 protected void onCreate(Bundle savedInstanceState) { 29 super.onCreate(savedInstanceState); 30 setupServices(OffHostService.COMPONENT, PollingLoopService.COMPONENT); 31 } 32 33 @Override onResume()34 protected void onResume() { 35 super.onResume(); 36 37 if (getIntent().getBooleanExtra(EXTRA_ENABLE_OBSERVE_MODE, false)) { 38 // Still need to set a preferred service to be able to set observe mode. 39 mCardEmulation.setPreferredService( 40 this, PollingLoopService.COMPONENT); 41 mAdapter.setObserveModeEnabled(true); 42 } 43 } 44 45 @Override onPause()46 public void onPause() { 47 super.onPause(); 48 if (getIntent().getBooleanExtra(EXTRA_ENABLE_OBSERVE_MODE, false)) { 49 mCardEmulation.unsetPreferredService(this); 50 mAdapter.setObserveModeEnabled(false); 51 } 52 } 53 54 @Override getPreferredServiceComponent()55 public ComponentName getPreferredServiceComponent() { 56 return PollingLoopService.COMPONENT; 57 } 58 } 59