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

Commit 9bb27519 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Cleanup references when turning BT off.

Bug: 5572649
Change-Id: I62f9e0620832b69995d5c6e1c24634c9a3895a4b
parent 6f9a6165
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -129,6 +129,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
        }
        }
    }
    }


    /*package*/ void close() {
        mServiceListener = null;
    }

    /**
    /**
     * Initiate connection to a profile of the remote bluetooth device.
     * Initiate connection to a profile of the remote bluetooth device.
     *
     *
+22 −4
Original line number Original line Diff line number Diff line
@@ -1180,11 +1180,29 @@ public final class BluetoothAdapter {
     * @param proxy Profile proxy object
     * @param proxy Profile proxy object
     */
     */
    public void closeProfileProxy(int profile, BluetoothProfile proxy) {
    public void closeProfileProxy(int profile, BluetoothProfile proxy) {
        if (profile == BluetoothProfile.HEADSET) {
        if (proxy == null) return;

        switch (profile) {
            case BluetoothProfile.HEADSET:
                BluetoothHeadset headset = (BluetoothHeadset)proxy;
                BluetoothHeadset headset = (BluetoothHeadset)proxy;
            if (headset != null) {
                headset.close();
                headset.close();
            }
                break;
            case BluetoothProfile.A2DP:
                BluetoothA2dp a2dp = (BluetoothA2dp)proxy;
                a2dp.close();
                break;
            case BluetoothProfile.INPUT_DEVICE:
                BluetoothInputDevice iDev = (BluetoothInputDevice)proxy;
                iDev.close();
                break;
            case BluetoothProfile.PAN:
                BluetoothPan pan = (BluetoothPan)proxy;
                pan.close();
                break;
            case BluetoothProfile.HEALTH:
                BluetoothHealth health = (BluetoothHealth)proxy;
                health.close();
                break;
        }
        }
    }
    }


+25 −3
Original line number Original line Diff line number Diff line
@@ -109,6 +109,8 @@ public final class BluetoothDeviceProfileState extends StateMachine {
    private BluetoothA2dpService mA2dpService;
    private BluetoothA2dpService mA2dpService;
    private BluetoothHeadset  mHeadsetService;
    private BluetoothHeadset  mHeadsetService;
    private BluetoothPbap     mPbapService;
    private BluetoothPbap     mPbapService;
    private PbapServiceListener mPbap;
    private BluetoothAdapter mAdapter;
    private boolean mPbapServiceConnected;
    private boolean mPbapServiceConnected;
    private boolean mAutoConnectionPending;
    private boolean mAutoConnectionPending;
    private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN;
    private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN;
@@ -249,11 +251,11 @@ public final class BluetoothDeviceProfileState extends StateMachine {


        mContext.registerReceiver(mBroadcastReceiver, filter);
        mContext.registerReceiver(mBroadcastReceiver, filter);


        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener,
        mAdapter.getProfileProxy(mContext, mBluetoothProfileServiceListener,
                                BluetoothProfile.HEADSET);
                                BluetoothProfile.HEADSET);
        // TODO(): Convert PBAP to the new Profile APIs.
        // TODO(): Convert PBAP to the new Profile APIs.
        PbapServiceListener p = new PbapServiceListener();
        mPbap = new PbapServiceListener();


        mIncomingConnections = mService.getIncomingState(address);
        mIncomingConnections = mService.getIncomingState(address);
        mIncomingRejectTimer = readTimerValue();
        mIncomingRejectTimer = readTimerValue();
@@ -414,6 +416,26 @@ public final class BluetoothDeviceProfileState extends StateMachine {
                case TRANSITION_TO_STABLE:
                case TRANSITION_TO_STABLE:
                    // ignore.
                    // ignore.
                    break;
                    break;
                case SM_QUIT_CMD:
                    mContext.unregisterReceiver(mBroadcastReceiver);
                    mBroadcastReceiver = null;
                    mAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mHeadsetService);
                    mBluetoothProfileServiceListener = null;
                    mOutgoingHandsfree = null;
                    mPbap = null;
                    mPbapService.close();
                    mPbapService = null;
                    mIncomingHid = null;
                    mOutgoingHid = null;
                    mIncomingHandsfree = null;
                    mOutgoingHandsfree = null;
                    mIncomingA2dp = null;
                    mOutgoingA2dp = null;
                    mBondedDevice = null;
                    // There is a problem in the State Machine code
                    // where things are not cleaned up properly, when quit message
                    // is handled so return NOT_HANDLED as a workaround.
                    return NOT_HANDLED;
                default:
                default:
                    return NOT_HANDLED;
                    return NOT_HANDLED;
            }
            }
+1 −0
Original line number Original line Diff line number Diff line
@@ -245,6 +245,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
            mContext.unbindService(mConnection);
            mContext.unbindService(mConnection);
            mConnection = null;
            mConnection = null;
        }
        }
        mServiceListener = null;
    }
    }


    /**
    /**
+4 −0
Original line number Original line Diff line number Diff line
@@ -452,6 +452,10 @@ public final class BluetoothHealth implements BluetoothProfile {
        }
        }
    }
    }


    /*package*/ void close() {
        mServiceListener = null;
    }

    private boolean isEnabled() {
    private boolean isEnabled() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();


Loading