Update ControllerAlwaysOnStateCallback to ControllerAlwaysOnListener am: 78fad0d6d3 am: 9aa1fc83e5

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

Change-Id: I02383b4083d6df09d78861df0274451295103754
This commit is contained in:
George Chang
2021-04-15 16:27:50 +00:00
committed by Automerger Merge Worker
5 changed files with 64 additions and 64 deletions

View File

@@ -6735,16 +6735,16 @@ package android.nfc {
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enableSecureNfc(boolean); method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enableSecureNfc(boolean);
method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean isControllerAlwaysOn(); method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean isControllerAlwaysOn();
method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean isControllerAlwaysOnSupported(); method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean isControllerAlwaysOnSupported();
method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public void registerControllerAlwaysOnStateCallback(@NonNull java.util.concurrent.Executor, @NonNull android.nfc.NfcAdapter.ControllerAlwaysOnStateCallback); method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public void registerControllerAlwaysOnListener(@NonNull java.util.concurrent.Executor, @NonNull android.nfc.NfcAdapter.ControllerAlwaysOnListener);
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 removeNfcUnlockHandler(android.nfc.NfcAdapter.NfcUnlockHandler);
method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean setControllerAlwaysOn(boolean); method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean setControllerAlwaysOn(boolean);
method public void setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity, int); method public void setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity, int);
method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public void unregisterControllerAlwaysOnStateCallback(@NonNull android.nfc.NfcAdapter.ControllerAlwaysOnStateCallback); method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public void unregisterControllerAlwaysOnListener(@NonNull android.nfc.NfcAdapter.ControllerAlwaysOnListener);
field public static final int FLAG_NDEF_PUSH_NO_CONFIRM = 1; // 0x1 field public static final int FLAG_NDEF_PUSH_NO_CONFIRM = 1; // 0x1
} }
public static interface NfcAdapter.ControllerAlwaysOnStateCallback { public static interface NfcAdapter.ControllerAlwaysOnListener {
method public void onStateChanged(boolean); method public void onControllerAlwaysOnChanged(boolean);
} }
public static interface NfcAdapter.NfcUnlockHandler { public static interface NfcAdapter.NfcUnlockHandler {

View File

@@ -24,7 +24,7 @@ import android.nfc.Tag;
import android.nfc.TechListParcel; import android.nfc.TechListParcel;
import android.nfc.IAppCallback; import android.nfc.IAppCallback;
import android.nfc.INfcAdapterExtras; import android.nfc.INfcAdapterExtras;
import android.nfc.INfcControllerAlwaysOnStateCallback; import android.nfc.INfcControllerAlwaysOnListener;
import android.nfc.INfcTag; import android.nfc.INfcTag;
import android.nfc.INfcCardEmulation; import android.nfc.INfcCardEmulation;
import android.nfc.INfcFCardEmulation; import android.nfc.INfcFCardEmulation;
@@ -76,6 +76,6 @@ interface INfcAdapter
boolean setControllerAlwaysOn(boolean value); boolean setControllerAlwaysOn(boolean value);
boolean isControllerAlwaysOn(); boolean isControllerAlwaysOn();
boolean isControllerAlwaysOnSupported(); boolean isControllerAlwaysOnSupported();
void registerControllerAlwaysOnStateCallback(in INfcControllerAlwaysOnStateCallback callback); void registerControllerAlwaysOnListener(in INfcControllerAlwaysOnListener listener);
void unregisterControllerAlwaysOnStateCallback(in INfcControllerAlwaysOnStateCallback callback); void unregisterControllerAlwaysOnListener(in INfcControllerAlwaysOnListener listener);
} }

View File

@@ -19,11 +19,11 @@ package android.nfc;
/** /**
* @hide * @hide
*/ */
oneway interface INfcControllerAlwaysOnStateCallback { oneway interface INfcControllerAlwaysOnListener {
/** /**
* Called whenever the controller always on state changes * Called whenever the controller always on state changes
* *
* @param isEnabled true if the state is enabled, false otherwise * @param isEnabled true if the state is enabled, false otherwise
*/ */
void onControllerAlwaysOnStateChanged(boolean isEnabled); void onControllerAlwaysOnChanged(boolean isEnabled);
} }

View File

@@ -67,7 +67,7 @@ import java.util.concurrent.Executor;
public final class NfcAdapter { public final class NfcAdapter {
static final String TAG = "NFC"; static final String TAG = "NFC";
private final NfcControllerAlwaysOnStateListener mControllerAlwaysOnStateListener; private final NfcControllerAlwaysOnListener mControllerAlwaysOnListener;
/** /**
* Intent to start an activity when a tag with NDEF payload is discovered. * Intent to start an activity when a tag with NDEF payload is discovered.
@@ -418,19 +418,19 @@ public final class NfcAdapter {
} }
/** /**
* A callback to be invoked when NFC controller always on state changes. * A listener to be invoked when NFC controller always on state changes.
* <p>Register your {@code ControllerAlwaysOnStateCallback} implementation with {@link * <p>Register your {@code ControllerAlwaysOnListener} implementation with {@link
* NfcAdapter#registerControllerAlwaysOnStateCallback} and disable it with {@link * NfcAdapter#registerControllerAlwaysOnListener} and disable it with {@link
* NfcAdapter#unregisterControllerAlwaysOnStateCallback}. * NfcAdapter#unregisterControllerAlwaysOnListener}.
* @see #registerControllerAlwaysOnStateCallback * @see #registerControllerAlwaysOnListener
* @hide * @hide
*/ */
@SystemApi @SystemApi
public interface ControllerAlwaysOnStateCallback { public interface ControllerAlwaysOnListener {
/** /**
* Called on NFC controller always on state changes * Called on NFC controller always on state changes
*/ */
void onStateChanged(boolean isEnabled); void onControllerAlwaysOnChanged(boolean isEnabled);
} }
/** /**
@@ -748,7 +748,7 @@ public final class NfcAdapter {
mNfcUnlockHandlers = new HashMap<NfcUnlockHandler, INfcUnlockHandler>(); mNfcUnlockHandlers = new HashMap<NfcUnlockHandler, INfcUnlockHandler>();
mTagRemovedListener = null; mTagRemovedListener = null;
mLock = new Object(); mLock = new Object();
mControllerAlwaysOnStateListener = new NfcControllerAlwaysOnStateListener(getService()); mControllerAlwaysOnListener = new NfcControllerAlwaysOnListener(getService());
} }
/** /**
@@ -2246,12 +2246,12 @@ public final class NfcAdapter {
* <p>This API is for the NFCC internal state management. It allows to discriminate * <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 * the controller function from the NFC function by keeping the NFC controller on without
* any NFC RF enabled if necessary. * any NFC RF enabled if necessary.
* <p>This call is asynchronous. Register a callback {@link #ControllerAlwaysOnStateCallback} * <p>This call is asynchronous. Register a listener {@link #ControllerAlwaysOnListener}
* by {@link #registerControllerAlwaysOnStateCallback} to find out when the operation is * by {@link #registerControllerAlwaysOnListener} to find out when the operation is
* complete. * complete.
* <p>If this returns true, then either NFCC always on state has been set based on the value, * <p>If this returns true, then either NFCC always on state has been set based on the value,
* or a {@link ControllerAlwaysOnStateCallback#onStateChanged(boolean)} will be invoked to * or a {@link ControllerAlwaysOnListener#onControllerAlwaysOnChanged(boolean)} will be invoked
* indicate the state change. * to indicate the state change.
* If this returns false, then there is some problem that prevents an attempt to turn NFCC * If this returns false, then there is some problem that prevents an attempt to turn NFCC
* always on. * always on.
* @param value if true the NFCC will be kept on (with no RF enabled if NFC adapter is * @param value if true the NFCC will be kept on (with no RF enabled if NFC adapter is
@@ -2344,37 +2344,37 @@ public final class NfcAdapter {
} }
/** /**
* Register a {@link ControllerAlwaysOnStateCallback} to listen for NFC controller always on * Register a {@link ControllerAlwaysOnListener} to listen for NFC controller always on
* state changes * state changes
* <p>The provided callback will be invoked by the given {@link Executor}. * <p>The provided listener will be invoked by the given {@link Executor}.
* *
* @param executor an {@link Executor} to execute given callback * @param executor an {@link Executor} to execute given listener
* @param callback user implementation of the {@link ControllerAlwaysOnStateCallback} * @param listener user implementation of the {@link ControllerAlwaysOnListener}
* @hide * @hide
*/ */
@SystemApi @SystemApi
@RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON)
public void registerControllerAlwaysOnStateCallback( public void registerControllerAlwaysOnListener(
@NonNull @CallbackExecutor Executor executor, @NonNull @CallbackExecutor Executor executor,
@NonNull ControllerAlwaysOnStateCallback callback) { @NonNull ControllerAlwaysOnListener listener) {
mControllerAlwaysOnStateListener.register(executor, callback); mControllerAlwaysOnListener.register(executor, listener);
} }
/** /**
* Unregister the specified {@link ControllerAlwaysOnStateCallback} * Unregister the specified {@link ControllerAlwaysOnListener}
* <p>The same {@link ControllerAlwaysOnStateCallback} object used when calling * <p>The same {@link ControllerAlwaysOnListener} object used when calling
* {@link #registerControllerAlwaysOnStateCallback(Executor, ControllerAlwaysOnStateCallback)} * {@link #registerControllerAlwaysOnListener(Executor, ControllerAlwaysOnListener)}
* must be used. * must be used.
* *
* <p>Callbacks are automatically unregistered when application process goes away * <p>Listeners are automatically unregistered when application process goes away
* *
* @param callback user implementation of the {@link ControllerAlwaysOnStateCallback} * @param listener user implementation of the {@link ControllerAlwaysOnListener}
* @hide * @hide
*/ */
@SystemApi @SystemApi
@RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON)
public void unregisterControllerAlwaysOnStateCallback( public void unregisterControllerAlwaysOnListener(
@NonNull ControllerAlwaysOnStateCallback callback) { @NonNull ControllerAlwaysOnListener listener) {
mControllerAlwaysOnStateListener.unregister(callback); mControllerAlwaysOnListener.unregister(listener);
} }
} }

View File

@@ -17,7 +17,7 @@
package android.nfc; package android.nfc;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.nfc.NfcAdapter.ControllerAlwaysOnStateCallback; import android.nfc.NfcAdapter.ControllerAlwaysOnListener;
import android.os.Binder; import android.os.Binder;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log; import android.util.Log;
@@ -29,77 +29,77 @@ import java.util.concurrent.Executor;
/** /**
* @hide * @hide
*/ */
public class NfcControllerAlwaysOnStateListener extends INfcControllerAlwaysOnStateCallback.Stub { public class NfcControllerAlwaysOnListener extends INfcControllerAlwaysOnListener.Stub {
private static final String TAG = "NfcControllerAlwaysOnStateListener"; private static final String TAG = NfcControllerAlwaysOnListener.class.getSimpleName();
private final INfcAdapter mAdapter; private final INfcAdapter mAdapter;
private final Map<ControllerAlwaysOnStateCallback, Executor> mCallbackMap = new HashMap<>(); private final Map<ControllerAlwaysOnListener, Executor> mListenerMap = new HashMap<>();
private boolean mCurrentState = false; private boolean mCurrentState = false;
private boolean mIsRegistered = false; private boolean mIsRegistered = false;
public NfcControllerAlwaysOnStateListener(@NonNull INfcAdapter adapter) { public NfcControllerAlwaysOnListener(@NonNull INfcAdapter adapter) {
mAdapter = adapter; mAdapter = adapter;
} }
/** /**
* Register a {@link ControllerAlwaysOnStateCallback} with this * Register a {@link ControllerAlwaysOnListener} with this
* {@link NfcControllerAlwaysOnStateListener} * {@link NfcControllerAlwaysOnListener}
* *
* @param executor an {@link Executor} to execute given callback * @param executor an {@link Executor} to execute given listener
* @param callback user implementation of the {@link ControllerAlwaysOnStateCallback} * @param listener user implementation of the {@link ControllerAlwaysOnListener}
*/ */
public void register(@NonNull Executor executor, public void register(@NonNull Executor executor,
@NonNull ControllerAlwaysOnStateCallback callback) { @NonNull ControllerAlwaysOnListener listener) {
synchronized (this) { synchronized (this) {
if (mCallbackMap.containsKey(callback)) { if (mListenerMap.containsKey(listener)) {
return; return;
} }
mCallbackMap.put(callback, executor); mListenerMap.put(listener, executor);
if (!mIsRegistered) { if (!mIsRegistered) {
try { try {
mAdapter.registerControllerAlwaysOnStateCallback(this); mAdapter.registerControllerAlwaysOnListener(this);
mIsRegistered = true; mIsRegistered = true;
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(TAG, "Failed to register ControllerAlwaysOnStateListener"); Log.w(TAG, "Failed to register");
} }
} }
} }
} }
/** /**
* Unregister the specified {@link ControllerAlwaysOnStateCallback} * Unregister the specified {@link ControllerAlwaysOnListener}
* *
* @param callback user implementation of the {@link ControllerAlwaysOnStateCallback} * @param listener user implementation of the {@link ControllerAlwaysOnListener}
*/ */
public void unregister(@NonNull ControllerAlwaysOnStateCallback callback) { public void unregister(@NonNull ControllerAlwaysOnListener listener) {
synchronized (this) { synchronized (this) {
if (!mCallbackMap.containsKey(callback)) { if (!mListenerMap.containsKey(listener)) {
return; return;
} }
mCallbackMap.remove(callback); mListenerMap.remove(listener);
if (mCallbackMap.isEmpty() && mIsRegistered) { if (mListenerMap.isEmpty() && mIsRegistered) {
try { try {
mAdapter.unregisterControllerAlwaysOnStateCallback(this); mAdapter.unregisterControllerAlwaysOnListener(this);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(TAG, "Failed to unregister ControllerAlwaysOnStateListener"); Log.w(TAG, "Failed to unregister");
} }
mIsRegistered = false; mIsRegistered = false;
} }
} }
} }
private void sendCurrentState(@NonNull ControllerAlwaysOnStateCallback callback) { private void sendCurrentState(@NonNull ControllerAlwaysOnListener listener) {
synchronized (this) { synchronized (this) {
Executor executor = mCallbackMap.get(callback); Executor executor = mListenerMap.get(listener);
final long identity = Binder.clearCallingIdentity(); final long identity = Binder.clearCallingIdentity();
try { try {
executor.execute(() -> callback.onStateChanged( executor.execute(() -> listener.onControllerAlwaysOnChanged(
mCurrentState)); mCurrentState));
} finally { } finally {
Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity);
@@ -108,10 +108,10 @@ public class NfcControllerAlwaysOnStateListener extends INfcControllerAlwaysOnSt
} }
@Override @Override
public void onControllerAlwaysOnStateChanged(boolean isEnabled) { public void onControllerAlwaysOnChanged(boolean isEnabled) {
synchronized (this) { synchronized (this) {
mCurrentState = isEnabled; mCurrentState = isEnabled;
for (ControllerAlwaysOnStateCallback cb : mCallbackMap.keySet()) { for (ControllerAlwaysOnListener cb : mListenerMap.keySet()) {
sendCurrentState(cb); sendCurrentState(cb);
} }
} }