Methods Summary |
---|
public BeamShareData | createBeamShareData()Callback from NFC service, usually on binder thread
NfcAdapter.CreateNdefMessageCallback ndefCallback;
NfcAdapter.CreateBeamUrisCallback urisCallback;
NdefMessage message;
Activity activity;
Uri[] uris;
int flags;
synchronized (NfcActivityManager.this) {
NfcActivityState state = findResumedActivityState();
if (state == null) return null;
ndefCallback = state.ndefMessageCallback;
urisCallback = state.uriCallback;
message = state.ndefMessage;
uris = state.uris;
flags = state.flags;
activity = state.activity;
}
// Make callbacks without lock
if (ndefCallback != null) {
message = ndefCallback.createNdefMessage(mDefaultEvent);
}
if (urisCallback != null) {
uris = urisCallback.createBeamUris(mDefaultEvent);
if (uris != null) {
ArrayList<Uri> validUris = new ArrayList<Uri>();
for (Uri uri : uris) {
if (uri == null) {
Log.e(TAG, "Uri not allowed to be null.");
continue;
}
String scheme = uri.getScheme();
if (scheme == null || (!scheme.equalsIgnoreCase("file") &&
!scheme.equalsIgnoreCase("content"))) {
Log.e(TAG, "Uri needs to have " +
"either scheme file or scheme content");
continue;
}
uri = ContentProvider.maybeAddUserId(uri, UserHandle.myUserId());
validUris.add(uri);
}
uris = validUris.toArray(new Uri[validUris.size()]);
}
}
if (uris != null && uris.length > 0) {
for (Uri uri : uris) {
// Grant the NFC process permission to read these URIs
activity.grantUriPermission("com.android.nfc", uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
return new BeamShareData(message, uris, UserHandle.CURRENT, flags);
|
synchronized void | destroyActivityState(android.app.Activity activity)
NfcActivityState activityState = findActivityState(activity);
if (activityState != null) {
activityState.destroy();
mActivities.remove(activityState);
}
|
public void | disableReaderMode(android.app.Activity activity)
boolean isResumed;
Binder token;
synchronized (NfcActivityManager.this) {
NfcActivityState state = getActivityState(activity);
state.readerCallback = null;
state.readerModeFlags = 0;
state.readerModeExtras = null;
token = state.token;
isResumed = state.resumed;
}
if (isResumed) {
setReaderMode(token, 0, null);
}
|
public void | enableReaderMode(android.app.Activity activity, android.nfc.NfcAdapter.ReaderCallback callback, int flags, android.os.Bundle extras)
boolean isResumed;
Binder token;
synchronized (NfcActivityManager.this) {
NfcActivityState state = getActivityState(activity);
state.readerCallback = callback;
state.readerModeFlags = flags;
state.readerModeExtras = extras;
token = state.token;
isResumed = state.resumed;
}
if (isResumed) {
setReaderMode(token, flags, extras);
}
|
synchronized android.nfc.NfcActivityManager$NfcActivityState | findActivityState(android.app.Activity activity)find activity state from mActivities
for (NfcActivityState state : mActivities) {
if (state.activity == activity) {
return state;
}
}
return null;
|
android.nfc.NfcActivityManager$NfcApplicationState | findAppState(android.app.Application app)
for (NfcApplicationState appState : mApps) {
if (appState.app == app) {
return appState;
}
}
return null;
|
synchronized android.nfc.NfcActivityManager$NfcActivityState | findResumedActivityState()
for (NfcActivityState state : mActivities) {
if (state.resumed) {
return state;
}
}
return null;
|
synchronized android.nfc.NfcActivityManager$NfcActivityState | getActivityState(android.app.Activity activity)find or create activity state from mActivities
NfcActivityState state = findActivityState(activity);
if (state == null) {
state = new NfcActivityState(activity);
mActivities.add(state);
}
return state;
|
public void | onActivityCreated(android.app.Activity activity, android.os.Bundle savedInstanceState)Callback from Activity life-cycle, on main thread /* NO-OP */
|
public void | onActivityDestroyed(android.app.Activity activity)Callback from Activity life-cycle, on main thread
synchronized (NfcActivityManager.this) {
NfcActivityState state = findActivityState(activity);
if (DBG) Log.d(TAG, "onDestroy() for " + activity + " " + state);
if (state != null) {
// release all associated references
destroyActivityState(activity);
}
}
|
public void | onActivityPaused(android.app.Activity activity)Callback from Activity life-cycle, on main thread
boolean readerModeFlagsSet;
Binder token;
synchronized (NfcActivityManager.this) {
NfcActivityState state = findActivityState(activity);
if (DBG) Log.d(TAG, "onPause() for " + activity + " " + state);
if (state == null) return;
state.resumed = false;
token = state.token;
readerModeFlagsSet = state.readerModeFlags != 0;
}
if (readerModeFlagsSet) {
// Restore default p2p modes
setReaderMode(token, 0, null);
}
|
public void | onActivityResumed(android.app.Activity activity)Callback from Activity life-cycle, on main thread
int readerModeFlags = 0;
Bundle readerModeExtras = null;
Binder token;
synchronized (NfcActivityManager.this) {
NfcActivityState state = findActivityState(activity);
if (DBG) Log.d(TAG, "onResume() for " + activity + " " + state);
if (state == null) return;
state.resumed = true;
token = state.token;
readerModeFlags = state.readerModeFlags;
readerModeExtras = state.readerModeExtras;
}
if (readerModeFlags != 0) {
setReaderMode(token, readerModeFlags, readerModeExtras);
}
requestNfcServiceCallback();
|
public void | onActivitySaveInstanceState(android.app.Activity activity, android.os.Bundle outState)Callback from Activity life-cycle, on main thread /* NO-OP */
|
public void | onActivityStarted(android.app.Activity activity)Callback from Activity life-cycle, on main thread /* NO-OP */
|
public void | onActivityStopped(android.app.Activity activity)Callback from Activity life-cycle, on main thread /* NO-OP */
|
public void | onNdefPushComplete()Callback from NFC service, usually on binder thread
NfcAdapter.OnNdefPushCompleteCallback callback;
synchronized (NfcActivityManager.this) {
NfcActivityState state = findResumedActivityState();
if (state == null) return;
callback = state.onNdefPushCompleteCallback;
}
// Make callback without lock
if (callback != null) {
callback.onNdefPushComplete(mDefaultEvent);
}
|
public void | onTagDiscovered(Tag tag)
NfcAdapter.ReaderCallback callback;
synchronized (NfcActivityManager.this) {
NfcActivityState state = findResumedActivityState();
if (state == null) return;
callback = state.readerCallback;
}
// Make callback without lock
if (callback != null) {
callback.onTagDiscovered(tag);
}
|
void | registerApplication(android.app.Application app)
NfcApplicationState appState = findAppState(app);
if (appState == null) {
appState = new NfcApplicationState(app);
mApps.add(appState);
}
appState.register();
|
void | requestNfcServiceCallback()Request or unrequest NFC service callbacks.
Makes IPC call - do not hold lock.
try {
NfcAdapter.sService.setAppCallback(this);
} catch (RemoteException e) {
mAdapter.attemptDeadServiceRecovery(e);
}
|
public void | setNdefPushContentUri(android.app.Activity activity, android.net.Uri[] uris)
boolean isResumed;
synchronized (NfcActivityManager.this) {
NfcActivityState state = getActivityState(activity);
state.uris = uris;
isResumed = state.resumed;
}
if (isResumed) {
// requestNfcServiceCallback() verifies permission also
requestNfcServiceCallback();
} else {
// Crash API calls early in case NFC permission is missing
verifyNfcPermission();
}
|
public void | setNdefPushContentUriCallback(android.app.Activity activity, NfcAdapter.CreateBeamUrisCallback callback)
boolean isResumed;
synchronized (NfcActivityManager.this) {
NfcActivityState state = getActivityState(activity);
state.uriCallback = callback;
isResumed = state.resumed;
}
if (isResumed) {
// requestNfcServiceCallback() verifies permission also
requestNfcServiceCallback();
} else {
// Crash API calls early in case NFC permission is missing
verifyNfcPermission();
}
|
public void | setNdefPushMessage(android.app.Activity activity, NdefMessage message, int flags)
boolean isResumed;
synchronized (NfcActivityManager.this) {
NfcActivityState state = getActivityState(activity);
state.ndefMessage = message;
state.flags = flags;
isResumed = state.resumed;
}
if (isResumed) {
// requestNfcServiceCallback() verifies permission also
requestNfcServiceCallback();
} else {
// Crash API calls early in case NFC permission is missing
verifyNfcPermission();
}
|
public void | setNdefPushMessageCallback(android.app.Activity activity, NfcAdapter.CreateNdefMessageCallback callback, int flags)
boolean isResumed;
synchronized (NfcActivityManager.this) {
NfcActivityState state = getActivityState(activity);
state.ndefMessageCallback = callback;
state.flags = flags;
isResumed = state.resumed;
}
if (isResumed) {
// requestNfcServiceCallback() verifies permission also
requestNfcServiceCallback();
} else {
// Crash API calls early in case NFC permission is missing
verifyNfcPermission();
}
|
public void | setOnNdefPushCompleteCallback(android.app.Activity activity, NfcAdapter.OnNdefPushCompleteCallback callback)
boolean isResumed;
synchronized (NfcActivityManager.this) {
NfcActivityState state = getActivityState(activity);
state.onNdefPushCompleteCallback = callback;
isResumed = state.resumed;
}
if (isResumed) {
// requestNfcServiceCallback() verifies permission also
requestNfcServiceCallback();
} else {
// Crash API calls early in case NFC permission is missing
verifyNfcPermission();
}
|
public void | setReaderMode(android.os.Binder token, int flags, android.os.Bundle extras)
if (DBG) Log.d(TAG, "Setting reader mode");
try {
NfcAdapter.sService.setReaderMode(token, this, flags, extras);
} catch (RemoteException e) {
mAdapter.attemptDeadServiceRecovery(e);
}
|
void | unregisterApplication(android.app.Application app)
NfcApplicationState appState = findAppState(app);
if (appState == null) {
Log.e(TAG, "app was not registered " + app);
return;
}
appState.unregister();
|
void | verifyNfcPermission()
try {
NfcAdapter.sService.verifyNfcPermission();
} catch (RemoteException e) {
mAdapter.attemptDeadServiceRecovery(e);
}
|