summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2012-04-04 11:10:45 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-04 11:10:45 -0700
commitf7e47ba32ee50480c5f4a9f49b817320f1df26b6 (patch)
tree4dc805b195d9889b2f5c2824eba2f4a8fe3c6f16
parentb77b5e0cc31765d0149759f22196cc35a2eda961 (diff)
parenteec585407f2cfc47814f572a1e2a0f7d56b41451 (diff)
downloadpackages_apps_nfc-f7e47ba32ee50480c5f4a9f49b817320f1df26b6.zip
packages_apps_nfc-f7e47ba32ee50480c5f4a9f49b817320f1df26b6.tar.gz
packages_apps_nfc-f7e47ba32ee50480c5f4a9f49b817320f1df26b6.tar.bz2
Merge "Allow applications to disable default Beam behavior."
-rwxr-xr-xsrc/com/android/nfc/P2pLinkManager.java56
1 files 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:
+ * <pre>{@code
+ * <application ...>
+ * <meta-data android:name="android.nfc.disable_beam_default"
+ * android:value="true" />
+ * </application>
+ * }</pre>
+ */
+ 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<RunningTaskInfo> 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<RunningTaskInfo> 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 });
}
/**