final class NfcAdapterService extends INfcAdapter.Stub {
@Override
public boolean enable() throws RemoteException {
NfcService.enforceAdminPerm(mContext);
saveNfcOnSetting(true);
if (mIsAirplaneSensitive && isAirplaneModeOn()) {
if (!mIsAirplaneToggleable) {
Log.i(TAG, "denying enable() request (airplane mode)");
return false;
}
// Make sure the override survives a reboot
mPrefsEditor.putBoolean(PREF_AIRPLANE_OVERRIDE, true);
mPrefsEditor.apply();
}
new EnableDisableTask().execute(TASK_ENABLE);
return true;
}
@Override
public boolean disable(boolean saveState) throws RemoteException {
NfcService.enforceAdminPerm(mContext);
if (saveState) {
saveNfcOnSetting(false);
}
new EnableDisableTask().execute(TASK_DISABLE);
return true;
}
@Override
public boolean isNdefPushEnabled() throws RemoteException {
synchronized (NfcService.this) {
return mState == NfcAdapter.STATE_ON && mIsNdefPushEnabled;
}
}
@Override
public boolean enableNdefPush() throws RemoteException {
NfcService.enforceAdminPerm(mContext);
synchronized(NfcService.this) {
if (mIsNdefPushEnabled) {
return true;
}
Log.i(TAG, "enabling NDEF Push");
mPrefsEditor.putBoolean(PREF_NDEF_PUSH_ON, true);
mPrefsEditor.apply();
mIsNdefPushEnabled = true;
if (isNfcEnabled()) {
mP2pLinkManager.enableDisable(true, true);
}
}
return true;
}
@Override
public boolean disableNdefPush() throws RemoteException {
NfcService.enforceAdminPerm(mContext);
synchronized(NfcService.this) {
if (!mIsNdefPushEnabled) {
return true;
}
Log.i(TAG, "disabling NDEF Push");
mPrefsEditor.putBoolean(PREF_NDEF_PUSH_ON, false);
mPrefsEditor.apply();
mIsNdefPushEnabled = false;
if (isNfcEnabled()) {
mP2pLinkManager.enableDisable(false, true);
}
}
return true;
}
@Override
public void setForegroundDispatch(PendingIntent intent,
IntentFilter[] filters, TechListParcel techListsParcel) {
mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR);
// Short-cut the disable path
if (intent == null && filters == null && techListsParcel == null) {
mNfcDispatcher.setForegroundDispatch(null, null, null);
return;
}
// Validate the IntentFilters
if (filters != null) {
if (filters.length == 0) {
filters = null;
} else {
for (IntentFilter filter : filters) {
if (filter == null) {
throw new IllegalArgumentException("null IntentFilter");
}
}
}
}
// Validate the tech lists
String[][] techLists = null;
if (techListsParcel != null) {
techLists = techListsParcel.getTechLists();
}
mNfcDispatcher.setForegroundDispatch(intent, filters, techLists);
}
@Override
public void setNdefPushCallback(INdefPushCallback callback) {
mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR);
mP2pLinkManager.setNdefCallback(callback);
}
@Override
public INfcTag getNfcTagInterface() throws RemoteException {
return mNfcTagService;
}
@Override
public INfcAdapterExtras getNfcAdapterExtrasInterface(String pkg) {
NfcService.this.enforceNfceeAdminPerm(pkg);
return mExtrasService;
}
@Override
public int getState() throws RemoteException {
synchronized (NfcService.this) {
return mState;
}
}
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
NfcService.this.dump(fd, pw, args);
}
@Override
public void dispatch(Tag tag) throws RemoteException {
enforceAdminPerm(mContext);
mNfcDispatcher.dispatchTag(tag);
}
@Override
public void setP2pModes(int initiatorModes, int targetModes) throws RemoteException {
enforceAdminPerm(mContext);
mDeviceHost.setP2pInitiatorModes(initiatorModes);
mDeviceHost.setP2pTargetModes(targetModes);
mDeviceHost.disableDiscovery();
mDeviceHost.enableDiscovery();
}
}
文章标题
最新推荐文章于 2022-04-19 15:05:43 发布