diff options
author | Jeff Hamilton <jham@android.com> | 2011-07-27 09:05:27 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-27 09:05:27 -0700 |
commit | 0429f95d2f5502b3660bd4e3bd68bd5755960640 (patch) | |
tree | 22b842328affc918e8fcbb854bbec77abd399b5d /src/com/android/nfc/NfcService.java | |
parent | 4fb958ad2bcd32a83171f8f59cb252f7ea3ce41a (diff) | |
parent | d2d5dddf17ac2008547172cd72faa034a89d569b (diff) | |
download | packages_apps_nfc-0429f95d2f5502b3660bd4e3bd68bd5755960640.zip packages_apps_nfc-0429f95d2f5502b3660bd4e3bd68bd5755960640.tar.gz packages_apps_nfc-0429f95d2f5502b3660bd4e3bd68bd5755960640.tar.bz2 |
Merge "Play an animation for outbound NFC P2P."
Diffstat (limited to 'src/com/android/nfc/NfcService.java')
-rwxr-xr-x | src/com/android/nfc/NfcService.java | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 64f862c..f72aa8a 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -31,7 +31,6 @@ import com.android.nfc3.R; import android.app.Application; import android.app.KeyguardManager; import android.app.PendingIntent; -import android.app.StatusBarManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -55,7 +54,6 @@ import android.nfc.IP2pInitiator; import android.nfc.IP2pTarget; import android.nfc.LlcpPacket; import android.nfc.NdefMessage; -import android.nfc.NdefRecord; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.TechListParcel; @@ -72,11 +70,9 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.util.Log; -import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -84,7 +80,13 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; -public class NfcService extends Application implements DeviceHostListener { +interface P2pStatusListener { + void onP2pBegin(); + void onP2pEnd(); + void onP2pError(); +} + +public class NfcService extends Application implements DeviceHostListener, P2pStatusListener { private static final String ACTION_MASTER_CLEAR_NOTIFICATION = "android.intent.action.MASTER_CLEAR_NOTIFICATION"; static final boolean DBG = true; @@ -161,6 +163,9 @@ public class NfcService extends Application implements DeviceHostListener { private OpenSecureElement mOpenEe; // null when EE closed private int mEeRoutingState; // contactless interface routing + // fields below must be used only on the UI thread and therefore aren't synchronized + boolean mP2pStarted = false; + // fields below are used in multiple threads and protected by synchronized(this) private final HashMap<Integer, Object> mObjectMap = new HashMap<Integer, Object>(); private final HashMap<Integer, Object> mSocketMap = new HashMap<Integer, Object>(); @@ -280,7 +285,7 @@ public class NfcService extends Application implements DeviceHostListener { mDeviceHost = new NativeNfcManager(this, this); mDeviceHost.initializeNativeStructure(); - mP2pManager = new NdefP2pManager(this, mNfcAdapter); + mP2pManager = new NdefP2pManager(this, this); mNfcDispatcher = new NfcDispatcher(this, mP2pManager); mSecureElement = new NativeNfcSecureElement(); @@ -325,13 +330,37 @@ public class NfcService extends Application implements DeviceHostListener { t.start(); } - public void playSound(int sound) { + private void playSound(int sound) { synchronized (this) { mSoundPool.play(sound, 1.0f, 1.0f, 0, 0, 1.0f); } } @Override + public void onP2pBegin() { + if (!mP2pStarted) { + playSound(mStartSound); + mP2pStarted = true; + } + } + + @Override + public void onP2pEnd() { + if (mP2pStarted) { + playSound(mEndSound); + mP2pStarted = false; + } + } + + @Override + public void onP2pError() { + if (mP2pStarted) { + playSound(mErrorSound); + mP2pStarted = false; + } + } + + @Override public void onTerminate() { super.onTerminate(); // NFC application is persistent, it should not be destroyed by framework @@ -2132,9 +2161,7 @@ public class NfcService extends Application implements DeviceHostListener { Log.d(TAG, tag.toString()); boolean delivered = mNfcDispatcher.dispatchTag(tag, new NdefMessage[] { ndefMsg }); if (delivered) { - playSound(mEndSound); - } else { - playSound(mErrorSound); + onP2pEnd(); } break; } @@ -2154,6 +2181,7 @@ public class NfcService extends Application implements DeviceHostListener { dispatchTagEndpoint(tag, null); } else { tag.disconnect(); + playSound(mErrorSound); } } break; @@ -2207,11 +2235,7 @@ public class NfcService extends Application implements DeviceHostListener { break; case MSG_LLCP_LINK_ACTIVATION: - if (llcpActivated((NfcDepEndpoint) msg.obj)) { - playSound(mStartSound); - } else { - playSound(mErrorSound); - } + llcpActivated((NfcDepEndpoint) msg.obj); break; case MSG_LLCP_LINK_DEACTIVATED: |