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

Commit 4cc747c4 authored by Etienne Ruffieux's avatar Etienne Ruffieux
Browse files

BluetoothInCallService: clear when BT turns off

BluetoothInCallService Object is not destroyed when disable component by Bluetooth Off
Cherry-picked from aosp/1886855

Bug: 199429807
Tag: #feature
Sponsor: zachoverflow@
Test: manual
Change-Id: Ia4e6887cf7766b453dadeede6fd7594b9d926332
parent f7dcd357
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -16,8 +16,12 @@

package com.android.bluetooth.hfp;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;

import java.util.List;

@@ -36,6 +40,14 @@ public class BluetoothHeadsetProxy {
        mBluetoothHeadset = headset;
    }

    public void closeBluetoothHeadsetProxy(Context context) {
        final BluetoothManager btManager =
                context.getSystemService(BluetoothManager.class);
        if (btManager != null) {
            btManager.getAdapter().closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
        }
    }

    public void clccResponse(int index, int direction, int status, int mode, boolean mpty,
            String number, int type) {

+16 −1
Original line number Diff line number Diff line
@@ -170,6 +170,8 @@ public class BluetoothInCallService extends InCallService {
                Log.d(TAG, "Bluetooth Adapter state: " + state);
                if (state == BluetoothAdapter.STATE_ON) {
                    queryPhoneState();
                } else if (state == BluetoothAdapter.STATE_TURNING_OFF) {
                    clear();
                }
            }
        }
@@ -620,6 +622,12 @@ public class BluetoothInCallService extends InCallService {
    @Override
    public void onDestroy() {
        Log.d(TAG, "onDestroy");
        clear();
        super.onDestroy();
    }

    private void clear() {
        Log.d(TAG, "clear");
        if (mBluetoothOnModeChangedListener != null) {
            mAudioManager.removeOnModeChangedListener(mBluetoothOnModeChangedListener);
            mBluetoothOnModeChangedListener = null;
@@ -628,8 +636,15 @@ public class BluetoothInCallService extends InCallService {
            unregisterReceiver(mBluetoothAdapterReceiver);
            mBluetoothAdapterReceiver = null;
        }
        if (mBluetoothHeadset != null) {
            mBluetoothHeadset.closeBluetoothHeadsetProxy(this);
            mBluetoothHeadset = null;
        }
        mProfileListener = null;
        sInstance = null;
        super.onDestroy();
        mCallbacks.clear();
        mBluetoothCallHashMap.clear();
        mClccIndexMap.clear();
    }

    private void sendListOfCalls(boolean shouldLog) {