Commit 0b3b8ab6 authored by Nick Pelly's avatar Nick Pelly
Browse files

NFC service updates for moving NDEF push to a fragment.

enable()/disable() -> set()
ZeroClick -> NdefPush

Change-Id: I21806665b8fd29e4580bd2e3200858d834605f6f
parent a8c50384
......@@ -73,16 +73,9 @@ public class NfcDispatcher {
mPackageManager = context.getPackageManager();
}
public synchronized void disableForegroundDispatch() {
if (DBG) Log.d(TAG, "Disable Foreground Dispatch");
mOverrideIntent = null;
mOverrideFilters = null;
mOverrideTechLists = null;
}
public synchronized void enableForegroundDispatch(PendingIntent intent,
public synchronized void setForegroundDispatch(PendingIntent intent,
IntentFilter[] filters, String[][] techLists) {
if (DBG) Log.d(TAG, "Enable Foreground Dispatch");
if (DBG) Log.d(TAG, "Set Foreground Dispatch");
mOverrideIntent = intent;
mOverrideFilters = filters;
mOverrideTechLists = techLists;
......
......@@ -91,8 +91,8 @@ public class NfcService extends Application implements DeviceHostListener {
private static final String PREF_NFC_ON = "nfc_on";
private static final boolean NFC_ON_DEFAULT = true;
private static final String PREF_ZEROCLICK_ON = "zeroclick_on";
private static final boolean ZEROCLICK_ON_DEFAULT = true;
private static final String PREF_NDEF_PUSH_ON = "ndef_push_on";
private static final boolean NDEF_PUSH_ON_DEFAULT = true;
private static final String PREF_FIRST_BOOT = "first_boot";
......@@ -165,7 +165,7 @@ public class NfcService extends Application implements DeviceHostListener {
private final HashMap<Integer, Object> mObjectMap = new HashMap<Integer, Object>();
private HashSet<String> mSePackages = new HashSet<String>();
private boolean mIsScreenUnlocked;
private boolean mIsZeroClickRequested;
private boolean mIsNdefPushEnabled;
// mState is protected by this, however it is only modified in onCreate()
// and the default AsyncTask thread so it is read unprotected from that
......@@ -303,7 +303,7 @@ public class NfcService extends Application implements DeviceHostListener {
mPrefsEditor = mPrefs.edit();
mState = NfcAdapter.STATE_OFF;
mIsZeroClickRequested = mPrefs.getBoolean(PREF_ZEROCLICK_ON, ZEROCLICK_ON_DEFAULT);
mIsNdefPushEnabled = mPrefs.getBoolean(PREF_NDEF_PUSH_ON, NDEF_PUSH_ON_DEFAULT);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
......@@ -446,7 +446,7 @@ public class NfcService extends Application implements DeviceHostListener {
synchronized(NfcService.this) {
mObjectMap.clear();
mP2pLinkManager.enableDisable(mIsZeroClickRequested, true);
mP2pLinkManager.enableDisable(mIsNdefPushEnabled, true);
updateState(NfcAdapter.STATE_ON);
}
......@@ -482,7 +482,7 @@ public class NfcService extends Application implements DeviceHostListener {
applyRouting();
maybeDisconnectTarget();
mNfcDispatcher.disableForegroundDispatch();
mNfcDispatcher.setForegroundDispatch(null, null, null);
boolean result = mDeviceHost.deinitialize();
if (DBG) Log.d(TAG, "mDeviceHost.deinitialize() = " + result);
......@@ -593,23 +593,23 @@ public class NfcService extends Application implements DeviceHostListener {
}
@Override
public boolean isZeroClickEnabled() throws RemoteException {
public boolean isNdefPushEnabled() throws RemoteException {
synchronized (NfcService.this) {
return mIsZeroClickRequested;
return mIsNdefPushEnabled;
}
}
@Override
public boolean enableZeroClick() throws RemoteException {
public boolean enableNdefPush() throws RemoteException {
NfcService.enforceAdminPerm(mContext);
synchronized(NfcService.this) {
if (mIsZeroClickRequested) {
if (mIsNdefPushEnabled) {
return true;
}
Log.i(TAG, "enabling 0-click");
mPrefsEditor.putBoolean(PREF_ZEROCLICK_ON, true);
Log.i(TAG, "enabling NDEF Push");
mPrefsEditor.putBoolean(PREF_NDEF_PUSH_ON, true);
mPrefsEditor.apply();
mIsZeroClickRequested = true;
mIsNdefPushEnabled = true;
if (isNfcEnabled()) {
mP2pLinkManager.enableDisable(true, true);
}
......@@ -618,16 +618,16 @@ public class NfcService extends Application implements DeviceHostListener {
}
@Override
public boolean disableZeroClick() throws RemoteException {
public boolean disableNdefPush() throws RemoteException {
NfcService.enforceAdminPerm(mContext);
synchronized(NfcService.this) {
if (!mIsZeroClickRequested) {
if (!mIsNdefPushEnabled) {
return true;
}
Log.i(TAG, "disabling 0-click");
mPrefsEditor.putBoolean(PREF_ZEROCLICK_ON, false);
Log.i(TAG, "disabling NDEF Push");
mPrefsEditor.putBoolean(PREF_NDEF_PUSH_ON, false);
mPrefsEditor.apply();
mIsZeroClickRequested = false;
mIsNdefPushEnabled = false;
if (isNfcEnabled()) {
mP2pLinkManager.enableDisable(false, true);
}
......@@ -636,14 +636,14 @@ public class NfcService extends Application implements DeviceHostListener {
}
@Override
public void enableForegroundDispatch(ComponentName activity, PendingIntent intent,
public void setForegroundDispatch(PendingIntent intent,
IntentFilter[] filters, TechListParcel techListsParcel) {
// Permission check
mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR);
// Argument validation
if (activity == null || intent == null) {
throw new IllegalArgumentException();
// Short-cut the disable path
if (intent == null && filters == null && techListsParcel == null) {
mNfcDispatcher.setForegroundDispatch(null, null, null);
return;
}
// Validate the IntentFilters
......@@ -665,39 +665,13 @@ public class NfcService extends Application implements DeviceHostListener {
techLists = techListsParcel.getTechLists();
}
mNfcDispatcher.enableForegroundDispatch(intent, filters, techLists);
}
@Override
public void disableForegroundDispatch(ComponentName activity) {
mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR);
mNfcDispatcher.disableForegroundDispatch();
}
@Override
public void enableForegroundNdefPush(ComponentName activity, NdefMessage msg) {
mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR);
if (activity == null || msg == null) {
throw new IllegalArgumentException();
}
mP2pLinkManager.setNdefToSend(msg, null);
}
@Override
public void enableForegroundNdefPushWithCallback(ComponentName activity,
INdefPushCallback callback) {
mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR);
if (activity == null || callback == null) {
throw new IllegalArgumentException();
}
mP2pLinkManager.setNdefToSend(null, callback);
mNfcDispatcher.setForegroundDispatch(intent, filters, techLists);
}
@Override
public void disableForegroundNdefPush(ComponentName activity) {
public void setForegroundNdefPush(NdefMessage msg, INdefPushCallback callback) {
mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR);
mP2pLinkManager.setNdefToSend(null, null);
mP2pLinkManager.setNdefToSend(msg, callback);
}
@Override
......@@ -1724,7 +1698,7 @@ public class NfcService extends Application implements DeviceHostListener {
void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
synchronized (this) {
pw.println("mState=" + stateToString(mState));
pw.println("mIsZeroClickRequested=" + mIsZeroClickRequested);
pw.println("mIsZeroClickRequested=" + mIsNdefPushEnabled);
pw.println("mIsScreenUnlocked=" + mIsScreenUnlocked);
pw.println("mIsAirplaneSensitive=" + mIsAirplaneSensitive);
pw.println("mIsAirplaneToggleable=" + mIsAirplaneToggleable);
......
......@@ -230,7 +230,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
if (callback != null) {
try {
messageToSend = callback.onConnect();
messageToSend = callback.createMessage();
} catch (RemoteException e) {
// Ignore
}
......@@ -429,7 +429,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba
mEventListener.onP2pSendComplete();
if (mCallbackNdef != null) {
try {
mCallbackNdef.onMessagePushed();
mCallbackNdef.onNdefPushComplete();
} catch (RemoteException e) { }
}
mSendTask = null;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment