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

Commit e46715ff authored by William Escande's avatar William Escande
Browse files

InCallService: Close profile on the same adapter

Test: atest BluetoothInstrumentationTests:BluetoothInCallServiceTest
Flag: Exempt refactor
Bug: 330247213
Change-Id: Ia42b26511769ed24f5d5cf2767f878417854f6ef
parent ed26173a
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -16,11 +16,10 @@

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;

@@ -39,11 +38,8 @@ 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 closeBluetoothHeadsetProxy(BluetoothAdapter adapter) {
        adapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
    }

    public void clccResponse(
+3 −9
Original line number Diff line number Diff line
@@ -17,11 +17,10 @@

package com.android.bluetooth.tbs;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothLeCall;
import android.bluetooth.BluetoothLeCallControl;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;

import java.util.List;
import java.util.UUID;
@@ -52,13 +51,8 @@ public class BluetoothLeCallControlProxy {
        mBluetoothLeCallControl = tbs;
    }

    public void closeBluetoothLeCallControlProxy(Context context) {
        final BluetoothManager btManager = context.getSystemService(BluetoothManager.class);
        if (btManager != null) {
            btManager
                    .getAdapter()
                    .closeProfileProxy(BluetoothProfile.LE_CALL_CONTROL, mBluetoothLeCallControl);
        }
    public void closeBluetoothLeCallControlProxy(BluetoothAdapter adapter) {
        adapter.closeProfileProxy(BluetoothProfile.LE_CALL_CONTROL, mBluetoothLeCallControl);
    }

    public boolean registerBearer(
+10 −6
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

package com.android.bluetooth.telephony;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothLeCall;
import android.bluetooth.BluetoothLeCallControl;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -143,6 +146,8 @@ public class BluetoothInCallService extends InCallService {

    private int mMaxNumberOfCalls = 0;

    private BluetoothAdapter mAdapter = null;

    /**
     * Listens to connections and disconnections of bluetooth headsets. We need to save the current
     * bluetooth headset so that we know where to send BluetoothCall updates.
@@ -735,10 +740,9 @@ public class BluetoothInCallService extends InCallService {
    public void onCreate() {
        Log.d(TAG, "onCreate");
        super.onCreate();
        BluetoothAdapter.getDefaultAdapter()
                .getProfileProxy(this, mProfileListener, BluetoothProfile.HEADSET);
        BluetoothAdapter.getDefaultAdapter()
                .getProfileProxy(this, mProfileListener, BluetoothProfile.LE_CALL_CONTROL);
        mAdapter = requireNonNull(getSystemService(BluetoothManager.class)).getAdapter();
        mAdapter.getProfileProxy(this, mProfileListener, BluetoothProfile.HEADSET);
        mAdapter.getProfileProxy(this, mProfileListener, BluetoothProfile.LE_CALL_CONTROL);
        mBluetoothAdapterReceiver = new BluetoothAdapterReceiver();
        IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
        intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
@@ -768,12 +772,12 @@ public class BluetoothInCallService extends InCallService {
            mBluetoothAdapterReceiver = null;
        }
        if (mBluetoothHeadset != null) {
            mBluetoothHeadset.closeBluetoothHeadsetProxy(this);
            mBluetoothHeadset.closeBluetoothHeadsetProxy(mAdapter);
            mBluetoothHeadset = null;
        }
        if (mBluetoothLeCallControl != null) {
            mBluetoothLeCallControl.unregisterBearer();
            mBluetoothLeCallControl.closeBluetoothLeCallControlProxy(this);
            mBluetoothLeCallControl.closeBluetoothLeCallControlProxy(mAdapter);
        }
        mProfileListener = null;
        sInstance = null;