Don't allow receiving files in provision mode.

Bug: 24152924
Change-Id: I66e3a1d4c2d8606c1cb986c0c67edaf80303e683
diff --git a/src/com/android/nfc/NfcDispatcher.java b/src/com/android/nfc/NfcDispatcher.java
index 53ba0f3..5177b85 100644
--- a/src/com/android/nfc/NfcDispatcher.java
+++ b/src/com/android/nfc/NfcDispatcher.java
@@ -228,6 +228,7 @@
         PendingIntent overrideIntent;
         IntentFilter[] overrideFilters;
         String[][] overrideTechLists;
+        String[] provisioningMimes;
         boolean provisioningOnly;
 
         synchronized (this) {
@@ -235,6 +236,7 @@
             overrideIntent = mOverrideIntent;
             overrideTechLists = mOverrideTechLists;
             provisioningOnly = mProvisioningOnly;
+            provisioningMimes = mProvisioningMimes;
         }
 
         boolean screenUnlocked = false;
@@ -257,6 +259,20 @@
             }
         }
 
+        if (provisioningOnly) {
+            if (message == null) {
+                // We only allow NDEF-message dispatch in provisioning mode
+                return DISPATCH_FAIL;
+            }
+            // Restrict to mime-types in whitelist.
+            String ndefMimeType = message.getRecords()[0].toMimeType();
+            if (provisioningMimes == null ||
+                    !(Arrays.asList(provisioningMimes).contains(ndefMimeType))) {
+                Log.e(TAG, "Dropping NFC intent in provisioning mode.");
+                return DISPATCH_FAIL;
+            }
+        }
+
         if (DBG) Log.d(TAG, "dispatch tag: " + tag.toString() + " message: " + message);
 
         DispatchInfo dispatch = new DispatchInfo(mContext, tag, message);
@@ -278,7 +294,7 @@
             return screenUnlocked ? DISPATCH_UNLOCK : DISPATCH_SUCCESS;
         }
 
-        if (tryNdef(dispatch, message, provisioningOnly)) {
+        if (tryNdef(dispatch, message)) {
             return screenUnlocked ? DISPATCH_UNLOCK : DISPATCH_SUCCESS;
         }
 
@@ -287,11 +303,6 @@
             return DISPATCH_UNLOCK;
         }
 
-        if (provisioningOnly) {
-            // We only allow NDEF-based mimeType matching
-            return DISPATCH_FAIL;
-        }
-
         // Only allow NDEF-based mimeType matching for unlock tags
         if (tryTech(dispatch, tag)) {
             return DISPATCH_SUCCESS;
@@ -450,7 +461,7 @@
         return false;
     }
 
-    boolean tryNdef(DispatchInfo dispatch, NdefMessage message, boolean provisioningOnly) {
+    boolean tryNdef(DispatchInfo dispatch, NdefMessage message) {
         if (message == null) {
             return false;
         }
@@ -459,14 +470,6 @@
         // Bail out if the intent does not contain filterable NDEF data
         if (intent == null) return false;
 
-        if (provisioningOnly) {
-            if (mProvisioningMimes == null ||
-                    !(Arrays.asList(mProvisioningMimes).contains(intent.getType()))) {
-                Log.e(TAG, "Dropping NFC intent in provisioning mode.");
-                return false;
-            }
-        }
-
         // Try to start AAR activity with matching filter
         List<String> aarPackages = extractAarPackages(message);
         for (String pkg : aarPackages) {