summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2012-04-12 16:33:40 -0700
committerMartijn Coenen <maco@google.com>2012-04-12 16:36:12 -0700
commit83558889207858d7ce8500f9fce8a707a86b495e (patch)
tree1909f76de2f01d880b19947560fd573e30ab00c5
parent95fc9d620a8619617fbe6f6e7835ab960e763eab (diff)
downloadpackages_apps_nfc-83558889207858d7ce8500f9fce8a707a86b495e.tar.gz
packages_apps_nfc-83558889207858d7ce8500f9fce8a707a86b495e.tar.bz2
packages_apps_nfc-83558889207858d7ce8500f9fce8a707a86b495e.zip
Support for the new Uri[] Beam push API.
Support multiple URIs, move query for the mime type to NFC service. Change-Id: Ib055efca843b41f6d29cda7d67b23f4b9946113c
-rwxr-xr-xsrc/com/android/nfc/P2pLinkManager.java34
-rw-r--r--src/com/android/nfc/handover/BluetoothOppHandover.java54
-rw-r--r--src/com/android/nfc/handover/HandoverManager.java5
3 files changed, 57 insertions, 36 deletions
diff --git a/src/com/android/nfc/P2pLinkManager.java b/src/com/android/nfc/P2pLinkManager.java
index 885e38b..89c3dc8 100755
--- a/src/com/android/nfc/P2pLinkManager.java
+++ b/src/com/android/nfc/P2pLinkManager.java
@@ -158,8 +158,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
boolean mIsSendEnabled;
boolean mIsReceiveEnabled;
NdefMessage mMessageToSend; // valid during SEND_STATE_NEED_CONFIRMATION or SEND_STATE_SENDING
- Uri mUriToSend; // valid during SEND_STATE_NEED_CONFIRMATION or SEND_STATE_SENDING
- String mMimeTypeToSend; // valid during SEND_STATE_NEED_CONFIRMATION or SEND_STATE_SENDING
+ Uri[] mUrisToSend; // valid during SEND_STATE_NEED_CONFIRMATION or SEND_STATE_SENDING
INdefPushCallback mCallbackNdef;
SendTask mSendTask;
SharedPreferences mPrefs;
@@ -243,7 +242,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
mEventListener.onP2pInRange();
prepareMessageToSend();
- if (mMessageToSend != null || mUriToSend != null) {
+ if (mMessageToSend != null || mUrisToSend != null) {
mSendState = SEND_STATE_NEED_CONFIRMATION;
if (DBG) Log.d(TAG, "onP2pSendConfirmationRequested()");
mEventListener.onP2pSendConfirmationRequested();
@@ -269,8 +268,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
synchronized (P2pLinkManager.this) {
if (!mIsSendEnabled) {
mMessageToSend = null;
- mUriToSend = null;
- mMimeTypeToSend = null;
+ mUrisToSend = null;
return;
}
@@ -279,8 +277,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
if (mCallbackNdef != null) {
try {
mMessageToSend = mCallbackNdef.createMessage();
- mUriToSend = mCallbackNdef.getUri();
- mMimeTypeToSend = mCallbackNdef.getMimeType();
+ mUrisToSend = mCallbackNdef.getUris();
return;
} catch (RemoteException e) {
// Ignore
@@ -302,8 +299,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
mMessageToSend = null;
}
if (DBG) Log.d(TAG, "mMessageToSend = " + mMessageToSend);
- if (DBG) Log.d(TAG, "mUriToSend = " + mUriToSend);
- if (DBG) Log.d(TAG, "mMimeTypeToSend = " + mMimeTypeToSend);
+ if (DBG) Log.d(TAG, "mUrisToSend = " + mUrisToSend);
}
}
@@ -384,8 +380,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
@Override
public Void doInBackground(Void... args) {
NdefMessage m;
- Uri uri;
- String mimeType;
+ Uri[] uris;
boolean result;
synchronized (P2pLinkManager.this) {
@@ -393,8 +388,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
return null;
}
m = mMessageToSend;
- uri = mUriToSend;
- mimeType = mMimeTypeToSend;
+ uris = mUrisToSend;
}
long time = SystemClock.elapsedRealtime();
@@ -402,7 +396,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
try {
if (DBG) Log.d(TAG, "Sending ndef via SNEP");
- result = doSnepProtocol(mHandoverManager, m, mimeType, uri);
+ result = doSnepProtocol(mHandoverManager, m, uris);
} catch (IOException e) {
Log.i(TAG, "Failed to connect over SNEP, trying NPP");
@@ -424,7 +418,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
}
static boolean doSnepProtocol(HandoverManager handoverManager,
- NdefMessage msg, String mimeType, Uri uri) throws IOException {
+ NdefMessage msg, Uri[] uris) throws IOException {
SnepClient snepClient = new SnepClient();
try {
snepClient.connect();
@@ -435,12 +429,12 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
}
try {
- if (uri != null) {
+ if (uris != null) {
SnepMessage snepResponse =
snepClient.get(handoverManager.createHandoverRequestMessage());
NdefMessage response = snepResponse.getNdefMessage();
if (response != null) {
- handoverManager.doHandoverUri(mimeType, uri, response);
+ handoverManager.doHandoverUri(uris, response);
}
} else if (msg != null) {
snepClient.put(msg);
@@ -514,8 +508,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
mLinkState = LINK_STATE_DOWN;
mSendState = SEND_STATE_NOTHING_TO_SEND;
mMessageToSend = null;
- mUriToSend = null;
- mMimeTypeToSend = null;
+ mUrisToSend = null;
if (DBG) Log.d(TAG, "onP2pOutOfRange()");
mEventListener.onP2pOutOfRange();
}
@@ -664,8 +657,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
pw.println("mCallbackNdef=" + mCallbackNdef);
pw.println("mMessageToSend=" + mMessageToSend);
- pw.println("mUriToSend=" + mUriToSend);
- pw.println("mMimeTypeToSend=" + mMimeTypeToSend);
+ pw.println("mUrisToSend=" + mUrisToSend);
}
}
}
diff --git a/src/com/android/nfc/handover/BluetoothOppHandover.java b/src/com/android/nfc/handover/BluetoothOppHandover.java
index 196bcf5..9c1a60d 100644
--- a/src/com/android/nfc/handover/BluetoothOppHandover.java
+++ b/src/com/android/nfc/handover/BluetoothOppHandover.java
@@ -1,32 +1,52 @@
package com.android.nfc.handover;
import android.bluetooth.BluetoothDevice;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
+import android.webkit.MimeTypeMap;
+
+import java.util.ArrayList;
+import java.util.Arrays;
public class BluetoothOppHandover {
static final String TAG = "BluetoothOppHandover";
static final boolean D = true;
-
+
final Context mContext;
final BluetoothDevice mDevice;
- final Uri mUri;
- final String mMimeType;
+ final Uri[] mUris;
public interface Callback {
public void onBluetoothOppHandoverComplete();
}
-
- public BluetoothOppHandover(Context context, BluetoothDevice device, String mimeType,
- Uri uri) {
+
+ public BluetoothOppHandover(Context context, BluetoothDevice device,
+ Uri[] uris) {
mContext = context;
mDevice = device;
- mMimeType = mimeType;
- mUri = uri;
+ mUris = uris;
}
-
+
+ public String getMimeTypeForUri(Uri uri) {
+ if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
+ ContentResolver cr = mContext.getContentResolver();
+ return cr.getType(uri);
+ } else if (uri.getScheme().equals(ContentResolver.SCHEME_FILE)) {
+ String extension = MimeTypeMap.getFileExtensionFromUrl(uri.getPath());
+ if (extension != null) {
+ return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
+ } else {
+ return null;
+ }
+ } else {
+ Log.d(TAG, "Could not determine mime type for Uri " + uri);
+ return null;
+ }
+ }
+
/**
* Main entry point. This method is usually called after construction,
* to begin the BT sequence. Must be called on Main thread.
@@ -35,12 +55,20 @@ public class BluetoothOppHandover {
//TODO: either open up BluetoothOppLauncherActivity to all MIME types
// or gracefully handle mime types that can't be sent
Log.d(TAG, "Sending handover intent for " + mDevice.getAddress());
- Intent intent = new Intent(Intent.ACTION_SEND);
- // TODO see if this can be made more robust
+ Intent intent = new Intent();
intent.setPackage("com.android.bluetooth");
- intent.setType(mMimeType);
- intent.putExtra(Intent.EXTRA_STREAM, mUri);
+ String mimeType = getMimeTypeForUri(mUris[0]);
+ Log.d(TAG, "Determined mime type as " + mimeType);
+ intent.setType(mimeType);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
+ if (mUris.length == 1) {
+ intent.setAction(Intent.ACTION_SEND);
+ intent.putExtra(Intent.EXTRA_STREAM, mUris[0]);
+ } else {
+ ArrayList<Uri> uris = (ArrayList<Uri>)Arrays.asList(mUris);
+ intent.setAction(Intent.ACTION_SEND_MULTIPLE);
+ intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
+ }
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
diff --git a/src/com/android/nfc/handover/HandoverManager.java b/src/com/android/nfc/handover/HandoverManager.java
index fd44007..bbb42cc 100644
--- a/src/com/android/nfc/handover/HandoverManager.java
+++ b/src/com/android/nfc/handover/HandoverManager.java
@@ -183,10 +183,11 @@ public class HandoverManager implements BluetoothProfile.ServiceListener,
return true;
}
- public void doHandoverUri(String mimeType, Uri uri, NdefMessage m) {
+ // This starts sending an Uri over BT
+ public void doHandoverUri(Uri[] uris, NdefMessage m) {
BluetoothHandoverData data = parse(m);
BluetoothOppHandover handover = new BluetoothOppHandover(mContext, data.device,
- mimeType, uri);
+ uris);
handover.start();
}