Merge "Added setAlwaysOn feature" am: 66e56014df am: 0eda082f6a

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1477323

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I16b13b49d5b4b5b7c0d6f63893c552a9c0734c07
This commit is contained in:
Treehugger Robot
2021-01-20 19:47:59 +00:00
committed by Automerger Merge Worker
3 changed files with 124 additions and 0 deletions

View File

@@ -6925,7 +6925,10 @@ package android.nfc {
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enable();
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enableNdefPush();
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enableSecureNfc(boolean);
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean isAlwaysOnEnabled();
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean isAlwaysOnSupported();
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean removeNfcUnlockHandler(android.nfc.NfcAdapter.NfcUnlockHandler);
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean setAlwaysOn(boolean);
method public void setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity, int);
field public static final int FLAG_NDEF_PUSH_NO_CONFIRM = 1; // 0x1
}

View File

@@ -72,4 +72,7 @@ interface INfcAdapter
boolean deviceSupportsNfcSecure();
boolean setNfcSecure(boolean enable);
boolean setAlwaysOn(boolean value);
boolean isAlwaysOnEnabled();
boolean isAlwaysOnSupported();
}

View File

@@ -349,6 +349,22 @@ public final class NfcAdapter {
public static final String EXTRA_HANDOVER_TRANSFER_STATUS =
"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 */
@@ -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;
}
}
}