Merge changes from topic 'nfc-data-type-changes'

* changes:
  nfc: Change the data type in log messages to match the new types.
  Changes TRUE/FALSE to true/false
  Changes data types to standard type
diff --git a/nci/jni/CondVar.cpp b/nci/jni/CondVar.cpp
index 02a81ab..29372c3 100644
--- a/nci/jni/CondVar.cpp
+++ b/nci/jni/CondVar.cpp
@@ -24,7 +24,7 @@
 #include <errno.h>
 #include <string.h>
 
-#include <android/log.h>
+#include <log/log.h>
 
 /*******************************************************************************
 **
diff --git a/nci/jni/DataQueue.cpp b/nci/jni/DataQueue.cpp
index 07ccac1..1b7193e 100644
--- a/nci/jni/DataQueue.cpp
+++ b/nci/jni/DataQueue.cpp
@@ -23,7 +23,7 @@
 #include <malloc.h>
 #include <string.h>
 
-#include <android/log.h>
+#include <log/log.h>
 
 /*******************************************************************************
 **
diff --git a/nci/jni/Mutex.cpp b/nci/jni/Mutex.cpp
index 003887b..22c1f00 100644
--- a/nci/jni/Mutex.cpp
+++ b/nci/jni/Mutex.cpp
@@ -24,7 +24,7 @@
 #include <errno.h>
 #include <string.h>
 
-#include <android/log.h>
+#include <log/log.h>
 
 /*******************************************************************************
 **
diff --git a/nci/jni/NfcJniUtil.cpp b/nci/jni/NfcJniUtil.cpp
index 619261d..a5eacef 100755
--- a/nci/jni/NfcJniUtil.cpp
+++ b/nci/jni/NfcJniUtil.cpp
@@ -18,7 +18,7 @@
 
 #include <errno.h>
 
-#include <android/log.h>
+#include <log/log.h>
 
 #include <JNIHelp.h>
 #include <ScopedLocalRef.h>
diff --git a/nci/jni/RoutingManager.cpp b/nci/jni/RoutingManager.cpp
index 6bdd97b..3839ec3 100755
--- a/nci/jni/RoutingManager.cpp
+++ b/nci/jni/RoutingManager.cpp
@@ -18,7 +18,8 @@
  *  Manage the listen-mode routing table.
  */
 
-#include <android/log.h>
+#include <log/log.h>
+
 #include <ScopedLocalRef.h>
 #include <JNIHelp.h>
 #include "config.h"
diff --git a/nci/jni/extns/pn54x/src/log/phNxpLog.c b/nci/jni/extns/pn54x/src/log/phNxpLog.c
index 4b568e2..15b1d20 100755
--- a/nci/jni/extns/pn54x/src/log/phNxpLog.c
+++ b/nci/jni/extns/pn54x/src/log/phNxpLog.c
@@ -22,6 +22,7 @@
 #    include "phNxpConfig.h"
 #endif
 #include <cutils/properties.h>
+#include <log/log.h>
 
 const char * NXPLOG_ITEM_EXTNS   = "NxpExtns";
 const char * NXPLOG_ITEM_NCIHAL  = "NxpHal";
diff --git a/nci/jni/extns/pn54x/src/log/phNxpLog.h b/nci/jni/extns/pn54x/src/log/phNxpLog.h
index 6ed0226..32cbfc1 100755
--- a/nci/jni/extns/pn54x/src/log/phNxpLog.h
+++ b/nci/jni/extns/pn54x/src/log/phNxpLog.h
@@ -17,7 +17,7 @@
 #if !defined (NXPLOG__H_INCLUDED)
 #define NXPLOG__H_INCLUDED
 
-#include <android/log.h>
+#include <log/log.h>
 
 typedef struct nci_log_level
 {
diff --git a/nci/jni/extns/pn54x/src/mifare/phNxpExtns_MifareStd.c b/nci/jni/extns/pn54x/src/mifare/phNxpExtns_MifareStd.c
index 30a8865..162196a 100755
--- a/nci/jni/extns/pn54x/src/mifare/phNxpExtns_MifareStd.c
+++ b/nci/jni/extns/pn54x/src/mifare/phNxpExtns_MifareStd.c
@@ -15,6 +15,8 @@
  */
 #define LOG_TAG "pn54x"
 
+#include <log/log.h>
+
 #include <nfc_api.h>
 #include <rw_api.h>
 #include <phNfcCompId.h>
diff --git a/nci/jni/extns/pn54x/src/phNxpExtns.c b/nci/jni/extns/pn54x/src/phNxpExtns.c
index c2ea9b8..1c2afdc 100755
--- a/nci/jni/extns/pn54x/src/phNxpExtns.c
+++ b/nci/jni/extns/pn54x/src/phNxpExtns.c
@@ -22,6 +22,8 @@
 #include <sys/ioctl.h>
 #include <sys/time.h>
 
+#include <log/log.h>
+
 #include <phNxpExtns_MifareStd.h>
 #include <phNxpLog.h>
 #include <phNxpConfig.h>
diff --git a/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java b/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java
index 6e5ffca..720df29 100755
--- a/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java
+++ b/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java
@@ -793,7 +793,7 @@
             int supportedNdefLength = ndefinfo[0];
             int cardState = ndefinfo[1];
             byte[] buff = readNdef();
-            if (buff != null) {
+            if (buff != null && buff.length > 0) {
                 try {
                     ndefMsg = new NdefMessage(buff);
                     addNdefTechnology(ndefMsg,
@@ -806,12 +806,18 @@
                    // Create an intent anyway, without NDEF messages
                    generateEmptyNdef = true;
                 }
-            } else {
+            } else if(buff != null){
+                // Empty buffer, unformatted tags fall into this case
                 generateEmptyNdef = true;
             }
 
             if (generateEmptyNdef) {
                 ndefMsg = null;
+                addNdefTechnology(null,
+                      getConnectedHandle(),
+                      getConnectedLibNfcType(),
+                      getConnectedTechnology(),
+                      supportedNdefLength, cardState);
                 foundFormattable = false;
                 reconnect();
             }
diff --git a/res/values/live_cases.xml b/res/values/live_cases.xml
new file mode 100644
index 0000000..fc22b21
--- /dev/null
+++ b/res/values/live_cases.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- NFC resources that may need to be customized
+     for different hardware or product builds. -->
+<resources>
+    <!-- Whether the device can receive NFC data in setup wizard -->
+    <bool name="enable_live_cases">true</bool>
+
+    <!-- The accepted mime-types when NFC is enabled at locked screen.
+         Mime-types must be lower case, wildcards are *not* accepted. -->
+    <string-array name="live_case_mime_types">
+        <item>application/vnd.google.android.apps.workshop</item>
+        <item>application/vnd.google.android.apps.live_case</item>
+    </string-array>
+
+    <!-- The accepted tag technology types which will be detected for live case
+         NFC at lock screen. Mime-types must be lower case, wildcards are *not*
+         accepted. -->
+    <string-array name="live_case_tag_types">
+        <item>TypeA</item>
+    </string-array>
+</resources>
diff --git a/src/com/android/nfc/BeamShareActivity.java b/src/com/android/nfc/BeamShareActivity.java
index 5b8acac..dca4cc7 100644
--- a/src/com/android/nfc/BeamShareActivity.java
+++ b/src/com/android/nfc/BeamShareActivity.java
@@ -142,7 +142,8 @@
     }
 
     public void parseShareIntentAndFinish(Intent intent) {
-        if (intent == null || (!intent.getAction().equalsIgnoreCase(Intent.ACTION_SEND) &&
+        if (intent == null || intent.getAction() == null ||
+                (!intent.getAction().equalsIgnoreCase(Intent.ACTION_SEND) &&
                 !intent.getAction().equalsIgnoreCase(Intent.ACTION_SEND_MULTIPLE))) return;
 
         // First, see if the intent contains clip-data, and if so get data from there
diff --git a/src/com/android/nfc/NfcDispatcher.java b/src/com/android/nfc/NfcDispatcher.java
index ff86d6a..9f70b2e 100644
--- a/src/com/android/nfc/NfcDispatcher.java
+++ b/src/com/android/nfc/NfcDispatcher.java
@@ -75,6 +75,7 @@
     private final ContentResolver mContentResolver;
     private final HandoverDataParser mHandoverDataParser;
     private final String[] mProvisioningMimes;
+    private final String[] mLiveCaseMimes;
     private final ScreenStateHelper mScreenStateHelper;
     private final NfcUnlockManager mNfcUnlockManager;
     private final boolean mDeviceSupportsBluetooth;
@@ -112,6 +113,16 @@
             }
         }
         mProvisioningMimes = provisionMimes;
+
+        String[] liveCaseMimes = null;
+        try {
+            // Get accepted mime-types
+            liveCaseMimes = context.getResources().
+                    getStringArray(R.array.live_case_mime_types);
+        } catch (NotFoundException e) {
+           liveCaseMimes = null;
+        }
+        mLiveCaseMimes = liveCaseMimes;
     }
 
     public synchronized void setForegroundDispatch(PendingIntent intent,
@@ -231,6 +242,8 @@
         IntentFilter[] overrideFilters;
         String[][] overrideTechLists;
         String[] provisioningMimes;
+        String[] liveCaseMimes;
+        NdefMessage message = null;
         boolean provisioningOnly;
 
         synchronized (this) {
@@ -239,19 +252,31 @@
             overrideTechLists = mOverrideTechLists;
             provisioningOnly = mProvisioningOnly;
             provisioningMimes = mProvisioningMimes;
+            liveCaseMimes = mLiveCaseMimes;
         }
 
         boolean screenUnlocked = false;
+        boolean liveCaseDetected = false;
+        Ndef ndef = Ndef.get(tag);
         if (!provisioningOnly &&
                 mScreenStateHelper.checkScreenState() == ScreenStateHelper.SCREEN_STATE_ON_LOCKED) {
             screenUnlocked = handleNfcUnlock(tag);
-            if (!screenUnlocked) {
-                return DISPATCH_FAIL;
+
+            if (ndef != null) {
+                message = ndef.getCachedNdefMessage();
+                if (message != null) {
+                    String ndefMimeType = message.getRecords()[0].toMimeType();
+                    if (liveCaseMimes != null &&
+                            Arrays.asList(liveCaseMimes).contains(ndefMimeType)) {
+                        liveCaseDetected = true;
+                    }
+                }
             }
+
+            if (!screenUnlocked && !liveCaseDetected)
+                return DISPATCH_FAIL;
         }
 
-        NdefMessage message = null;
-        Ndef ndef = Ndef.get(tag);
         if (ndef != null) {
             message = ndef.getCachedNdefMessage();
         } else {
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index 704d3d8..37645b0 100755
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -255,6 +255,9 @@
 
     private static NfcService sService;
 
+    boolean mIsLiveCaseEnabled; // whether live cases are enabled
+    int mLiveCaseTechnology; // Technology mask of accepted NFC tags
+
     public static NfcService getInstance() {
         return sService;
     }
@@ -355,6 +358,31 @@
         } catch (NotFoundException e) {
         }
 
+        try {
+            mIsLiveCaseEnabled = mContext.getResources().getBoolean(R.bool.enable_live_cases);
+        } catch (NotFoundException e) {
+            mIsLiveCaseEnabled = false;
+        }
+
+        mLiveCaseTechnology = 0;
+        String[] liveCaseTechList;
+        try {
+            liveCaseTechList = mContext.getResources().getStringArray(R.array.live_case_tag_types);
+            for (int i=0; i < liveCaseTechList.length; i++) {
+                if (liveCaseTechList[i].equals("TypeA")) {
+                    mLiveCaseTechnology |= NFC_POLL_A;
+                } else if (liveCaseTechList[i].equals("TypeB")) {
+                    mLiveCaseTechnology |= NFC_POLL_B;
+                } else if (liveCaseTechList[i].equals("TypeF")) {
+                    mLiveCaseTechnology |= NFC_POLL_F;
+                } else if (liveCaseTechList[i].equals("TypeV")) {
+                    mLiveCaseTechnology |= NFC_POLL_ISO15693;
+                }
+            }
+        } catch (NotFoundException e) {
+            mLiveCaseTechnology = 0;
+        }
+
         if (isNfcProvisioningEnabled) {
             mInProvisionMode = Settings.Secure.getInt(mContentResolver,
                     Settings.Global.DEVICE_PROVISIONED, 0) == 0;
@@ -1553,9 +1581,14 @@
             // enable P2P for MFM/EDU/Corp provisioning
             paramsBuilder.setEnableP2p(true);
         } else if (screenState == ScreenStateHelper.SCREEN_STATE_ON_LOCKED &&
-                mNfcUnlockManager.isLockscreenPollingEnabled()) {
-            // For lock-screen tags, no low-power polling
-            paramsBuilder.setTechMask(mNfcUnlockManager.getLockscreenPollMask());
+                (mIsLiveCaseEnabled || mNfcUnlockManager.isLockscreenPollingEnabled())) {
+            int techMask = 0;
+            // enable polling for Live Case technologies
+            if (mIsLiveCaseEnabled)
+                techMask |= mLiveCaseTechnology;
+            if (mNfcUnlockManager.isLockscreenPollingEnabled())
+                techMask |= mNfcUnlockManager.getLockscreenPollMask();
+            paramsBuilder.setTechMask(techMask);
             paramsBuilder.setEnableLowPowerDiscovery(false);
             paramsBuilder.setEnableP2p(false);
         }
diff --git a/src/com/android/nfc/P2pLinkManager.java b/src/com/android/nfc/P2pLinkManager.java
index b083549..a9d57d3 100755
--- a/src/com/android/nfc/P2pLinkManager.java
+++ b/src/com/android/nfc/P2pLinkManager.java
@@ -763,7 +763,10 @@
                     response = snepResponse.getNdefMessage();
                 }
                 if (response == null) {
-                    return HANDOVER_UNSUPPORTED;
+                    if (snepClient != null)
+                        return HANDOVER_UNSUPPORTED;
+                    else
+                        return HANDOVER_FAILURE;
                 }
             } else {
                 return HANDOVER_UNSUPPORTED;
diff --git a/src/com/android/nfc/beam/BeamManager.java b/src/com/android/nfc/beam/BeamManager.java
index ba16aa5..87ea881 100644
--- a/src/com/android/nfc/beam/BeamManager.java
+++ b/src/com/android/nfc/beam/BeamManager.java
@@ -15,6 +15,7 @@
 */
 package com.android.nfc.beam;
 
+import com.android.nfc.NfcService;
 import com.android.nfc.handover.HandoverDataParser;
 
 import android.bluetooth.BluetoothDevice;
@@ -45,6 +46,8 @@
     private boolean mBeamInProgress;
     private final Handler mCallback;
 
+    private NfcService mNfcService;
+
     private static final class Singleton {
         public static final BeamManager INSTANCE = new BeamManager();
     }
@@ -53,6 +56,7 @@
         mLock = new Object();
         mBeamInProgress = false;
         mCallback = new Handler(Looper.getMainLooper(), this);
+        mNfcService = NfcService.getInstance();
     }
 
     public static BeamManager getInstance() {
@@ -118,6 +122,11 @@
             synchronized (mLock) {
                 mBeamInProgress = false;
             }
+
+            boolean success = msg.arg1 == 1;
+            if (success) {
+                mNfcService.playSound(NfcService.SOUND_END);
+            }
             return true;
         }
         return false;
diff --git a/src/com/android/nfc/beam/BeamReceiveService.java b/src/com/android/nfc/beam/BeamReceiveService.java
index 7deb014..9d24dd0 100644
--- a/src/com/android/nfc/beam/BeamReceiveService.java
+++ b/src/com/android/nfc/beam/BeamReceiveService.java
@@ -1,15 +1,11 @@
 package com.android.nfc.beam;
 
-import com.android.nfc.R;
-
 import android.app.Service;
 import android.bluetooth.BluetoothAdapter;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.media.AudioManager;
-import android.media.SoundPool;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
@@ -33,8 +29,6 @@
     private BeamStatusReceiver mBeamStatusReceiver;
     private boolean mBluetoothEnabledByNfc;
     private int mStartId;
-    private SoundPool mSoundPool;
-    private int mSuccessSound;
     private BeamTransferManager mTransferManager;
     private Messenger mCompleteCallback;
 
@@ -75,7 +69,7 @@
             if (DBG) Log.i(TAG, "Ready for incoming Beam transfer");
             return START_STICKY;
         } else {
-            invokeCompleteCallback();
+            invokeCompleteCallback(false);
             stopSelf(startId);
             return START_NOT_STICKY;
         }
@@ -86,9 +80,6 @@
     public void onCreate() {
         super.onCreate();
 
-        mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
-        mSuccessSound = mSoundPool.load(this, R.raw.end, 1);
-
         // register BT state receiver
         IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
         registerReceiver(mBluetoothStateReceiver, filter);
@@ -97,10 +88,6 @@
     @Override
     public void onDestroy() {
         super.onDestroy();
-        if (mSoundPool != null) {
-            mSoundPool.release();
-        }
-
         if (mBeamStatusReceiver != null) {
             unregisterReceiver(mBeamStatusReceiver);
         }
@@ -139,10 +126,12 @@
         return true;
     }
 
-    private void invokeCompleteCallback() {
+    private void invokeCompleteCallback(boolean success) {
         if (mCompleteCallback != null) {
             try {
-                mCompleteCallback.send(Message.obtain(null, BeamManager.MSG_BEAM_COMPLETE));
+                Message msg = Message.obtain(null, BeamManager.MSG_BEAM_COMPLETE);
+                msg.arg1 = success ? 1 : 0;
+                mCompleteCallback.send(msg);
             } catch (RemoteException e) {
                 Log.e(TAG, "failed to invoke Beam complete callback", e);
             }
@@ -152,9 +141,7 @@
     @Override
     public void onTransferComplete(BeamTransferManager transfer, boolean success) {
         // Play success sound
-        if (success) {
-            mSoundPool.play(mSuccessSound, 1.0f, 1.0f, 0, 0, 1.0f);
-        } else {
+        if (!success) {
             if (DBG) Log.d(TAG, "Transfer failed, final state: " +
                     Integer.toString(transfer.mState));
         }
@@ -164,7 +151,7 @@
             mBluetoothAdapter.disable();
         }
 
-        invokeCompleteCallback();
+        invokeCompleteCallback(success);
         stopSelf(mStartId);
     }
 
diff --git a/src/com/android/nfc/beam/BeamSendService.java b/src/com/android/nfc/beam/BeamSendService.java
index 59019d5..6c013ea 100644
--- a/src/com/android/nfc/beam/BeamSendService.java
+++ b/src/com/android/nfc/beam/BeamSendService.java
@@ -16,16 +16,12 @@
 
 package com.android.nfc.beam;
 
-import com.android.nfc.R;
-
 import android.app.Service;
 import android.bluetooth.BluetoothAdapter;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.media.AudioManager;
-import android.media.SoundPool;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
@@ -47,8 +43,6 @@
     private boolean mBluetoothEnabledByNfc;
     private Messenger mCompleteCallback;
     private int mStartId;
-    SoundPool mSoundPool;
-    int mSuccessSound;
 
     private final BluetoothAdapter mBluetoothAdapter;
     private final BroadcastReceiver mBluetoothStateReceiver = new BroadcastReceiver() {
@@ -69,9 +63,6 @@
     public void onCreate() {
         super.onCreate();
 
-        mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
-        mSuccessSound = mSoundPool.load(this, R.raw.end, 1);
-
         // register BT state receiver
         IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
         registerReceiver(mBluetoothStateReceiver, filter);
@@ -80,9 +71,6 @@
     @Override
     public void onDestroy() {
         super.onDestroy();
-        if (mSoundPool != null) {
-            mSoundPool.release();
-        }
 
         if (mBeamStatusReceiver != null) {
             unregisterReceiver(mBeamStatusReceiver);
@@ -108,7 +96,7 @@
             if (DBG) Log.i(TAG, "Starting outgoing Beam transfer");
             return START_STICKY;
         } else {
-            invokeCompleteCallback();
+            invokeCompleteCallback(false);
             stopSelf(startId);
             return START_NOT_STICKY;
         }
@@ -170,10 +158,12 @@
         }
     }
 
-    private void invokeCompleteCallback() {
+    private void invokeCompleteCallback(boolean success) {
         if (mCompleteCallback != null) {
             try {
-                mCompleteCallback.send(Message.obtain(null, BeamManager.MSG_BEAM_COMPLETE));
+                Message msg = Message.obtain(null, BeamManager.MSG_BEAM_COMPLETE);
+                msg.arg1 = success ? 1 : 0;
+                mCompleteCallback.send(msg);
             } catch (RemoteException e) {
                 Log.e(TAG, "failed to invoke Beam complete callback", e);
             }
@@ -183,9 +173,7 @@
     @Override
     public void onTransferComplete(BeamTransferManager transfer, boolean success) {
         // Play success sound
-        if (success) {
-            mSoundPool.play(mSuccessSound, 1.0f, 1.0f, 0, 0, 1.0f);
-        } else {
+        if (!success) {
             if (DBG) Log.d(TAG, "Transfer failed, final state: " +
                     Integer.toString(transfer.mState));
         }
@@ -195,7 +183,7 @@
             mBluetoothAdapter.disable();
         }
 
-        invokeCompleteCallback();
+        invokeCompleteCallback(success);
         stopSelf(mStartId);
     }
 
diff --git a/src/com/android/nfc/beam/SendUi.java b/src/com/android/nfc/beam/SendUi.java
index 254acfa..f681962 100644
--- a/src/com/android/nfc/beam/SendUi.java
+++ b/src/com/android/nfc/beam/SendUi.java
@@ -530,7 +530,9 @@
         mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
         mScreenshotBitmap = null;
         if (mToastString != null) {
-            Toast.makeText(mContext, mToastString, Toast.LENGTH_LONG).show();
+            Toast toast = Toast.makeText(mContext, mToastString, Toast.LENGTH_LONG);
+            toast.getWindowParams().privateFlags |= LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
+            toast.show();
         }
         mToastString = null;
     }
diff --git a/src/com/android/nfc/cardemulation/CardEmulationManager.java b/src/com/android/nfc/cardemulation/CardEmulationManager.java
index 750356b..ff4324e 100644
--- a/src/com/android/nfc/cardemulation/CardEmulationManager.java
+++ b/src/com/android/nfc/cardemulation/CardEmulationManager.java
@@ -207,49 +207,7 @@
         ComponentName defaultPaymentService =
                 getDefaultServiceForCategory(userId, CardEmulation.CATEGORY_PAYMENT, false);
         if (DBG) Log.d(TAG, "Current default: " + defaultPaymentService);
-        if (defaultPaymentService != null) {
-            // Validate the default is still installed and handling payment
-            ApduServiceInfo serviceInfo = mServiceCache.getService(userId, defaultPaymentService);
-            if (serviceInfo == null || !serviceInfo.hasCategory(CardEmulation.CATEGORY_PAYMENT)) {
-                if (serviceInfo == null) {
-                    Log.e(TAG, "Default payment service unexpectedly removed.");
-                } else if (!serviceInfo.hasCategory(CardEmulation.CATEGORY_PAYMENT)) {
-                    if (DBG) Log.d(TAG, "Default payment service had payment category removed");
-                }
-                int numPaymentServices = 0;
-                ComponentName lastFoundPaymentService = null;
-                for (ApduServiceInfo service : services) {
-                    if (service.hasCategory(CardEmulation.CATEGORY_PAYMENT))  {
-                        numPaymentServices++;
-                        lastFoundPaymentService = service.getComponent();
-                    }
-                }
-                if (DBG) Log.d(TAG, "Number of payment services is " +
-                        Integer.toString(numPaymentServices));
-                if (numPaymentServices == 0) {
-                    if (DBG) Log.d(TAG, "Default removed, no services left.");
-                    // No payment services left, unset default and don't ask the user
-                    setDefaultServiceForCategoryChecked(userId, null, CardEmulation.CATEGORY_PAYMENT);
-                } else if (numPaymentServices == 1) {
-                    // Only one left, automatically make it the default
-                    if (DBG) Log.d(TAG, "Default removed, making remaining service default.");
-                    setDefaultServiceForCategoryChecked(userId, lastFoundPaymentService,
-                            CardEmulation.CATEGORY_PAYMENT);
-                } else if (numPaymentServices > 1) {
-                    // More than one left, unset default and ask the user if he wants
-                    // to set a new one
-                    if (DBG) Log.d(TAG, "Default removed, asking user to pick.");
-                    setDefaultServiceForCategoryChecked(userId, null,
-                            CardEmulation.CATEGORY_PAYMENT);
-                    Intent intent = new Intent(mContext, DefaultRemovedActivity.class);
-                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
-                    mContext.startActivityAsUser(intent, UserHandle.CURRENT);
-                }
-            } else {
-                // Default still exists and handles the category, nothing do
-                if (DBG) Log.d(TAG, "Default payment service still ok.");
-            }
-        } else {
+        if (defaultPaymentService == null) {
             // A payment service may have been removed, leaving only one;
             // in that case, automatically set that app as default.
             int numPaymentServices = 0;