diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-01-20 19:13:43 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-01-20 19:13:43 +0000 |
| commit | 66e56014dff39bdd729364b61cac02c3ade20f83 (patch) | |
| tree | a242813e767fa7fbe54412f8253cf18a9bc568ba /core/java/android | |
| parent | 87bc42389d6c0ca584e32ddf6b1315d1c18e225b (diff) | |
| parent | a0f9f4b73bababd5c56e6a2b22b21bb14ac4514c (diff) | |
Merge "Added setAlwaysOn feature"
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/nfc/INfcAdapter.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/nfc/NfcAdapter.java | 118 |
2 files changed, 121 insertions, 0 deletions
diff --git a/core/java/android/nfc/INfcAdapter.aidl b/core/java/android/nfc/INfcAdapter.aidl index 0b2cfdd9ece3..bc3d5c4ab1ac 100644 --- a/core/java/android/nfc/INfcAdapter.aidl +++ b/core/java/android/nfc/INfcAdapter.aidl @@ -72,4 +72,7 @@ interface INfcAdapter boolean deviceSupportsNfcSecure(); boolean setNfcSecure(boolean enable); + boolean setAlwaysOn(boolean value); + boolean isAlwaysOnEnabled(); + boolean isAlwaysOnSupported(); } diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index f05706b0e710..e85eb935a8e7 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -350,6 +350,22 @@ public final class NfcAdapter { "android.nfc.extra.HANDOVER_TRANSFER_STATUS"; /** @hide */ + public static final String ACTION_ALWAYS_ON_STATE_CHANGED = + "android.nfc.action.ALWAYS_ON_STATE_CHANGED"; + + /** + * Used as an int extra field in {@link #ACTION_ALWAYS_ON_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_ALWAYS_ON_STATE = + "android.nfc.extra.ALWAYS_ON_STATE"; + + /** @hide */ public static final int HANDOVER_TRANSFER_STATUS_SUCCESS = 0; /** @hide */ public static final int HANDOVER_TRANSFER_STATUS_FAILURE = 1; @@ -2219,4 +2235,106 @@ public final class NfcAdapter { return mContext.getApplicationInfo().targetSdkVersion; } } + + /** + * Sets NFC controller always on feature. + * <p>This API is for the NFCC internal state management. It allows to discriminate + * the controller function from the NFC function by keeping the NFC Controller on without + * any NFC RF enabled if necessary. + * <p>This call is asynchronous. Listen for {@link #ACTION_ALWAYS_ON_STATE_CHANGED} + * broadcasts to find out when the operation is complete. + * <p>If this returns true, then either NFCC is already on, or + * a {@link #ACTION_ALWAYS_ON_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 NFCC on. + * @param value if true the NFCC will be kept on (with no RF enabled if NFC adapter is + * disabled), if false the NFCC will follow completely the Nfc adapter state. + * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @return void + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) + public boolean setAlwaysOn(boolean value) { + if (!sHasNfcFeature) { + throw new UnsupportedOperationException(); + } + try { + return sService.setAlwaysOn(value); + } catch (RemoteException e) { + attemptDeadServiceRecovery(e); + // Try one more time + if (sService == null) { + Log.e(TAG, "Failed to recover NFC Service."); + return false; + } + try { + return sService.setAlwaysOn(value); + } catch (RemoteException ee) { + Log.e(TAG, "Failed to recover NFC Service."); + } + return false; + } + } + + /** + * Checks NFC controller always on feature is enabled. + * + * @return True if NFC controller always on is enabled, false otherwise + * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @hide + */ + + @SystemApi + @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) + public boolean isAlwaysOnEnabled() { + try { + return sService.isAlwaysOnEnabled(); + } catch (RemoteException e) { + attemptDeadServiceRecovery(e); + // Try one more time + if (sService == null) { + Log.e(TAG, "Failed to recover NFC Service."); + return false; + } + try { + return sService.isAlwaysOnEnabled(); + } catch (RemoteException ee) { + Log.e(TAG, "Failed to recover NFC Service."); + } + return false; + } + } + + /** + * Checks if the device supports NFC controller always on functionality. + * + * @return True if device supports NFC controller always on, false otherwise + * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. + * @hide + */ + + @SystemApi + @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) + public boolean isAlwaysOnSupported() { + if (!sHasNfcFeature) { + throw new UnsupportedOperationException(); + } + try { + return sService.isAlwaysOnSupported(); + } catch (RemoteException e) { + attemptDeadServiceRecovery(e); + // Try one more time + if (sService == null) { + Log.e(TAG, "Failed to recover NFC Service."); + return false; + } + try { + return sService.isAlwaysOnSupported(); + } catch (RemoteException ee) { + Log.e(TAG, "Failed to recover NFC Service."); + } + return false; + } + } } |
