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

Commit a94735d5 authored by Nitin Shivpure's avatar Nitin Shivpure Committed by Steve Kondik
Browse files

Bluetooth: Disable bluetooth only if BT Sevice is connected

Bluetooth service is imidiately disconnected from the adapter
after SSR OR if any bluetooth services is crashed OR framework
is crashed. As Bluetooth  service is not connected OR Bluetooth
is not enabled, So BT disable should be ignored & bluetooth
persist setting should not be changed.

CRs-Fixed: 499116

Change-Id: I19de939346d014cdf918e11711f2d6066e55d054
parent c0f34c90
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    private HandlerThread mThread;
    private final BluetoothHandler mHandler;
    private int mErrorRecoveryRetryCounter;
    private boolean mIsBluetoothServiceConnected = false;

    private void registerForAirplaneMode(IntentFilter filter) {
        final ContentResolver resolver = mContext.getContentResolver();
@@ -427,6 +428,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            return false;
        }

        if (!mIsBluetoothServiceConnected || mState != BluetoothAdapter.STATE_ON)
        {
            Log.d(TAG, "Disable(): Service is not Connected Or Bluetooth is not enabled");
            return true;
        }

        if (DBG) {
            Log.d(TAG,"disable(): mBluetooth = " + mBluetooth +
                " mBinding = " + mBinding);
@@ -784,6 +791,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                {
                    if (DBG) Log.d(TAG,"MESSAGE_BLUETOOTH_SERVICE_CONNECTED: " + msg.arg1);

                    mIsBluetoothServiceConnected = true;

                    IBinder service = (IBinder) msg.obj;
                    synchronized(mConnection) {
                        if (msg.arg1 == SERVICE_IBLUETOOTHGATT) {
@@ -872,6 +881,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                case MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED:
                {
                    Log.e(TAG, "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED: " + msg.arg1);

                    mIsBluetoothServiceConnected = false;

                    synchronized(mConnection) {
                        if (msg.arg1 == SERVICE_IBLUETOOTH) {
                            // if service is unbinded already, do nothing and return
@@ -887,6 +899,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                    }

                    if (mEnable) {
                        if (!isBluetoothPersistedStateOn())
                            mEnable = false;
                        // Send a Bluetooth Restart message
                        Message restartMsg = mHandler.obtainMessage(