Merge "Snap for 8580505 from 16fe3488b20e3b79a45a17e2e81627ce818e9f6e to main-cg-testing-release" into main-cg-testing-release
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index 573c5ca..3b13de1 100644
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -3108,10 +3108,10 @@
                     unregisterObject(tagEndpoint.getHandle());
                     if (mPollDelay > NO_POLL_DELAY) {
                         tagEndpoint.stopPresenceChecking();
-                        mDeviceHost.startStopPolling(false);
                         synchronized (NfcService.this) {
                             if (!mPollingDelayed) {
                                 mPollingDelayed = true;
+                                mDeviceHost.startStopPolling(false);
                                 if (DBG) Log.d(TAG, "Polling delayed");
                                 mHandler.sendMessageDelayed(
                                         mHandler.obtainMessage(MSG_DELAY_POLLING), mPollDelay);
@@ -3288,6 +3288,10 @@
                     action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
                 updatePackageCache();
             } else if (action.equals(Intent.ACTION_SHUTDOWN)) {
+                if (DBG) Log.d(TAG, "Shutdown received with UserId: " + getSendingUserId());
+                if (getSendingUserId() != UserHandle.USER_ALL) {
+                    return;
+                }
                 if (DBG) Log.d(TAG, "Device is shutting down.");
                 if (mIsAlwaysOnSupported && mAlwaysOnState == NfcAdapter.STATE_ON) {
                     new EnableDisableTask().execute(TASK_DISABLE_ALWAYS_ON);
diff --git a/src/com/android/nfc/handover/BluetoothPeripheralHandover.java b/src/com/android/nfc/handover/BluetoothPeripheralHandover.java
index 86176ae..b08c9df 100644
--- a/src/com/android/nfc/handover/BluetoothPeripheralHandover.java
+++ b/src/com/android/nfc/handover/BluetoothPeripheralHandover.java
@@ -271,8 +271,7 @@
                         if (mInput.getConnectionState(mDevice)
                                 != BluetoothProfile.STATE_DISCONNECTED) {
                             mHidResult = RESULT_PENDING;
-                            mInput.setConnectionPolicy(mDevice,
-                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
+                            mDevice.disconnect();
                             toast(getToastString(R.string.disconnecting_peripheral));
                             break;
                         } else {
@@ -282,20 +281,17 @@
                         if (mHeadset.getConnectionState(mDevice)
                                 != BluetoothProfile.STATE_DISCONNECTED) {
                             mHfpResult = RESULT_PENDING;
-                            mHeadset.setConnectionPolicy(mDevice,
-                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                         } else {
                             mHfpResult = RESULT_DISCONNECTED;
                         }
                         if (mA2dp.getConnectionState(mDevice)
                                 != BluetoothProfile.STATE_DISCONNECTED) {
                             mA2dpResult = RESULT_PENDING;
-                            mA2dp.setConnectionPolicy(mDevice,
-                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                         } else {
                             mA2dpResult = RESULT_DISCONNECTED;
                         }
                         if (mA2dpResult == RESULT_PENDING || mHfpResult == RESULT_PENDING) {
+                            mDevice.disconnect();
                             toast(getToastString(R.string.disconnecting_peripheral));
                             break;
                         }