diff options
| -rw-r--r-- | core/api/current.txt | 21 | ||||
| -rw-r--r-- | core/java/android/nfc/AvailableNfcAntenna.aidl | 19 | ||||
| -rw-r--r-- | core/java/android/nfc/AvailableNfcAntenna.java | 117 | ||||
| -rw-r--r-- | core/java/android/nfc/INfcAdapter.aidl | 2 | ||||
| -rw-r--r-- | core/java/android/nfc/NfcAdapter.java | 31 | ||||
| -rw-r--r-- | core/java/android/nfc/NfcAntennaInfo.aidl | 19 | ||||
| -rw-r--r-- | core/java/android/nfc/NfcAntennaInfo.java | 117 |
7 files changed, 326 insertions, 0 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 2f1845f9c18f..b9ad95b2d80d 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -27354,6 +27354,15 @@ package android.net.vcn { package android.nfc { + public final class AvailableNfcAntenna implements android.os.Parcelable { + ctor public AvailableNfcAntenna(int, int); + method public int describeContents(); + method public int getLocationX(); + method public int getLocationY(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator<android.nfc.AvailableNfcAntenna> CREATOR; + } + public class FormatException extends java.lang.Exception { ctor public FormatException(); ctor public FormatException(String); @@ -27415,6 +27424,7 @@ package android.nfc { method @Deprecated public void enableForegroundNdefPush(android.app.Activity, android.nfc.NdefMessage); method public void enableReaderMode(android.app.Activity, android.nfc.NfcAdapter.ReaderCallback, int, android.os.Bundle); method public static android.nfc.NfcAdapter getDefaultAdapter(android.content.Context); + method @Nullable public android.nfc.NfcAntennaInfo getNfcAntennaInfo(); method public boolean ignore(android.nfc.Tag, int, android.nfc.NfcAdapter.OnTagRemovedListener, android.os.Handler); method @Deprecated public boolean invokeBeam(android.app.Activity); method public boolean isEnabled(); @@ -27477,6 +27487,17 @@ package android.nfc { method public void onTagDiscovered(android.nfc.Tag); } + public final class NfcAntennaInfo implements android.os.Parcelable { + ctor public NfcAntennaInfo(int, int, boolean, @NonNull java.util.List<android.nfc.AvailableNfcAntenna>); + method public int describeContents(); + method @NonNull public java.util.List<android.nfc.AvailableNfcAntenna> getAvailableNfcAntennas(); + method public int getDeviceHeight(); + method public int getDeviceWidth(); + method public boolean isDeviceFoldable(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator<android.nfc.NfcAntennaInfo> CREATOR; + } + public final class NfcEvent { field public final android.nfc.NfcAdapter nfcAdapter; field public final int peerLlcpMajorVersion; diff --git a/core/java/android/nfc/AvailableNfcAntenna.aidl b/core/java/android/nfc/AvailableNfcAntenna.aidl new file mode 100644 index 000000000000..9d06e2d7d5eb --- /dev/null +++ b/core/java/android/nfc/AvailableNfcAntenna.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.nfc; + +parcelable AvailableNfcAntenna; diff --git a/core/java/android/nfc/AvailableNfcAntenna.java b/core/java/android/nfc/AvailableNfcAntenna.java new file mode 100644 index 000000000000..946ba67b2397 --- /dev/null +++ b/core/java/android/nfc/AvailableNfcAntenna.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.nfc; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Represents a single available Nfc antenna + * on an Android device. + */ +public final class AvailableNfcAntenna implements Parcelable { + /** + * Location on the antenna on the Y axis in millimeters. + * 0 is the bottom-left when the user is facing the screen. + */ + private final int mLocationX; + /** + * Location on the antenna on the Y axis in millimeters. + * 0 is the bottom-left when the user is facing the screen. + */ + private final int mLocationY; + + public AvailableNfcAntenna(int locationX, int locationY) { + this.mLocationX = locationX; + this.mLocationY = locationY; + } + + /** + * Location on the antenna on the X axis in millimeters. + * 0 is the bottom-left when the user is facing the screen. + */ + public int getLocationX() { + return mLocationX; + } + + /** + * Location on the antenna on the Y axis in millimeters. + * 0 is the bottom-left when the user is facing the screen. + */ + public int getLocationY() { + return mLocationY; + } + + private AvailableNfcAntenna(Parcel in) { + this.mLocationX = in.readInt(); + this.mLocationY = in.readInt(); + } + + public static final @android.annotation.NonNull Parcelable.Creator<AvailableNfcAntenna> + CREATOR = new Parcelable.Creator<AvailableNfcAntenna>() { + @Override + public AvailableNfcAntenna createFromParcel(Parcel in) { + return new AvailableNfcAntenna(in); + } + + @Override + public AvailableNfcAntenna[] newArray(int size) { + return new AvailableNfcAntenna[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeInt(mLocationX); + dest.writeInt(mLocationY); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + mLocationX; + result = prime * result + mLocationY; + return result; + } + + /** + * Returns true if the specified AvailableNfcAntenna contains + * identical specifications. + */ + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + AvailableNfcAntenna other = (AvailableNfcAntenna) obj; + if (this.mLocationX != other.mLocationX) return false; + return this.mLocationY == other.mLocationY; + } + + @Override + public String toString() { + return "AvailableNfcAntenna " + "x: " + mLocationX + " y: " + mLocationY; + } +} diff --git a/core/java/android/nfc/INfcAdapter.aidl b/core/java/android/nfc/INfcAdapter.aidl index cb9a3e43db81..de107a2c7c70 100644 --- a/core/java/android/nfc/INfcAdapter.aidl +++ b/core/java/android/nfc/INfcAdapter.aidl @@ -31,6 +31,7 @@ import android.nfc.INfcFCardEmulation; import android.nfc.INfcUnlockHandler; import android.nfc.ITagRemovedCallback; import android.nfc.INfcDta; +import android.nfc.NfcAntennaInfo; import android.os.Bundle; /** @@ -72,6 +73,7 @@ interface INfcAdapter boolean isNfcSecureEnabled(); boolean deviceSupportsNfcSecure(); boolean setNfcSecure(boolean enable); + NfcAntennaInfo getNfcAntennaInfo(); boolean setControllerAlwaysOn(boolean value); boolean isControllerAlwaysOn(); diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index 3282d567d369..f545c305bda2 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -18,6 +18,7 @@ package android.nfc; import android.annotation.CallbackExecutor; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; @@ -1854,6 +1855,36 @@ public final class NfcAdapter { } /** + * Returns information regarding Nfc antennas on the device + * such as their relative positioning on the device. + * + * @return Information on the nfc antenna(s) on the device. + * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + */ + @Nullable + public NfcAntennaInfo getNfcAntennaInfo() { + if (!sHasNfcFeature) { + throw new UnsupportedOperationException(); + } + try { + return sService.getNfcAntennaInfo(); + } catch (RemoteException e) { + attemptDeadServiceRecovery(e); + // Try one more time + if (sService == null) { + Log.e(TAG, "Failed to recover NFC Service."); + return null; + } + try { + return sService.getNfcAntennaInfo(); + } catch (RemoteException ee) { + Log.e(TAG, "Failed to recover NFC Service."); + } + return null; + } + } + + /** * Checks Secure NFC feature is enabled. * * @return True if Secure NFC is enabled, false otherwise diff --git a/core/java/android/nfc/NfcAntennaInfo.aidl b/core/java/android/nfc/NfcAntennaInfo.aidl new file mode 100644 index 000000000000..d5e79fc37282 --- /dev/null +++ b/core/java/android/nfc/NfcAntennaInfo.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.nfc; + +parcelable NfcAntennaInfo; diff --git a/core/java/android/nfc/NfcAntennaInfo.java b/core/java/android/nfc/NfcAntennaInfo.java new file mode 100644 index 000000000000..d54fcd2ed5b3 --- /dev/null +++ b/core/java/android/nfc/NfcAntennaInfo.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.nfc; + +import android.annotation.NonNull; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; +import java.util.List; + + +/** + * Contains information on all available Nfc + * antennas on an Android device as well as information + * on the device itself in relation positioning of the + * antennas. + */ +public final class NfcAntennaInfo implements Parcelable { + // Width of the device in millimeters. + private final int mDeviceWidth; + // Height of the device in millimeters. + private final int mDeviceHeight; + // Whether the device is foldable. + private final boolean mDeviceFoldable; + // All available Nfc Antennas on the device. + private final List<AvailableNfcAntenna> mAvailableNfcAntennas; + + public NfcAntennaInfo(int deviceWidth, int deviceHeight, boolean deviceFoldable, + @NonNull List<AvailableNfcAntenna> availableNfcAntennas) { + this.mDeviceWidth = deviceWidth; + this.mDeviceHeight = deviceHeight; + this.mDeviceFoldable = deviceFoldable; + this.mAvailableNfcAntennas = availableNfcAntennas; + } + + /** + * Width of the device in millimeters. + */ + public int getDeviceWidth() { + return mDeviceWidth; + } + + /** + * Height of the device in millimeters. + */ + public int getDeviceHeight() { + return mDeviceHeight; + } + + /** + * Whether the device is foldable. When the device is foldable, + * the 0, 0 is considered to be bottom-left when the device is unfolded and + * the screens are facing the user. For non-foldable devices 0, 0 + * is bottom-left when the user is facing the screen. + */ + public boolean isDeviceFoldable() { + return mDeviceFoldable; + } + + /** + * Get all NFC antennas that exist on the device. + */ + @NonNull + public List<AvailableNfcAntenna> getAvailableNfcAntennas() { + return mAvailableNfcAntennas; + } + + private NfcAntennaInfo(Parcel in) { + this.mDeviceWidth = in.readInt(); + this.mDeviceHeight = in.readInt(); + this.mDeviceFoldable = in.readByte() != 0; + this.mAvailableNfcAntennas = new ArrayList<>(); + in.readParcelableList(this.mAvailableNfcAntennas, + AvailableNfcAntenna.class.getClassLoader()); + } + + public static final @NonNull Parcelable.Creator<NfcAntennaInfo> CREATOR = + new Parcelable.Creator<NfcAntennaInfo>() { + @Override + public NfcAntennaInfo createFromParcel(Parcel in) { + return new NfcAntennaInfo(in); + } + + @Override + public NfcAntennaInfo[] newArray(int size) { + return new NfcAntennaInfo[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeInt(mDeviceWidth); + dest.writeInt(mDeviceHeight); + dest.writeByte((byte) (mDeviceFoldable ? 1 : 0)); + dest.writeTypedList(mAvailableNfcAntennas, 0); + } +} |