diff --git a/api/current.txt b/api/current.txt index 1f9c1638829c8..2a0bdd4ca8199 100644 --- a/api/current.txt +++ b/api/current.txt @@ -17033,6 +17033,7 @@ package android.provider { field public static final deprecated java.lang.String PARENTAL_CONTROL_REDIRECT_URL = "parental_control_redirect_url"; field public static final java.lang.String RADIO_BLUETOOTH = "bluetooth"; field public static final java.lang.String RADIO_CELL = "cell"; + field public static final java.lang.String RADIO_NFC = "nfc"; field public static final java.lang.String RADIO_WIFI = "wifi"; field public static final java.lang.String RINGTONE = "ringtone"; field public static final java.lang.String SCREEN_BRIGHTNESS = "screen_brightness"; diff --git a/core/java/android/nfc/INfcAdapter.aidl b/core/java/android/nfc/INfcAdapter.aidl index 83a055c7b4cb5..4fc248f6c3c02 100644 --- a/core/java/android/nfc/INfcAdapter.aidl +++ b/core/java/android/nfc/INfcAdapter.aidl @@ -35,7 +35,7 @@ interface INfcAdapter INfcAdapterExtras getNfcAdapterExtrasInterface(); // NfcAdapter-class related methods - boolean isEnabled(); + int getState(); void enableForegroundDispatch(in ComponentName activity, in PendingIntent intent, in IntentFilter[] filters, in TechListParcel techLists); void disableForegroundDispatch(in ComponentName activity); @@ -48,5 +48,5 @@ interface INfcAdapter boolean enable(); boolean enableZeroClick(); boolean disableZeroClick(); - boolean zeroClickEnabled(); + boolean isZeroClickEnabled(); } diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index 4d04027ec57c6..6a904aeb0d4b5 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -157,23 +157,35 @@ public final class NfcAdapter { public static final String EXTRA_ID = "android.nfc.extra.ID"; /** - * Broadcast Action: an adapter's state changed between enabled and disabled. - * - * The new value is stored in the extra EXTRA_NEW_BOOLEAN_STATE and just contains - * whether it's enabled or disabled, not including any information about whether it's - * actively enabling or disabling. - * + * Broadcast Action: The state of the local NFC adapter has been + * changed. + *
For example, NFC has been turned on or off. + *
Always contains the extra field {@link #EXTRA_STATE} * @hide */ - public static final String ACTION_ADAPTER_STATE_CHANGE = - "android.nfc.action.ADAPTER_STATE_CHANGE"; + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_ADAPTER_STATE_CHANGED = + "android.nfc.action.ADAPTER_STATE_CHANGED"; /** - * The Intent extra for ACTION_ADAPTER_STATE_CHANGE, saying what the new state is. - * + * Used as an int extra field in {@link #ACTION_STATE_CHANGED} + * intents to request the current power state. Possible values are: + * {@link #STATE_OFF}, + * {@link #STATE_TURNING_ON}, + * {@link #STATE_ON}, + * {@link #STATE_TURNING_OFF}, * @hide */ - public static final String EXTRA_NEW_BOOLEAN_STATE = "android.nfc.isEnabled"; + public static final String EXTRA_ADAPTER_STATE = "android.nfc.extra.ADAPTER_STATE"; + + /** @hide */ + public static final int STATE_OFF = 1; + /** @hide */ + public static final int STATE_TURNING_ON = 2; + /** @hide */ + public static final int STATE_ON = 3; + /** @hide */ + public static final int STATE_TURNING_OFF = 4; /** * LLCP link status: The LLCP link is activated. @@ -430,18 +442,48 @@ public final class NfcAdapter { */ public boolean isEnabled() { try { - return sService.isEnabled(); + return sService.getState() == STATE_ON; } catch (RemoteException e) { attemptDeadServiceRecovery(e); return false; } } + /** + * Return the state of this NFC Adapter. + * + *
Returns one of {@link #STATE_ON}, {@link #STATE_TURNING_ON}, + * {@link #STATE_OFF}, {@link #STATE_TURNING_OFF}. + * + *
{@link #isEnabled()} is equivalent to
+ * {@link #getAdapterState()} == {@link #STATE_ON}
+ *
+ * @return the current state of this NFC adapter
+ *
+ * @hide
+ */
+ public int getAdapterState() {
+ try {
+ return sService.getState();
+ } catch (RemoteException e) {
+ attemptDeadServiceRecovery(e);
+ return NfcAdapter.STATE_OFF;
+ }
+ }
+
/**
* Enable NFC hardware.
- *
- * NOTE: may block for ~second or more. Poor API. Avoid - * calling from the UI thread. + * + *
This call is asynchronous. Listen for + * {@link #ACTION_ADAPTER_STATE_CHANGED} broadcasts to find out when the + * operation is complete. + * + *
If this returns true, then either NFC is already on, or + * a {@link #ACTION_ADAPTER_STATE_CHANGED} broadcast will be sent + * to indicate a state transition. If this returns false, then + * there is some problem that prevents an attempt to turn + * NFC on (for example we are in airplane mode and NFC is not + * toggleable in airplane mode on this platform). * * @hide */ @@ -456,11 +498,19 @@ public final class NfcAdapter { /** * Disable NFC hardware. - * No NFC features will work after this call, and the hardware + * + *
No NFC features will work after this call, and the hardware * will not perform or respond to any NFC communication. - *
- * NOTE: may block for ~second or more. Poor API. Avoid - * calling from the UI thread. + * + *
This call is asynchronous. Listen for + * {@link #ACTION_ADAPTER_STATE_CHANGED} broadcasts to find out when the + * operation is complete. + * + *
If this returns true, then either NFC is already off, or + * a {@link #ACTION_ADAPTER_STATE_CHANGED} broadcast will be sent + * to indicate a state transition. If this returns false, then + * there is some problem that prevents an attempt to turn + * NFC off. * * @hide */ @@ -712,14 +762,20 @@ public final class NfcAdapter { } /** - * Return true if zero-click sharing is enabled. + * Return true if zero-click sharing feature is enabled. + *
This function can return true even if NFC is currently turned-off. + * This indicates that zero-click is not currently active, but it has + * been requested by the user and will be active as soon as NFC is turned + * on. + *
If you want to check if zero-click sharing is currently active, use
+ * {@link #isEnabled()} && {@link #isZeroClickEnabled()}
*
* @return true if zero-click sharing is enabled
* @hide
*/
- public boolean zeroClickEnabled() {
+ public boolean isZeroClickEnabled() {
try {
- return sService.zeroClickEnabled();
+ return sService.isZeroClickEnabled();
} catch (RemoteException e) {
attemptDeadServiceRecovery(e);
return false;
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 1ecdfceaf015d..f8702b9d91178 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1168,6 +1168,11 @@ public final class Settings {
*/
public static final String RADIO_CELL = "cell";
+ /**
+ * Constant for use in AIRPLANE_MODE_RADIOS to specify NFC radio.
+ */
+ public static final String RADIO_NFC = "nfc";
+
/**
* A comma separated list of radios that need to be disabled when airplane mode
* is on. This overrides WIFI_ON and BLUETOOTH_ON, if Wi-Fi and bluetooth are
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index 12dbdf99736f7..3920257a7c433 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -21,8 +21,8 @@