Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c39eec6 authored by Sal Savage's avatar Sal Savage
Browse files

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
parent 2dcade2c
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -346,7 +346,9 @@ public class AdapterService extends Service {
    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,8 +6894,10 @@ public class AdapterService extends Service {

    /** Update PhonePolicy when new {@link BluetoothDevice} creates an ACL connection. */
    public void updatePhonePolicyOnAclConnect(BluetoothDevice device) {
        if (mPhonePolicy != null) {
            mPhonePolicy.handleAclConnected(device);
        }
    }

    /**
     * Notify GATT of a Bluetooth profile's connection state change for a given {@link
@@ -6915,15 +6919,19 @@ public class AdapterService extends Service {
     */
    public void handleProfileConnectionStateChange(
            int profile, BluetoothDevice device, int fromState, int 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);
        if (mPhonePolicy != null) {
            mPhonePolicy.profileActiveDeviceChanged(profile, device);
        }
    }

    static int convertScanModeToHal(int mode) {
        switch (mode) {