diff options
author | Martijn Coenen <maco@google.com> | 2012-04-13 15:22:11 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-04-13 15:22:11 -0700 |
commit | a94afeb5b3c3c95c6d2cf0cd4d69587aba569cfb (patch) | |
tree | 092280ea7d53086241a35ff4ea546e43ebd884fa /core | |
parent | e64d187553cb3fa193b5748b5c99ad85cf9ccba1 (diff) | |
parent | 20e8dd9f9e7cff63c83e36a1761538a04c224cc1 (diff) | |
download | frameworks_base-a94afeb5b3c3c95c6d2cf0cd4d69587aba569cfb.zip frameworks_base-a94afeb5b3c3c95c6d2cf0cd4d69587aba569cfb.tar.gz frameworks_base-a94afeb5b3c3c95c6d2cf0cd4d69587aba569cfb.tar.bz2 |
Merge "Unhide new Beam push APIs."
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/nfc/INdefPushCallback.aidl | 3 | ||||
-rw-r--r-- | core/java/android/nfc/NfcActivityManager.java | 57 | ||||
-rw-r--r-- | core/java/android/nfc/NfcAdapter.java | 43 |
3 files changed, 76 insertions, 27 deletions
diff --git a/core/java/android/nfc/INdefPushCallback.aidl b/core/java/android/nfc/INdefPushCallback.aidl index 4e79822..1c6d5d0 100644 --- a/core/java/android/nfc/INdefPushCallback.aidl +++ b/core/java/android/nfc/INdefPushCallback.aidl @@ -25,7 +25,6 @@ import android.net.Uri; interface INdefPushCallback { NdefMessage createMessage(); - Uri getUri(); - String getMimeType(); + Uri[] getUris(); void onNdefPushComplete(); } diff --git a/core/java/android/nfc/NfcActivityManager.java b/core/java/android/nfc/NfcActivityManager.java index f80dae4..7ffa575 100644 --- a/core/java/android/nfc/NfcActivityManager.java +++ b/core/java/android/nfc/NfcActivityManager.java @@ -108,8 +108,8 @@ public final class NfcActivityManager extends INdefPushCallback.Stub NdefMessage ndefMessage = null; // static NDEF message NfcAdapter.CreateNdefMessageCallback ndefMessageCallback = null; NfcAdapter.OnNdefPushCompleteCallback onNdefPushCompleteCallback = null; - Uri uri = null; - String mimeType = null; + NfcAdapter.CreateBeamUrisCallback uriCallback = null; + Uri[] uris = null; public NfcActivityState(Activity activity) { if (activity.getWindow().isDestroyed()) { throw new IllegalStateException("activity is already destroyed"); @@ -128,14 +128,19 @@ public final class NfcActivityManager extends INdefPushCallback.Stub ndefMessage = null; ndefMessageCallback = null; onNdefPushCompleteCallback = null; - uri = null; - mimeType = null; + uriCallback = null; + uris = null; } @Override public String toString() { StringBuilder s = new StringBuilder("[").append(" "); s.append(ndefMessage).append(" ").append(ndefMessageCallback).append(" "); - s.append(onNdefPushCompleteCallback).append(" ").append(uri).append("]"); + s.append(uriCallback).append(" "); + if (uris != null) { + for (Uri uri : uris) { + s.append(onNdefPushCompleteCallback).append(" ").append(uri).append("]"); + } + } return s.toString(); } } @@ -184,12 +189,25 @@ public final class NfcActivityManager extends INdefPushCallback.Stub mDefaultEvent = new NfcEvent(mAdapter); } - public void setNdefPushContentUri(Activity activity, String mimeType, Uri uri) { + public void setNdefPushContentUri(Activity activity, Uri[] uris) { + boolean isResumed; + synchronized (NfcActivityManager.this) { + NfcActivityState state = getActivityState(activity); + state.uris = uris; + isResumed = state.resumed; + } + if (isResumed) { + requestNfcServiceCallback(true); + } + } + + + public void setNdefPushContentUriCallback(Activity activity, + NfcAdapter.CreateBeamUrisCallback callback) { boolean isResumed; synchronized (NfcActivityManager.this) { NfcActivityState state = getActivityState(activity); - state.uri = uri; - state.mimeType = mimeType; + state.uriCallback = callback; isResumed = state.resumed; } if (isResumed) { @@ -271,24 +289,22 @@ public final class NfcActivityManager extends INdefPushCallback.Stub /** Callback from NFC service, usually on binder thread */ @Override - public Uri getUri() { + public Uri[] getUris() { + Uri[] uris; + NfcAdapter.CreateBeamUrisCallback callback; synchronized (NfcActivityManager.this) { NfcActivityState state = findResumedActivityState(); if (state == null) return null; - - return state.uri; + uris = state.uris; + callback = state.uriCallback; } - } - /** Callback from NFC service, usually on binder thread */ - @Override - public String getMimeType() { - synchronized (NfcActivityManager.this) { - NfcActivityState state = findResumedActivityState(); - if (state == null) return null; - - return state.mimeType; + if (callback != null) { + return callback.createBeamUris(mDefaultEvent); + } else { + return uris; } } + /** Callback from NFC service, usually on binder thread */ @Override public void onNdefPushComplete() { @@ -358,4 +374,5 @@ public final class NfcActivityManager extends INdefPushCallback.Stub } } } + } diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index 917751c..90f5bef 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -203,6 +203,27 @@ public final class NfcAdapter { /** @hide */ public static final int STATE_TURNING_OFF = 4; + /** @hide */ + public static final String ACTION_HANDOVER_TRANSFER_STARTED = + "android.nfc.action.HANDOVER_TRANSFER_STARTED"; + + /** @hide */ + public static final String ACTION_HANDOVER_TRANSFER_DONE = + "android.nfc.action.HANDOVER_TRANSFER_DONE"; + + /** @hide */ + public static final String EXTRA_HANDOVER_TRANSFER_STATUS = + "android.nfc.extra.HANDOVER_TRANSFER_STATUS"; + + /** @hide */ + public static final int HANDOVER_TRANSFER_STATUS_SUCCESS = 0; + /** @hide */ + public static final int HANDOVER_TRANSFER_STATUS_FAILURE = 1; + + /** @hide */ + public static final String EXTRA_HANDOVER_TRANSFER_URI = + "android.nfc.extra.HANDOVER_TRANSFER_URI"; + // Guarded by NfcAdapter.class static boolean sIsInitialized = false; @@ -281,6 +302,12 @@ public final class NfcAdapter { public NdefMessage createNdefMessage(NfcEvent event); } + + // TODO javadoc + public interface CreateBeamUrisCallback { + public Uri[] createBeamUris(NfcEvent event); + } + /** * Helper to check if this device has FEATURE_NFC, but without using * a context. @@ -556,16 +583,22 @@ public final class NfcAdapter { } } - //TODO: Consider a callback alternative - //TOOD: See if we get rid of mimeType //TODO: make sure NFC service has permission for URI + //TODO: see if we will eventually support multiple URIs //TODO: javadoc - /** @hide */ - public void setBeamPushUri(String mimeType, Uri uri, Activity activity) { + public void setBeamPushUris(Uri[] uris, Activity activity) { + if (activity == null) { + throw new NullPointerException("activity cannot be null"); + } + mNfcActivityManager.setNdefPushContentUri(activity, uris); + } + + // TODO javadoc + public void setBeamPushUrisCallback(CreateBeamUrisCallback callback, Activity activity) { if (activity == null) { throw new NullPointerException("activity cannot be null"); } - mNfcActivityManager.setNdefPushContentUri(activity, mimeType, uri); + mNfcActivityManager.setNdefPushContentUriCallback(activity, callback); } /** |