Set a configurable flag for tag dispatch failed toast

It's a normal case when a device detects a tag but do nothing,
because there's no apps registered to handle it.
Don't show a toast by default, set to true if you need it.

Bug: 148996958
Test: read a tag without toast
Merged-In: I2d4e9193feadb9d9aafe6a85acf6fd26cc54d235
Change-Id: I2d4e9193feadb9d9aafe6a85acf6fd26cc54d235
diff --git a/res/values/config.xml b/res/values/config.xml
index f5585dd..c5354c2 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -3,6 +3,7 @@
     <string name="bluetooth_package" translatable="false">com.android.bluetooth</string>
     <bool name="enable_nfc_url_open_dialog">false</bool>
     <bool name="enable_auto_play">true</bool>
+    <bool name="enable_notify_dispatch_failed">false</bool>
 
     <!-- List of SKUs where Secure NFC functionality is supported -->
     <string-array name="config_skuSupportsSecureNfc" translatable="false" />
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index 6699a8b..48c3594 100644
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -2562,7 +2562,8 @@
                 int dispatchResult = mNfcDispatcher.dispatchTag(tag);
                 if (dispatchResult == NfcDispatcher.DISPATCH_FAIL && !mInProvisionMode) {
                     unregisterObject(tagEndpoint.getHandle());
-                    if (mScreenState == ScreenStateHelper.SCREEN_STATE_ON_UNLOCKED) {
+                    if (mScreenState == ScreenStateHelper.SCREEN_STATE_ON_UNLOCKED &&
+                        mContext.getResources().getBoolean(R.bool.enable_notify_dispatch_failed)) {
                         if (mToast != null) {
                             if (mToast.getView().isShown()) mToast.cancel();
                         }