summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Hamilton <jham@android.com>2011-06-17 15:47:23 -0500
committerJeff Hamilton <jham@android.com>2011-06-17 16:55:15 -0500
commitd704c298a5a1e783c71db6f39b2eef0a909b0e88 (patch)
tree8067e5959204b29382583619939a609255338d97
parentf10df01e4ab7ba48556aed137a8f33d79a398a87 (diff)
downloadpackages_apps_nfc-d704c298a5a1e783c71db6f39b2eef0a909b0e88.zip
packages_apps_nfc-d704c298a5a1e783c71db6f39b2eef0a909b0e88.tar.gz
packages_apps_nfc-d704c298a5a1e783c71db6f39b2eef0a909b0e88.tar.bz2
Play sounds for start, end, and error.
This needs some cleanup to handle the error states better, but works ok for now. Change-Id: I803c339de593acfe5bb7f1007a965f203e0e1a30
-rw-r--r--res/raw/end.oggbin0 -> 12201 bytes
-rw-r--r--res/raw/error.oggbin0 -> 12099 bytes
-rw-r--r--res/raw/start.oggbin0 -> 13020 bytes
-rw-r--r--src/com/android/nfc/NfcDispatcher.java5
-rwxr-xr-xsrc/com/android/nfc/NfcService.java135
5 files changed, 90 insertions, 50 deletions
diff --git a/res/raw/end.ogg b/res/raw/end.ogg
new file mode 100644
index 0000000..886ce19
--- /dev/null
+++ b/res/raw/end.ogg
Binary files differ
diff --git a/res/raw/error.ogg b/res/raw/error.ogg
new file mode 100644
index 0000000..a5f7aa1
--- /dev/null
+++ b/res/raw/error.ogg
Binary files differ
diff --git a/res/raw/start.ogg b/res/raw/start.ogg
new file mode 100644
index 0000000..e6e59ca
--- /dev/null
+++ b/res/raw/start.ogg
Binary files differ
diff --git a/src/com/android/nfc/NfcDispatcher.java b/src/com/android/nfc/NfcDispatcher.java
index ed4a69a..2e10091 100644
--- a/src/com/android/nfc/NfcDispatcher.java
+++ b/src/com/android/nfc/NfcDispatcher.java
@@ -16,6 +16,8 @@
package com.android.nfc;
+import com.android.nfc.RegisteredComponentCache.ComponentInfo;
+
import android.app.Activity;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
@@ -37,9 +39,6 @@ import android.nfc.Tag;
import android.os.RemoteException;
import android.util.Log;
-import com.android.nfc.ndefpush.NdefPushClient;
-import com.android.nfc.RegisteredComponentCache.ComponentInfo;
-
import java.nio.charset.Charsets;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index 48b6762..f27f6b1 100755
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -39,6 +39,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
+import android.media.AudioManager;
+import android.media.SoundPool;
import android.net.Uri;
import android.nfc.ErrorCodes;
import android.nfc.FormatException;
@@ -153,6 +155,10 @@ public class NfcService extends Application implements DeviceHostListener {
private SharedPreferences.Editor mPrefsEditor;
private PowerManager.WakeLock mWakeLock;
NdefP2pManager mP2pManager;
+ int mStartSound;
+ int mEndSound;
+ int mErrorSound;
+ SoundPool mSoundPool; // playback synchronized on this
private NfcDispatcher mNfcDispatcher;
private KeyguardManager mKeyguard;
@@ -184,6 +190,7 @@ public class NfcService extends Application implements DeviceHostListener {
/**
* Notifies transaction
*/
+ @Override
public void onCardEmulationDeselected() {
sendMessage(NfcService.MSG_TARGET_DESELECTED, null);
}
@@ -191,6 +198,7 @@ public class NfcService extends Application implements DeviceHostListener {
/**
* Notifies transaction
*/
+ @Override
public void onCardEmulationAidSelected(byte[] aid) {
sendMessage(NfcService.MSG_CARD_EMULATION, aid);
}
@@ -206,14 +214,17 @@ public class NfcService extends Application implements DeviceHostListener {
/**
* Notifies P2P Device detected, to activate LLCP link
*/
+ @Override
public void onLlcpLinkDeactivated(NfcDepEndpoint device) {
sendMessage(NfcService.MSG_LLCP_LINK_DEACTIVATED, device);
}
+ @Override
public void onRemoteFieldActivated() {
sendMessage(NfcService.MSG_SE_FIELD_ACTIVATED, null);
}
+ @Override
public void onRemoteFieldDeactivated() {
sendMessage(NfcService.MSG_SE_FIELD_DEACTIVATED, null);
}
@@ -226,6 +237,11 @@ public class NfcService extends Application implements DeviceHostListener {
sService = this;
+ mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
+ mStartSound = mSoundPool.load(this, R.raw.start, 1);
+ mEndSound = mSoundPool.load(this, R.raw.end, 1);
+ mErrorSound = mSoundPool.load(this, R.raw.error, 1);
+
mContext = this;
mDeviceHost = new NativeNfcManager(this, this);
mDeviceHost.initializeNativeStructure();
@@ -274,6 +290,12 @@ public class NfcService extends Application implements DeviceHostListener {
t.start();
}
+ public void playSound(int sound) {
+ synchronized (this) {
+ mSoundPool.play(sound, 1.0f, 1.0f, 0, 0, 1.0f);
+ }
+ }
+
@Override
public void onTerminate() {
super.onTerminate();
@@ -2099,13 +2121,19 @@ public class NfcService extends Application implements DeviceHostListener {
new Bundle[] { });
Log.d(TAG, "mock NDEF tag, starting corresponding activity");
Log.d(TAG, tag.toString());
- mNfcDispatcher.dispatchTag(tag, new NdefMessage[] { ndefMsg });
+ boolean delivered = mNfcDispatcher.dispatchTag(tag, new NdefMessage[] { ndefMsg });
+ if (delivered) {
+ playSound(mEndSound);
+ } else {
+ playSound(mErrorSound);
+ }
break;
}
case MSG_NDEF_TAG:
if (DBG) Log.d(TAG, "Tag detected, notifying applications");
TagEndpoint tag = (TagEndpoint) msg.obj;
+ playSound(mStartSound);
NdefMessage[] ndefMsgs = tag.findAndReadNdef();
if (ndefMsgs != null) {
@@ -2135,55 +2163,15 @@ public class NfcService extends Application implements DeviceHostListener {
break;
case MSG_LLCP_LINK_ACTIVATION:
- NfcDepEndpoint device = (NfcDepEndpoint) msg.obj;
-
- Log.d(TAG, "LLCP Activation message");
-
- if (device.getMode() == NfcDepEndpoint.MODE_P2P_TARGET) {
- if (DBG) Log.d(TAG, "NativeP2pDevice.MODE_P2P_TARGET");
- if (device.connect()) {
- /* Check Llcp compliancy */
- if (mDeviceHost.doCheckLlcp()) {
- /* Activate Llcp Link */
- if (mDeviceHost.doActivateLlcp()) {
- if (DBG) Log.d(TAG, "Initiator Activate LLCP OK");
- // Register P2P device
- mObjectMap.put(device.getHandle(), device);
- mP2pManager.llcpActivated();
- } else {
- /* should not happen */
- Log.w(TAG, "Initiator Activate LLCP NOK. Disconnect.");
- device.disconnect();
- }
-
- } else {
- if (DBG) Log.d(TAG, "Remote Target does not support LLCP. Disconnect.");
- device.disconnect();
- }
- } else {
- if (DBG) Log.d(TAG, "Cannot connect remote Target. Polling loop restarted...");
- /* The polling loop should have been restarted in failing doConnect */
- }
-
- } else if (device.getMode() == NfcDepEndpoint.MODE_P2P_INITIATOR) {
- if (DBG) Log.d(TAG, "NativeP2pDevice.MODE_P2P_INITIATOR");
- /* Check Llcp compliancy */
- if (mDeviceHost.doCheckLlcp()) {
- /* Activate Llcp Link */
- if (mDeviceHost.doActivateLlcp()) {
- if (DBG) Log.d(TAG, "Target Activate LLCP OK");
- // Register P2P device
- mObjectMap.put(device.getHandle(), device);
- mP2pManager.llcpActivated();
- }
- } else {
- Log.w(TAG, "checkLlcp failed");
- }
+ if (llcpActivated((NfcDepEndpoint) msg.obj)) {
+ playSound(mStartSound);
+ } else {
+ playSound(mErrorSound);
}
break;
case MSG_LLCP_LINK_DEACTIVATED:
- device = (NfcDepEndpoint) msg.obj;
+ NfcDepEndpoint device = (NfcDepEndpoint) msg.obj;
Log.d(TAG, "LLCP Link Deactivated message. Restart polling loop.");
synchronized (NfcService.this) {
@@ -2248,13 +2236,66 @@ public class NfcService extends Application implements DeviceHostListener {
}
}
+ private boolean llcpActivated(NfcDepEndpoint device) {
+ Log.d(TAG, "LLCP Activation message");
+
+ if (device.getMode() == NfcDepEndpoint.MODE_P2P_TARGET) {
+ if (DBG) Log.d(TAG, "NativeP2pDevice.MODE_P2P_TARGET");
+ if (device.connect()) {
+ /* Check LLCP compliancy */
+ if (mDeviceHost.doCheckLlcp()) {
+ /* Activate LLCP Link */
+ if (mDeviceHost.doActivateLlcp()) {
+ if (DBG) Log.d(TAG, "Initiator Activate LLCP OK");
+ // Register P2P device
+ mObjectMap.put(device.getHandle(), device);
+ mP2pManager.llcpActivated();
+ return true;
+ } else {
+ /* should not happen */
+ Log.w(TAG, "Initiator LLCP activation failed. Disconnect.");
+ device.disconnect();
+ }
+ } else {
+ if (DBG) Log.d(TAG, "Remote Target does not support LLCP. Disconnect.");
+ device.disconnect();
+ }
+ } else {
+ if (DBG) Log.d(TAG, "Cannot connect remote Target. Polling loop restarted.");
+ /*
+ * The polling loop should have been restarted in failing
+ * doConnect
+ */
+ }
+ } else if (device.getMode() == NfcDepEndpoint.MODE_P2P_INITIATOR) {
+ if (DBG) Log.d(TAG, "NativeP2pDevice.MODE_P2P_INITIATOR");
+ /* Check LLCP compliancy */
+ if (mDeviceHost.doCheckLlcp()) {
+ /* Activate LLCP Link */
+ if (mDeviceHost.doActivateLlcp()) {
+ if (DBG) Log.d(TAG, "Target Activate LLCP OK");
+ // Register P2P device
+ mObjectMap.put(device.getHandle(), device);
+ mP2pManager.llcpActivated();
+ return true;
+ }
+ } else {
+ Log.w(TAG, "checkLlcp failed");
+ }
+ }
+
+ return false;
+ }
+
private void dispatchTagEndpoint(TagEndpoint tagEndpoint, NdefMessage[] msgs) {
Tag tag = new Tag(tagEndpoint.getUid(), tagEndpoint.getTechList(),
tagEndpoint.getTechExtras(), tagEndpoint.getHandle(), mNfcTagService);
registerTagObject(tagEndpoint);
if (!mNfcDispatcher.dispatchTag(tag, msgs)) {
unregisterObject(tagEndpoint.getHandle());
- tagEndpoint.disconnect();
+ playSound(mErrorSound);
+ } else {
+ playSound(mEndSound);
}
}
}