diff options
author | Nick Pelly <npelly@google.com> | 2011-08-09 07:03:49 -0700 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2011-08-09 16:31:46 -0700 |
commit | 8d32a01bd24b8a0d1a98f0581b3394a78fab8242 (patch) | |
tree | f1684fadc90c4701943f98d57f6997ed4fefd7e2 | |
parent | a4418e0fd94f27c0b40abe17d42af0880cb3effb (diff) | |
download | frameworks_base-8d32a01bd24b8a0d1a98f0581b3394a78fab8242.zip frameworks_base-8d32a01bd24b8a0d1a98f0581b3394a78fab8242.tar.gz frameworks_base-8d32a01bd24b8a0d1a98f0581b3394a78fab8242.tar.bz2 |
Add NFC to airplane mode
NFC now observes airplanes mode, and is by default toggleable in airplane mode.
Change-Id: I5f19d35422c9eb1cffb0b5e0631b3f3c5eeaedcf
-rw-r--r-- | api/current.txt | 1 | ||||
-rw-r--r-- | core/java/android/nfc/INfcAdapter.aidl | 4 | ||||
-rw-r--r-- | core/java/android/nfc/NfcAdapter.java | 100 | ||||
-rw-r--r-- | core/java/android/provider/Settings.java | 5 | ||||
-rw-r--r-- | packages/SettingsProvider/res/values/defaults.xml | 4 | ||||
-rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java | 21 |
6 files changed, 108 insertions, 27 deletions
diff --git a/api/current.txt b/api/current.txt index 72ba551..6b224d2 100644 --- a/api/current.txt +++ b/api/current.txt @@ -17032,6 +17032,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 83a055c..4fc248f 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 4d04027..6a904ae 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. + * <p>For example, NFC has been turned on or off. + * <p>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,7 +442,7 @@ public final class NfcAdapter { */ public boolean isEnabled() { try { - return sService.isEnabled(); + return sService.getState() == STATE_ON; } catch (RemoteException e) { attemptDeadServiceRecovery(e); return false; @@ -438,10 +450,40 @@ public final class NfcAdapter { } /** + * Return the state of this NFC Adapter. + * + * <p>Returns one of {@link #STATE_ON}, {@link #STATE_TURNING_ON}, + * {@link #STATE_OFF}, {@link #STATE_TURNING_OFF}. + * + * <p>{@link #isEnabled()} is equivalent to + * <code>{@link #getAdapterState()} == {@link #STATE_ON}</code> + * + * @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. - * <p> - * NOTE: may block for ~second or more. Poor API. Avoid - * calling from the UI thread. + * + * <p>This call is asynchronous. Listen for + * {@link #ACTION_ADAPTER_STATE_CHANGED} broadcasts to find out when the + * operation is complete. + * + * <p>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 + * + * <p>No NFC features will work after this call, and the hardware * will not perform or respond to any NFC communication. - * <p> - * NOTE: may block for ~second or more. Poor API. Avoid - * calling from the UI thread. + * + * <p>This call is asynchronous. Listen for + * {@link #ACTION_ADAPTER_STATE_CHANGED} broadcasts to find out when the + * operation is complete. + * + * <p>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. + * <p>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. + * <p>If you want to check if zero-click sharing is currently active, use + * <code>{@link #isEnabled()} && {@link #isZeroClickEnabled()}</code> * * @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 1ecdfce..f8702b9 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -1169,6 +1169,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 * included in the comma separated list. diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml index 12dbdf9..3920257 100644 --- a/packages/SettingsProvider/res/values/defaults.xml +++ b/packages/SettingsProvider/res/values/defaults.xml @@ -21,8 +21,8 @@ <integer name="def_screen_off_timeout">60000</integer> <bool name="def_airplane_mode_on">false</bool> <!-- Comma-separated list of bluetooth, wifi, and cell. --> - <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi</string> - <string name="airplane_mode_toggleable_radios" translatable="false">bluetooth,wifi</string> + <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc</string> + <string name="airplane_mode_toggleable_radios" translatable="false">bluetooth,wifi,nfc</string> <bool name="def_auto_time">true</bool> <bool name="def_auto_time_zone">true</bool> <bool name="def_accelerometer_rotation">true</bool> diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java index f4890e0..5495d08 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java @@ -63,7 +63,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' // is properly propagated through your change. Not doing so will result in a loss of user // settings. - private static final int DATABASE_VERSION = 69; + private static final int DATABASE_VERSION = 70; private Context mContext; @@ -917,6 +917,25 @@ public class DatabaseHelper extends SQLiteOpenHelper { upgradeVersion = 69; } + if (upgradeVersion == 69) { + // Add RADIO_NFC to AIRPLANE_MODE_RADIO and AIRPLANE_MODE_TOGGLEABLE_RADIOS + String airplaneRadios = mContext.getResources().getString( + R.string.def_airplane_mode_radios); + String toggleableRadios = mContext.getResources().getString( + R.string.airplane_mode_toggleable_radios); + db.beginTransaction(); + try { + db.execSQL("UPDATE system SET value='" + airplaneRadios + "' " + + "WHERE name='" + Settings.System.AIRPLANE_MODE_RADIOS + "'"); + db.execSQL("UPDATE system SET value='" + toggleableRadios + "' " + + "WHERE name='" + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'"); + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + upgradeVersion = 70; + } + // *** Remember to update DATABASE_VERSION above! if (upgradeVersion != currentVersion) { |