From eec585407f2cfc47814f572a1e2a0f7d56b41451 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Mon, 2 Apr 2012 09:15:02 -0700 Subject: Allow applications to disable default Beam behavior. By adding a meta-data entry to the application section of the applications manifest: Bug: 6257668 Change-Id: I73c27d8c642acd85f678fb42b4379f6bc21189b9 --- src/com/android/nfc/P2pLinkManager.java | 56 +++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/src/com/android/nfc/P2pLinkManager.java b/src/com/android/nfc/P2pLinkManager.java index 499a52b..fdc037d 100755 --- a/src/com/android/nfc/P2pLinkManager.java +++ b/src/com/android/nfc/P2pLinkManager.java @@ -35,6 +35,7 @@ import android.nfc.INdefPushCallback; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.os.AsyncTask; +import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.RemoteException; @@ -98,6 +99,17 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba static final String TAG = "NfcP2pLinkManager"; static final boolean DBG = true; + /** Include this constant as a meta-data entry in the manifest + * of an application to disable beaming the market/AAR link, like this: + *
{@code
+     *  
+     *      
+     *  
+     *  }
+ */ + static final String DISABLE_BEAM_DEFAULT = "android.nfc.disable_beam_default"; + /** Enables the LLCP EchoServer, which can be used to test the android * LLCP stack against nfcpy. */ @@ -266,23 +278,41 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba } } - // fall back to default NDEF for this activity - mMessageToSend = createDefaultNdef(); + // fall back to default NDEF for this activity, unless the + // application disabled this explicitly in their manifest. + List tasks = mActivityManager.getRunningTasks(1); + if (tasks.size() > 0) { + String pkg = tasks.get(0).baseActivity.getPackageName(); + if (beamDefaultDisabled(pkg)) { + Log.d(TAG, "Disabling default Beam behavior"); + mMessageToSend = null; + } else { + mMessageToSend = createDefaultNdef(pkg); + } + } else { + mMessageToSend = null; + } } } - NdefMessage createDefaultNdef() { - List tasks = mActivityManager.getRunningTasks(1); - if (tasks.size() > 0) { - String pkg = tasks.get(0).baseActivity.getPackageName(); - NdefRecord appUri = NdefRecord.createUri(Uri.parse( - "http://play.google.com/store/apps/details?id=" + pkg + "&feature=beam")); - NdefRecord appRecord = NdefRecord.createApplicationRecord(pkg); - return new NdefMessage(new NdefRecord[] { appUri, appRecord }); - } else { - Log.d(TAG, "no foreground activity"); + boolean beamDefaultDisabled(String pkgName) { + try { + ApplicationInfo ai = mPackageManager.getApplicationInfo(pkgName, + PackageManager.GET_META_DATA); + if (ai == null || ai.metaData == null) { + return false; + } + return ai.metaData.getBoolean(DISABLE_BEAM_DEFAULT); + } catch (NameNotFoundException e) { + return false; } - return null; + } + + NdefMessage createDefaultNdef(String pkgName) { + NdefRecord appUri = NdefRecord.createUri(Uri.parse( + "http://play.google.com/store/apps/details?id=" + pkgName + "&feature=beam")); + NdefRecord appRecord = NdefRecord.createApplicationRecord(pkgName); + return new NdefMessage(new NdefRecord[] { appUri, appRecord }); } /** -- cgit v1.1