diff options
| author | Ruchi Kandoi <kandoiruchi@google.com> | 2018-10-23 14:40:29 -0700 |
|---|---|---|
| committer | Ruchi Kandoi <kandoiruchi@google.com> | 2019-01-04 21:49:00 +0000 |
| commit | 96fe50bc1bb2c53b7e9d1069a14eec77a9c116d5 (patch) | |
| tree | b9c08170328317f1577a18dd2d311265809f083d /core/java/android | |
| parent | 54502d68ea0b966cfc99623bab9d406639892ff9 (diff) | |
Deprecate Android beam APIs and create a feature flag to gate them
Test: Test application trying to invoke the API
Bug: 117519147
Change-Id: Icd3187e4f3e0f180cb42d36011f60895fb395002
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/content/pm/PackageManager.java | 7 | ||||
| -rw-r--r-- | core/java/android/nfc/NfcAdapter.java | 72 |
2 files changed, 78 insertions, 1 deletions
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 25edf9cff5c7..83e8785f29f1 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -1931,6 +1931,13 @@ public abstract class PackageManager { /** * Feature for {@link #getSystemAvailableFeatures} and + * {@link #hasSystemFeature}: The Beam API is enabled on the device. + */ + @SdkConstant(SdkConstantType.FEATURE) + public static final String FEATURE_NFC_BEAM = "android.sofware.nfc.beam"; + + /** + * Feature for {@link #getSystemAvailableFeatures} and * {@link #hasSystemFeature}: The device supports any * one of the {@link #FEATURE_NFC}, {@link #FEATURE_NFC_HOST_CARD_EMULATION}, * or {@link #FEATURE_NFC_HOST_CARD_EMULATION_NFCF} features. diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index 877187053486..e55e0364f5d4 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -325,6 +325,7 @@ public final class NfcAdapter { // Guarded by NfcAdapter.class static boolean sIsInitialized = false; static boolean sHasNfcFeature; + static boolean sHasBeamFeature; // Final after first constructor, except for // attemptDeadServiceRecovery() when NFC crashes - we accept a best effort @@ -372,7 +373,9 @@ public final class NfcAdapter { * A callback to be invoked when the system successfully delivers your {@link NdefMessage} * to another device. * @see #setOnNdefPushCompleteCallback + * @deprecated this feature is deprecated. */ + @java.lang.Deprecated public interface OnNdefPushCompleteCallback { /** * Called on successful NDEF push. @@ -395,7 +398,9 @@ public final class NfcAdapter { * content currently visible to the user. Alternatively, you can call {@link * #setNdefPushMessage setNdefPushMessage()} if the {@link NdefMessage} always contains the * same data. + * @deprecated this feature is deprecated. */ + @java.lang.Deprecated public interface CreateNdefMessageCallback { /** * Called to provide a {@link NdefMessage} to push. @@ -421,7 +426,10 @@ public final class NfcAdapter { } - // TODO javadoc + /** + * @deprecated this feature is deprecated. + */ + @java.lang.Deprecated public interface CreateBeamUrisCallback { public Uri[] createBeamUris(NfcEvent event); } @@ -449,6 +457,25 @@ public final class NfcAdapter { public boolean onUnlockAttempted(Tag tag); } + /** + * Helper to check if this device has FEATURE_NFC_BEAM, but without using + * a context. + * Equivalent to + * context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_BEAM) + */ + private static boolean hasBeamFeature() { + IPackageManager pm = ActivityThread.getPackageManager(); + if (pm == null) { + Log.e(TAG, "Cannot get package manager, assuming no Android Beam feature"); + return false; + } + try { + return pm.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM, 0); + } catch (RemoteException e) { + Log.e(TAG, "Package manager query failed, assuming no Android Beam feature", e); + return false; + } + } /** * Helper to check if this device has FEATURE_NFC, but without using @@ -528,6 +555,7 @@ public final class NfcAdapter { public static synchronized NfcAdapter getNfcAdapter(Context context) { if (!sIsInitialized) { sHasNfcFeature = hasNfcFeature(); + sHasBeamFeature = hasBeamFeature(); boolean hasHceFeature = hasNfcHceFeature(); /* is this device meant to have NFC */ if (!sHasNfcFeature && !hasHceFeature) { @@ -953,12 +981,17 @@ public final class NfcAdapter { * @param uris an array of Uri(s) to push over Android Beam * @param activity activity for which the Uri(s) will be pushed * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @deprecated this feature is deprecated. */ + @java.lang.Deprecated public void setBeamPushUris(Uri[] uris, Activity activity) { synchronized (NfcAdapter.class) { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } + if (!sHasBeamFeature) { + return; + } } if (activity == null) { throw new NullPointerException("activity cannot be null"); @@ -1035,12 +1068,17 @@ public final class NfcAdapter { * @param callback callback, or null to disable * @param activity activity for which the Uri(s) will be pushed * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @deprecated this feature is deprecated. */ + @java.lang.Deprecated public void setBeamPushUrisCallback(CreateBeamUrisCallback callback, Activity activity) { synchronized (NfcAdapter.class) { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } + if (!sHasBeamFeature) { + return; + } } if (activity == null) { throw new NullPointerException("activity cannot be null"); @@ -1119,13 +1157,18 @@ public final class NfcAdapter { * to only register one at a time, and to do so in that activity's * {@link Activity#onCreate} * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @deprecated this feature is deprecated. */ + @java.lang.Deprecated public void setNdefPushMessage(NdefMessage message, Activity activity, Activity ... activities) { synchronized (NfcAdapter.class) { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } + if (!sHasBeamFeature) { + return; + } } int targetSdkVersion = getSdkVersion(); try { @@ -1232,13 +1275,18 @@ public final class NfcAdapter { * to only register one at a time, and to do so in that activity's * {@link Activity#onCreate} * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @deprecated this feature is deprecated. */ + @java.lang.Deprecated public void setNdefPushMessageCallback(CreateNdefMessageCallback callback, Activity activity, Activity ... activities) { synchronized (NfcAdapter.class) { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } + if (!sHasBeamFeature) { + return; + } } int targetSdkVersion = getSdkVersion(); try { @@ -1313,13 +1361,18 @@ public final class NfcAdapter { * to only register one at a time, and to do so in that activity's * {@link Activity#onCreate} * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @deprecated this feature is deprecated. */ + @java.lang.Deprecated public void setOnNdefPushCompleteCallback(OnNdefPushCompleteCallback callback, Activity activity, Activity ... activities) { synchronized (NfcAdapter.class) { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } + if (!sHasBeamFeature) { + return; + } } int targetSdkVersion = getSdkVersion(); try { @@ -1524,12 +1577,17 @@ public final class NfcAdapter { * @param activity the current foreground Activity that has registered data to share * @return whether the Beam animation was successfully invoked * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @deprecated this feature is deprecated. */ + @java.lang.Deprecated public boolean invokeBeam(Activity activity) { synchronized (NfcAdapter.class) { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } + if (!sHasBeamFeature) { + return false; + } } if (activity == null) { throw new NullPointerException("activity may not be null."); @@ -1593,6 +1651,9 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } + if (!sHasBeamFeature) { + return; + } } if (activity == null || message == null) { throw new NullPointerException(); @@ -1627,6 +1688,9 @@ public final class NfcAdapter { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } + if (!sHasBeamFeature) { + return; + } } if (activity == null) { throw new NullPointerException(); @@ -1700,12 +1764,18 @@ public final class NfcAdapter { * @see android.provider.Settings#ACTION_NFCSHARING_SETTINGS * @return true if NDEF Push feature is enabled * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @deprecated this feature is deprecated. */ + @java.lang.Deprecated + public boolean isNdefPushEnabled() { synchronized (NfcAdapter.class) { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } + if (!sHasBeamFeature) { + return false; + } } try { return sService.isNdefPushEnabled(); |
