diff options
| -rw-r--r-- | api/current.xml | 11 | ||||
| -rw-r--r-- | core/java/android/nfc/NdefTag.java | 48 | ||||
| -rw-r--r-- | core/java/android/nfc/NdefTagConnection.java | 38 | ||||
| -rw-r--r-- | core/java/android/nfc/NfcAdapter.java | 29 | ||||
| -rw-r--r-- | core/java/android/nfc/RawTagConnection.java | 39 | ||||
| -rw-r--r-- | core/java/android/nfc/Tag.java | 73 | ||||
| -rw-r--r-- | core/java/android/widget/StackView.java | 75 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 33 | ||||
| -rw-r--r-- | core/java/com/android/internal/nfc/LlcpConnectionlessSocket.java (renamed from core/java/com/trustedlogic/trustednfc/android/LlcpConnectionlessSocket.java) | 28 | ||||
| -rw-r--r-- | core/java/com/android/internal/nfc/LlcpException.java (renamed from core/java/com/trustedlogic/trustednfc/android/LlcpException.java) | 11 | ||||
| -rw-r--r-- | core/java/com/android/internal/nfc/LlcpServiceSocket.java (renamed from core/java/com/trustedlogic/trustednfc/android/LlcpServiceSocket.java) | 23 | ||||
| -rw-r--r-- | core/java/com/android/internal/nfc/LlcpSocket.java (renamed from core/java/com/trustedlogic/trustednfc/android/LlcpSocket.java) | 31 | ||||
| -rw-r--r-- | core/java/com/android/internal/nfc/NfcException.java (renamed from core/java/com/trustedlogic/trustednfc/android/NfcException.java) | 11 | ||||
| -rw-r--r-- | core/java/com/android/internal/nfc/P2pDevice.java (renamed from core/java/com/trustedlogic/trustednfc/android/P2pDevice.java) | 12 | ||||
| -rw-r--r-- | core/java/com/android/internal/nfc/P2pInitiator.java (renamed from core/java/com/trustedlogic/trustednfc/android/P2pInitiator.java) | 12 | ||||
| -rw-r--r-- | core/java/com/android/internal/nfc/P2pTarget.java (renamed from core/java/com/trustedlogic/trustednfc/android/P2pTarget.java) | 17 | ||||
| -rw-r--r-- | core/java/com/trustedlogic/trustednfc/android/package.html | 473 | ||||
| -rw-r--r-- | core/res/AndroidManifest.xml | 33 | ||||
| -rwxr-xr-x | core/res/res/values/strings.xml | 24 | ||||
| -rw-r--r-- | include/ui/InputReader.h | 10 | ||||
| -rw-r--r-- | libs/ui/InputReader.cpp | 38 |
21 files changed, 324 insertions, 745 deletions
diff --git a/api/current.xml b/api/current.xml index 5611e0d..3df27fd 100644 --- a/api/current.xml +++ b/api/current.xml @@ -705,6 +705,17 @@ visibility="public" > </field> +<field name="NFC" + type="java.lang.String" + transient="false" + volatile="false" + value=""android.permission.NFC"" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> <field name="PERSISTENT_ACTIVITY" type="java.lang.String" transient="false" diff --git a/core/java/android/nfc/NdefTag.java b/core/java/android/nfc/NdefTag.java index 6d44e6e..45cdc31 100644 --- a/core/java/android/nfc/NdefTag.java +++ b/core/java/android/nfc/NdefTag.java @@ -16,6 +16,8 @@ package android.nfc; +import java.util.HashMap; + import android.os.Parcel; import android.os.Parcelable; @@ -41,8 +43,8 @@ public class NdefTag extends Tag implements Parcelable { * tag is discovered and by Parcelable methods. * @hide */ - public NdefTag(int type, byte[] uid, int nativeHandle, NdefMessage[] messages) { - super(type, true, uid, nativeHandle); + public NdefTag(String typeName, byte[] uid, int nativeHandle, NdefMessage[] messages) { + super(typeName, true, uid, nativeHandle); mMessages = messages.clone(); } @@ -62,10 +64,22 @@ public class NdefTag extends Tag implements Parcelable { /** * Get only the NDEF Messages from a single NDEF target on a tag. + * <p> + * This retrieves the NDEF Messages that were found on the Tag at discovery + * time. It does not cause any further RF activity, and does not block. + * <p> + * Most tags only contain a single NDEF message. + * + * @param target One of targets strings provided by getNdefTargets() + * @return NDEF Messages found at Tag discovery */ public NdefMessage[] getNdefMessages(String target) { - //TODO(nxp): new api method - throw new UnsupportedOperationException(); + // TODO: handle multiprotocol + String[] localTypes = convertToNdefType(mTypeName); + if (!target.equals(localTypes[0])) { + throw new IllegalArgumentException(); + } + return getNdefMessages(); } /** TODO(npelly): @@ -79,13 +93,35 @@ public class NdefTag extends Tag implements Parcelable { public static final String TARGET_MIFARE_CLASSIC = "type_mifare_classic"; public static final String TARGET_OTHER = "other"; + private static final HashMap<String, String[]> NDEF_TYPES_CONVERTION_TABLE = new HashMap<String, String[]>() { + { + // TODO: handle multiprotocol + // TODO: move INTERNAL_TARGET_Type to TARGET_TYPE mapping to NFC service + put(Tag.INTERNAL_TARGET_TYPE_JEWEL, new String[] { NdefTag.TARGET_TYPE_1 }); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_UL, new String[] { NdefTag.TARGET_TYPE_2 }); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_1K, new String[] { NdefTag.TARGET_MIFARE_CLASSIC }); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_4K, new String[] { NdefTag.TARGET_MIFARE_CLASSIC }); + put(Tag.INTERNAL_TARGET_TYPE_FELICA, new String[] { NdefTag.TARGET_TYPE_3 }); + put(Tag.INTERNAL_TARGET_TYPE_ISO14443_4, new String[] { NdefTag.TARGET_TYPE_4 }); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_DESFIRE, new String[] { NdefTag.TARGET_TYPE_4 }); + } + }; + + private String[] convertToNdefType(String internalTypeName) { + String[] result = NDEF_TYPES_CONVERTION_TABLE.get(internalTypeName); + if (result == null) { + return new String[] { NdefTag.TARGET_OTHER }; + } + return result; + } + /** * Return the * * @return */ public String[] getNdefTargets() { - throw new UnsupportedOperationException(); + return convertToNdefType(mTypeName); } @Override @@ -107,7 +143,7 @@ public class NdefTag extends Tag implements Parcelable { int messagesLength = in.readInt(); NdefMessage[] messages = new NdefMessage[messagesLength]; in.readTypedArray(messages, NdefMessage.CREATOR); - return new NdefTag(tag.mType, tag.mUid, tag.mNativeHandle, messages); + return new NdefTag(tag.mTypeName, tag.mUid, tag.mNativeHandle, messages); } public NdefTag[] newArray(int size) { return new NdefTag[size]; diff --git a/core/java/android/nfc/NdefTagConnection.java b/core/java/android/nfc/NdefTagConnection.java index 8038d1a..4795fa7 100644 --- a/core/java/android/nfc/NdefTagConnection.java +++ b/core/java/android/nfc/NdefTagConnection.java @@ -25,6 +25,9 @@ import android.util.Log; * A connection to an NDEF target on an {@link NdefTag}. * <p>You can acquire this kind of connection with {@link NfcAdapter#createNdefTagConnection * createNdefTagConnection()}. Use the connection to read or write {@link NdefMessage}s. + * <p class="note"><strong>Note:</strong> + * Use of this class requires the {@link android.Manifest.permission#NFC} + * permission. */ public class NdefTagConnection extends RawTagConnection { public static final int NDEF_MODE_READ_ONCE = 1; @@ -39,8 +42,29 @@ public class NdefTagConnection extends RawTagConnection { * Internal constructor, to be used by NfcAdapter * @hide */ - NdefTagConnection(INfcAdapter service, NdefTag tag) throws RemoteException { + /* package private */ NdefTagConnection(INfcAdapter service, NdefTag tag, String target) throws RemoteException { super(service, tag); + String[] targets = tag.getNdefTargets(); + int i; + + // Check target validity + for (i=0; i<targets.length; i++) { + if (target.equals(targets[i])) { + break; + } + } + if (i >= targets.length) { + // Target not found + throw new IllegalArgumentException(); + } + } + + /** + * Internal constructor, to be used by NfcAdapter + * @hide + */ + /* package private */ NdefTagConnection(INfcAdapter service, NdefTag tag) throws RemoteException { + this(service, tag, tag.getNdefTargets()[0]); } /** @@ -48,7 +72,7 @@ public class NdefTagConnection extends RawTagConnection { * This will always return the most up to date payload, and can block. * It can be canceled with {@link RawTagConnection#close}. * Most NDEF tags will contain just one NDEF message. - * <p> + * <p>Requires {@link android.Manifest.permission#NFC} permission. * @throws FormatException if the tag is not NDEF formatted * @throws IOException if the target is lost or connection closed * @throws FormatException @@ -88,8 +112,9 @@ public class NdefTagConnection extends RawTagConnection { * message. Use {@link NdefRecord} to write several records to a single tag. * For write-many tags, use {@link #makeReadOnly} after this method to attempt * to prevent further modification. For write-once tags this is not - * neccesary. - * Requires NFC_WRITE permission. + * necessary. + * <p>Requires {@link android.Manifest.permission#NFC} permission. + * * @throws FormatException if the tag is not suitable for NDEF messages * @throws IOException if the target is lost or connection closed or the * write failed @@ -117,7 +142,7 @@ public class NdefTagConnection extends RawTagConnection { * Attempts to make the NDEF data in this tag read-only. * This method will block until the action is complete. It can be canceled * with {@link RawTagConnection#close}. - * Requires NFC_WRITE permission. + * <p>Requires {@link android.Manifest.permission#NFC} permission. * @return true if the tag is now read-only * @throws IOException if the target is lost, or connection closed */ @@ -143,7 +168,8 @@ public class NdefTagConnection extends RawTagConnection { /** * Read/Write mode hint. - * Provides a hint if further reads or writes are likely to suceed. + * Provides a hint if further reads or writes are likely to succeed. + * <p>Requires {@link android.Manifest.permission#NFC} permission. * @return one of NDEF_MODE * @throws IOException if the target is lost or connection closed */ diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index 37243f7..6f718d3 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -22,7 +22,6 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.util.Log; -//TODO(npelly) permission {@link android.Manifest.permission#NFC_MODIFY} /** * Represents the device's local NFC adapter. * <p> @@ -35,7 +34,7 @@ import android.util.Log; * to NFC Tags. * <p class="note"> * <strong>Note:</strong> Some methods require the - * TODO permission. + * {@link android.Manifest.permission#NFC} permission. */ public final class NfcAdapter { /** @@ -231,8 +230,7 @@ public final class NfcAdapter { * <li>provide the NDEF message on over LLCP to peer NFC adapters * </ul> * The NDEF message is preserved across reboot. - * <p> - * Requires NFC_WRITE permission + * <p>Requires {@link android.Manifest.permission#NFC} permission. * * @param message NDEF message to make public */ @@ -246,8 +244,7 @@ public final class NfcAdapter { /** * Get the NDEF Message that this adapter appears as to Tag readers. - * <p> - * Requires NFC_WRITE permission + * <p>Requires {@link android.Manifest.permission#NFC} permission. * * @return NDEF Message that is publicly readable */ @@ -262,6 +259,7 @@ public final class NfcAdapter { /** * Create a raw tag connection to the default Target + * <p>Requires {@link android.Manifest.permission#NFC} permission. */ public RawTagConnection createRawTagConnection(Tag tag) { try { @@ -274,14 +272,20 @@ public final class NfcAdapter { /** * Create a raw tag connection to the specified Target + * <p>Requires {@link android.Manifest.permission#NFC} permission. */ public RawTagConnection createRawTagConnection(Tag tag, String target) { - //TODO - throw new UnsupportedOperationException(); + try { + return new RawTagConnection(mService, tag, target); + } catch (RemoteException e) { + Log.e(TAG, "NFC service died", e); + return null; + } } /** * Create an NDEF tag connection to the default Target + * <p>Requires {@link android.Manifest.permission#NFC} permission. */ public NdefTagConnection createNdefTagConnection(NdefTag tag) { try { @@ -294,9 +298,14 @@ public final class NfcAdapter { /** * Create an NDEF tag connection to the specified Target + * <p>Requires {@link android.Manifest.permission#NFC} permission. */ public NdefTagConnection createNdefTagConnection(NdefTag tag, String target) { - //TODO - throw new UnsupportedOperationException(); + try { + return new NdefTagConnection(mService, tag, target); + } catch (RemoteException e) { + Log.e(TAG, "NFC service died", e); + return null; + } } } diff --git a/core/java/android/nfc/RawTagConnection.java b/core/java/android/nfc/RawTagConnection.java index 50e2a5d..265eb1b 100644 --- a/core/java/android/nfc/RawTagConnection.java +++ b/core/java/android/nfc/RawTagConnection.java @@ -30,7 +30,7 @@ import android.util.Log; * Applications must implement their own protocol stack on top of {@link #transceive transceive()}. * * <p class="note"><strong>Note:</strong> - * Most methods require the TODO + * Use of this class requires the {@link android.Manifest.permission#NFC} * permission. */ public class RawTagConnection { @@ -39,33 +39,56 @@ public class RawTagConnection { /*package*/ final INfcTag mTagService; /*package*/ final Tag mTag; /*package*/ boolean mIsConnected; + /*package*/ String mSelectedTarget; private static final String TAG = "NFC"; - /* package private */ RawTagConnection(INfcAdapter service, Tag tag) throws RemoteException { + /* package private */ RawTagConnection(INfcAdapter service, Tag tag, String target) throws RemoteException { + String[] targets = tag.getRawTargets(); + int i; + + // Check target validity + for (i=0;i<targets.length;i++) { + if (target.equals(targets[i])) { + break; + } + } + if (i >= targets.length) { + // Target not found + throw new IllegalArgumentException(); + } + mService = service; mTagService = service.getNfcTagInterface(); mService.openTagConnection(tag); // TODO(nxp): don't connect until connect() mTag = tag; + mSelectedTarget = target; + } + + /* package private */ RawTagConnection(INfcAdapter service, Tag tag) throws RemoteException { + this(service, tag, tag.getRawTargets()[0]); } /** * Get the {@link Tag} this connection is associated with. + * <p>Requires {@link android.Manifest.permission#NFC} permission. */ public Tag getTag() { return mTag; } + /** + * <p>Requires {@link android.Manifest.permission#NFC} permission. + */ public String getTagTarget() { - //TODO - throw new UnsupportedOperationException(); + return mSelectedTarget; } /** * Helper to indicate if {@link #transceive transceive()} calls might succeed. * <p> * Does not cause RF activity, and does not block. - * <p> + * <p>Requires {@link android.Manifest.permission#NFC} permission. * @return true if {@link #connect} has completed successfully and the {@link Tag} is believed * to be within range. Applications must still handle {@link java.io.IOException} * while using {@link #transceive transceive()}, in case connection is lost after this method @@ -85,7 +108,7 @@ public class RawTagConnection { * <p> * {@link #close} can be called from another thread to cancel this connection * attempt. - * + * <p>Requires {@link android.Manifest.permission#NFC} permission. * @throws IOException if the target is lost, or connect canceled */ public void connect() throws IOException { @@ -101,6 +124,7 @@ public class RawTagConnection { * <p> * Once this method is called, this object cannot be re-used and should be discarded. Further * calls to {@link #transceive transceive()} or {@link #connect} will fail. + * <p>Requires {@link android.Manifest.permission#NFC} permission. */ public void close() { mIsConnected = false; @@ -116,8 +140,7 @@ public class RawTagConnection { * <p> * This method will block until the response is received. It can be canceled * with {@link #close}. - * <p> - * Requires NFC_WRITE permission. + * <p>Requires {@link android.Manifest.permission#NFC} permission. * * @param data bytes to send * @return bytes received in response diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java index ea21790..abf02b5 100644 --- a/core/java/android/nfc/Tag.java +++ b/core/java/android/nfc/Tag.java @@ -16,6 +16,8 @@ package android.nfc; +import java.util.HashMap; + import android.os.Parcel; import android.os.Parcelable; @@ -113,17 +115,73 @@ public class Tag implements Parcelable { public static final String TARGET_OTHER = "other"; - /*package*/ final int mType; + /*package*/ final String mTypeName; /*package*/ final boolean mIsNdef; /*package*/ final byte[] mUid; /*package*/ final int mNativeHandle; + /*package*/ static final String INTERNAL_TARGET_TYPE_ISO14443_3A = "Iso14443-3A"; + /*package*/ static final String INTERNAL_TARGET_TYPE_ISO14443_3B = "Iso14443-3B"; + /*package*/ static final String INTERNAL_TARGET_TYPE_ISO14443_4 = "Iso14443-4"; + /*package*/ static final String INTERNAL_TARGET_TYPE_MIFARE_UL = "MifareUL"; + /*package*/ static final String INTERNAL_TARGET_TYPE_MIFARE_1K = "Mifare1K"; + /*package*/ static final String INTERNAL_TARGET_TYPE_MIFARE_4K = "Mifare4K"; + /*package*/ static final String INTERNAL_TARGET_TYPE_MIFARE_DESFIRE = "MifareDESFIRE"; + /*package*/ static final String INTERNAL_TARGET_TYPE_MIFARE_UNKNOWN = "Unknown Mifare"; + /*package*/ static final String INTERNAL_TARGET_TYPE_FELICA = "Felica"; + /*package*/ static final String INTERNAL_TARGET_TYPE_JEWEL = "Jewel"; + /*package*/ static final String INTERNAL_TARGET_TYPE_UNKNOWN = "Unknown Type"; + + private static final HashMap<String, Integer> INT_TYPES_CONVERTION_TABLE = new HashMap<String, Integer>() { + { + put(Tag.INTERNAL_TARGET_TYPE_ISO14443_3A, Tag.NFC_TAG_ISO14443_A ); + put(Tag.INTERNAL_TARGET_TYPE_ISO14443_3B, Tag.NFC_TAG_ISO14443_B ); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_UL, Tag.NFC_TAG_MIFARE ); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_1K, Tag.NFC_TAG_MIFARE ); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_4K, Tag.NFC_TAG_MIFARE ); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_DESFIRE, Tag.NFC_TAG_MIFARE ); + put(Tag.INTERNAL_TARGET_TYPE_FELICA, Tag.NFC_TAG_FELICA ); + put(Tag.INTERNAL_TARGET_TYPE_JEWEL, Tag.NFC_TAG_JEWEL ); + } + }; + + private int convertToInt(String internalTypeName) { + Integer result = INT_TYPES_CONVERTION_TABLE.get(internalTypeName); + if (result == null) { + return Tag.NFC_TAG_OTHER; + } + return result; + } + + private static final HashMap<String, String[]> RAW_TYPES_CONVERTION_TABLE = new HashMap<String, String[]>() { + { + /* TODO: handle multiprotocol */ + put(Tag.INTERNAL_TARGET_TYPE_ISO14443_3A, new String[] { Tag.TARGET_ISO_14443_3A }); + put(Tag.INTERNAL_TARGET_TYPE_ISO14443_3B, new String[] { Tag.TARGET_ISO_14443_3B }); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_UL, new String[] { Tag.TARGET_ISO_14443_3A }); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_1K, new String[] { Tag.TARGET_ISO_14443_3A }); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_4K, new String[] { Tag.TARGET_ISO_14443_3A }); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_DESFIRE, new String[] { Tag.TARGET_ISO_14443_3A }); + put(Tag.INTERNAL_TARGET_TYPE_MIFARE_UNKNOWN, new String[] { Tag.TARGET_ISO_14443_3A }); + put(Tag.INTERNAL_TARGET_TYPE_FELICA, new String[] { Tag.TARGET_JIS_X_6319_4 }); + put(Tag.INTERNAL_TARGET_TYPE_JEWEL, new String[] { Tag.TARGET_TOPAZ }); + } + }; + + private String[] convertToRaw(String internalTypeName) { + String[] result = RAW_TYPES_CONVERTION_TABLE.get(internalTypeName); + if (result == null) { + return new String[] { Tag.TARGET_OTHER }; + } + return result; + } + /** * Hidden constructor to be used by NFC service only. * @hide */ - public Tag(int type, boolean isNdef, byte[] uid, int nativeHandle) { - mType = type; + public Tag(String typeName, boolean isNdef, byte[] uid, int nativeHandle) { + mTypeName = typeName; mIsNdef = isNdef; mUid = uid.clone(); mNativeHandle = nativeHandle; @@ -144,8 +202,7 @@ public class Tag implements Parcelable { * @return */ public String[] getRawTargets() { - //TODO - throw new UnsupportedOperationException(); + return convertToRaw(mTypeName); } /** @@ -159,7 +216,7 @@ public class Tag implements Parcelable { * @hide */ public int getType() { - return mType; + return convertToInt(mTypeName); } /** @@ -188,7 +245,7 @@ public class Tag implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { boolean[] booleans = new boolean[] {mIsNdef}; - dest.writeInt(mType); + dest.writeString(mTypeName); dest.writeBooleanArray(booleans); dest.writeInt(mUid.length); dest.writeByteArray(mUid); @@ -199,7 +256,7 @@ public class Tag implements Parcelable { new Parcelable.Creator<Tag>() { public Tag createFromParcel(Parcel in) { boolean[] booleans = new boolean[1]; - int type = in.readInt(); + String type = in.readString(); in.readBooleanArray(booleans); boolean isNdef = booleans[0]; int uidLength = in.readInt(); diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java index 1f5b790..4c3927b 100644 --- a/core/java/android/widget/StackView.java +++ b/core/java/android/widget/StackView.java @@ -28,6 +28,7 @@ import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; +import android.graphics.Region; import android.graphics.TableMaskFilter; import android.util.AttributeSet; import android.util.Log; @@ -113,10 +114,9 @@ public class StackView extends AdapterViewAnimator { private ImageView mHighlight; private StackSlider mStackSlider; private boolean mFirstLayoutHappened = false; - private ViewGroup mAncestorContainingAllChildren = null; - private int mAncestorHeight = 0; private int mStackMode; private int mFramePadding; + private final Rect invalidateRect = new Rect(); public StackView(Context context) { super(context); @@ -269,24 +269,18 @@ public class StackView extends AdapterViewAnimator { @Override protected void dispatchDraw(Canvas canvas) { - super.dispatchDraw(canvas); - } - - // TODO: right now, this code walks up the hierarchy as far as needed and disables clipping - // so that the stack's children can draw outside of the stack's bounds. This is fine within - // the context of widgets in the launcher, but is destructive in general, as the clipping - // values are not being reset. For this to be a full framework level widget, we will need - // framework level support for drawing outside of a parent's bounds. - private void disableParentalClipping() { - if (mAncestorContainingAllChildren != null) { - ViewGroup vg = this; - while (vg.getParent() != null && vg.getParent() instanceof ViewGroup) { - if (vg == mAncestorContainingAllChildren) break; - vg = (ViewGroup) vg.getParent(); - vg.setClipChildren(false); - vg.setClipToPadding(false); - } + canvas.getClipBounds(invalidateRect); + final int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + LayoutParams lp = (LayoutParams) getChildAt(i).getLayoutParams(); + invalidateRect.union(lp.getInvalidateRect()); + lp.resetInvalidateRect(); } + + canvas.save(Canvas.CLIP_SAVE_FLAG); + canvas.clipRect(invalidateRect, Region.Op.UNION); + super.dispatchDraw(canvas); + canvas.restore(); } private void onLayout() { @@ -343,6 +337,8 @@ public class StackView extends AdapterViewAnimator { cancelLongPress(); requestDisallowInterceptTouchEvent(true); + if (mAdapter == null) return; + int activeIndex; if (mStackMode == ITEMS_SLIDE_UP) { activeIndex = (swipeGestureType == GESTURE_SLIDE_DOWN) ? @@ -352,8 +348,6 @@ public class StackView extends AdapterViewAnimator { mNumActiveViews - 2 : mNumActiveViews - 1; } - if (mAdapter == null) return; - if (mLoopViews) { mStackSlider.setMode(StackSlider.NORMAL_MODE); } else if (mCurrentWindowStartUnbounded + activeIndex == 0) { @@ -845,6 +839,11 @@ public class StackView extends AdapterViewAnimator { int horizontalOffset; int verticalOffset; View mView; + int left, top, right, bottom; + private final Rect parentRect = new Rect(); + private final Rect invalidateRect = new Rect(); + private final RectF invalidateRectf = new RectF(); + private final Rect globalInvalidateRect = new Rect(); LayoutParams(View view) { super(0, 0); @@ -863,8 +862,9 @@ public class StackView extends AdapterViewAnimator { height = 0; } - private Rect parentRect = new Rect(); void invalidateGlobalRegion(View v, Rect r) { + // We need to make a new rect here, so as not to modify the one passed + globalInvalidateRect.set(r); View p = v; if (!(v.getParent() != null && v.getParent() instanceof View)) return; @@ -872,9 +872,10 @@ public class StackView extends AdapterViewAnimator { parentRect.set(0, 0, 0, 0); int depth = 0; while (p.getParent() != null && p.getParent() instanceof View - && !parentRect.contains(r)) { + && !parentRect.contains(globalInvalidateRect)) { if (!firstPass) { - r.offset(p.getLeft() - p.getScrollX(), p.getTop() - p.getScrollY()); + globalInvalidateRect.offset(p.getLeft() - p.getScrollX(), p.getTop() + - p.getScrollY()); depth++; } firstPass = false; @@ -882,22 +883,20 @@ public class StackView extends AdapterViewAnimator { parentRect.set(p.getScrollX(), p.getScrollY(), p.getWidth() + p.getScrollX(), p.getHeight() + p.getScrollY()); - // TODO: we need to stop early here if we've hit the edge of the screen - // so as to prevent us from walking too high in the hierarchy. A lot of this - // code might become a lot more straightforward. } - if (depth > mAncestorHeight) { - mAncestorContainingAllChildren = (ViewGroup) p; - mAncestorHeight = depth; - disableParentalClipping(); - } + p.invalidate(globalInvalidateRect.left, globalInvalidateRect.top, + globalInvalidateRect.right, globalInvalidateRect.bottom); + } + + Rect getInvalidateRect() { + return invalidateRect; + } - p.invalidate(r.left, r.top, r.right, r.bottom); + void resetInvalidateRect() { + invalidateRect.set(0, 0, 0, 0); } - private Rect invalidateRect = new Rect(); - private RectF invalidateRectf = new RectF(); // This is public so that ObjectAnimator can access it public void setVerticalOffset(int newVerticalOffset) { int offsetDelta = newVerticalOffset - verticalOffset; @@ -908,14 +907,14 @@ public class StackView extends AdapterViewAnimator { int top = Math.min(mView.getTop() + offsetDelta, mView.getTop()); int bottom = Math.max(mView.getBottom() + offsetDelta, mView.getBottom()); - invalidateRectf.set(mView.getLeft(), top, mView.getRight(), bottom); + invalidateRectf.set(mView.getLeft(), top, mView.getRight(), bottom); float xoffset = -invalidateRectf.left; float yoffset = -invalidateRectf.top; invalidateRectf.offset(xoffset, yoffset); mView.getMatrix().mapRect(invalidateRectf); invalidateRectf.offset(-xoffset, -yoffset); - invalidateRect.set((int) Math.floor(invalidateRectf.left), + invalidateRect.union((int) Math.floor(invalidateRectf.left), (int) Math.floor(invalidateRectf.top), (int) Math.ceil(invalidateRectf.right), (int) Math.ceil(invalidateRectf.bottom)); @@ -940,7 +939,7 @@ public class StackView extends AdapterViewAnimator { mView.getMatrix().mapRect(invalidateRectf); invalidateRectf.offset(-xoffset, -yoffset); - invalidateRect.set((int) Math.floor(invalidateRectf.left), + invalidateRect.union((int) Math.floor(invalidateRectf.left), (int) Math.floor(invalidateRectf.top), (int) Math.ceil(invalidateRectf.right), (int) Math.ceil(invalidateRectf.bottom)); diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 9e6f342..d071dd2 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -3015,6 +3015,25 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (imm != null) imm.restartInput(this); } + /** + * It would be better to rely on the input type for everything. A password inputType should have + * a password transformation. We should hence use isPasswordInputType instead of this method. + * + * We should: + * - Call setInputType in setKeyListener instead of changing the input type directly (which + * would install the correct transformation). + * - Refuse the installation of a non-password transformation in setTransformation if the input + * type is password. + * + * However, this is like this for legacy reasons and we cannot break existing apps. This method + * is useful since it matches what the user can see (obfuscated text or not). + * + * @return true if the current transformation method is of the password type. + */ + private boolean hasPasswordTransformationMethod() { + return mTransformation instanceof PasswordTransformationMethod; + } + private boolean isPasswordInputType(int inputType) { final int variation = inputType & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_MASK_VARIATION); @@ -7233,7 +7252,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } private boolean canCut() { - if (mTransformation instanceof PasswordTransformationMethod) { + if (hasPasswordTransformationMethod()) { return false; } @@ -7247,7 +7266,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } private boolean canCopy() { - if (mTransformation instanceof PasswordTransformationMethod) { + if (hasPasswordTransformationMethod()) { return false; } @@ -7721,11 +7740,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mode.setTitle(mContext.getString(com.android.internal.R.string.textSelectionCABTitle)); mode.setSubtitle(null); - selectCurrentWord(); - boolean atLeastOne = false; if (canSelectText()) { + if (hasPasswordTransformationMethod()) { + // selectCurrentWord is not available on a password field and would return an + // arbitrary 10-charater selection around pressed position. Select all instead. + Selection.setSelection((Spannable) mText, 0, mText.length()); + } else { + selectCurrentWord(); + } + menu.add(0, ID_SELECT_ALL, 0, com.android.internal.R.string.selectAll). setIcon(com.android.internal.R.drawable.ic_menu_select_all). setAlphabeticShortcut('a'). diff --git a/core/java/com/trustedlogic/trustednfc/android/LlcpConnectionlessSocket.java b/core/java/com/android/internal/nfc/LlcpConnectionlessSocket.java index eccdeb1..a9cf6b8 100644 --- a/core/java/com/trustedlogic/trustednfc/android/LlcpConnectionlessSocket.java +++ b/core/java/com/android/internal/nfc/LlcpConnectionlessSocket.java @@ -14,48 +14,28 @@ * limitations under the License. */ -/** - * File : LlcpConnectionLessSocket.java - * Original-Author : Trusted Logic S.A. (Daniel Tomas) - * Created : 18-02-2010 - */ - -package com.trustedlogic.trustednfc.android; +package com.android.internal.nfc; import java.io.IOException; import android.nfc.ErrorCodes; import android.nfc.ILlcpConnectionlessSocket; import android.nfc.LlcpPacket; - import android.os.RemoteException; import android.util.Log; -/** - * LlcpConnectionlessSocket represents a LLCP Connectionless object to be used - * in a connectionless communication - * - * @since AA02.01 - * @hide - */ public class LlcpConnectionlessSocket { - - private static final String TAG = "LlcpConnectionlessSocket"; /** * The handle returned by the NFC service and used to identify the LLCP connectionless socket in * every call of this class. - * - * @hide */ protected int mHandle; /** * The entry point for LLCP Connectionless socket operations. - * - * @hide */ protected ILlcpConnectionlessSocket mService; @@ -66,7 +46,6 @@ public class LlcpConnectionlessSocket { * @param service The entry point to the Nfc Service for LLCP Connectionless socket class. * @param handle The handle returned by the NFC service and used to identify * the socket in subsequent calls. - * @hide */ LlcpConnectionlessSocket(ILlcpConnectionlessSocket service, int handle) { this.mService = service; @@ -79,7 +58,6 @@ public class LlcpConnectionlessSocket { * @param packet Service Access Point number related to a LLCP * Connectionless client and a data buffer to send * @throws IOException if the LLCP link has been lost or deactivated. - * @since AA02.01 */ public void sendTo(LlcpPacket packet) throws IOException { try { @@ -99,7 +77,6 @@ public class LlcpConnectionlessSocket { * @return data data received from a specific LLCP Connectionless client * @throws IOException if the LLCP link has been lost or deactivated. * @see LlcpPacket - * @since AA02.01 */ public LlcpPacket receiveFrom() throws IOException { try { @@ -118,8 +95,6 @@ public class LlcpConnectionlessSocket { /** * Close the created Connectionless socket. - * - * @since AA02.01 */ public void close() { try { @@ -133,7 +108,6 @@ public class LlcpConnectionlessSocket { * Returns the local Service Access Point number of the socket * * @return sap - * @since AA02.01 */ public int getSap() { int sap = 0; diff --git a/core/java/com/trustedlogic/trustednfc/android/LlcpException.java b/core/java/com/android/internal/nfc/LlcpException.java index 1e2e2da..da4e91e 100644 --- a/core/java/com/trustedlogic/trustednfc/android/LlcpException.java +++ b/core/java/com/android/internal/nfc/LlcpException.java @@ -14,20 +14,11 @@ * limitations under the License. */ -/** - * File : LLCPException.java - * Original-Author : Trusted Logic S.A. (Daniel Tomas) - * Created : 24-02-2010 - */ - -package com.trustedlogic.trustednfc.android; +package com.android.internal.nfc; /** * Generic exception thrown in case something unexpected happened during a * LLCP communication. - * - * @since AA02.01 - * @hide */ public class LlcpException extends Exception { /** diff --git a/core/java/com/trustedlogic/trustednfc/android/LlcpServiceSocket.java b/core/java/com/android/internal/nfc/LlcpServiceSocket.java index 1bdf72f..4607527 100644 --- a/core/java/com/trustedlogic/trustednfc/android/LlcpServiceSocket.java +++ b/core/java/com/android/internal/nfc/LlcpServiceSocket.java @@ -14,29 +14,19 @@ * limitations under the License. */ -/** - * File : LLCPServerSocket.java - * Original-Author : Trusted Logic S.A. (Daniel Tomas) - * Created : 18-02-2010 - */ - -package com.trustedlogic.trustednfc.android; +package com.android.internal.nfc; import java.io.IOException; import android.nfc.ErrorCodes; import android.nfc.ILlcpSocket; import android.nfc.ILlcpServiceSocket; - import android.os.RemoteException; import android.util.Log; /** * LlcpServiceSocket represents a LLCP Service to be used in a * Connection-oriented communication - * - * @since AA02.01 - * @hide */ public class LlcpServiceSocket { @@ -45,15 +35,11 @@ public class LlcpServiceSocket { /** * The handle returned by the NFC service and used to identify the LLCP * Service socket in every call of this class. - * - * @hide */ protected int mHandle; /** * The entry point for LLCP Service socket operations. - * - * @hide */ protected ILlcpServiceSocket mService; @@ -92,7 +78,6 @@ public class LlcpServiceSocket { * @param handle * The handle returned by the NFC service and used to identify * the socket in subsequent calls. - * @hide */ LlcpServiceSocket(ILlcpServiceSocket service, ILlcpSocket socketService, int handle) { this.mService = service; @@ -112,7 +97,6 @@ public class LlcpServiceSocket { * if not enough ressources are available * * @see LlcpSocket - * @since AA02.01 */ public LlcpSocket accept() throws IOException, LlcpException { @@ -141,7 +125,6 @@ public class LlcpServiceSocket { * * @param timeout * value of the timeout for the accept request - * @since AA02.01 */ public void setAcceptTimeout(int timeout) { try { @@ -155,7 +138,6 @@ public class LlcpServiceSocket { * Get the timeout value of the accept request * * @return mTimeout - * @since AA02.01 */ public int getAcceptTimeout() { try { @@ -168,8 +150,6 @@ public class LlcpServiceSocket { /** * Close the created Llcp Service socket - * - * @since AA02.01 */ public void close() { try { @@ -178,5 +158,4 @@ public class LlcpServiceSocket { Log.e(TAG, "RemoteException in close(): ", e); } } - } diff --git a/core/java/com/trustedlogic/trustednfc/android/LlcpSocket.java b/core/java/com/android/internal/nfc/LlcpSocket.java index ebde3e1..ae74002 100644 --- a/core/java/com/trustedlogic/trustednfc/android/LlcpSocket.java +++ b/core/java/com/android/internal/nfc/LlcpSocket.java @@ -14,28 +14,18 @@ * limitations under the License. */ -/** - * File : LlcpClientSocket.java - * Original-Author : Trusted Logic S.A. (Daniel Tomas) - * Created : 18-02-2010 - */ - -package com.trustedlogic.trustednfc.android; +package com.android.internal.nfc; import java.io.IOException; import android.nfc.ErrorCodes; import android.nfc.ILlcpSocket; - import android.os.RemoteException; import android.util.Log; /** * LlcpClientSocket represents a LLCP Connection-Oriented client to be used in a * connection-oriented communication - * - * @since AA02.01 - * @hide */ public class LlcpSocket { @@ -44,15 +34,11 @@ public class LlcpSocket { /** * The handle returned by the NFC service and used to identify the LLCP * socket in every call of this class. - * - * @hide */ protected int mHandle; /** * The entry point for LLCP socket operations. - * - * @hide */ protected ILlcpSocket mService; @@ -92,7 +78,6 @@ public class LlcpSocket { * @param handle * The handle returned by the NFC service and used to identify * the socket in subsequent calls. - * @hide */ LlcpSocket(ILlcpSocket service, int handle) { this.mService = service; @@ -109,7 +94,6 @@ public class LlcpSocket { * @throws LlcpException * if the connection request is rejected by the remote LLCP * Service - * @since AA02.01 */ public void connect(int sap) throws IOException, LlcpException { try { @@ -137,7 +121,6 @@ public class LlcpSocket { * @throws LlcpException * if the connection request is rejected by the remote LLCP * Service - * @since AA02.01 */ public void connect(String sn) throws IOException, LlcpException { try { @@ -160,7 +143,6 @@ public class LlcpSocket { * * @param timeout * timeout value for the connect request - * @since AA02.01 */ public void setConnectTimeout(int timeout) { try { @@ -174,7 +156,6 @@ public class LlcpSocket { * Get the timeout value of the connect request * * @return mTimeout - * @since AA02.01 */ public int getConnectTimeout() { try { @@ -191,7 +172,6 @@ public class LlcpSocket { * * @throws IOException * if the LLCP has been lost or deactivated. - * @since AA02.01 */ public void close() throws IOException { try { @@ -210,7 +190,6 @@ public class LlcpSocket { * * @throws IOException * if the LLCP has been lost or deactivated. - * @since AA02.01 */ public void send(byte[] data) throws IOException { try { @@ -232,7 +211,6 @@ public class LlcpSocket { * @return length length of the data received * @throws IOException * if the LLCP has been lost or deactivated. - * @since AA02.01 */ public int receive(byte[] receiveBuffer) throws IOException { int receivedLength = 0; @@ -252,7 +230,6 @@ public class LlcpSocket { * Returns the local Service Access Point number of the socket * * @return localSap - * @since AA02.01 */ public int getLocalSap() { try { @@ -267,7 +244,6 @@ public class LlcpSocket { * Returns the local Maximum Information Unit(MIU) of the socket * * @return miu - * @since AA02.01 */ public int getLocalSocketMiu() { try { @@ -282,7 +258,6 @@ public class LlcpSocket { * Returns the local Receive Window(RW) of the socket * * @return rw - * @since AA02.01 */ public int getLocalSocketRw() { try { @@ -301,7 +276,6 @@ public class LlcpSocket { * @return remoteMiu * @throws LlcpException * if the LlcpClientSocket is not in a CONNECTED_STATE - * @since AA02.01 */ public int getRemoteSocketMiu() throws LlcpException { try { @@ -325,7 +299,6 @@ public class LlcpSocket { * @return rw * @throws LlcpException * if the LlcpClientSocket is not in a CONNECTED_STATE - * @since AA02.01 */ public int getRemoteSocketRw() throws LlcpException { try { @@ -340,6 +313,4 @@ public class LlcpSocket { return 0; } } - - } diff --git a/core/java/com/trustedlogic/trustednfc/android/NfcException.java b/core/java/com/android/internal/nfc/NfcException.java index 2497c15..29a99c6 100644 --- a/core/java/com/trustedlogic/trustednfc/android/NfcException.java +++ b/core/java/com/android/internal/nfc/NfcException.java @@ -14,20 +14,11 @@ * limitations under the License. */ -/** - * File : NFCException.java - * Original-Author : Trusted Logic S.A. (Jeremie Corbier) - * Created : 26-08-2009 - */ - -package com.trustedlogic.trustednfc.android; +package com.android.internal.nfc; /** * Generic exception thrown in case something unexpected happened during the * NFCManager operations. - * - * @since AA01.04 - * @hide */ public class NfcException extends Exception { /** diff --git a/core/java/com/trustedlogic/trustednfc/android/P2pDevice.java b/core/java/com/android/internal/nfc/P2pDevice.java index 65800f2..8ab9aad 100644 --- a/core/java/com/trustedlogic/trustednfc/android/P2pDevice.java +++ b/core/java/com/android/internal/nfc/P2pDevice.java @@ -14,20 +14,13 @@ * limitations under the License. */ -/** - * File : P2PDevice.java - * Original-Author : Trusted Logic S.A. (Daniel Tomas) - * Created : 26-02-2010 - */ - -package com.trustedlogic.trustednfc.android; +package com.android.internal.nfc; import java.io.IOException; /** * P2pDevice is the abstract base class for all supported P2P targets the * NfcManager can handle. - * @hide */ public abstract class P2pDevice { @@ -48,19 +41,16 @@ public abstract class P2pDevice { /** * Target handle, used by native calls. - * @hide */ protected int mHandle; /** * Flag set when the object is closed and thus not usable any more. - * @hide */ protected boolean isClosed = false; /** * Prevent default constructor to be public. - * @hide */ protected P2pDevice() { } diff --git a/core/java/com/trustedlogic/trustednfc/android/P2pInitiator.java b/core/java/com/android/internal/nfc/P2pInitiator.java index 6b93bce..46ae9ab 100644 --- a/core/java/com/trustedlogic/trustednfc/android/P2pInitiator.java +++ b/core/java/com/android/internal/nfc/P2pInitiator.java @@ -14,12 +14,7 @@ * limitations under the License. */ -/** - * File : P2PInitiator.java - * Original-Author : Trusted Logic S.A. (Daniel Tomas) - */ - -package com.trustedlogic.trustednfc.android; +package com.android.internal.nfc; import java.io.IOException; @@ -32,8 +27,6 @@ import android.util.Log; * communication. * * @see P2pTarget - * @since AA02.01 - * @hide */ public class P2pInitiator extends P2pDevice { @@ -41,7 +34,6 @@ public class P2pInitiator extends P2pDevice { /** * The entry point for P2P tag operations. - * @hide */ private final IP2pInitiator mService; @@ -50,8 +42,6 @@ public class P2pInitiator extends P2pDevice { * * @param handle The handle returned by the NFC service and used to identify * the tag in subsequent calls. - * - * @hide */ P2pInitiator(IP2pInitiator service, int handle) { this.mService = service; diff --git a/core/java/com/trustedlogic/trustednfc/android/P2pTarget.java b/core/java/com/android/internal/nfc/P2pTarget.java index aa9e94f..7b59da3 100644 --- a/core/java/com/trustedlogic/trustednfc/android/P2pTarget.java +++ b/core/java/com/android/internal/nfc/P2pTarget.java @@ -14,12 +14,7 @@ * limitations under the License. */ -/** - * File : P2PTarget.java - * Original-Author : Trusted Logic S.A. (Daniel Tomas) - */ - -package com.trustedlogic.trustednfc.android; +package com.android.internal.nfc; import java.io.IOException; @@ -32,8 +27,6 @@ import android.util.Log; * P2pTarget represents the target in an NFC-IP1 peer-to-peer communication. * * @see P2pInitiator - * @since AA02.01 - * @hide */ public class P2pTarget extends P2pDevice { @@ -41,19 +34,16 @@ public class P2pTarget extends P2pDevice { /** * The entry point for P2P tag operations. - * @hide */ private final IP2pTarget mService; /** * Flag set when the object is closed and thus not usable any more. - * @hide */ private final boolean isClosed = false; /** * Flag set when the tag is connected. - * @hide */ private boolean isConnected = false; @@ -62,8 +52,6 @@ public class P2pTarget extends P2pDevice { * * @return data sent by the P2pInitiator. * @throws NfcException if accessing a closed target. - * - * @hide */ public void checkState() throws NfcException { if(isClosed) { @@ -76,8 +64,6 @@ public class P2pTarget extends P2pDevice { * * @param handle The handle returned by the NFC service and used to identify * the tag in subsequent calls. - * - * @hide */ P2pTarget(IP2pTarget service, int handle) { this.mService = service; @@ -181,5 +167,4 @@ public class P2pTarget extends P2pDevice { public int getMode() { return P2pDevice.MODE_P2P_TARGET; } - } diff --git a/core/java/com/trustedlogic/trustednfc/android/package.html b/core/java/com/trustedlogic/trustednfc/android/package.html deleted file mode 100644 index 0c0b605..0000000 --- a/core/java/com/trustedlogic/trustednfc/android/package.html +++ /dev/null @@ -1,473 +0,0 @@ -<html> -<body> - -<p>Provides classes that manage the NFC functionality.</p> - -<p>The NFC functionality is related to Near Field Communication.</p> - -<p>The NFC APIs let applications:</p> -<ul> - <li>Scan for remote NFC targets (NFC Tag or NFC Peer)</li> - <li>Transfer raw data to and from remote NFC targets (NFC Tags or NFC Peer)</li> - <li>Read/Write NDEF data from/to remote NFC targets (NFC Tags)</li> - <li>Establish LLCP connection with a remote NFC target (NFC Peer with LLCP support)</li> - <li>Exchange data with a remote NFC target through LLCP services (NFC Peer with LLCP support)</li> - <li>Be notified of transactions on the local Secure Element by an external NFC reader</li> -</ul> - - -<h1>Setting Up NFC</h1> - -<p> -Before an application can use the NFC feature, it needs to check if NFC is -supported on the device by getting an instance of the -{@link com.trustedlogic.trustednfc.android.NfcManager} class. -</p> - -<pre> - NfcManager mNfcManager = (NfcManager) getSystemService(Context.NFC_SERVICE); - if (mNfcManager == null) { - // Device does not support NFC - } -</pre> - -<p> -An application can ensure that NFC is enabled. -If not, an application with the needed permission can request that NFC be -enabled. -</p> - -<pre> - if (!mNfcManager.isEnabled) { - // NFC is currently disabled. - // Enable NFC. - mNfcManager.enable(); - } -</pre> - -<p> -Before using the card emulation mode, an application can ensure that a secure -element is selected ({@link com.trustedlogic.trustednfc.android.NfcManager#getSelectedSecureElement}). -If not, an application with the needed permission can recover the list of -available secure elements on the device -({@link com.trustedlogic.trustednfc.android.NfcManager#getSecureElementList}) and select one -({@link com.trustedlogic.trustednfc.android.NfcManager#selectSecureElement}). -</p> - -<p> -Before using the NFC feature, an application can configure the NFC device by -calling {@link com.trustedlogic.trustednfc.android.NfcManager#setProperties}. This function allows: -</p> -<ul> - <li>Enabling/disabling the NFC device capabilities (RF types, baudrates, - NFCIP-1 mode and role...)</li> - <li>Settings the NFCIP-1 general bytes and the LLCP link parameters</li> -</ul> -<p> -The setting properties can be customized according to the Device capabilities. -The next table give the minimal set of properties supported by the Device. -Depending on the implementation, the table may be completed. -</p> -<table> - <TR><TH> Property Name </TH><TH> Property Values </TH></TR> - <TR><TD> discovery.felica </TD><TD> <b>true</b>|false </TD></TR> - <TR><TD> discovery.iso14443A </TD><TD> <b>true</b>|false </TD></TR> - <TR><TD> discovery.iso14443B </TD><TD> <b>true</b>|false </TD></TR> - <TR><TD> discovery.iso15693 </TD><TD> <b>true</b>|false </TD></TR> - <TR><TD> discovery.nfcip </TD><TD> <b>true</b>|false </TD></TR> - <TR><TD> nfcip.baudrate </TD><TD> 106|212|424 </TD></TR> - <TR><TD> nfcip.generalbytes </TD><TD> </TD></TR> - <TR><TD> nfcip.mode </TD><TD> active|passive|<b>all</b> </TD></TR> - <TR><TD> nfcip.role </TD><TD> initiator|target|<b>both</b> </TD></TR> - <TR><TD> llcp.lto </TD><TD> <b>150</b> (0 to 255) </TD></TR> - <TR><TD> llcp.opt </TD><TD> <b>0</b> (0 to 3) </TD></TR> - <TR><TD> llcp.miu </TD><TD> <b>128</b> (128 to 2176) </TD></TR> - <TR><TD> llcp.wks </TD><TD> <b>1</b> (0 to 15) </TD></TR> -</table> -<p>(default values in bold)</p> - - -<h1>NFC Permissions</h1> - -<p> -To change the NFC service settings such as enabling the NFC targets -discovery or activating the secure element, an application must declare the -NFC_ADMIN permission. -</p> -<p> -To perform NFC raw communication with a remote NFC target in -Reader/Write Mode or Peer-to-Peer Mode, an application must declare the NFC_RAW -permission. -</p> -<p> -To receive NDEF message or Secure Element intents, an application must declare -the NFC_NOTIFY permission. -</p> -<p> -To receive the LLCP link intent and perform an LLCP communication with a remote NFC target, an application must -declare the NFC_LLCP permission. -</p> - - -<h1>NFC Usage</h1> - -<p> -The following code samples illustrate the APIs usage regarding the NFC service -use cases. -</p> - -<h2>Reader/Writer Mode NDEF message notification</h2> - -<p> -This code sample illustrates the NDEF message notification through an Intent declared in the manifest and a receiver implemented in the application. -</p> -<p>Main involved classes/methods:</p> - -<p>Manifest Example:</p> -<pre> - <receiver android:name=".NfcReaderDemoReceiver"> - <intent-filter> - <action android:name= "com.trustedlogic.trustednfc.android.action.NDEF_TAG_DISCOVERED"/> - </intent-filter> - </receiver> -</pre> - -<p>Receiver Example:</p> -<ul> - <li>{@link com.trustedlogic.trustednfc.android.NdefMessage}</li> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#NDEF_TAG_DISCOVERED_ACTION}</li> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#NDEF_MESSAGE_EXTRA}</li> -</ul> -<pre> -public class NdefMessageReceiverSample extends BroadcastReceiver { - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(NfcManager.NDEF_TAG_DISCOVERERD_ACTION)) { - NdefMessage msg = intent.getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA); - - /* Manage the NdefMessage received */ - } -</pre> - -<h2>Reader/Writer Mode raw exchange</h2> - -<p> -This code sample illustrates raw exchanges with a NFC target in Reader/Writer -mode. -</p> -<p>Main involved classes/methods:</p> -<ul> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#openTagConnection}</li> - <li>{@link com.trustedlogic.trustednfc.android.NfcTag}</li> -</ul> - -<pre> -public class TagReaderSample { - - /** The NFC manager to access NFC features */ - private NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE); - - private void runTagReader() { - NfcTag tag = null; - String type; - byte[] cmd = { 0x01, 0x02, 0x03 }; - byte[] res; - - while (true) { - try { - Log.i("NFC example", "Please wave in front of the tag"); - // Open a connection on next available tag - try { - tag = manager.openTagConnection(); - } catch (NfcException e) { - // TODO: Handle open failure - } - - // Look for a mifare 4k - type = tag.getType(); - if (type.equals("Mifare4K")) { - Log.i("NFC example", "Tag detected"); - tag.connect(); - // Ready to communicate, we can send transceive ! - res = tag.transceive(cmd); - } else { - Log.i("NFC example", "Unknown tag"); - } - } catch (IOException e) { - // TODO: Handle broken connection - } finally { - if (tag != null) { - tag.close(); - } - } - } - } -} -</pre> - -<h2>Peer-to-Peer Mode raw exchange</h2> - -<p> -This code sample illustrates raw exchanges with a NFC target in Peer-to-Peer -mode. -</p> -<p>Main involved classes/methods:</p> -<ul> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#openP2pConnection}</li> - <li>{@link com.trustedlogic.trustednfc.android.P2pDevice}</li> - <li>{@link com.trustedlogic.trustednfc.android.P2pInitiator}</li> - <li>{@link com.trustedlogic.trustednfc.android.P2pTarget}</li> -</ul> - -<pre> -public class P2pSample { - - /** The NFC manager to access NFC features */ - private NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE); - - private void runP2p() { - P2pDevice deviceP2p; - P2pInitiator initiator; - P2pTarget target; - byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - byte[] echo = new byte[data.length * 10]; - - try { - deviceP2p = manager.openP2pConnection(); - - if (deviceP2p.getMode() == P2pDevice.MODE_P2P_INITIATOR) { - target = new P2pTarget(deviceP2p); - // Connect to the detected P2P target - target.connect(); - // send data to the target - target.transceive(data); - // disconnect the connected target - target.disconnect(); - } else if (deviceP2p.getMode() == P2pDevice.MODE_P2P_TARGET) { - initiator = new P2pInitiator(deviceP2p); - //target in receive state - echo = initiator.receive(); - // send back the data received - initiator.send(echo); - } - } catch (IOException e0) { - - } catch (NfcException e1) { - - } - } -} -</pre> - -<h2>Peer-to-Peer Mode LLCP exchange</h2> - -<p> -This code sample illustrates how to get LLCP link state notification with the declaration of a Receiver in the manifest of the application and the implementation -of the receiver in the application. -</p> -<p>Manifest Example:</p> -<pre> - <receiver android:name=".LlcpModeReceiverSample"> - <intent-filter> - <action android:name= "com.trustedlogic.trustednfc.android.action.LLCP_LINK_STATE_CHANGED"/> - </intent-filter> - </receiver> -</pre> - -<p>Receiver Example:</p> -<ul> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#LLCP_LINK_STATE_CHANGED_ACTION}</li> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#LLCP_LINK_STATE_CHANGED_EXTRA}</li> -</ul> -<pre> -public class LlcpModeReceiverSample extends BroadcastReceiver { - public void onReceive(Context context, Intent intent) { - - if (intent.getAction().equals(NfcManager.LLCP_LINK_STATE_CHANGED_ACTION)){ - byte[] aid = intent.getByteArrayExtra(NfcManager.LLCP_LINK_STATE_CHANGED_EXTRA); - /* Create an LLCP service or client and start an LLCP communication */ - } - } -</pre> - - -<p> -This code samples illustrate LLCP exchanges with a NFC Peer. -</p> -<p>Main involved classes/methods:</p> -<ul> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpSocket}</li> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpConnectionlessSocket}</li> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpServiceSocket}</li> - <li>{@link com.trustedlogic.trustednfc.android.LlcpSocket}</li> - <li>{@link com.trustedlogic.trustednfc.android.LlcpConnectionlessSocket}</li> - <li>{@link com.trustedlogic.trustednfc.android.LlcpPacket}</li> - <li>{@link com.trustedlogic.trustednfc.android.LlcpServiceSocket}</li> -</ul> - -<pre> -public class LlcpServerSample { - - /** The NFC manager to access NFC features */ - private NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE); - - private void runLlcpClient() { - LlcpSocket sock; - byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - byte[] echo = new byte[data.length * 10]; - int length = 0; - - sock = manager.createLlcpSocket((short) 128, (byte) 2, 1024); - - // set a timeout in ms for connect request - sock.setConnectTimeout(10); - - try { - // Connect to remote service - // NOTE: could be sock.connect("com.trusted-logic.tnfc.testapp"); - sock.connect((byte) 0x10); - - // Send data - for (int i = 0; i < 10; i++) { - sock.send(data); - } - - // Receive echo - while (length < 10 * data.length) { - length += sock.receive(echo); - } - - } catch (IOException e) { - // TODO: Handle broken connection broken (link down, remote closure - // or connect rejected) or Timeout expired - } - } -} -</pre> - -<pre> -public class LlcpClientSample { - - /** The NFC manager to access NFC features */ - private NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE); - - private void runLlcpClient() { - LlcpSocket sock; - byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - byte[] echo = new byte[data.length * 10]; - int length = 0; - - sock = manager.createLlcpSocket((short) 128, (byte) 2, 1024); - try { - // Connect to remote service - // NOTE: could be sock.connect("com.trusted-logic.tnfc.testapp"); - sock.connect((byte) 0x10); - - // Send data - for (int i = 0; i < 10; i++) { - sock.send(data); - } - - // Receive echo - while (length < 10 * data.length) { - length += sock.receive(echo); - } - - } catch (IOException e) { - // TODO: Handle broken connection broken (link down, remote closure - // or connect rejected) - } - } -} -</pre> - -<h2>Card Emulation Mode transaction notification</h2> - -<p> -This code sample illustrates how to get the card emulation notification with the declaration of a Receiver in the manifest of the application and the implementation -of the receiver in the application. -</p> -<p>Manifest Example:</p> -<pre> - <receiver android:name=".NfcReaderDemoReceiver"> - <intent-filter> - <action android:name= "com.trustedlogic.trustednfc.android.action.TRANSACTION_DETECTED"/> - </intent-filter> - </receiver> -</pre> - -<p>Receiver Example:</p> -<ul> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#TRANSACTION_DETECTED_ACTION}</li> - <li>{@link com.trustedlogic.trustednfc.android.NfcManager#AID_EXTRA}</li> -</ul> -<pre> -public class CardEmulationReceiverSample extends BroadcastReceiver { - public void onReceive(Context context, Intent intent) { - - if (intent.getAction().equals(NfcManager.TRANSACTION_DETECTED_ACTION)){ - byte[] aid = intent.getByteArrayExtra(NfcManager.AID_EXTRA); - /* Manage the AID: */ - /* For example start an activity related to this AID value or display a popup with the AID */ - } - } -</pre> - - - -<h1>Multiple Applications rules</h1> - -<p> -Several LLCP sockets can be created by a single application or by multiple -applications by calling {@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpSocket}, -{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpConnectionlessSocket} or -{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpServiceSocket}, provided the local SAP -numbers are differents. -</p> - -<p> -Only one application can open a raw connection by calling -{@link com.trustedlogic.trustednfc.android.NfcManager#openTagConnection} or -{@link com.trustedlogic.trustednfc.android.NfcManager#openP2pConnection}. -While this application has not closed or cancelled its connection, any other -application that attempts to open another raw connection will raise an -exception. -During an open connnection, the card emulation mode is always enabled and -applications are able to receive card emulation intents. -</p> - -<p> -When an application opens a tag connection by calling -{@link com.trustedlogic.trustednfc.android.NfcManager#openTagConnection}, this operation is exclusive, no NDEF message intent are -broadcast while the connection is not closed or canceled. -</p> - -<p> -When an application opens a peer-to-peer connection by calling -{@link com.trustedlogic.trustednfc.android.NfcManager#openP2pConnection}, this operation is exclusive, no LLCP intent are broadcast and LLCP sockets are -disabled while the connection is not closed or canceled. -</p> - - -<h1>NFC Tag types</h1> - -<p> -The {@link com.trustedlogic.trustednfc.android.NfcTag} type returned by -{@link com.trustedlogic.trustednfc.android.NfcTag#getType} indicates the set of -commands supported by the tag. These commands can be used in -{@link com.trustedlogic.trustednfc.android.NfcTag#transceive}. -</p> - -<TABLE BORDER="1"> - <TR><TH> Tag Type </TH><TH> Returned string </TH></TR> - <TR><TD> Jewel/Topaz </TD><TD> Jewel </TD></TR> - <TR><TD> Mifare UltraLight </TD><TD> MifareUL </TD></TR> - <TR><TD> Mifare Standard 1K </TD><TD> Mifare1K </TD></TR> - <TR><TD> Mifare Standard 4K </TD><TD> Mifare4K </TD></TR> - <TR><TD> Mifare DESFIRE </TD><TD> MifareDESFIRE </TD></TR> - <TR><TD> Felica </TD><TD> Felica </TD></TR> - <TR><TD> ISO14443-4 A or B </TD><TD> Iso14443 </TD></TR> - <TR><TD> ISO15693 </TD><TD> Iso15693 </TD></TR> -</TABLE> - -</body> -</html> diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 3e99541..122fdf8 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -343,29 +343,12 @@ android:description="@string/permdesc_bluetooth" android:label="@string/permlab_bluetooth" /> - <!-- Allows applications to access remote NFC devices - @hide --> - <permission android:name="com.trustedlogic.trustednfc.permission.NFC_RAW" + <!-- Allows applications to directly communicate over NFC --> + <permission android:name="android.permission.NFC" android:permissionGroup="android.permission-group.NETWORK" android:protectionLevel="dangerous" - android:description="@string/permdesc_nfcRaw" - android:label="@string/permlab_nfcRaw" /> - - <!-- Allows applications to be notified of remote NFC devices - @hide --> - <permission android:name="com.trustedlogic.trustednfc.permission.NFC_NOTIFY" - android:permissionGroup="android.permission-group.NETWORK" - android:protectionLevel="dangerous" - android:description="@string/permdesc_nfcNotify" - android:label="@string/permlab_nfcNotify" /> - - <!-- Allows applications to be notified of remote NFC LLCP devices - @hide --> - <permission android:name="com.trustedlogic.trustednfc.permission.NFC_LLCP" - android:permissionGroup="android.permission-group.NETWORK" - android:protectionLevel="dangerous" - android:description="@string/permdesc_nfcLlcp" - android:label="@string/permlab_nfcLlcp" /> + android:description="@string/permdesc_nfc" + android:label="@string/permlab_nfc" /> <!-- Allows an application to use SIP service --> <permission android:name="android.permission.USE_SIP" @@ -884,14 +867,6 @@ android:description="@string/permdesc_bluetoothAdmin" android:label="@string/permlab_bluetoothAdmin" /> - <!-- Allows applications to change NFC connectivity settings - @hide --> - <permission android:name="com.trustedlogic.trustednfc.permission.NFC_ADMIN" - android:permissionGroup="android.permission-group.SYSTEM_TOOLS" - android:protectionLevel="dangerous" - android:description="@string/permdesc_nfcAdmin" - android:label="@string/permlab_nfcAdmin" /> - <!-- Allows an application to clear the caches of all installed applications on the device. --> <permission android:name="android.permission.CLEAR_APP_CACHE" diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 1d2e780..edb0819 100755 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -1166,28 +1166,10 @@ connections with paired devices.</string> <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permlab_nfcAdmin">NFC administration</string> + <string name="permlab_nfc">control Near Field Communication</string> <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permdesc_nfcAdmin">Allows an application to configure - the local NFC phone.</string> - - <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permlab_nfcRaw">NFC full access to remote device</string> - <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permdesc_nfcRaw">Allows an application to access - remote NFC devices.</string> - - <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permlab_nfcNotify">NFC notification from remote device</string> - <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permdesc_nfcNotify">Allows an application to be notified - of operations related to remote NFC devices.</string> - - <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permlab_nfcLlcp">NFC notification from remote LLCP device</string> - <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permdesc_nfcLlcp">Allows an application to be notified - of LLCP operations related to remote NFC devices.</string> + <string name="permdesc_nfc">Allows an application to communicate + with Near Field Communication (NFC) tags, cards, and readers.</string> <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> <string name="permlab_disableKeyguard">disable keylock</string> diff --git a/include/ui/InputReader.h b/include/ui/InputReader.h index eb88d8b..2d4bf8b 100644 --- a/include/ui/InputReader.h +++ b/include/ui/InputReader.h @@ -584,6 +584,16 @@ protected: // Immutable calibration parameters in parsed form. struct Calibration { + // Position + bool haveXOrigin; + int32_t xOrigin; + bool haveYOrigin; + int32_t yOrigin; + bool haveXScale; + float xScale; + bool haveYScale; + float yScale; + // Touch Size enum TouchSizeCalibration { TOUCH_SIZE_CALIBRATION_DEFAULT, diff --git a/libs/ui/InputReader.cpp b/libs/ui/InputReader.cpp index 01ebda9..88b91e0 100644 --- a/libs/ui/InputReader.cpp +++ b/libs/ui/InputReader.cpp @@ -1344,7 +1344,7 @@ void TouchInputMapper::dump(String8& dump) { dumpRawAxes(dump); dumpCalibration(dump); dumpSurfaceLocked(dump); - dump.appendFormat(INDENT3 "Translation and Scaling Factors:"); + dump.appendFormat(INDENT3 "Translation and Scaling Factors:\n"); dump.appendFormat(INDENT4 "XOrigin: %d\n", mLocked.xOrigin); dump.appendFormat(INDENT4 "YOrigin: %d\n", mLocked.yOrigin); dump.appendFormat(INDENT4 "XScale: %0.3f\n", mLocked.xScale); @@ -1481,10 +1481,18 @@ bool TouchInputMapper::configureSurfaceLocked() { // Configure X and Y factors. if (mRawAxes.x.valid && mRawAxes.y.valid) { - mLocked.xOrigin = mRawAxes.x.minValue; - mLocked.yOrigin = mRawAxes.y.minValue; - mLocked.xScale = float(width) / mRawAxes.x.getRange(); - mLocked.yScale = float(height) / mRawAxes.y.getRange(); + mLocked.xOrigin = mCalibration.haveXOrigin + ? mCalibration.xOrigin + : mRawAxes.x.minValue; + mLocked.yOrigin = mCalibration.haveYOrigin + ? mCalibration.yOrigin + : mRawAxes.y.minValue; + mLocked.xScale = mCalibration.haveXScale + ? mCalibration.xScale + : float(width) / mRawAxes.x.getRange(); + mLocked.yScale = mCalibration.haveYScale + ? mCalibration.yScale + : float(height) / mRawAxes.y.getRange(); mLocked.xPrecision = 1.0f / mLocked.xScale; mLocked.yPrecision = 1.0f / mLocked.yScale; @@ -1750,6 +1758,12 @@ void TouchInputMapper::parseCalibration() { const InputDeviceCalibration& in = getDevice()->getCalibration(); Calibration& out = mCalibration; + // Position + out.haveXOrigin = in.tryGetProperty(String8("touch.position.xOrigin"), out.xOrigin); + out.haveYOrigin = in.tryGetProperty(String8("touch.position.yOrigin"), out.yOrigin); + out.haveXScale = in.tryGetProperty(String8("touch.position.xScale"), out.xScale); + out.haveYScale = in.tryGetProperty(String8("touch.position.yScale"), out.yScale); + // Touch Size out.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_DEFAULT; String8 touchSizeCalibrationString; @@ -1959,6 +1973,20 @@ void TouchInputMapper::resolveCalibration() { void TouchInputMapper::dumpCalibration(String8& dump) { dump.append(INDENT3 "Calibration:\n"); + // Position + if (mCalibration.haveXOrigin) { + dump.appendFormat(INDENT4 "touch.position.xOrigin: %d\n", mCalibration.xOrigin); + } + if (mCalibration.haveYOrigin) { + dump.appendFormat(INDENT4 "touch.position.yOrigin: %d\n", mCalibration.yOrigin); + } + if (mCalibration.haveXScale) { + dump.appendFormat(INDENT4 "touch.position.xScale: %0.3f\n", mCalibration.xScale); + } + if (mCalibration.haveYScale) { + dump.appendFormat(INDENT4 "touch.position.yScale: %0.3f\n", mCalibration.yScale); + } + // Touch Size switch (mCalibration.touchSizeCalibration) { case Calibration::TOUCH_SIZE_CALIBRATION_NONE: |
