Ignore silent mode when user is locked.

Tyipcally the BluetoothManagerService will maintain the
correct bluetooth adapter state.  Silent mode is only necessary to
monitor in the case of an already unlocked user.

Bug: 172840542
Test: adb shell cmd car_service silent-mode forced-silent; adb reboot
Change-Id: I0dd9063004709a2c95c3e16eae365442abc51c4e
diff --git a/service/src/com/android/car/BluetoothDeviceConnectionPolicy.java b/service/src/com/android/car/BluetoothDeviceConnectionPolicy.java
index b16ffaa..ce0d045 100644
--- a/service/src/com/android/car/BluetoothDeviceConnectionPolicy.java
+++ b/service/src/com/android/car/BluetoothDeviceConnectionPolicy.java
@@ -33,6 +33,7 @@
 import android.content.IntentFilter;
 import android.os.RemoteException;
 import android.os.UserHandle;
+import android.os.UserManager;
 import android.provider.Settings;
 import android.util.Log;
 import android.util.Slog;
@@ -58,11 +59,16 @@
     private final BluetoothAdapter mBluetoothAdapter;
     private final CarBluetoothService mCarBluetoothService;
     private final CarServicesHelper mCarHelper;
+    private final UserManager mUserManager;
 
     private final SilentModeController.SilentModeListener mSilentModeListener =
             new SilentModeController.SilentModeListener() {
                 @Override
                 public void onModeChange(boolean isSilent) {
+                    if (!mUserManager.isUserUnlocked(mUserId)) {
+                        logd("User " + mUserId + " is locked, ignoring silent mode " + isSilent);
+                        return;
+                    }
                     if (isSilent) {
                         // we'll turn off Bluetooth to disconnect devices and better the "off"
                         // illusion
@@ -271,6 +277,7 @@
         mBluetoothBroadcastReceiver = new BluetoothBroadcastReceiver();
         mBluetoothAdapter = Objects.requireNonNull(BluetoothAdapter.getDefaultAdapter());
         mCarHelper = new CarServicesHelper();
+        mUserManager = mContext.getSystemService(UserManager.class);
     }
 
     /**