Null check new usages of mPhonePolicy

mPhonePolicy is nullable and usages without null checks can cause null
pointer exceptions and crashes on non-phone devices.

Tag: #stability
Bug: 302007575
Test: atest BluetoothInstrumentationTests
Change-Id: Ia9604a49e4d419a27e41b1553bd5b4a627396309
diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterService.java b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
index e6a1a4c..80ad944 100644
--- a/android/app/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
@@ -346,7 +346,9 @@
     private UserManager mUserManager;
     private CompanionDeviceManager mCompanionDeviceManager;
 
-    private PhonePolicy mPhonePolicy;
+    // Phone Policy is not used on all devices. Ensure you null check before using it
+    @Nullable private PhonePolicy mPhonePolicy;
+
     private ActiveDeviceManager mActiveDeviceManager;
     private DatabaseManager mDatabaseManager;
     private SilenceDeviceManager mSilenceDeviceManager;
@@ -6892,7 +6894,9 @@
 
     /** Update PhonePolicy when new {@link BluetoothDevice} creates an ACL connection. */
     public void updatePhonePolicyOnAclConnect(BluetoothDevice device) {
-        mPhonePolicy.handleAclConnected(device);
+        if (mPhonePolicy != null) {
+            mPhonePolicy.handleAclConnected(device);
+        }
     }
 
     /**
@@ -6915,14 +6919,18 @@
      */
     public void handleProfileConnectionStateChange(
             int profile, BluetoothDevice device, int fromState, int toState) {
-        mPhonePolicy.profileConnectionStateChanged(profile, device, fromState, toState);
+        if (mPhonePolicy != null) {
+            mPhonePolicy.profileConnectionStateChanged(profile, device, fromState, toState);
+        }
     }
 
     /** Handle Bluetooth app state when active device changes for a given {@code profile}. */
     public void handleActiveDeviceChange(int profile, BluetoothDevice device) {
         mActiveDeviceManager.profileActiveDeviceChanged(profile, device);
         mSilenceDeviceManager.profileActiveDeviceChanged(profile, device);
-        mPhonePolicy.profileActiveDeviceChanged(profile, device);
+        if (mPhonePolicy != null) {
+            mPhonePolicy.profileActiveDeviceChanged(profile, device);
+        }
     }
 
     static int convertScanModeToHal(int mode) {